| | |
| | | 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; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.hdf.extractor.TC; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | Date endTime = DateUtil.getDate_str4(split[1]); |
| | | wrapper.between("create_time",startTime,endTime); |
| | | } |
| | | wrapper.ne("status", StatusEnum.DELETE.getCode()); |
| | | wrapper.orderBy(true,"create_time",false); |
| | | return tCouponService.selectList(wrapper); |
| | | } |
| | |
| | | @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; |
| | | } |
| | | |
| | | /** |
| | | * 修改优惠券状态 |
| | | */ |
| | | @RequestMapping(value = "/update-status") |
| | | @ResponseBody |
| | | public Object updateStatus(Integer id,Integer status) { |
| | | TCoupon tCoupon = tCouponService.selectById(id); |
| | | |
| | | // 查询已启用的新人券数量 |
| | | int count = tCouponService.selectCount(new EntityWrapper<TCoupon>().eq("coupon_state", 1) |
| | | .eq("coupon_type",2)); |
| | | |
| | | // 判断是否为新人券,新人券只可启用一条记录 |
| | | if(count > 0 && 2 == tCoupon.getCouponType() && 2 == status){ |
| | | return new SuccessTip(500,"已有启动的新人券!"); |
| | | } |
| | | |
| | | if(1 == status){ |
| | | tCoupon.setCouponState(2); |
| | | } |
| | | if(2 == status){ |
| | | tCoupon.setCouponState(1); |
| | | } |
| | | tCouponService.updateById(tCoupon); |
| | | 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和类型 |
| | | tUserToCoupon.setObjectId(ShiroKit.getUser().getObjectId()); |
| | | tUserToCoupon.setRoleType(ShiroKit.getUser().getRoleType()); |
| | | |
| | | tUserToCoupons.add(tUserToCoupon); |
| | | } |
| | | tUserToCouponService.insertBatch(tUserToCoupons); |