发放优惠券
This commit is contained in:
@@ -2,7 +2,6 @@ package com.czg.controller.admin;
|
||||
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.market.dto.ChatCouponDTO;
|
||||
import com.czg.market.dto.ChatCouponGrantDTO;
|
||||
import com.czg.market.entity.ChatCoupon;
|
||||
import com.czg.market.entity.MkShopCouponRecord;
|
||||
import com.czg.market.service.ChatCouponService;
|
||||
@@ -61,15 +60,6 @@ public class AChatCouponController {
|
||||
chatCouponService.expiredChatCoupon(shopId, id);
|
||||
return CzgResult.success();
|
||||
}
|
||||
/**
|
||||
* 群聊优惠券活动-发放优惠券
|
||||
*/
|
||||
@PostMapping("/grant")
|
||||
@SaAdminCheckPermission(value = "chat:coupon:grant", name = "群聊优惠券活动-发放优惠券")
|
||||
public CzgResult<Void> grantChatCoupon(@RequestBody ChatCouponGrantDTO chatCouponGrant) {
|
||||
chatCouponService.grantChatCoupon(chatCouponGrant.getId(), chatCouponGrant.getShopUserId(), chatCouponGrant.getUserId());
|
||||
return CzgResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 群聊优惠券活动-发放记录
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.czg.controller.user;
|
||||
|
||||
import com.czg.market.dto.ChatCouponGrantDTO;
|
||||
import com.czg.market.service.ChatCouponService;
|
||||
import com.czg.resp.CzgResult;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
* @description
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/chat/coupon")
|
||||
public class UChatCouponController {
|
||||
@Resource
|
||||
private ChatCouponService chatCouponService;
|
||||
|
||||
/**
|
||||
* 群聊优惠券活动-发放优惠券
|
||||
*/
|
||||
@PostMapping("/grant")
|
||||
public CzgResult<Void> grantChatCoupon(@RequestBody ChatCouponGrantDTO chatCouponGrant) {
|
||||
chatCouponService.grantChatCoupon(chatCouponGrant.getId(), chatCouponGrant.getShopUserId(), chatCouponGrant.getUserId());
|
||||
return CzgResult.success();
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,21 @@ public class MkShopCouponRecord implements Serializable {
|
||||
*/
|
||||
private LocalDateTime useEndTime;
|
||||
private LocalDateTime useStartTime;
|
||||
/**
|
||||
* 有效期类型:fixed(固定时间),custom(自定义时间)
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private String validType;
|
||||
/**
|
||||
* 有效天数
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private Integer validDays;
|
||||
/**
|
||||
* 隔天生效
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private Integer daysToTakeEffect;
|
||||
|
||||
@Column(onInsertValue = "now()", onUpdateValue = "now()")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
@@ -514,20 +514,8 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
||||
/**
|
||||
* 组装信息
|
||||
*/
|
||||
@Override
|
||||
public MkShopCouponRecord assembleRecord(Long chatCouponId, ShopCoupon coupon) {
|
||||
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
|
||||
LocalDateTime end = null;
|
||||
if ("fixed".equals(coupon.getValidType())) {
|
||||
//固定时间
|
||||
if (coupon.getDaysToTakeEffect() != null && coupon.getDaysToTakeEffect() > 0) {
|
||||
start = LocalDateTimeUtil.offset(start, coupon.getDaysToTakeEffect(), ChronoUnit.DAYS).with(LocalTime.MIN);
|
||||
}
|
||||
end = LocalDateTimeUtil.offset(start, coupon.getValidDays(), ChronoUnit.DAYS).with(LocalTime.MAX).truncatedTo(ChronoUnit.SECONDS);
|
||||
} else if ("custom".equals(coupon.getValidType())) {
|
||||
//自定义时间
|
||||
start = coupon.getValidStartTime();
|
||||
end = coupon.getValidEndTime();
|
||||
}
|
||||
MkShopCouponRecord record = new MkShopCouponRecord();
|
||||
record.setShopId(coupon.getShopId());
|
||||
|
||||
@@ -544,8 +532,13 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
||||
record.setMaxDiscountAmount(coupon.getMaxDiscountAmount());
|
||||
record.setCreateTime(LocalDateTime.now());
|
||||
record.setIsDel(0);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
if ("fixed".equals(coupon.getValidType())) {
|
||||
record.setDaysToTakeEffect(coupon.getDaysToTakeEffect());
|
||||
record.setValidDays(coupon.getValidDays());
|
||||
} else if ("custom".equals(coupon.getValidType())) {
|
||||
record.setUseStartTime(coupon.getValidStartTime());
|
||||
record.setUseEndTime(coupon.getValidEndTime());
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
@@ -564,10 +557,20 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
|
||||
return;
|
||||
}
|
||||
coupon.setGiftNum(coupon.getGiftNum() + number);
|
||||
if ("fixed".equals(record.getValidType())) {
|
||||
LocalDateTime start = LocalDateTime.now().with(LocalTime.MIN);
|
||||
//固定时间
|
||||
if (record.getDaysToTakeEffect() != null && record.getDaysToTakeEffect() > 0) {
|
||||
start = LocalDateTimeUtil.offset(start, record.getDaysToTakeEffect(), ChronoUnit.DAYS).with(LocalTime.MIN);
|
||||
}
|
||||
LocalDateTime end = LocalDateTimeUtil.offset(start, record.getValidDays(), ChronoUnit.DAYS).with(LocalTime.MAX).truncatedTo(ChronoUnit.SECONDS);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
}
|
||||
for (int i = 0; i < number; i++) {
|
||||
recordList.add(record);
|
||||
}
|
||||
mapper.insertBatchSelective(recordList, 50);
|
||||
mapper.insertBatchSelective(recordList, 10);
|
||||
|
||||
QueryWrapper queryWrapper = new QueryWrapper();
|
||||
ShopCoupon newCoupon = new ShopCoupon();
|
||||
|
||||
Reference in New Issue
Block a user