|
|
|
@ -5,16 +5,27 @@
|
|
|
|
|
*/ |
|
|
|
|
package co.yixiang.modules.activity.rest; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.iocoder.yudao.framework.common.exception.YshopException; |
|
|
|
|
import co.yixiang.enums.CouponEnum; |
|
|
|
|
import co.yixiang.event.TemplateBean; |
|
|
|
|
import co.yixiang.event.TemplateEvent; |
|
|
|
|
import co.yixiang.event.TemplateListenEnum; |
|
|
|
|
import co.yixiang.logging.aop.log.Log; |
|
|
|
|
import co.yixiang.modules.activity.domain.YxStoreCoupon; |
|
|
|
|
import co.yixiang.modules.activity.service.YxStoreCouponIssueService; |
|
|
|
|
import co.yixiang.modules.activity.service.YxStoreCouponIssueUserService; |
|
|
|
|
import co.yixiang.modules.activity.service.YxStoreCouponService; |
|
|
|
|
import co.yixiang.modules.activity.service.YxStoreCouponUserService; |
|
|
|
|
import co.yixiang.modules.activity.service.dto.YxStoreCouponQueryCriteria; |
|
|
|
|
import co.yixiang.modules.aop.ForbidSubmit; |
|
|
|
|
import co.yixiang.modules.user.domain.YxUser; |
|
|
|
|
import io.swagger.annotations.Api; |
|
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
import lombok.Data; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.context.ApplicationEventPublisher; |
|
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
@ -29,6 +40,9 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author hupeng |
|
|
|
|
* @date 2019-11-09 |
|
|
|
@ -39,6 +53,17 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
public class StoreCouponController { |
|
|
|
|
|
|
|
|
|
private final YxStoreCouponService yxStoreCouponService; |
|
|
|
|
@Autowired |
|
|
|
|
private YxStoreCouponUserService storeCouponUserService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private YxStoreCouponIssueService couponIssueService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private ApplicationEventPublisher publisher; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private YxStoreCouponIssueUserService storeCouponIssueUserService; |
|
|
|
|
|
|
|
|
|
public StoreCouponController(YxStoreCouponService yxStoreCouponService) { |
|
|
|
|
this.yxStoreCouponService = yxStoreCouponService; |
|
|
|
@ -67,6 +92,35 @@ public class StoreCouponController {
|
|
|
|
|
return new ResponseEntity<>(yxStoreCouponService.save(resources),HttpStatus.CREATED); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Log("发放优惠券") |
|
|
|
|
@ApiOperation(value = "发放优惠券") |
|
|
|
|
@PostMapping(value = "/yxStoreCoupon/give") |
|
|
|
|
@PreAuthorize("@ss.hasAnyPermissions('admin','YXSTORECOUPON_ALL','YXSTORECOUPON_EDIT')") |
|
|
|
|
public ResponseEntity giveOut(@Validated @RequestBody CouponGive couponGive){ |
|
|
|
|
Long couponId = couponGive.getCouponId(); |
|
|
|
|
couponGive.getUserIds().forEach(yxUser -> { |
|
|
|
|
//用户的券记录
|
|
|
|
|
storeCouponUserService.addUserCoupon(yxUser.getUid(),Math.toIntExact(couponId)); |
|
|
|
|
// //领取记录
|
|
|
|
|
// storeCouponIssueUserService.addUserIssue(yxUser.getUid(),Math.toIntExact(couponId));
|
|
|
|
|
//这里调用微信订阅模板发送消息
|
|
|
|
|
TemplateBean templateBean = TemplateBean.builder() |
|
|
|
|
.couponId(Math.toIntExact(couponId)) |
|
|
|
|
.uid(yxUser.getUid()) |
|
|
|
|
.templateType(TemplateListenEnum.TYPE_10.getValue()) |
|
|
|
|
.time(DateUtil.formatTime(new Date())) |
|
|
|
|
.build(); |
|
|
|
|
publisher.publishEvent(new TemplateEvent(this, templateBean)); |
|
|
|
|
}); |
|
|
|
|
return new ResponseEntity(HttpStatus.OK); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//优惠券发放内部类
|
|
|
|
|
@Data |
|
|
|
|
static class CouponGive{ |
|
|
|
|
private Long couponId; |
|
|
|
|
private List<YxUser> userIds; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Log("修改") |
|
|
|
|
@ApiOperation(value = "修改") |
|
|
|
|