JK пре 3 година
родитељ
комит
d5322b54b2

+ 32 - 0
YijiaRestful/src/main/java/com/platform/yijia/controller/CouponController.java

@@ -393,6 +393,38 @@ public class CouponController {
         return gson.toJson(resultData);
     }
 
+    //异业端核销优惠券,兑换券
+    @RequestMapping(value = "/writeOffCoupon", method = RequestMethod.GET)
+    @ResponseBody
+    @Transactional
+    @ApiOperation(value = "获取优惠券信息", httpMethod = "GET", notes = "获取优惠券信息")
+    public String writeOffCoupon(@ApiParam(value = "优惠券核销编码", required = true) @RequestParam String couponNo){
+        Gson gson =new Gson();
+        ResultData resultData = null;
+        try {
+            UserCoupon userCoupon = new UserCoupon();
+            userCoupon.setCouponNo(couponNo);
+            UserCoupon userCouponInfo = couponService.selectUserCouponInfo(userCoupon);
+            if(userCouponInfo !=null){
+                userCoupon.setCouponIsUsed("1");
+                couponService.updateCouponUserInfo(userCoupon);
+                CouponVerification couponVerification = new CouponVerification();
+                couponVerification.setCouponUserId(userCouponInfo.getId());
+                couponVerification.setCreateTime(new Date());
+                couponVerification.setVerification(userCouponInfo.getStationId().toString());
+                couponService.addCouponVerificationRecord(couponVerification);
+                resultData = ResultData.success("核销成功!");
+            }else {
+                resultData = ResultData.error(CodeMsg.NO_COUPON);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return  gson.toJson(resultData);
+    }
+
+
+
     /***
      * //营销方案活动日优惠
      * @param discountType              活动日时间类型

+ 7 - 4
YijiaRestful/src/main/java/com/platform/yijia/dao/CouponMapper.java

@@ -1,10 +1,7 @@
 package com.platform.yijia.dao;
 
 
-import com.platform.yijia.pojo.Coupon;
-import com.platform.yijia.pojo.CouponIssue;
-import com.platform.yijia.pojo.CouponUserGiveCount;
-import com.platform.yijia.pojo.UserCoupon;
+import com.platform.yijia.pojo.*;
 
 import java.util.List;
 
@@ -39,4 +36,10 @@ public interface CouponMapper {
 
     //更新用户进入领取页面次数
     void addCouponUserGiveCount(CouponUserGiveCount couponUserGiveCount);
+
+    //更新用户优惠券状态
+    void updateCouponUserInfo(UserCoupon userCoupon);
+
+    //添加核销记录
+    void addCouponVerificationRecord(CouponVerification couponVerification);
 }

+ 6 - 4
YijiaRestful/src/main/java/com/platform/yijia/pojo/CouponVerification.java

@@ -2,14 +2,16 @@ package com.platform.yijia.pojo;
 
 import lombok.Data;
 
+import java.util.Date;
+
 /**
  * 兑换券核销站点表
  */
 @Data
 public class CouponVerification {
     private Integer couponVerificationId;   //主键
-    Integer couponId;               //优惠券Id
-    private Integer verificationStationId;                 //优惠券Id
-    private String verification;            //站点
-    private String verificationName;        //
+    private Integer couponUserId;            //用户领取的优惠券Id
+    private String verification;            //优惠券核销站点Id
+    private String verificationName;        //核销站点名称
+    private Date createTime;                //创建时间
 }

+ 7 - 4
YijiaRestful/src/main/java/com/platform/yijia/service/CouponService.java

@@ -1,10 +1,7 @@
 package com.platform.yijia.service;
 
 
-import com.platform.yijia.pojo.Coupon;
-import com.platform.yijia.pojo.CouponIssue;
-import com.platform.yijia.pojo.CouponUserGiveCount;
-import com.platform.yijia.pojo.UserCoupon;
+import com.platform.yijia.pojo.*;
 
 import java.util.List;
 
@@ -39,4 +36,10 @@ public interface CouponService {
 
     //更新用户进入领取页面次数
     void addCouponUserGiveCount(CouponUserGiveCount couponUserGiveCount);
+
+    //更新用户优惠券状态
+    void updateCouponUserInfo(UserCoupon userCoupon);
+
+    //添加核销记录
+    void addCouponVerificationRecord(CouponVerification couponVerification);
 }

+ 13 - 4
YijiaRestful/src/main/java/com/platform/yijia/service/impl/CouponServiceImpl.java

@@ -1,10 +1,7 @@
 package com.platform.yijia.service.impl;
 
 import com.platform.yijia.dao.CouponMapper;
-import com.platform.yijia.pojo.Coupon;
-import com.platform.yijia.pojo.CouponIssue;
-import com.platform.yijia.pojo.CouponUserGiveCount;
-import com.platform.yijia.pojo.UserCoupon;
+import com.platform.yijia.pojo.*;
 import com.platform.yijia.service.CouponService;
 import org.springframework.stereotype.Service;
 
@@ -71,6 +68,18 @@ public class CouponServiceImpl implements CouponService {
         return couponMapper.addUserCoupon(userCoupon);
     }
 
+    //更新用户优惠券状态
+    @Override
+    public void updateCouponUserInfo(UserCoupon userCoupon) {
+        couponMapper.updateCouponUserInfo(userCoupon);
+    }
+
+    //添加核销记录
+    @Override
+    public void addCouponVerificationRecord(CouponVerification couponVerification) {
+        couponMapper.addCouponVerificationRecord(couponVerification);
+    }
+
     //用户已领取的优惠券数量
     @Override
     public int selectUserCouponCount(UserCoupon userCoupon) {

+ 60 - 0
YijiaRestful/src/main/resources/mapper/CouponMapper.xml

@@ -336,6 +336,63 @@
         </where>
     </update>
 
+    <!-- 更新用户订单信息-->
+    <update id="updateCouponUserInfo" parameterType="com.platform.yijia.pojo.UserCoupon">
+        UPDATE coupon_user
+        <set>
+            <if test="updateTime != null">
+                update_time = #{updateTime},
+            </if>
+            <if test="couponIsUsed != null">
+                coupon_is_used = #{couponIsUsed},
+            </if>
+        </set>
+        <where>
+            <if test="unionId !=null and unionId !=''">
+                union_id = #{unionId}
+            </if>
+            <if test="stationId !=null">
+                AND station_id = #{stationId}
+            </if>
+            <if test="couponIsUsed !=null and couponIsUsed !=''">
+                AND coupon_is_used = #{couponIsUsed}
+            </if>
+            <if test="couponNo !=null and couponNo !=''">
+                AND coupon_no = #{couponNo}
+            </if>
+            <if test="id !=null">
+                AND id = #{id}
+            </if>
+        </where>
+    </update>
+
+    <!--新增用户进入领取页面的次数-->
+    <insert id="addCouponVerificationRecord"  parameterType="com.platform.yijia.pojo.CouponVerification" >
+        INSERT INTO coupon_verification_record
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="couponUserId !=null">
+                coupon_user_id,
+            </if>
+            <if test="verification !=null">
+                verification,
+            </if>
+            <if test="createTime !=null">
+                create_time,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="couponUserId !=null">
+                #{couponUserId},
+            </if>
+            <if test="verification !=null">
+                #{verification},
+            </if>
+            <if test="createTime !=null">
+                #{createTime},
+            </if>
+        </trim>
+    </insert>
+
     <!--新增用户进入领取页面的次数-->
     <insert id="addCouponUserGiveCount"  parameterType="com.platform.yijia.pojo.CouponUserGiveCount" >
         INSERT INTO coupon_user_give_count
@@ -393,6 +450,9 @@
           <if test="id !=null">
             T1.id = #{id}
           </if>
+            <if test="couponNo !=null">
+                T1.coupon_no = #{couponNo}
+            </if>
         </where>
   </select>