Commit 02cb26ea by 吕明尚

增加劵码只能一个人使用的限制

parent 725c41cd
...@@ -3,6 +3,8 @@ package share.web.controller.system; ...@@ -3,6 +3,8 @@ package share.web.controller.system;
import com.dianping.openapi.sdk.api.tuangou.entity.*; import com.dianping.openapi.sdk.api.tuangou.entity.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -46,7 +48,12 @@ public class QPController { ...@@ -46,7 +48,12 @@ public class QPController {
//用户验券接口 //用户验券接口
@GetMapping("/consumeByUser") @GetMapping("/consumeByUser")
public R<TuangouReceiptPrepareResponseEntityVo> consumeByUser(String code, String openShopUuid) { public R<TuangouReceiptPrepareResponseEntityVo> consumeByUser(String code, String openShopUuid) {
return R.ok(qpService.consumeByUser(code, openShopUuid)); TuangouReceiptPrepareResponseEntityVo tuangouReceiptPrepareResponseEntityVo = qpService.consumeByUser(code, openShopUuid);
if (ObjectUtils.isEmpty(tuangouReceiptPrepareResponseEntityVo)) {
return R.fail(tuangouReceiptPrepareResponseEntityVo, "该券码已被使用");
} else {
return R.ok(tuangouReceiptPrepareResponseEntityVo);
}
} }
//用户销券接口 //用户销券接口
......
...@@ -65,7 +65,7 @@ public class SConsumerCouponController extends BaseController { ...@@ -65,7 +65,7 @@ public class SConsumerCouponController extends BaseController {
public R<List<SConsumerCoupon>> query(@RequestBody @Validated CouponRequest couponRequest) { public R<List<SConsumerCoupon>> query(@RequestBody @Validated CouponRequest couponRequest) {
List<SConsumerCoupon> sConsumerCoupons = sConsumerCouponService.availableCouponList(couponRequest); List<SConsumerCoupon> sConsumerCoupons = sConsumerCouponService.availableCouponList(couponRequest);
if (CollectionUtils.isEmpty(sConsumerCoupons)) { if (CollectionUtils.isEmpty(sConsumerCoupons)) {
return R.ok(sConsumerCoupons, "暂无可用优惠券"); return R.fail(sConsumerCoupons, "暂无可用优惠券");
} else { } else {
return R.ok(sConsumerCoupons); return R.ok(sConsumerCoupons);
} }
......
...@@ -72,11 +72,12 @@ public class QPServiceImpl implements QPService { ...@@ -72,11 +72,12 @@ public class QPServiceImpl implements QPService {
LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SConsumerCoupon> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SConsumerCoupon::getDealId, prepare.getDeal_id()); queryWrapper.eq(SConsumerCoupon::getDealId, prepare.getDeal_id());
queryWrapper.eq(SConsumerCoupon::getCouponCode, code); queryWrapper.eq(SConsumerCoupon::getCouponCode, code);
queryWrapper.eq(SConsumerCoupon::getUseStatus, UserStatusEnum.UNUSED.getCode());
SConsumerCoupon two = isConsumerCouponService.getOne(queryWrapper); SConsumerCoupon two = isConsumerCouponService.getOne(queryWrapper);
if (ObjectUtils.isNotEmpty(two)) { if (ObjectUtils.isNotEmpty(two)) {
//判断是否本人领取过 //判断是否本人领取过
if (!two.getConsumerId().equals(user.getId())) { if (!two.getConsumerId().equals(user.getId())) {
throw new RuntimeException("该券码已被领取"); return null;
} else { } else {
//领取删除原来的 //领取删除原来的
isConsumerCouponService.deleteSConsumerCouponById(two.getId()); isConsumerCouponService.deleteSConsumerCouponById(two.getId());
...@@ -123,6 +124,7 @@ public class QPServiceImpl implements QPService { ...@@ -123,6 +124,7 @@ public class QPServiceImpl implements QPService {
}); });
sConsumerCoupon.setCouponTimeStart("00:00"); sConsumerCoupon.setCouponTimeStart("00:00");
sConsumerCoupon.setCouponTimeEnd("24:00"); sConsumerCoupon.setCouponTimeEnd("24:00");
sConsumerCoupon.setUseStatus(UserStatusEnum.UNUSED.getCode());
sConsumerCoupon.setCreateBy(String.valueOf(user.getId())); sConsumerCoupon.setCreateBy(String.valueOf(user.getId()));
sConsumerCoupon.setCreateTime(new Date()); sConsumerCoupon.setCreateTime(new Date());
isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon); isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon);
...@@ -148,6 +150,7 @@ public class QPServiceImpl implements QPService { ...@@ -148,6 +150,7 @@ public class QPServiceImpl implements QPService {
sConsumerCoupon.setEndDate(prepare.getReceiptEndDate()); sConsumerCoupon.setEndDate(prepare.getReceiptEndDate());
sConsumerCoupon.setCouponTimeStart(sCoupon.getValidStartTime()); sConsumerCoupon.setCouponTimeStart(sCoupon.getValidStartTime());
sConsumerCoupon.setCouponTimeEnd(sCoupon.getValidEndTime()); sConsumerCoupon.setCouponTimeEnd(sCoupon.getValidEndTime());
sConsumerCoupon.setUseStatus(UserStatusEnum.UNUSED.getCode());
sConsumerCoupon.setCreateBy(String.valueOf(user.getId())); sConsumerCoupon.setCreateBy(String.valueOf(user.getId()));
sConsumerCoupon.setCreateTime(new Date()); sConsumerCoupon.setCreateTime(new Date());
isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon); isConsumerCouponService.insertSConsumerCoupon(sConsumerCoupon);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment