| | |
| | | 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.model.TUserToCoupon; |
| | | import com.stylefeng.guns.modular.system.service.ITUserToCouponService; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.util.Assert; |
| | |
| | | import com.stylefeng.guns.modular.system.model.TCoupon; |
| | | import com.stylefeng.guns.modular.system.service.ITCouponService; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private ITCouponService tCouponService; |
| | | @Autowired |
| | | private ITUserToCouponService tUserToCouponService; |
| | | |
| | | /** |
| | | * 跳转到首页 |
| | |
| | | */ |
| | | @RequestMapping(value = "/list") |
| | | @ResponseBody |
| | | public Object list(Integer couponType,Integer couponServiceType,String createtime) { |
| | | public Object list(Integer couponType,Integer couponServiceType,String createTime) { |
| | | EntityWrapper<TCoupon> wrapper = new EntityWrapper<>(); |
| | | if(Objects.nonNull(couponType)){ |
| | | wrapper.eq("coupon_type",couponType); |
| | |
| | | wrapper.eq("coupon_service_type",couponServiceType); |
| | | } |
| | | // 开始,结束时间 |
| | | if(StringUtils.hasLength(createtime)){ |
| | | String[] split = createtime.split(" - "); |
| | | if(StringUtils.hasLength(createTime)){ |
| | | String[] split = createTime.split(" - "); |
| | | Date startTime = DateUtil.getDate_str4(split[0]); |
| | | Date endTime = DateUtil.getDate_str4(split[1]); |
| | | wrapper.between("createtime",startTime,endTime); |
| | | wrapper.between("create_time",startTime,endTime); |
| | | } |
| | | wrapper.orderBy(true,"createtime",false); |
| | | wrapper.groupBy(true,"coupon_name"); |
| | | wrapper.groupBy(true,"coupon_type"); |
| | | wrapper.orderBy(true,"create_time",false); |
| | | return tCouponService.selectList(wrapper); |
| | | } |
| | | |
| | | /** |
| | | * 获取活动券列表 |
| | | */ |
| | | @RequestMapping(value = "/activityCouponList") |
| | | @ResponseBody |
| | | public Object activityCouponList(String couponName) { |
| | | EntityWrapper<TCoupon> wrapper = new EntityWrapper<>(); |
| | | if(StringUtils.hasLength(couponName)){ |
| | | wrapper.like("coupon_name",couponName); |
| | | } |
| | | wrapper.eq("coupon_type",1); |
| | | wrapper.eq("coupon_state",1); |
| | | wrapper.orderBy(true,"create_time",false); |
| | | return tCouponService.selectList(wrapper); |
| | | } |
| | | |
| | |
| | | |
| | | List<Integer> userIds = couponSendReq.getUserIds(); |
| | | |
| | | // 查询选择的优惠券 |
| | | TCoupon tCoupon = tCouponService.selectById(couponSendReq.getCouponId()); |
| | | |
| | | List<TUserToCoupon> tUserToCoupons = new ArrayList<>(userIds.size()); |
| | | |
| | | for (Integer userId : userIds) { |
| | | // 创建用户优惠券关联表 |
| | | TUserToCoupon tUserToCoupon = new TUserToCoupon(); |
| | | tUserToCoupon.setCouponId(tCoupon.getId()); |
| | | tUserToCoupon.setUserId(userId); |
| | | 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); |
| | | tUserToCoupons.add(tUserToCoupon); |
| | | } |
| | | tUserToCouponService.insertBatch(tUserToCoupons); |
| | | |
| | | // 查询该优惠券的列表 |
| | | List<TCoupon> tCoupons = tCouponService.selectList(new EntityWrapper<TCoupon>().eq("coupon_name", couponSendReq.getCouponName()) |
| | | /*List<TCoupon> tCoupons = tCouponService.selectList(new EntityWrapper<TCoupon>().eq("coupon_name", couponSendReq.getCouponName()) |
| | | .eq("coupon_status",CouponStatusEnum.UNISSUED.getCode())); |
| | | Assert.isTrue(!CollectionUtils.isEmpty(tCoupons),"该优惠券不存在!"); |
| | | List<TCoupon> tCouponList = new ArrayList<>(); |
| | |
| | | } |
| | | if(!CollectionUtils.isEmpty(tCouponList)){ |
| | | tCouponService.updateBatchById(tCouponList); |
| | | } |
| | | }*/ |
| | | return SUCCESS_TIP; |
| | | } |
| | | |