package com.dsh.guns.modular.system.controller.code; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.dsh.course.feignClient.account.AppUserClient; import com.dsh.course.feignClient.account.CityManagerClient; import com.dsh.course.feignClient.account.model.CityManager; import com.dsh.course.feignClient.account.model.Coach; import com.dsh.course.feignClient.account.model.TAppUser; import com.dsh.course.feignClient.course.*; import com.dsh.course.feignClient.course.model.*; import com.dsh.course.feignClient.other.BannerClient; import com.dsh.course.feignClient.other.SiteClient; import com.dsh.course.feignClient.other.StoreClient; import com.dsh.course.feignClient.other.model.Banner; import com.dsh.course.util.UUIDUtil; import com.dsh.guns.config.UserExt; import com.dsh.guns.core.base.controller.BaseController; import com.dsh.guns.modular.system.model.*; import com.dsh.course.entity.CoursePackageOrderStudent; import com.dsh.guns.modular.system.model.TCoursePackagePayment; import com.dsh.guns.modular.system.model.dto.CoursePackage; import com.dsh.guns.modular.system.service.ICityService; import com.dsh.guns.modular.system.service.ICoursePackageService; import com.dsh.guns.modular.system.service.IStoreService; import com.dsh.guns.modular.system.util.ResultUtil; import net.sf.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; /** * 广告管理控制器 * */ @Controller @RequestMapping("/cpPayment") public class CoursePackagePaymentController extends BaseController { private String PREFIX = "/system/cpPayment/"; @Autowired private BannerClient bannerClient; @Autowired private IStoreService storeService; @Autowired private ICityService cityService; @Autowired private CoursePackageTypeClient coursePackageTypeClient; @Autowired private CoursePackagePaymentClient coursePackagePaymentClient; @Autowired private AppUserClient appUserClient; @Autowired private StoreClient storeClient; @Autowired private CoursePackageDiscountClient coursePackageDiscountClient; @Autowired private CoursePackagePaymentConfigClient coursePackagePaymentConfigClient; @Autowired private CoursePackageClient coursePackageClient; /** * 跳转到购课记录页面 */ @RequestMapping("") public String index(Model model) { List list = cityService.list(new LambdaQueryWrapper().eq(TCity::getParentId, 0)); List coursePackage = coursePackageTypeClient.queryAllCoursePackageType(); model.addAttribute("coursePackage",coursePackage); model.addAttribute("list",list); Integer roleType = UserExt.getUser().getObjectType(); model.addAttribute("roleType",roleType); return PREFIX + "cpPayment.html"; } /** * 跳转到广告添加页面 */ @RequestMapping("/add") public String operator(Model model) { List list = cityService.list(new LambdaQueryWrapper().eq(TCity::getParentId, 0)); model.addAttribute("list",list); Integer roleType = UserExt.getUser().getObjectType(); if (roleType==2){ Integer objectId = UserExt.getUser().getObjectId(); List operatorId = storeService.list(new QueryWrapper().eq("operatorId", objectId)); model.addAttribute("stores",operatorId); }else{ model.addAttribute("stores",new ArrayList<>()); } // 获取所有课包类型 List tCoursePackageTypes = coursePackageTypeClient.queryAllCoursePackageType(); model.addAttribute("roleType",roleType); if(UserExt.getUser().getObjectType()==3){ List list1 = storeService.list(new LambdaQueryWrapper().eq(TStore::getId, UserExt.getUser().getObjectId())); model.addAttribute("stores",list1); } model.addAttribute("coursePackageType",tCoursePackageTypes); return PREFIX + "cpPayment_add.html"; } /** * 添加购课记录 */ @ResponseBody @PostMapping(value = "/addCoursePackagePayment") public Object addCoach(@RequestBody TCoursePackagePayment tCoursePackagePayment) { Integer objectId = UserExt.getUser().getObjectId(); Integer objectType = UserExt.getUser().getObjectType(); String name = UserExt.getUser().getName(); tCoursePackagePayment.setPayUserId(objectId); // 获取课包id Integer coursePackageId = tCoursePackagePayment.getCoursePackageId(); List list = coursePackageDiscountClient.queryByCoursePackageId(coursePackageId); Date currentDate = new Date(); Calendar calendar = Calendar.getInstance(); calendar.setTime(currentDate); calendar.add(Calendar.DAY_OF_MONTH, 20); Date updatedDate = calendar.getTime(); tCoursePackagePayment.setOriginalPrice(tCoursePackagePayment.getCashPayment().doubleValue()); // 获取所选课时的课包价格配置 if (tCoursePackagePayment.getCoursePackageConfigId()!=null) { List coursePackagePaymentConfigs = coursePackagePaymentConfigClient.queryCoursePackagePaymentConfigList1 (tCoursePackagePayment.getCoursePackageConfigId()); if (coursePackagePaymentConfigs.size() != 0) { CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigs.get(0); tCoursePackagePayment.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); } }else { List coursePackagePaymentConfigs = coursePackagePaymentConfigClient.queryCoursePackagePaymentConfigList(coursePackageId); CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigs.get(0); tCoursePackagePayment.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); tCoursePackagePayment.setCode(code); return coursePackagePaymentClient.addCoursePackagePayment(tCoursePackagePayment); } /** * 获取列表 */ @RequestMapping(value = "/listAll") @ResponseBody public List listAll(CoursePackagePaymentQuery query) { Integer objectType = UserExt.getUser().getObjectType(); List ids =new ArrayList<>(); if(objectType==3){ // 找出当前门店的课包 ids = coursePackageClient.queryIdsByStore(UserExt.getUser().getObjectId()); query.setIds(ids); } if (objectType == 2){ Integer objectId = UserExt.getUser().getObjectId(); List operatorId = storeService.list(new QueryWrapper().eq("operatorId", objectId)) .stream().map(TStore::getId).collect(Collectors.toList()); query.setStoreIds(operatorId); } return coursePackagePaymentClient.listAll(query); } /** * 手动支付 */ @RequestMapping(value = "/pay") @ResponseBody public Object pay(@RequestBody CoursePackagePayDTO dto) { String name = UserExt.getUser().getName(); dto.setPayUserName(name); dto.setUserId(UserExt.getUser().getId()); coursePackagePaymentClient.changeState(dto); return ResultUtil.success(); } /** * 根据用户电话 获取用户 */ @RequestMapping(value = "/getUserByPhone/{phone}") @ResponseBody public TAppUser getUserByPhone(@PathVariable("phone") String phone) { return appUserClient.getAppUserByPhone(phone); } /** * 根据用户id 获取用户电话 */ @RequestMapping(value = "/queryStudentList") @ResponseBody public List queryStudentList(Integer appUserId) { return appUserClient.queryStudentList(appUserId); } /** * 根据市获取门店 */ @RequestMapping(value = "/getStore") @ResponseBody public List getStore(String city) { return storeClient.getStore(city); } /** * 根据课包id 获取课时规格 */ @RequestMapping(value = "/getCoursePackageConfig") @ResponseBody public List getCoursePackageConfig(Integer id) { if (id == null){ return null; } return coursePackagePaymentConfigClient.queryCoursePackagePaymentConfigList(id); } @RequestMapping(value = "/getCoursePackageType") @ResponseBody public Integer getCoursePackageType(Integer id) { TCoursePackage coursePackage = coursePackageClient.queryById(id); return coursePackage.getType(); } }