Bladeren bron

赠送优惠券支持 按每月赠送

wuxw 3 jaren geleden
bovenliggende
commit
306a4cd34c

+ 10 - 0
java110-bean/src/main/java/com/java110/dto/couponPropertyUser/CouponPropertyUserDto.java

@@ -40,6 +40,8 @@ public class CouponPropertyUserDto extends PageDto implements Serializable {
 
     private String statusCd = "0";
 
+    private String startTime;
+
 
     public String getCouponName() {
         return couponName;
@@ -178,4 +180,12 @@ public class CouponPropertyUserDto extends PageDto implements Serializable {
     public void setIsExpire(String isExpire) {
         this.isExpire = isExpire;
     }
+
+    public String getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(String startTime) {
+        this.startTime = startTime;
+    }
 }

+ 72 - 40
java110-bean/src/main/java/com/java110/po/couponPropertyUser/CouponPropertyUserPo.java

@@ -16,7 +16,7 @@
 package com.java110.po.couponPropertyUser;
 
 import java.io.Serializable;
-import java.util.Date;
+
 /**
  * 类表述: Po 数据模型实体对象 基本保持与数据库模型一直 用于 增加修改删除 等时的数据载体
  * add by 吴学文 at 2022-11-21 12:08:05 mail: 928255095@qq.com
@@ -28,97 +28,129 @@ import java.util.Date;
 public class CouponPropertyUserPo implements Serializable {
 
     private String couponName;
-private String toType;
-private String validityDay;
-private String statusCd = "0";
-private String couponId;
-private String userName;
-private String userId;
-private String cppId;
-private String tel;
-private String state;
-private String stock;
-private String communityId;
-private String value;
-public String getCouponName() {
+    private String toType;
+    private String validityDay;
+    private String statusCd = "0";
+    private String couponId;
+    private String userName;
+    private String userId;
+    private String cppId;
+    private String tel;
+    private String state;
+    private String stock;
+    private String communityId;
+    private String value;
+    private String startTime;
+
+    public String getCouponName() {
         return couponName;
     }
-public void setCouponName(String couponName) {
+
+    public void setCouponName(String couponName) {
         this.couponName = couponName;
     }
-public String getToType() {
+
+    public String getToType() {
         return toType;
     }
-public void setToType(String toType) {
+
+    public void setToType(String toType) {
         this.toType = toType;
     }
-public String getValidityDay() {
+
+    public String getValidityDay() {
         return validityDay;
     }
-public void setValidityDay(String validityDay) {
+
+    public void setValidityDay(String validityDay) {
         this.validityDay = validityDay;
     }
-public String getStatusCd() {
+
+    public String getStatusCd() {
         return statusCd;
     }
-public void setStatusCd(String statusCd) {
+
+    public void setStatusCd(String statusCd) {
         this.statusCd = statusCd;
     }
-public String getCouponId() {
+
+    public String getCouponId() {
         return couponId;
     }
-public void setCouponId(String couponId) {
+
+    public void setCouponId(String couponId) {
         this.couponId = couponId;
     }
-public String getUserName() {
+
+    public String getUserName() {
         return userName;
     }
-public void setUserName(String userName) {
+
+    public void setUserName(String userName) {
         this.userName = userName;
     }
-public String getUserId() {
+
+    public String getUserId() {
         return userId;
     }
-public void setUserId(String userId) {
+
+    public void setUserId(String userId) {
         this.userId = userId;
     }
-public String getCppId() {
+
+    public String getCppId() {
         return cppId;
     }
-public void setCppId(String cppId) {
+
+    public void setCppId(String cppId) {
         this.cppId = cppId;
     }
-public String getTel() {
+
+    public String getTel() {
         return tel;
     }
-public void setTel(String tel) {
+
+    public void setTel(String tel) {
         this.tel = tel;
     }
-public String getState() {
+
+    public String getState() {
         return state;
     }
-public void setState(String state) {
+
+    public void setState(String state) {
         this.state = state;
     }
-public String getStock() {
+
+    public String getStock() {
         return stock;
     }
-public void setStock(String stock) {
+
+    public void setStock(String stock) {
         this.stock = stock;
     }
-public String getCommunityId() {
+
+    public String getCommunityId() {
         return communityId;
     }
-public void setCommunityId(String communityId) {
+
+    public void setCommunityId(String communityId) {
         this.communityId = communityId;
     }
-public String getValue() {
+
+    public String getValue() {
         return value;
     }
-public void setValue(String value) {
+
+    public void setValue(String value) {
         this.value = value;
     }
 
+    public String getStartTime() {
+        return startTime;
+    }
 
-
+    public void setStartTime(String startTime) {
+        this.startTime = startTime;
+    }
 }

+ 16 - 6
java110-db/src/main/resources/mapper/acct/CouponPropertyUserV1ServiceDaoImplMapper.xml

@@ -8,9 +8,9 @@
     <!-- 保存用户优惠券信息 add by wuxw 2018-07-03 -->
     <insert id="saveCouponPropertyUserInfo" parameterType="Map">
         insert into coupon_property_user(
-        coupon_name,to_type,validity_day,coupon_id,user_name,user_id,cpp_id,tel,state,stock,community_id,value
+        coupon_name,to_type,validity_day,coupon_id,user_name,user_id,cpp_id,tel,state,stock,community_id,value,start_time
         ) values (
-        #{couponName},#{toType},#{validityDay},#{couponId},#{userName},#{userId},#{cppId},#{tel},#{state},#{stock},#{communityId},#{value}
+        #{couponName},#{toType},#{validityDay},#{couponId},#{userName},#{userId},#{cppId},#{tel},#{state},#{stock},#{communityId},#{value},#{startTime}
         )
     </insert>
 
@@ -20,7 +20,7 @@
         select t.coupon_name,t.coupon_name couponName,t.to_type,t.to_type toType,t.validity_day,t.validity_day
         validityDay,t.status_cd,t.status_cd statusCd,t.coupon_id,t.coupon_id couponId,t.user_name,t.user_name
         userName,t.user_id,t.user_id couponUserId,t.cpp_id,t.cpp_id cppId,t.tel,t.state,t.stock,t.community_id,t.community_id
-        communityId,t.value,td.`name` toTypeName,t.create_time createTime
+        communityId,t.value,td.`name` toTypeName,t.create_time createTime,t.start_time startTime
         from coupon_property_user t
         left join t_dict td on td.status_cd = t.to_type and td.table_name = 'coupon_property_pool' and td.table_columns = 'to_type'
         where 1 =1
@@ -57,6 +57,9 @@
         <if test="stock !=null and stock != ''">
             and t.stock= #{stock}
         </if>
+        <if test="startTime !=null and startTime != ''">
+            and t.start_time= #{startTime}
+        </if>
         <if test="communityId !=null and communityId != ''">
             and t.community_id= #{communityId}
         </if>
@@ -104,16 +107,20 @@
         <if test="stock !=null and stock != ''">
             , t.stock= #{stock}
         </if>
-        <if test="communityId !=null and communityId != ''">
-            , t.community_id= #{communityId}
-        </if>
+
         <if test="value !=null and value != ''">
             , t.value= #{value}
         </if>
+        <if test="startTime !=null and startTime != ''">
+            , t.start_time= #{startTime}
+        </if>
         where 1=1
         <if test="couponId !=null and couponId != ''">
             and t.coupon_id= #{couponId}
         </if>
+        <if test="communityId !=null and communityId != ''">
+            and t.community_id= #{communityId}
+        </if>
 
     </update>
 
@@ -161,6 +168,9 @@
         <if test="value !=null and value != ''">
             and t.value= #{value}
         </if>
+        <if test="startTime !=null and startTime != ''">
+            and t.start_time= #{startTime}
+        </if>
 
 
     </select>

+ 29 - 5
service-job/src/main/java/com/java110/job/adapt/payment/coupon/PayFeeGiftCouponAdapt.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.core.log.LoggerFactory;
+import com.java110.core.smo.IComputeFeeSMO;
 import com.java110.dto.couponPropertyPool.CouponPropertyPoolDto;
 import com.java110.dto.couponPropertyPoolConfig.CouponPropertyPoolConfigDto;
 import com.java110.dto.couponPropertyUser.CouponPropertyUserDto;
@@ -24,6 +25,7 @@ import com.java110.job.adapt.DatabusAdaptImpl;
 import com.java110.po.couponPropertyPool.CouponPropertyPoolPo;
 import com.java110.po.couponPropertyPoolDetail.CouponPropertyPoolDetailPo;
 import com.java110.po.couponPropertyUser.CouponPropertyUserPo;
+import com.java110.po.couponRuleCpps.CouponRuleCppsPo;
 import com.java110.po.fee.PayFeeDetailPo;
 import com.java110.po.logSystemError.LogSystemErrorPo;
 import com.java110.service.smo.ISaveSystemErrorSMO;
@@ -36,9 +38,7 @@ import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * 缴费 赠送 优惠券
@@ -85,6 +85,10 @@ public class PayFeeGiftCouponAdapt extends DatabusAdaptImpl {
     @Autowired
     private ICouponPropertyUserV1InnerServiceSMO couponPropertyUserV1InnerServiceSMOImpl;
 
+
+    @Autowired
+    private IComputeFeeSMO computeFeeSMOImpl;
+
     //模板信息推送地址
     private static String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";
 
@@ -187,9 +191,28 @@ public class PayFeeGiftCouponAdapt extends DatabusAdaptImpl {
      */
     private void giftCoupon(List<CouponRuleCppsDto> couponRuleCppsDtos, FeeDto feeDto, PayFeeDetailPo payFeeDetailPo) {
 
+        Date startTime = null;
+        Date endTime = null;
         for (CouponRuleCppsDto couponRuleCppsDto : couponRuleCppsDtos) {
             try {
-                doGiftCoupon(couponRuleCppsDto, feeDto, payFeeDetailPo);
+                if(CouponRuleCppsDto.FREQUENCY_ONCE.equals(couponRuleCppsDto.getGiftFrequency())) { // 只赠送一次
+                    doGiftCoupon(couponRuleCppsDto, feeDto, DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B));
+                }else if(CouponRuleCppsDto.FREQUENCY_MONTH.equals(couponRuleCppsDto.getGiftFrequency())){ // 每月赠送
+                    startTime = DateUtil.getDateFromString(payFeeDetailPo.getStartTime(), DateUtil.DATE_FORMATE_STRING_B);
+                    endTime = DateUtil.getDateFromString(payFeeDetailPo.getEndTime(), DateUtil.DATE_FORMATE_STRING_B);
+                    double maxMonth = Math.ceil(computeFeeSMOImpl.dayCompare(startTime, endTime));
+                    if (maxMonth < 1) {
+                        doGiftCoupon(couponRuleCppsDto, feeDto, DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_B));
+                        continue;
+                    }
+                    Calendar calendar = Calendar.getInstance();
+                    for (int month = 0; month < maxMonth; month++) {
+                        calendar.setTime(startTime);
+                        calendar.add(Calendar.MONTH, month);
+                        calendar.set(Calendar.DAY_OF_MONTH,1);
+                        doGiftCoupon(couponRuleCppsDto, feeDto, DateUtil.getFormatTimeString(calendar.getTime(),DateUtil.DATE_FORMATE_STRING_B));
+                    }
+                }
             } catch (Exception e) {
                 LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo();
                 logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId));
@@ -202,7 +225,7 @@ public class PayFeeGiftCouponAdapt extends DatabusAdaptImpl {
 
     }
 
-    private void doGiftCoupon(CouponRuleCppsDto couponRuleCppsDto, FeeDto feeDto, PayFeeDetailPo payFeeDetailPo) {
+    private void doGiftCoupon(CouponRuleCppsDto couponRuleCppsDto, FeeDto feeDto, String startTime) {
 
 
         String requestId = DistributedLock.getLockUUID();
@@ -276,6 +299,7 @@ public class PayFeeGiftCouponAdapt extends DatabusAdaptImpl {
             couponPropertyUserPo.setUserName(FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_NAME));
             couponPropertyUserPo.setTel(FeeAttrDto.getFeeAttrValue(feeDto, FeeAttrDto.SPEC_CD_OWNER_LINK));
             couponPropertyUserPo.setValue(value);
+            couponPropertyUserPo.setStartTime(startTime);
             couponPropertyUserV1InnerServiceSMOImpl.saveCouponPropertyUser(couponPropertyUserPo);
             //这里更新功能 关闭 因为优惠券有有效期 如果 修改显然不合适 modify by  2022-11-24 wuxw
 //            }else{