| | |
| | | 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; |
| | | |
| | |
| | | List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0)); |
| | | model.addAttribute("list",list); |
| | | Integer roleType = UserExt.getUser().getObjectType(); |
| | | if (roleType==2){ |
| | | Integer objectId = UserExt.getUser().getObjectId(); |
| | | List<TStore> operatorId = storeService.list(new QueryWrapper<TStore>().eq("operatorId", objectId)); |
| | | model.addAttribute("stores",operatorId); |
| | | }else{ |
| | | model.addAttribute("stores",new ArrayList<>()); |
| | | } |
| | | // 获取所有课包类型 |
| | | List<TCoursePackageType> tCoursePackageTypes = coursePackageTypeClient.queryAllCoursePackageType(); |
| | | model.addAttribute("roleType",roleType); |
| | | if(UserExt.getUser().getObjectType()==3){ |
| | | List<TStore> list1 = storeService.list(new LambdaQueryWrapper<TStore>().eq(TStore::getId, UserExt.getUser().getObjectId())); |
| | | model.addAttribute("stores",list1); |
| | | }else { |
| | | model.addAttribute("stores",new ArrayList<>()); |
| | | } |
| | | model.addAttribute("coursePackageType",tCoursePackageTypes); |
| | | return PREFIX + "cpPayment_add.html"; |
| | | } |
| | | /** |
| | | * 添加购课记录 |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping(value = "/addCoursePackagePayment/{id}") |
| | | public ResultUtil addCoach(@RequestBody TCoursePackagePayment tCoursePackagePayment, @PathVariable("id")Integer id) { |
| | | @PostMapping(value = "/addCoursePackagePayment") |
| | | public Object addCoach(@RequestBody TCoursePackagePayment tCoursePackagePayment) { |
| | | Integer objectId = UserExt.getUser().getObjectId(); |
| | | Integer objectType = UserExt.getUser().getObjectType(); |
| | | String name = UserExt.getUser().getName(); |
| | |
| | | // 获取课包id |
| | | Integer coursePackageId = tCoursePackagePayment.getCoursePackageId(); |
| | | List<TCoursePackageDiscount> list = coursePackageDiscountClient.queryByCoursePackageId(coursePackageId); |
| | | |
| | | // 获取当前课包价格配置 |
| | | CoursePackagePaymentConfig coursePackagePaymentConfigs = coursePackagePaymentConfigClient.getById(id); |
| | | Integer coursePackageId1 = tCoursePackagePayment.getCoursePackageId(); |
| | | TCoursePackage tCoursePackage = coursePackageClient.queryById(coursePackageId1); |
| | | Double cashPayment = coursePackagePaymentConfigs.getCashPayment(); |
| | | String c1 = Double.toString(cashPayment); |
| | | BigDecimal bigDecimal = new BigDecimal(c1); |
| | | tCoursePackagePayment.setCashPayment(bigDecimal); |
| | | Date currentDate = new Date(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(currentDate); |
| | | calendar.add(Calendar.DAY_OF_MONTH, 20); |
| | | Date updatedDate = calendar.getTime(); |
| | | tCoursePackagePayment.setOriginalPrice(cashPayment); |
| | | tCoursePackagePayment.setUseTime(updatedDate); |
| | | tCoursePackagePayment.setPlayPaiCoin(coursePackagePaymentConfigs.getPlayPaiCoin()); |
| | | coursePackagePaymentClient.addCoursePackagePayment(tCoursePackagePayment); |
| | | return ResultUtil.success("添加成功"); |
| | | tCoursePackagePayment.setOriginalPrice(tCoursePackagePayment.getCashPayment().doubleValue()); |
| | | // tCoursePackagePayment.setUseTime(updatedDate); |
| | | // // 查询当前课包有没有课包折扣 |
| | | // List<TCoursePackageDiscount> tCoursePackageDiscounts = coursePackageDiscountClient.queryByCoursePackageId(coursePackageId); |
| | | // // 判断当前用户是不是会员 |
| | | // Integer appUserId = tCoursePackagePayment.getAppUserId(); |
| | | // Date vipEndTime = appUserClient.queryAppUser1(appUserId).getVipEndTime(); |
| | | // // 会员折扣 |
| | | // double c1 = 0.00; |
| | | // // 续课优惠 |
| | | // double c2 = 0.00; |
| | | // // 显示折扣 |
| | | // double c3 = 0.00; |
| | | // for (TCoursePackageDiscount tCoursePackageDiscount : tCoursePackageDiscounts) { |
| | | // char c = tCoursePackageDiscount.getContent().charAt(0); |
| | | // String value1 = String.valueOf(c); |
| | | // |
| | | // JSONObject jsonObject ; |
| | | // if (value1.equals("[")){ |
| | | // jsonObject = JSONObject.fromObject(tCoursePackageDiscount.getContent() |
| | | // .substring(1,tCoursePackageDiscount.getContent().length() - 1)); |
| | | // }else{ |
| | | // jsonObject = JSONObject.fromObject(tCoursePackageDiscount.getContent()); |
| | | // } |
| | | // // 获取所选课时的课包价格配置 |
| | | if (tCoursePackagePayment.getCoursePackageConfigId()!=null) { |
| | | List<CoursePackagePaymentConfig> coursePackagePaymentConfigs = |
| | | coursePackagePaymentConfigClient.queryCoursePackagePaymentConfigList1 |
| | | (tCoursePackagePayment.getCoursePackageConfigId()); |
| | | if (coursePackagePaymentConfigs.size() != 0) { |
| | | CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigs.get(0); |
| | | tCoursePackagePayment.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); |
| | | // tCoursePackagePayment.setPlayPaiCoin(coursePackagePaymentConfig.getPlayPaiCoin()); |
| | | } |
| | | }else { |
| | | List<CoursePackagePaymentConfig> coursePackagePaymentConfigs = coursePackagePaymentConfigClient.queryCoursePackagePaymentConfigList(coursePackageId); |
| | | CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigs.get(0); |
| | | tCoursePackagePayment.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); |
| | | |
| | | } |
| | | // // 原价 |
| | | // Double originalPrice = tCoursePackagePayment.getOriginalPrice(); |
| | | // |
| | | // BigDecimal d1 = new BigDecimal(Double.toString(originalPrice)); |
| | | // |
| | | // // 计算课包折扣 |
| | | // switch (tCoursePackageDiscount.getType()){ |
| | | // case 1: |
| | | // // 是会员 |
| | | // if (!vipEndTime.before(new Date())){ |
| | | // // 会员折扣金额 |
| | | // double discountMember = jsonObject.getDouble("discountMember"); |
| | | // Double aDouble = new Double(discountMember); |
| | | // if (aDouble!=null){ |
| | | // String value = String.valueOf(discountMember); |
| | | // // 折扣比例 |
| | | // Double aDouble1 = Double.valueOf(value); |
| | | // c1 = aDouble1; |
| | | // } |
| | | // } |
| | | // break; |
| | | // case 2: |
| | | // // 判断当前用户是否已经购买过当前课包 |
| | | // List<CoursePackageOrderStudent> result= |
| | | // coursePackagePaymentClient.getByUserIdAndCoursePackageId(tCoursePackagePayment.getAppUserId(), |
| | | // tCoursePackagePayment.getCoursePackageId()); |
| | | // // 已经购买了 |
| | | // if (result.size()!=0){ |
| | | // // 会员续课折扣 |
| | | // double continuingMember = jsonObject.getDouble("continuingMember"); |
| | | // // 用户续课折扣 |
| | | // double continuingUser = jsonObject.getDouble("continuingUser"); |
| | | // // 是会员享受会员续课折扣 |
| | | // if (!vipEndTime.before(new Date())){ |
| | | // String value = String.valueOf(continuingMember); |
| | | // c2 = Double.valueOf(value); |
| | | // }else{ // 否则享受用户续课折扣 |
| | | // String value = String.valueOf(continuingUser); |
| | | // c2 = Double.valueOf(value); |
| | | // } |
| | | // } |
| | | // break; |
| | | // case 3: |
| | | // // 限时折扣判断是否在有效期 |
| | | // String timeFrameStart = jsonObject.getString("startDate"); |
| | | // String timeFrameEnd = jsonObject.getString("endDate"); |
| | | // try { |
| | | // // 判断当日时间是否能享受到折扣 |
| | | // String startTime = jsonObject.getString("startTime"); |
| | | // String endTime = jsonObject.getString("endTime"); |
| | | // // 获取当前时间 |
| | | // Date currentTime = new Date(); |
| | | // // 定义时间格式 |
| | | // SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); |
| | | // // 解析开始时间和结束时间为Date对象 |
| | | // Date startTime1 = sdf.parse(startTime); |
| | | // Date endTime1 = sdf.parse(endTime); |
| | | // Date date1 = new Date(); |
| | | // date1.setHours(startTime1.getHours()); |
| | | // date1.setMinutes(startTime1.getMinutes()); |
| | | // date1.setSeconds(startTime1.getSeconds()); |
| | | // Date date2 = new Date(); |
| | | // date2.setHours(endTime1.getHours()); |
| | | // date2.setMinutes(endTime1.getMinutes()); |
| | | // date2.setSeconds(endTime1.getSeconds()); |
| | | // // 检查当前时间是否在开始时间和结束时间之间 |
| | | // if (currentTime.after(date1) && currentTime.before(date2)) { |
| | | // System.out.println("当前时间在开始时间和结束时间之间。"); |
| | | // String cashPayment = jsonObject.getString("cashPayment"); |
| | | // c3 = Double.valueOf(cashPayment); |
| | | // } else { |
| | | // System.out.println("当前时间不在开始时间和结束时间之间。"); |
| | | // } |
| | | // } catch (ParseException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // break; |
| | | // case 4: |
| | | // // 赠送课时 判断当前课包有没有赠送课时 |
| | | // String weeks = jsonObject.getString("weeks"); |
| | | // // 判断当前周几 是否满足折扣规则 |
| | | // Calendar calendar9 = Calendar.getInstance(); |
| | | // int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); |
| | | // if (weeks.contains(String.valueOf(dayOfWeek))){ |
| | | // // 限时折扣判断是否在有效期 |
| | | // String timeFrameStart1 = jsonObject.getString("startDate"); |
| | | // String timeFrameEnd1 = jsonObject.getString("endDate"); |
| | | // try { |
| | | // // 判断当日时间是否能享受到折扣 |
| | | // String startTime = jsonObject.getString("startTime"); |
| | | // String endTime = jsonObject.getString("endTime"); |
| | | // // 获取当前时间 |
| | | // Date currentTime = new Date(); |
| | | // // 定义时间格式 |
| | | // SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); |
| | | // // 解析开始时间和结束时间为Date对象 |
| | | // Date startTime1 = sdf.parse(startTime); |
| | | // Date endTime1 = sdf.parse(endTime); |
| | | // Date date1 = new Date(); |
| | | // date1.setHours(startTime1.getHours()); |
| | | // date1.setMinutes(startTime1.getMinutes()); |
| | | // date1.setSeconds(startTime1.getSeconds()); |
| | | // Date date2 = new Date(); |
| | | // date2.setHours(endTime1.getHours()); |
| | | // date2.setMinutes(endTime1.getMinutes()); |
| | | // date2.setSeconds(endTime1.getSeconds()); |
| | | // // 检查当前时间是否在开始时间和结束时间之间 |
| | | // if (currentTime.after(date1) && currentTime.before(date2)) { |
| | | // System.out.println("当前时间在开始时间和结束时间之间。"); |
| | | // String hour = jsonObject.getString("hour"); |
| | | // tCoursePackagePayment.setGiftClassHours(Integer.valueOf(hour)); |
| | | // } else { |
| | | // System.out.println("当前时间不在开始时间和结束时间之间。"); |
| | | // } |
| | | // } catch (ParseException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // } |
| | | // break; |
| | | // } |
| | | // |
| | | // } |
| | | // // 判断三个折扣 谁所需支付金额最少 |
| | | // double minValue = 0.00; |
| | | // if (c1 != 0.00 && (c2 == 0.00 || c1 < c2) && (c3 == 0.00 || c1 < c3)) { |
| | | // minValue = c1; |
| | | // } else if (c2 != 0.00 && (c3 == 0.00 || c2 < c3)) { |
| | | // minValue = c2; |
| | | // } else if (c3 != 0.00) { |
| | | // minValue = c3; |
| | | // } |
| | | // if (minValue!=0.00){ |
| | | // BigDecimal bigDecimal = new BigDecimal(minValue); |
| | | // tCoursePackagePayment.setCashPayment(bigDecimal); |
| | | // } |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); |
| | | |
| | | String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5); |
| | | |
| | | tCoursePackagePayment.setCode(code); |
| | | return coursePackagePaymentClient.addCoursePackagePayment(tCoursePackagePayment); |
| | | } |
| | | |
| | | /** |
| | | * 获取列表 |
| | | */ |
| | |
| | | @RequestMapping(value = "/getCoursePackageConfig") |
| | | @ResponseBody |
| | | public List<CoursePackagePaymentConfig> 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(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |