| | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.stylefeng.guns.core.base.controller.BaseController; |
| | | import com.stylefeng.guns.core.base.tips.SuccessTip; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.DateUtil; |
| | | import com.stylefeng.guns.modular.system.controller.req.CouponSendReq; |
| | | import com.stylefeng.guns.modular.system.enums.CouponStatusEnum; |
| | | import com.stylefeng.guns.modular.system.enums.StatusEnum; |
| | | import com.stylefeng.guns.modular.system.model.TAgent; |
| | | import com.stylefeng.guns.modular.system.model.TUserToCoupon; |
| | | import com.stylefeng.guns.modular.system.service.ITUserToCouponService; |
| | |
| | | // 开始,结束时间 |
| | | if(StringUtils.hasLength(createTime)){ |
| | | String[] split = createTime.split(" - "); |
| | | Date startTime = DateUtil.getDate_str4(split[0]); |
| | | Date endTime = DateUtil.getDate_str4(split[1]); |
| | | Date startTime = DateUtil.getDate_str3(split[0]+" 00:00:00"); |
| | | Date endTime = DateUtil.getDate_str3(split[1]+" 23:59:59"); |
| | | wrapper.between("create_time",startTime,endTime); |
| | | } |
| | | wrapper.ne("status", StatusEnum.DELETE.getCode()); |
| | | wrapper.orderBy(true,"create_time",false); |
| | | return tCouponService.selectList(wrapper); |
| | | } |
| | |
| | | if(isExit){ |
| | | return new SuccessTip(500,"该优惠券名称与类型已存在!"); |
| | | } |
| | | // 如果是新人优惠券,查询是否存在已启用的新人优惠券 |
| | | if(tCoupon.getCouponType() == 2){ |
| | | int count = tCouponService.selectCount(new EntityWrapper<TCoupon>() |
| | | .eq("coupon_type", 2) |
| | | .eq("coupon_state", 1) |
| | | .eq("status", true)); |
| | | if(count>0){ |
| | | return new SuccessTip(500,"已存在已启用的新人优惠券!"); |
| | | } |
| | | } |
| | | tCouponService.insert(tCoupon); |
| | | return SUCCESS_TIP; |
| | | } |
| | |
| | | @RequestMapping(value = "/delete") |
| | | @ResponseBody |
| | | public Object delete(@RequestParam Integer tCouponId) { |
| | | /*TCoupon tCoupon = tCouponService.selectById(tCouponId); |
| | | tCoupon.setCouponStatus(StatusEnum.DELETE.getCode()); |
| | | tCouponService.updateById(tCoupon);*/ |
| | | tCouponService.deleteById(tCouponId); |
| | | return SUCCESS_TIP; |
| | | } |
| | |
| | | tUserToCoupon.setCouponTotal(1); |
| | | tUserToCoupon.setValidCount(1); |
| | | Date expireTime = Date.from(LocalDate.now().plusDays(tCoupon.getCouponValidity()).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); |
| | | System.err.println(expireTime); |
| | | tUserToCoupon.setExpireTime(expireTime); |
| | | |
| | | // 添加发放人id和类型 |
| | | if(ShiroKit.getUser().getRoleType() == 1){ |
| | | tUserToCoupon.setObjectId(1); |
| | | }else { |
| | | tUserToCoupon.setObjectId(ShiroKit.getUser().getObjectId()); |
| | | } |
| | | tUserToCoupon.setRoleType(ShiroKit.getUser().getRoleType()); |
| | | |
| | | tUserToCoupons.add(tUserToCoupon); |
| | | } |
| | | tUserToCouponService.insertBatch(tUserToCoupons); |