|
@@ -2,6 +2,7 @@ package com.qs.mp.web.controller.api.channel;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qs.mp.channel.domain.ChannelCouponVerifyLog;
|
|
|
import com.qs.mp.channel.service.IChannelCouponVerifyLogService;
|
|
|
import com.qs.mp.channel.service.IChannelService;
|
|
@@ -11,6 +12,7 @@ import com.qs.mp.common.enums.ErrorCodeEnum;
|
|
|
import com.qs.mp.common.enums.UserCouponStatusEnum;
|
|
|
import com.qs.mp.user.domain.UserCoupon;
|
|
|
import com.qs.mp.user.domain.UserCouponChannel;
|
|
|
+import com.qs.mp.user.domain.vo.UserCouponVO;
|
|
|
import com.qs.mp.user.service.IUserCouponChannelService;
|
|
|
import com.qs.mp.user.service.IUserCouponService;
|
|
|
import com.qs.mp.utils.SecurityUtils;
|
|
@@ -19,6 +21,7 @@ import io.swagger.annotations.Api;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import ma.glasnost.orika.MapperFacade;
|
|
|
+import org.apache.catalina.User;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -54,35 +57,68 @@ public class ChannelCouponVerifyController extends BaseApiController {
|
|
|
private MapperFacade mapperFacade;
|
|
|
|
|
|
/**
|
|
|
- * 优惠券核销
|
|
|
+ * 优惠券查询
|
|
|
*
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
- @PostMapping(value = "coupon/verify")
|
|
|
- public AjaxResult verify(@RequestBody JSONObject param) {
|
|
|
+ @PostMapping(value = "coupon/query")
|
|
|
+ public AjaxResult query(@RequestBody JSONObject param) {
|
|
|
String verifyCode = param.getString("verifyCode");
|
|
|
- if (StringUtils.isBlank(verifyCode)) {
|
|
|
- return error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
- }
|
|
|
Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
UserCoupon userCoupon = userCouponService.getOne(new LambdaQueryWrapper<UserCoupon>()
|
|
|
.eq(UserCoupon::getVerifyCode, verifyCode));
|
|
|
+ AjaxResult result = checkCoupon(verifyCode, channelId, userCoupon);
|
|
|
+ if (null != result) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ List<UserCouponVO> userCouponVOList = userCouponService.listUserCouponVO(
|
|
|
+ new QueryWrapper<UserCoupon>()
|
|
|
+ .eq("t1.verify_code", verifyCode));
|
|
|
+
|
|
|
+ return AjaxResult.success(userCouponVOList.get(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ private AjaxResult checkCoupon(String verifyCode, Long channelId, UserCoupon userCoupon) {
|
|
|
+ AjaxResult result = null;
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(verifyCode)) {
|
|
|
+ result = error(ErrorCodeEnum.ERROR_CODE_1001);
|
|
|
+ }
|
|
|
if (null == userCoupon) {
|
|
|
- return error("该券不存在!");
|
|
|
+ result = error("该券不存在!");
|
|
|
}
|
|
|
if (userCoupon.getStatus() == UserCouponStatusEnum.USED) {
|
|
|
- return error("该券已使用!");
|
|
|
+ result = error("该券已使用!");
|
|
|
}
|
|
|
if (userCoupon.getValidEnd().before(new Date())) {
|
|
|
- return error("该券已过期!");
|
|
|
+ result = error("该券已过期!");
|
|
|
}
|
|
|
UserCouponChannel couponChannel = userCouponChannelService.getOne(
|
|
|
new LambdaQueryWrapper<UserCouponChannel>()
|
|
|
.eq(UserCouponChannel::getUserCouponId, userCoupon.getId())
|
|
|
.eq(UserCouponChannel::getChannelId, channelId));
|
|
|
if (null == couponChannel) {
|
|
|
- return error("无权核销该券");
|
|
|
+ result = error("无权核销该券");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 优惠券核销
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping(value = "coupon/verify")
|
|
|
+ public AjaxResult verify(@RequestBody JSONObject param) {
|
|
|
+ String verifyCode = param.getString("verifyCode");
|
|
|
+ Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
+ UserCoupon userCoupon = userCouponService.getOne(new LambdaQueryWrapper<UserCoupon>()
|
|
|
+ .eq(UserCoupon::getVerifyCode, verifyCode));
|
|
|
+ AjaxResult result = checkCoupon(verifyCode, channelId, userCoupon);
|
|
|
+ if (null != result) {
|
|
|
+ return result;
|
|
|
}
|
|
|
channelCouponVerifyLogService.verify(channelId, userCoupon);
|
|
|
return AjaxResult.success("核销成功");
|
|
@@ -94,7 +130,7 @@ public class ChannelCouponVerifyController extends BaseApiController {
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("coupon/verify/log/list")
|
|
|
- public TableDataInfo listChannel(@RequestBody JSONObject jsonObject) {
|
|
|
+ public TableDataInfo list(@RequestBody JSONObject jsonObject) {
|
|
|
Long channelId = SecurityUtils.getLoginUser().getChannelId();
|
|
|
startPage();
|
|
|
List<ChannelCouponVerifyLog> verifyLogList = channelCouponVerifyLogService.list(
|