|
@@ -108,21 +108,7 @@ public class MerchantMealServiceImpl extends BaseServiceImpl<MerchantMeal, Strin
|
|
|
Merchant merchant=merchantService.getById(merchantId);
|
|
|
switch (merchant.getPosType()) {
|
|
|
case 2:
|
|
|
- //如果传入了日期,就按传入的日期处理。
|
|
|
- //如果激活日期和结束为空,就设置当前日期。
|
|
|
- boolean isActiveLog=false;
|
|
|
- if(merchant.getStartActiveTime()==null || merchant.getActiveTime()==null) {
|
|
|
- if(StringUtils.isNotEmpty(startActiveTime) && StringUtils.isNotEmpty(activeTime)) {
|
|
|
- merchant.setStartActiveTime(DateHelper.parseDate(startActiveTime, "yyyy-MM-dd"));
|
|
|
- merchant.setActiveTime(DateHelper.parseDate(activeTime, "yyyy-MM-dd"));
|
|
|
- isActiveLog=true;
|
|
|
- }else {
|
|
|
- merchant.setStartActiveTime(new Date());
|
|
|
- merchant.setActiveTime(new Date());
|
|
|
- }
|
|
|
- merchantService.save(merchant);
|
|
|
- }
|
|
|
-
|
|
|
+
|
|
|
MerchantMealOrder mealOrder=new MerchantMealOrder();
|
|
|
mealOrder.setStartActiveTime(StringUtils.isNotEmpty(startActiveTime) ? DateHelper.parseDate(startActiveTime, "yyyy-MM-dd") : null);
|
|
|
mealOrder.setActiveTime(StringUtils.isNotEmpty(activeTime) ? DateHelper.parseDate(activeTime, "yyyy-MM-dd") : null);
|
|
@@ -158,7 +144,7 @@ public class MerchantMealServiceImpl extends BaseServiceImpl<MerchantMeal, Strin
|
|
|
mrchantMealOrderService.save(mealOrder);
|
|
|
|
|
|
//添加激活期的记录
|
|
|
- if(isActiveLog) {
|
|
|
+ if(StringUtils.isNotEmpty(startActiveTime) && StringUtils.isNotEmpty(activeTime) && !activeTime.equals(startActiveTime)) {
|
|
|
Integer month=DateHelper.getDifferMonth(DateHelper.parseDate(startActiveTime, "yyyy-MM-dd"),DateHelper.parseDate(activeTime, "yyyy-MM-dd"));
|
|
|
Date startTime=DateHelper.parseDate(startActiveTime, "yyyy-MM-dd");
|
|
|
Date endTime=DateHelper.getMonthDate(startTime,1);
|
|
@@ -185,26 +171,20 @@ public class MerchantMealServiceImpl extends BaseServiceImpl<MerchantMeal, Strin
|
|
|
}
|
|
|
|
|
|
//端口商户的处理,
|
|
|
- Date signTime=new Date();
|
|
|
- MerchantMeal merchantMeal=this.getMerchantMealByMaxEndSignTime(merchantId);
|
|
|
- if(merchantMeal!=null ) {
|
|
|
- if(merchantMeal.getEndSignTime().getTime()>=new Date().getTime()) {
|
|
|
- signTime=merchantMeal.getEndSignTime();
|
|
|
- }
|
|
|
- }else {
|
|
|
- if(merchant.getComputeTime()!=null) {
|
|
|
- signTime=merchant.getComputeTime();
|
|
|
- }else {
|
|
|
- signTime=merchant.getActiveTime();
|
|
|
- }
|
|
|
- }
|
|
|
+ Date signTime=mealOrder.getActiveTime();
|
|
|
Date endSignTime=DateHelper.getMonthDate(signTime,1);
|
|
|
+ MerchantMeal nextMerchantMeal=dao.findMerchantMealByServiceMaxEnd(merchantId, signTime);
|
|
|
+ if(nextMerchantMeal!=null) {
|
|
|
+ endSignTime=nextMerchantMeal.getEndSignTime();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//添加赠送的记录
|
|
|
for (int i =1; i <=giveMonth; i++) {
|
|
|
MerchantMeal meal=new MerchantMeal();
|
|
|
meal.setMerchantId(merchantId);
|
|
|
meal.setSignTime(signTime);
|
|
|
- meal.setEndSignTime(DateHelper.getMonthDate(signTime,1));
|
|
|
+ meal.setEndSignTime(endSignTime);
|
|
|
meal.setSignType(signType);
|
|
|
meal.setType(2);
|
|
|
meal.setStatus(1);
|
|
@@ -290,12 +270,17 @@ public class MerchantMealServiceImpl extends BaseServiceImpl<MerchantMeal, Strin
|
|
|
}
|
|
|
mrchantMealOrderService.save(mealOrder);
|
|
|
|
|
|
-
|
|
|
Date signTime=DateHelper.parseDate(startActiveTime, "yyyy-MM-dd");
|
|
|
Date endSignTime=DateHelper.getMonthDate(signTime,1);
|
|
|
+ MerchantMeal nextMerchantMeal=dao.findMerchantMealByServiceMaxEnd(merchantId, signTime);
|
|
|
+ if(nextMerchantMeal!=null) {
|
|
|
+ endSignTime=nextMerchantMeal.getEndSignTime();
|
|
|
+ }
|
|
|
+
|
|
|
//添加购买的记录
|
|
|
int yearIndex = hisMonth/12;
|
|
|
int monthLeft = hisMonth%12;
|
|
|
+
|
|
|
for (int i =1; i <=month; i++) {
|
|
|
MerchantMeal meal=new MerchantMeal();
|
|
|
meal.setMerchantId(merchantId);
|
|
@@ -312,11 +297,13 @@ public class MerchantMealServiceImpl extends BaseServiceImpl<MerchantMeal, Strin
|
|
|
meal.setCreateTime(new Date());
|
|
|
meal.setOrderId(mealOrder.getId());
|
|
|
merchantMeals.add(meal);
|
|
|
+
|
|
|
if((monthLeft+i)%12==0){
|
|
|
meal.setYearIndex(yearIndex+(monthLeft+i)/12);
|
|
|
}else{
|
|
|
meal.setYearIndex(yearIndex+(monthLeft+i)/12+1);
|
|
|
}
|
|
|
+
|
|
|
signTime=endSignTime;
|
|
|
endSignTime=DateHelper.getMonthDate(signTime,1);
|
|
|
}
|
|
@@ -342,58 +329,38 @@ public class MerchantMealServiceImpl extends BaseServiceImpl<MerchantMeal, Strin
|
|
|
Merchant merchant=merchantService.getById(merchantId);
|
|
|
switch (merchant.getPosType()) {
|
|
|
case 2://端口商户
|
|
|
+ case 3://学校商户
|
|
|
|
|
|
//查询结束时间最大的数据。
|
|
|
MerchantMeal maxMerchantMeal=dao.getMerchantMealByMaxEndSignTime(merchantId);
|
|
|
+ //查询开始时间最小的数据。
|
|
|
+ MerchantMeal minMerchantMeal=dao.getMerchantMealByMinSignTime(merchantId);
|
|
|
+
|
|
|
//查询当前日期在服务期段的数据
|
|
|
- MerchantMeal merchantMeal=dao.getMerchantMealByCurTime(merchantId);
|
|
|
- if(merchantMeal==null) {
|
|
|
- //查出大于今天的服务数据
|
|
|
- merchantMeal=dao.getMerchantMealByCurSignTime(merchantId);
|
|
|
- }
|
|
|
- if(merchantMeal==null) {
|
|
|
- //查出没有大于今天的服务数据,就取最大的数据。
|
|
|
- merchantMeal=maxMerchantMeal;
|
|
|
- }
|
|
|
+ List<MerchantMeal> merchantMeals=dao.getMerchantMealByCurTime(merchantId);
|
|
|
|
|
|
- if(maxMerchantMeal!=null && merchantMeal!=null) {
|
|
|
- MerchantMealOrder merchantMealOrder=mrchantMealOrderService.getById(maxMerchantMeal.getOrderId());
|
|
|
- merchant.setEndActiveTime(maxMerchantMeal.getEndSignTime());
|
|
|
- merchant.setSignType(merchantMeal.getSignType());
|
|
|
- merchant.setPortNum(merchantMealOrder!=null ? merchantMealOrder.getPortNum() : 0);
|
|
|
- merchant.setLibService(merchantMeal.getLibService()+merchantSignService.getMerchantSignByCurLibService(merchantId));
|
|
|
- merchantService.save(merchant);
|
|
|
-
|
|
|
- //调用openApi接口
|
|
|
- if(StringUtils.isNotEmpty(merchant.getLibId())) {
|
|
|
- DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
- libVipServiceService.openApiServiceCRM(
|
|
|
- 3,
|
|
|
- merchant.getLibId(),
|
|
|
- merchant.getSignType(),
|
|
|
- merchant.getMealType(),
|
|
|
- merchant.getLibService(),
|
|
|
- merchant.getStartActiveTime()!=null ? format.format(merchant.getStartActiveTime()) : "",
|
|
|
- merchant.getStartActiveTime()!=null ? format.format(merchant.getStartActiveTime()) : "",
|
|
|
- merchant.getEndActiveTime()!=null ? format.format(merchant.getEndActiveTime()) : ""
|
|
|
- );
|
|
|
+ if(merchantMeals!=null && merchantMeals.size()>0) {
|
|
|
+ Integer maxSignType=null;
|
|
|
+ Integer maxPortNum=0;
|
|
|
+ Integer sumLibService=0;
|
|
|
+ for (MerchantMeal merchantMeal : merchantMeals) {
|
|
|
+ if(maxSignType==null || maxSignType<merchantMeal.getSignType()) {
|
|
|
+ maxSignType=merchantMeal.getSignType();
|
|
|
+ }
|
|
|
+
|
|
|
+ sumLibService=sumLibService+merchantMeal.getLibService();
|
|
|
}
|
|
|
- }
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- //学校商户
|
|
|
- MerchantMealOrder merchantMealOrder=mrchantMealOrderService.getMerchantMealOrderByCurTime(merchantId);
|
|
|
- if(merchantMealOrder==null) {
|
|
|
- merchantMealOrder=mrchantMealOrderService.getMerchantMealOrderByMaxCreateTime(merchantId);
|
|
|
- }
|
|
|
-
|
|
|
- if(merchantMealOrder!=null) {
|
|
|
- merchant.setStartActiveTime(merchantMealOrder.getSignTime());
|
|
|
- merchant.setActiveTime(merchantMealOrder.getSignTime());
|
|
|
- merchant.setEndActiveTime(merchantMealOrder.getEndSignTime());
|
|
|
- merchant.setSignType(merchantMealOrder.getSignType());
|
|
|
- merchant.setPortNum(merchantMealOrder.getPortNum());
|
|
|
- merchant.setLibService(merchantMealOrder.getLibService()+merchantSignService.getMerchantSignByCurLibService(merchantId));
|
|
|
+ //现在处理,不存在降级的操作,如果之前的type比现在的大,那就还是用之前的。
|
|
|
+ if(merchant.getSignType()!=null && merchant.getSignType()>maxSignType) {
|
|
|
+ maxSignType=merchant.getSignType();
|
|
|
+ }
|
|
|
+
|
|
|
+ merchant.setStartActiveTime(minMerchantMeal.getSignTime());
|
|
|
+ merchant.setActiveTime(minMerchantMeal.getSignTime());
|
|
|
+ merchant.setEndActiveTime(maxMerchantMeal.getEndSignTime());
|
|
|
+ merchant.setSignType(maxSignType);
|
|
|
+ merchant.setPortNum(maxPortNum);
|
|
|
+ merchant.setLibService(sumLibService+merchantSignService.getMerchantSignByCurLibService(merchantId));
|
|
|
merchantService.save(merchant);
|
|
|
|
|
|
//调用openApi接口
|
|
@@ -412,6 +379,35 @@ public class MerchantMealServiceImpl extends BaseServiceImpl<MerchantMeal, Strin
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
+// case 3://2021-03-16号改为和端口商户一样处理。
|
|
|
+//
|
|
|
+// MerchantMealOrder merchantMealOrder=mrchantMealOrderService.getMerchantMealOrderByCurTime(merchantId);
|
|
|
+//
|
|
|
+// if(merchantMealOrder!=null) {
|
|
|
+// merchant.setStartActiveTime(merchantMealOrder.getSignTime());
|
|
|
+// merchant.setActiveTime(merchantMealOrder.getSignTime());
|
|
|
+// merchant.setEndActiveTime(merchantMealOrder.getEndSignTime());
|
|
|
+// merchant.setSignType(merchantMealOrder.getSignType());
|
|
|
+// merchant.setPortNum(merchantMealOrder.getPortNum());
|
|
|
+// merchant.setLibService(merchantMealOrder.getLibService()+merchantSignService.getMerchantSignByCurLibService(merchantId));
|
|
|
+// merchantService.save(merchant);
|
|
|
+//
|
|
|
+// //调用openApi接口
|
|
|
+// if(StringUtils.isNotEmpty(merchant.getLibId())) {
|
|
|
+// DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+// libVipServiceService.openApiServiceCRM(
|
|
|
+// 3,
|
|
|
+// merchant.getLibId(),
|
|
|
+// merchant.getSignType(),
|
|
|
+// merchant.getMealType(),
|
|
|
+// merchant.getLibService(),
|
|
|
+// merchant.getStartActiveTime()!=null ? format.format(merchant.getStartActiveTime()) : "",
|
|
|
+// merchant.getStartActiveTime()!=null ? format.format(merchant.getStartActiveTime()) : "",
|
|
|
+// merchant.getEndActiveTime()!=null ? format.format(merchant.getEndActiveTime()) : ""
|
|
|
+// );
|
|
|
+// }
|
|
|
+// }
|
|
|
+// break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|