|
@@ -13,6 +13,7 @@ import com.sun.org.apache.bcel.internal.classfile.Code;
|
|
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;
|
|
|
|
+import io.swagger.models.auth.In;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -22,6 +23,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.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -58,37 +60,95 @@ public class CouponController {
|
|
Gson gson =new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
|
|
Gson gson =new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
|
|
ResultData resultData = null;
|
|
ResultData resultData = null;
|
|
try {
|
|
try {
|
|
|
|
+ //返回前端结果
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
StationInfo stationInfo = new StationInfo();
|
|
StationInfo stationInfo = new StationInfo();
|
|
stationInfo.setStationId(stationId);
|
|
stationInfo.setStationId(stationId);
|
|
StationInfo stationInfos = stationService.selectStationInfo(stationInfo);
|
|
StationInfo stationInfos = stationService.selectStationInfo(stationInfo);
|
|
if(stationInfos !=null && stationInfos.getCouponEnabledFlag().equals("1")){
|
|
if(stationInfos !=null && stationInfos.getCouponEnabledFlag().equals("1")){
|
|
- CouponUserGiveCount couponUserGiveCount = new CouponUserGiveCount();
|
|
|
|
- couponUserGiveCount.setStationId(stationId);
|
|
|
|
- couponUserGiveCount.setUnionId(unionId);
|
|
|
|
- couponUserGiveCount.setCouponIssueId(couponIssueId);
|
|
|
|
- //用户能进入领取界面的次数
|
|
|
|
- CouponUserGiveCount cgcInfo = couponService.selectCouponUserGiveCount(couponUserGiveCount);
|
|
|
|
- if(cgcInfo !=null && cgcInfo.getIssueGiveCount() >= cgcInfo.getGiveCount()){
|
|
|
|
- resultData = ResultData.error(CodeMsg.COUPON_GIVE_COUNT_MAX);
|
|
|
|
|
|
+ CouponIssue couponIssue = new CouponIssue();
|
|
|
|
+ couponIssue.setStationId(stationId);
|
|
|
|
+ couponIssue.setCouponIssueId(couponIssueId);
|
|
|
|
+ //获取该领取方式的状态是否启用 1启用 0未启用
|
|
|
|
+ List<CouponIssue> couponIssuesList = couponService.selectCouponIssueList(couponIssue);
|
|
|
|
+ if(couponIssuesList !=null && couponIssuesList.size() >0 && couponIssuesList.get(0).getStatus().equals("1")){
|
|
|
|
+ resultMap.put("giveLimit", couponIssuesList.get(0).getGiveLimit());
|
|
|
|
+ CouponUserGiveCount couponUserGiveCount = new CouponUserGiveCount();
|
|
|
|
+ couponUserGiveCount.setStationId(stationId);
|
|
|
|
+ couponUserGiveCount.setUnionId(unionId);
|
|
|
|
+ couponUserGiveCount.setCouponIssueId(couponIssueId);
|
|
|
|
+ //用户能进入领取界面的次数
|
|
|
|
+ CouponUserGiveCount cgcInfo = couponService.selectCouponUserGiveCount(couponUserGiveCount);
|
|
|
|
+ if(cgcInfo !=null && cgcInfo.getIssueGiveCount() >= cgcInfo.getGiveCount()){
|
|
|
|
+ resultData = ResultData.error(CodeMsg.COUPON_GIVE_COUNT_MAX);
|
|
|
|
+ }else {
|
|
|
|
+ //该领取方式能领取优惠券的时间类型
|
|
|
|
+ String availableControl = couponIssuesList.get(0).getAvailableControl();
|
|
|
|
+ switch (availableControl){
|
|
|
|
+ case "0":
|
|
|
|
+ List<Coupon> couponsList = this.selectCouponIssue(stationId, couponIssueId);
|
|
|
|
+ resultMap.put("couponsList", couponsList);
|
|
|
|
+ resultData = ResultData.success(resultMap);
|
|
|
|
+ break;
|
|
|
|
+ case "1":
|
|
|
|
+ String cycleDays_1 = couponIssuesList.get(0).getCycleDays();
|
|
|
|
+ if(!this.isActivityDay(availableControl, cycleDays_1)){
|
|
|
|
+ resultData = ResultData.error(CodeMsg.NOT_GIVE_COUPON_TIME);
|
|
|
|
+ }else {
|
|
|
|
+ List<Coupon> couponsList_1 = this.selectCouponIssue(stationId, couponIssueId);
|
|
|
|
+ resultMap.put("couponsList", couponsList_1);
|
|
|
|
+ resultData = ResultData.success(resultMap);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "2":
|
|
|
|
+ //String cycleDays_2 = couponIssuesList.get(0).getCycleDays();
|
|
|
|
+ if(!this.isActivityDay(availableControl, couponIssuesList.get(0).getCycleDays())){
|
|
|
|
+ resultData = ResultData.error(CodeMsg.NOT_GIVE_COUPON_TIME);
|
|
|
|
+ }else {
|
|
|
|
+ List<Coupon> couponsList_2 = this.selectCouponIssue(stationId, couponIssueId);
|
|
|
|
+ resultMap.put("couponsList", couponsList_2);
|
|
|
|
+ resultData = ResultData.success(resultMap);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "3":
|
|
|
|
+ String appointedDays_3 = couponIssuesList.get(0).getAppointedDays();
|
|
|
|
+ if(!this.isActivityDay(availableControl, appointedDays_3)){
|
|
|
|
+ resultData = ResultData.error(CodeMsg.NOT_GIVE_COUPON_TIME);
|
|
|
|
+ }else {
|
|
|
|
+ List<Coupon> couponsList_3 = this.selectCouponIssue(stationId, couponIssueId);
|
|
|
|
+ resultMap.put("couponsList", couponsList_3);
|
|
|
|
+ resultData = ResultData.success(resultMap);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}else {
|
|
}else {
|
|
- Coupon coupon = new Coupon();
|
|
|
|
- coupon.setStationId(stationId);
|
|
|
|
- coupon.setCouponIssueId(couponIssueId);
|
|
|
|
- //领取油站所分发的优惠券
|
|
|
|
- List<Coupon> couponsList = couponService.selectStaGrantCouponList(coupon);
|
|
|
|
- resultData = ResultData.success(couponsList);
|
|
|
|
|
|
+ // -7
|
|
|
|
+ resultData = ResultData.error(CodeMsg.ISSUE_CLOSE);
|
|
}
|
|
}
|
|
}else {
|
|
}else {
|
|
resultData = ResultData.error(CodeMsg.NO_ENABLE_COUPON);
|
|
resultData = ResultData.error(CodeMsg.NO_ENABLE_COUPON);
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
- //e.printStackTrace();
|
|
|
|
|
|
+ e.printStackTrace();
|
|
logger.error("获取油站已发放的优惠券错误信息:" + e.getMessage());
|
|
logger.error("获取油站已发放的优惠券错误信息:" + e.getMessage());
|
|
resultData = ResultData.error(CodeMsg.SEARCH_FAIL);
|
|
resultData = ResultData.error(CodeMsg.SEARCH_FAIL);
|
|
}
|
|
}
|
|
return gson.toJson(resultData);
|
|
return gson.toJson(resultData);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //油站所分发的优惠券
|
|
|
|
+ public List<Coupon> selectCouponIssue(Integer stationId, String couponIssueId){
|
|
|
|
+ //用户能进入领取界面的次数
|
|
|
|
+ Coupon coupon = new Coupon();
|
|
|
|
+ coupon.setStationId(stationId);
|
|
|
|
+ coupon.setCouponIssueId(couponIssueId);
|
|
|
|
+ //领取油站所分发的优惠券
|
|
|
|
+ List<Coupon> couponsList = couponService.selectStaGrantCouponList(coupon);
|
|
|
|
+ return couponsList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
//获取优惠券信息
|
|
//获取优惠券信息
|
|
@RequestMapping(value = "/selectCouponInfo", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/selectCouponInfo", method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ResponseBody
|
|
@@ -298,4 +358,43 @@ public class CouponController {
|
|
return gson.toJson(resultData);
|
|
return gson.toJson(resultData);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /***
|
|
|
|
+ * //营销方案活动日优惠
|
|
|
|
+ * @param discountType 活动日时间类型
|
|
|
|
+ * @param discountDate 活动日时间字符串,格式:1,2,3,4,5
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public boolean isActivityDay(String discountType, String discountDate){
|
|
|
|
+ boolean boo= false;
|
|
|
|
+ if(discountDate !=null && discountDate !=""){
|
|
|
|
+ String currentTime = null; //当前时间
|
|
|
|
+ String[] discountDateArray = discountDate.split(",");
|
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
|
+ calendar.setTime(new Date()); //获取当前时间
|
|
|
|
+ switch (discountType){
|
|
|
|
+ case "1": // 1.按周来
|
|
|
|
+ int day_Week = calendar.get(Calendar.DAY_OF_WEEK);
|
|
|
|
+ day_Week= day_Week-1; //减一原因:数据库存的下标从零开始
|
|
|
|
+ currentTime = String.valueOf(day_Week);
|
|
|
|
+ break;
|
|
|
|
+ case "2": // 2.每月的 多少号
|
|
|
|
+ int day_month = calendar.get(Calendar.DAY_OF_MONTH);
|
|
|
|
+ day_month = day_month-1; //减一原因:数据库存的下标从零开始
|
|
|
|
+ currentTime = String.valueOf(day_month); //当前时间
|
|
|
|
+ break;
|
|
|
|
+ case "3": // 3.固定日期
|
|
|
|
+ currentTime =new SimpleDateFormat("yyyy-MM-dd").format(new Date()); //当前时间
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ //活动日优惠金额
|
|
|
|
+ for (String s : discountDateArray){
|
|
|
|
+ if(s.equals(currentTime)){
|
|
|
|
+ boo = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return boo;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|