Browse Source

feat[litemall-db, litemall-wx-api]: 字段调整,更新代码

Junling Bu 7 years ago
parent
commit
a831c94899

+ 74 - 0
litemall-db/src/main/java/org/linlinjava/litemall/db/domain/LitemallCouponUser.java

@@ -71,6 +71,24 @@ public class LitemallCouponUser {
     /**
      *
      * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column litemall_coupon_user.start_time
+     *
+     * @mbg.generated
+     */
+    private LocalDateTime startTime;
+
+    /**
+     *
+     * This field was generated by MyBatis Generator.
+     * This field corresponds to the database column litemall_coupon_user.end_time
+     *
+     * @mbg.generated
+     */
+    private LocalDateTime endTime;
+
+    /**
+     *
+     * This field was generated by MyBatis Generator.
      * This field corresponds to the database column litemall_coupon_user.order_id
      *
      * @mbg.generated
@@ -226,6 +244,54 @@ public class LitemallCouponUser {
 
     /**
      * This method was generated by MyBatis Generator.
+     * This method returns the value of the database column litemall_coupon_user.start_time
+     *
+     * @return the value of litemall_coupon_user.start_time
+     *
+     * @mbg.generated
+     */
+    public LocalDateTime getStartTime() {
+        return startTime;
+    }
+
+    /**
+     * This method was generated by MyBatis Generator.
+     * This method sets the value of the database column litemall_coupon_user.start_time
+     *
+     * @param startTime the value for litemall_coupon_user.start_time
+     *
+     * @mbg.generated
+     */
+    public void setStartTime(LocalDateTime startTime) {
+        this.startTime = startTime;
+    }
+
+    /**
+     * This method was generated by MyBatis Generator.
+     * This method returns the value of the database column litemall_coupon_user.end_time
+     *
+     * @return the value of litemall_coupon_user.end_time
+     *
+     * @mbg.generated
+     */
+    public LocalDateTime getEndTime() {
+        return endTime;
+    }
+
+    /**
+     * This method was generated by MyBatis Generator.
+     * This method sets the value of the database column litemall_coupon_user.end_time
+     *
+     * @param endTime the value for litemall_coupon_user.end_time
+     *
+     * @mbg.generated
+     */
+    public void setEndTime(LocalDateTime endTime) {
+        this.endTime = endTime;
+    }
+
+    /**
+     * This method was generated by MyBatis Generator.
      * This method returns the value of the database column litemall_coupon_user.order_id
      *
      * @return the value of litemall_coupon_user.order_id
@@ -337,6 +403,8 @@ public class LitemallCouponUser {
         sb.append(", couponId=").append(couponId);
         sb.append(", status=").append(status);
         sb.append(", usedTime=").append(usedTime);
+        sb.append(", startTime=").append(startTime);
+        sb.append(", endTime=").append(endTime);
         sb.append(", orderId=").append(orderId);
         sb.append(", addTime=").append(addTime);
         sb.append(", updateTime=").append(updateTime);
@@ -368,6 +436,8 @@ public class LitemallCouponUser {
             && (this.getCouponId() == null ? other.getCouponId() == null : this.getCouponId().equals(other.getCouponId()))
             && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
             && (this.getUsedTime() == null ? other.getUsedTime() == null : this.getUsedTime().equals(other.getUsedTime()))
+            && (this.getStartTime() == null ? other.getStartTime() == null : this.getStartTime().equals(other.getStartTime()))
+            && (this.getEndTime() == null ? other.getEndTime() == null : this.getEndTime().equals(other.getEndTime()))
             && (this.getOrderId() == null ? other.getOrderId() == null : this.getOrderId().equals(other.getOrderId()))
             && (this.getAddTime() == null ? other.getAddTime() == null : this.getAddTime().equals(other.getAddTime()))
             && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
@@ -389,6 +459,8 @@ public class LitemallCouponUser {
         result = prime * result + ((getCouponId() == null) ? 0 : getCouponId().hashCode());
         result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
         result = prime * result + ((getUsedTime() == null) ? 0 : getUsedTime().hashCode());
+        result = prime * result + ((getStartTime() == null) ? 0 : getStartTime().hashCode());
+        result = prime * result + ((getEndTime() == null) ? 0 : getEndTime().hashCode());
         result = prime * result + ((getOrderId() == null) ? 0 : getOrderId().hashCode());
         result = prime * result + ((getAddTime() == null) ? 0 : getAddTime().hashCode());
         result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
@@ -420,6 +492,8 @@ public class LitemallCouponUser {
         couponId("coupon_id", "couponId", "INTEGER", false),
         status("status", "status", "SMALLINT", true),
         usedTime("used_time", "usedTime", "TIMESTAMP", false),
+        startTime("start_time", "startTime", "TIMESTAMP", false),
+        endTime("end_time", "endTime", "TIMESTAMP", false),
         orderId("order_id", "orderId", "INTEGER", false),
         addTime("add_time", "addTime", "TIMESTAMP", false),
         updateTime("update_time", "updateTime", "TIMESTAMP", false),

+ 264 - 0
litemall-db/src/main/java/org/linlinjava/litemall/db/domain/LitemallCouponUserExample.java

@@ -898,6 +898,270 @@ public class LitemallCouponUserExample {
             return (Criteria) this;
         }
 
+        public Criteria andStartTimeIsNull() {
+            addCriterion("start_time is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeIsNotNull() {
+            addCriterion("start_time is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeEqualTo(LocalDateTime value) {
+            addCriterion("start_time =", value, "startTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andStartTimeEqualToColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("start_time = ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeNotEqualTo(LocalDateTime value) {
+            addCriterion("start_time <>", value, "startTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andStartTimeNotEqualToColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("start_time <> ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeGreaterThan(LocalDateTime value) {
+            addCriterion("start_time >", value, "startTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andStartTimeGreaterThanColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("start_time > ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeGreaterThanOrEqualTo(LocalDateTime value) {
+            addCriterion("start_time >=", value, "startTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andStartTimeGreaterThanOrEqualToColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("start_time >= ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeLessThan(LocalDateTime value) {
+            addCriterion("start_time <", value, "startTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andStartTimeLessThanColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("start_time < ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeLessThanOrEqualTo(LocalDateTime value) {
+            addCriterion("start_time <=", value, "startTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andStartTimeLessThanOrEqualToColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("start_time <= ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeIn(List<LocalDateTime> values) {
+            addCriterion("start_time in", values, "startTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeNotIn(List<LocalDateTime> values) {
+            addCriterion("start_time not in", values, "startTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeBetween(LocalDateTime value1, LocalDateTime value2) {
+            addCriterion("start_time between", value1, value2, "startTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andStartTimeNotBetween(LocalDateTime value1, LocalDateTime value2) {
+            addCriterion("start_time not between", value1, value2, "startTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeIsNull() {
+            addCriterion("end_time is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeIsNotNull() {
+            addCriterion("end_time is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeEqualTo(LocalDateTime value) {
+            addCriterion("end_time =", value, "endTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andEndTimeEqualToColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("end_time = ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeNotEqualTo(LocalDateTime value) {
+            addCriterion("end_time <>", value, "endTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andEndTimeNotEqualToColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("end_time <> ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeGreaterThan(LocalDateTime value) {
+            addCriterion("end_time >", value, "endTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andEndTimeGreaterThanColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("end_time > ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeGreaterThanOrEqualTo(LocalDateTime value) {
+            addCriterion("end_time >=", value, "endTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andEndTimeGreaterThanOrEqualToColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("end_time >= ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeLessThan(LocalDateTime value) {
+            addCriterion("end_time <", value, "endTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andEndTimeLessThanColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("end_time < ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeLessThanOrEqualTo(LocalDateTime value) {
+            addCriterion("end_time <=", value, "endTime");
+            return (Criteria) this;
+        }
+
+        /**
+         * This method was generated by MyBatis Generator.
+         * This method corresponds to the database table litemall_coupon_user
+         *
+         * @mbg.generated
+         * @project https://github.com/itfsw/mybatis-generator-plugin
+         */
+        public Criteria andEndTimeLessThanOrEqualToColumn(LitemallCouponUser.Column column) {
+            addCriterion(new StringBuilder("end_time <= ").append(column.getEscapedColumnName()).toString());
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeIn(List<LocalDateTime> values) {
+            addCriterion("end_time in", values, "endTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeNotIn(List<LocalDateTime> values) {
+            addCriterion("end_time not in", values, "endTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeBetween(LocalDateTime value1, LocalDateTime value2) {
+            addCriterion("end_time between", value1, value2, "endTime");
+            return (Criteria) this;
+        }
+
+        public Criteria andEndTimeNotBetween(LocalDateTime value1, LocalDateTime value2) {
+            addCriterion("end_time not between", value1, value2, "endTime");
+            return (Criteria) this;
+        }
+
         public Criteria andOrderIdIsNull() {
             addCriterion("order_id is null");
             return (Criteria) this;

+ 10 - 0
litemall-db/src/main/java/org/linlinjava/litemall/db/service/CouponAssignService.java

@@ -39,6 +39,16 @@ public class CouponAssignService {
                 LitemallCouponUser couponUser = new LitemallCouponUser();
                 couponUser.setCouponId(couponId);
                 couponUser.setUserId(userId);
+                Short timeType = coupon.getTimeType();
+                if (timeType.equals(CouponConstant.TIME_TYPE_TIME)) {
+                    couponUser.setStartTime(coupon.getStartTime());
+                    couponUser.setEndTime(coupon.getEndTime());
+                }
+                else{
+                    LocalDateTime now = LocalDateTime.now();
+                    couponUser.setStartTime(now);
+                    couponUser.setEndTime(now.plusDays(coupon.getDays()));
+                }
                 couponUserService.add(couponUser);
 
                 limit--;

+ 12 - 0
litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCouponService.java

@@ -167,4 +167,16 @@ public class LitemallCouponService {
         }
         return code;
     }
+
+    /**
+     * 查询过期的优惠券:
+     * 注意:如果timeType=0, 即基于领取时间有效期的优惠券,则优惠券不会过期
+     *
+     * @return
+     */
+    public List<LitemallCoupon> queryExpired() {
+        LitemallCouponExample example = new LitemallCouponExample();
+        example.or().andStatusEqualTo(CouponConstant.STATUS_NORMAL).andTimeTypeEqualTo(CouponConstant.TIME_TYPE_TIME).andEndTimeLessThan(LocalDateTime.now()).andDeletedEqualTo(false);
+        return couponMapper.selectByExample(example);
+    }
 }

+ 6 - 0
litemall-db/src/main/java/org/linlinjava/litemall/db/service/LitemallCouponUserService.java

@@ -111,4 +111,10 @@ public class LitemallCouponUserService {
         couponUser.setUpdateTime(LocalDateTime.now());
         return couponUserMapper.updateByPrimaryKeySelective(couponUser);
     }
+
+    public List<LitemallCouponUser> queryExpired() {
+        LitemallCouponUserExample example = new LitemallCouponUserExample();
+        example.or().andStatusEqualTo(CouponUserConstant.STATUS_USABLE).andEndTimeLessThan(LocalDateTime.now()).andDeletedEqualTo(false);
+        return couponUserMapper.selectByExample(example);
+    }
 }

+ 44 - 11
litemall-db/src/main/resources/org/linlinjava/litemall/db/dao/LitemallCouponUserMapper.xml

@@ -11,6 +11,8 @@
     <result column="coupon_id" jdbcType="INTEGER" property="couponId" />
     <result column="status" jdbcType="SMALLINT" property="status" />
     <result column="used_time" jdbcType="TIMESTAMP" property="usedTime" />
+    <result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
+    <result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
     <result column="order_id" jdbcType="INTEGER" property="orderId" />
     <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
@@ -87,7 +89,8 @@
       WARNING - @mbg.generated
       This element is automatically generated by MyBatis Generator, do not modify.
     -->
-    id, user_id, coupon_id, `status`, used_time, order_id, add_time, update_time, deleted
+    id, user_id, coupon_id, `status`, used_time, start_time, end_time, order_id, add_time, 
+    update_time, deleted
   </sql>
   <select id="selectByExample" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponUserExample" resultMap="BaseResultMap">
     <!--
@@ -124,8 +127,8 @@
         </foreach>
       </when>
       <otherwise>
-        id, user_id, coupon_id, `status`, used_time, order_id, add_time, update_time, deleted
-          
+        id, user_id, coupon_id, `status`, used_time, start_time, end_time, order_id, add_time, 
+          update_time, deleted
       </otherwise>
     </choose>
     from litemall_coupon_user
@@ -184,8 +187,8 @@
         </foreach>
       </when>
       <otherwise>
-        id, user_id, coupon_id, `status`, used_time, order_id, add_time, update_time, deleted
-          
+        id, user_id, coupon_id, `status`, used_time, start_time, end_time, order_id, add_time, 
+          update_time, deleted
       </otherwise>
     </choose>
     from litemall_coupon_user
@@ -218,11 +221,13 @@
       SELECT LAST_INSERT_ID()
     </selectKey>
     insert into litemall_coupon_user (user_id, coupon_id, `status`, 
-      used_time, order_id, add_time, 
-      update_time, deleted)
+      used_time, start_time, end_time, 
+      order_id, add_time, update_time, 
+      deleted)
     values (#{userId,jdbcType=INTEGER}, #{couponId,jdbcType=INTEGER}, #{status,jdbcType=SMALLINT}, 
-      #{usedTime,jdbcType=TIMESTAMP}, #{orderId,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP}, 
-      #{updateTime,jdbcType=TIMESTAMP}, #{deleted,jdbcType=BIT})
+      #{usedTime,jdbcType=TIMESTAMP}, #{startTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, 
+      #{orderId,jdbcType=INTEGER}, #{addTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, 
+      #{deleted,jdbcType=BIT})
   </insert>
   <insert id="insertSelective" parameterType="org.linlinjava.litemall.db.domain.LitemallCouponUser">
     <!--
@@ -246,6 +251,12 @@
       <if test="usedTime != null">
         used_time,
       </if>
+      <if test="startTime != null">
+        start_time,
+      </if>
+      <if test="endTime != null">
+        end_time,
+      </if>
       <if test="orderId != null">
         order_id,
       </if>
@@ -272,6 +283,12 @@
       <if test="usedTime != null">
         #{usedTime,jdbcType=TIMESTAMP},
       </if>
+      <if test="startTime != null">
+        #{startTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="endTime != null">
+        #{endTime,jdbcType=TIMESTAMP},
+      </if>
       <if test="orderId != null">
         #{orderId,jdbcType=INTEGER},
       </if>
@@ -318,6 +335,12 @@
       <if test="record.usedTime != null">
         used_time = #{record.usedTime,jdbcType=TIMESTAMP},
       </if>
+      <if test="record.startTime != null">
+        start_time = #{record.startTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="record.endTime != null">
+        end_time = #{record.endTime,jdbcType=TIMESTAMP},
+      </if>
       <if test="record.orderId != null">
         order_id = #{record.orderId,jdbcType=INTEGER},
       </if>
@@ -346,6 +369,8 @@
       coupon_id = #{record.couponId,jdbcType=INTEGER},
       `status` = #{record.status,jdbcType=SMALLINT},
       used_time = #{record.usedTime,jdbcType=TIMESTAMP},
+      start_time = #{record.startTime,jdbcType=TIMESTAMP},
+      end_time = #{record.endTime,jdbcType=TIMESTAMP},
       order_id = #{record.orderId,jdbcType=INTEGER},
       add_time = #{record.addTime,jdbcType=TIMESTAMP},
       update_time = #{record.updateTime,jdbcType=TIMESTAMP},
@@ -373,6 +398,12 @@
       <if test="usedTime != null">
         used_time = #{usedTime,jdbcType=TIMESTAMP},
       </if>
+      <if test="startTime != null">
+        start_time = #{startTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="endTime != null">
+        end_time = #{endTime,jdbcType=TIMESTAMP},
+      </if>
       <if test="orderId != null">
         order_id = #{orderId,jdbcType=INTEGER},
       </if>
@@ -398,6 +429,8 @@
       coupon_id = #{couponId,jdbcType=INTEGER},
       `status` = #{status,jdbcType=SMALLINT},
       used_time = #{usedTime,jdbcType=TIMESTAMP},
+      start_time = #{startTime,jdbcType=TIMESTAMP},
+      end_time = #{endTime,jdbcType=TIMESTAMP},
       order_id = #{orderId,jdbcType=INTEGER},
       add_time = #{addTime,jdbcType=TIMESTAMP},
       update_time = #{updateTime,jdbcType=TIMESTAMP},
@@ -435,8 +468,8 @@
         </foreach>
       </when>
       <otherwise>
-        id, user_id, coupon_id, `status`, used_time, order_id, add_time, update_time, deleted
-          
+        id, user_id, coupon_id, `status`, used_time, start_time, end_time, order_id, add_time, 
+          update_time, deleted
       </otherwise>
     </choose>
     from litemall_coupon_user

+ 22 - 11
litemall-wx-api/src/main/java/org/linlinjava/litemall/wx/web/WxCouponController.java

@@ -113,16 +113,9 @@ public class WxCouponController {
             couponVo.setTag(coupon.getTag());
             couponVo.setMin(coupon.getMin().toPlainString());
             couponVo.setDiscount(coupon.getDiscount().toPlainString());
+            couponVo.setStartTime(couponUser.getStartTime());
+            couponVo.setEndTime(couponUser.getEndTime());
 
-            Short timeType = coupon.getTimeType();
-            if (timeType.equals(CouponConstant.TIME_TYPE_TIME)) {
-                couponVo.setStartTime(coupon.getStartTime());
-                couponVo.setEndTime(coupon.getEndTime());
-            }
-            else{
-                couponVo.setStartTime(coupon.getAddTime());
-                couponVo.setEndTime(coupon.getAddTime().plusDays(coupon.getDays()));
-            }
             couponVoList.add(couponVo);
         }
 
@@ -252,7 +245,16 @@ public class WxCouponController {
         LitemallCouponUser couponUser = new LitemallCouponUser();
         couponUser.setCouponId(couponId);
         couponUser.setUserId(userId);
-
+        Short timeType = coupon.getTimeType();
+        if (timeType.equals(CouponConstant.TIME_TYPE_TIME)) {
+            couponUser.setStartTime(coupon.getStartTime());
+            couponUser.setEndTime(coupon.getEndTime());
+        }
+        else{
+            LocalDateTime now = LocalDateTime.now();
+            couponUser.setStartTime(now);
+            couponUser.setEndTime(now.plusDays(coupon.getDays()));
+        }
         couponUserService.add(couponUser);
 
         return ResponseUtil.ok();
@@ -322,7 +324,16 @@ public class WxCouponController {
         LitemallCouponUser couponUser = new LitemallCouponUser();
         couponUser.setCouponId(couponId);
         couponUser.setUserId(userId);
-
+        Short timeType = coupon.getTimeType();
+        if (timeType.equals(CouponConstant.TIME_TYPE_TIME)) {
+            couponUser.setStartTime(coupon.getStartTime());
+            couponUser.setEndTime(coupon.getEndTime());
+        }
+        else{
+            LocalDateTime now = LocalDateTime.now();
+            couponUser.setStartTime(now);
+            couponUser.setEndTime(now.plusDays(coupon.getDays()));
+        }
         couponUserService.add(couponUser);
 
         return ResponseUtil.ok();