| | |
| | | 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; |
| | |
| | | * 添加购课记录 |
| | | */ |
| | | @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); |
| | | // 获取当前课包价格配置 |
| | | Integer coursePackageId1 = tCoursePackagePayment.getCoursePackageId(); |
| | | TCoursePackage tCoursePackage = coursePackageClient.queryById(coursePackageId1); |
| | | 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()); |
| | | tCoursePackagePayment.setUseTime(updatedDate); |
| | | // 查询当前课包有没有课包折扣 |
| | | List<TCoursePackageDiscount> tCoursePackageDiscounts = coursePackageDiscountClient.queryByCoursePackageId(coursePackageId); |
| | | // 判断当前用户是不是会员 |
| | | Integer appUserId = tCoursePackagePayment.getAppUserId(); |
| | | Date vipEndTime = appUserClient.queryAppUser1(appUserId).getVipEndTime(); |
| | | for (TCoursePackageDiscount tCoursePackageDiscount : tCoursePackageDiscounts) { |
| | | JSONObject jsonObject = JSONObject.fromObject(tCoursePackageDiscount.getContent()); |
| | | 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); |
| | | BigDecimal bigDecimal = new BigDecimal(value); |
| | | tCoursePackagePayment.setCashPayment(bigDecimal); |
| | | } |
| | | } |
| | | break; |
| | | case 2: |
| | | // 判断当前用户是否已经购买过当前课包 |
| | | List<com.dsh.course.feignClient.course.model.TCoursePackagePayment> 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); |
| | | BigDecimal bigDecimal = new BigDecimal(value); |
| | | tCoursePackagePayment.setCashPayment(bigDecimal); |
| | | }else{ // 否则享受用户续课折扣 |
| | | String value = String.valueOf(continuingUser); |
| | | BigDecimal bigDecimal = new BigDecimal(value); |
| | | tCoursePackagePayment.setCashPayment(bigDecimal); |
| | | } |
| | | } |
| | | break; |
| | | case 3: |
| | | // 限时折扣判断是否在有效期 |
| | | String timeFrameStart = jsonObject.getString("timeFrameStart"); |
| | | String timeFrameEnd = jsonObject.getString("timeFrameEnd"); |
| | | SimpleDateFormat format = new SimpleDateFormat(timeFrameStart); |
| | | SimpleDateFormat format1 = new SimpleDateFormat(timeFrameEnd); |
| | | try { |
| | | Date parse = format.parse(timeFrameStart); |
| | | Date parse1 = format1.parse(timeFrameEnd); |
| | | if (new Date().after(parse) && new Date().before(parse1)){ |
| | | double continuingMember = jsonObject.getDouble("discountMember"); |
| | | String value = String.valueOf(continuingMember); |
| | | BigDecimal bigDecimal = new BigDecimal(value); |
| | | tCoursePackagePayment.setCashPayment(bigDecimal); |
| | | } |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | break; |
| | | case 4: |
| | | // 赠送课时 |
| | | |
| | | break; |
| | | // 获取所选课时的课包价格配置 |
| | | if (tCoursePackagePayment.getCoursePackageConfigId()!=null) { |
| | | List<CoursePackagePaymentConfig> coursePackagePaymentConfigs = |
| | | coursePackagePaymentConfigClient.queryCoursePackagePaymentConfigList1 |
| | | (tCoursePackagePayment.getCoursePackageConfigId()); |
| | | if (coursePackagePaymentConfigs.size() != 0) { |
| | | CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigs.get(0); |
| | | tCoursePackagePayment.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); |
| | | } |
| | | }else { |
| | | List<CoursePackagePaymentConfig> coursePackagePaymentConfigs = coursePackagePaymentConfigClient.queryCoursePackagePaymentConfigList(coursePackageId); |
| | | CoursePackagePaymentConfig coursePackagePaymentConfig = coursePackagePaymentConfigs.get(0); |
| | | tCoursePackagePayment.setOriginalPrice(coursePackagePaymentConfig.getCashPayment()); |
| | | } |
| | | coursePackagePaymentClient.addCoursePackagePayment(tCoursePackagePayment); |
| | | return ResultUtil.success("添加成功"); |
| | | 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(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |