|
@@ -9,6 +9,7 @@ import com.platform.yijia.pojo.UserCoupon;
|
|
import com.platform.yijia.service.CouponService;
|
|
import com.platform.yijia.service.CouponService;
|
|
import com.platform.yijia.utils.CodeMsg;
|
|
import com.platform.yijia.utils.CodeMsg;
|
|
import com.platform.yijia.utils.ResultData;
|
|
import com.platform.yijia.utils.ResultData;
|
|
|
|
+import com.sun.corba.se.spi.ior.ObjectKey;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiParam;
|
|
import io.swagger.annotations.ApiParam;
|
|
@@ -20,9 +21,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/*
|
|
/*
|
|
* <Title> CouponController </Title>
|
|
* <Title> CouponController </Title>
|
|
@@ -115,22 +114,83 @@ public class CouponController {
|
|
@Transactional
|
|
@Transactional
|
|
@ApiOperation(value = "用户领取优惠券", httpMethod = "GET", notes = "用户领取优惠券")
|
|
@ApiOperation(value = "用户领取优惠券", httpMethod = "GET", notes = "用户领取优惠券")
|
|
public String addUserCoupon(@ApiParam(value = "用户unionId", required = true) @RequestParam String unionId,
|
|
public String addUserCoupon(@ApiParam(value = "用户unionId", required = true) @RequestParam String unionId,
|
|
- @ApiParam(value = "优惠券IDS", required = true) @RequestParam ArrayList<String> ids,
|
|
|
|
|
|
+ @ApiParam(value = "优惠券IDS", required = true) @RequestParam List<Integer> ids,
|
|
@ApiParam(value = "领取方式ID", required = true) @RequestParam Integer couponIssueId,
|
|
@ApiParam(value = "领取方式ID", required = true) @RequestParam Integer couponIssueId,
|
|
@ApiParam(value = "油站ID", required = true) @RequestParam Integer stationId){
|
|
@ApiParam(value = "油站ID", required = true) @RequestParam Integer stationId){
|
|
Gson gson = new Gson();
|
|
Gson gson = new Gson();
|
|
ResultData resultData = null;
|
|
ResultData resultData = null;
|
|
try{
|
|
try{
|
|
|
|
+ Coupon couponParam = new Coupon(); //查询优惠券参数
|
|
|
|
+ UserCoupon userCouponParam = new UserCoupon(); //用户优惠券新增参数
|
|
|
|
+ List<Map<String, Object>> successCouponList= new ArrayList<>(); //领取成功的优惠券
|
|
|
|
+ List<Map<String, Object>> failCouponList= new ArrayList<>(); //领取失败的优惠券
|
|
|
|
+ Map<String, Object> failMap = new HashMap<>(); //领取失败的优惠券失败原因
|
|
|
|
+ Map<String, Object> successMap = new HashMap<>(); //领取成功的优惠券信息
|
|
//获取领取方式信息
|
|
//获取领取方式信息
|
|
CouponIssue couponIssue = new CouponIssue();
|
|
CouponIssue couponIssue = new CouponIssue();
|
|
couponIssue.setStationId(stationId);
|
|
couponIssue.setStationId(stationId);
|
|
couponIssue.setCouponIssueId(couponIssueId);
|
|
couponIssue.setCouponIssueId(couponIssueId);
|
|
List<CouponIssue> couponIssueList = couponService.selectCouponIssueList(couponIssue);
|
|
List<CouponIssue> couponIssueList = couponService.selectCouponIssueList(couponIssue);
|
|
if(couponIssueList !=null && couponIssueList.size() ==1){
|
|
if(couponIssueList !=null && couponIssueList.size() ==1){
|
|
- //int size = ids.size();
|
|
|
|
- for(int i=0; i<ids.size(); i++){
|
|
|
|
-
|
|
|
|
|
|
+ int cs =0; //用户优惠券领取成功张数 couponSuccess
|
|
|
|
+ //领取成功的张数与该领取方式在当前页最多领取的张数
|
|
|
|
+ if(cs <= couponIssueList.get(0).getGiveLimit()){
|
|
|
|
+ for(int i=0; i<ids.size(); i++){
|
|
|
|
+ Integer couponId = ids.get(i);
|
|
|
|
+ couponParam.setId(couponId);
|
|
|
|
+ Coupon coupon = couponService.selectCouponInfo(couponParam);
|
|
|
|
+ //该优惠券是否存在
|
|
|
|
+ if(coupon !=null){
|
|
|
|
+ //该优惠券是否已被领完
|
|
|
|
+ if(coupon.getCouponNum() !=null && coupon.getCouponNum() >0){
|
|
|
|
+ userCouponParam.setCouponIsUsed("0"); //是否使用:0、未使用;1、已使用;
|
|
|
|
+ userCouponParam.setCouponNo(""); //优惠券编码
|
|
|
|
+ userCouponParam.setUnionId(unionId); //用户unionId
|
|
|
|
+ userCouponParam.setCouponId(coupon.getId()); //优惠券ID
|
|
|
|
+ userCouponParam.setStationId(stationId); //油站ID
|
|
|
|
+ userCouponParam.setCouponIsEffective("1"); //优惠券是否有效
|
|
|
|
+ userCouponParam.setGetCouponTime(new Date()); //优惠券领取时间
|
|
|
|
+ userCouponParam.setGetCouponOrigin("1"); //优惠券来源
|
|
|
|
+ String effectiveTimeType = coupon.getEffectiveTimeType();
|
|
|
|
+ //'有效时间类型: 1,固定时间;2,领取后x天内有效'
|
|
|
|
+ switch (effectiveTimeType){
|
|
|
|
+ case "1":
|
|
|
|
+ userCouponParam.setCouponEffectiveTime(coupon.getEffectiveTimeEnd()); //优惠券有效期截止时间
|
|
|
|
+ break;
|
|
|
|
+ case "2":
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.setTime(userCouponParam.getGetCouponTime());
|
|
|
|
+ calendar.add(Calendar.DATE, coupon.getEffectiveDayNum()); //领取后多少天有效
|
|
|
|
+ userCouponParam.setCouponEffectiveTime(calendar.getTime()); //优惠券有效期截止时间
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ //获取该用户所持有此优惠券的张数
|
|
|
|
+ int userCouponCount = couponService.selectUserCouponCount(userCouponParam);
|
|
|
|
+ if(userCouponCount > coupon.getCouponHoldNum()){
|
|
|
|
+ failMap.put("领取失败,该用户所持有此优惠券已达到最大数量", coupon.getId());
|
|
|
|
+ failCouponList.add(failMap);
|
|
|
|
+ }else {
|
|
|
|
+ int auc = couponService.addUserCoupon(userCouponParam);
|
|
|
|
+ if(auc ==1){
|
|
|
|
+ successMap.put("领取成功", coupon.getId());
|
|
|
|
+ successCouponList.add(successMap);
|
|
|
|
+ //领取成功后次数加1
|
|
|
|
+ cs++;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ failMap.put("领取失败,该优惠券已被领完", coupon.getId());
|
|
|
|
+ failCouponList.add(failMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ //领取成功
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
+ resultMap.put("successCouponList", successCouponList);
|
|
|
|
+ resultMap.put("failCouponList", failCouponList);
|
|
|
|
+ logger.info("用户领取到的优惠券:" + resultMap.toString());
|
|
|
|
+ resultData = ResultData.success(CodeMsg.SUCCESS);
|
|
}else {
|
|
}else {
|
|
resultData = ResultData.error(CodeMsg.YEWU_FAIL,"该领取方式不存在");
|
|
resultData = ResultData.error(CodeMsg.YEWU_FAIL,"该领取方式不存在");
|
|
}
|
|
}
|