浏览代码

一签一码

jk-GitHub-coder 3 年之前
父节点
当前提交
a94a4f27b3

+ 70 - 0
YijiaRestful/src/main/java/com/platform/yijia/controller/LabelController.java

@@ -0,0 +1,70 @@
+package com.platform.yijia.controller;
+
+import com.google.gson.Gson;
+import com.platform.yijia.config.YiJiaRequest;
+import com.platform.yijia.pojo.CustomerLabel;
+import com.platform.yijia.service.LabelService;
+import com.platform.yijia.utils.CodeMsg;
+import com.platform.yijia.utils.ResultData;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.Date;
+
+/*
+ * <Title> LabelController </Title>
+ * <Description> 标签模块 </Description>
+ * @Author JK
+ * @Date 2021年7月15日
+ */
+@Controller
+@YiJiaRequest()
+@CrossOrigin
+@Api(tags = "标签")
+public class LabelController {
+    private static Logger logger =(Logger) LoggerFactory.getLogger(LabelController.class);
+
+    @Resource
+    private LabelService labelService;
+    //用户扫码进标签
+    @RequestMapping(value = "/addUserToLabel", method = RequestMethod.GET)
+    @ResponseBody
+    @ApiOperation(value = "用户扫码进标签", httpMethod = "GET", notes = "用户扫码进标签")
+    public String addUserToLabel(@ApiParam(value = "油站ID", required = true) @RequestParam Integer stationId,
+                                 @ApiParam(value = "手机号", required = true) @RequestParam String phone,
+                                 @ApiParam(value = "标签ID", required = true) @RequestParam String labelId,
+                                 @ApiParam(value = "创建人", required = true) @RequestParam String createBy){
+        Gson gson =new Gson();
+        ResultData resultData = null;       //返回结果集
+        try {
+            CustomerLabel customerLabel = new CustomerLabel();
+            customerLabel.setStationId(stationId);
+            customerLabel.setPhone(phone);
+            //获取该标签用户信息
+            CustomerLabel c = labelService.getCustomerLabel(customerLabel);
+            if(c !=null){
+                customerLabel.setLabelId(labelId);
+                customerLabel.setUpdateBy(createBy);
+                customerLabel.setUpdateTime(new Date());
+                labelService.updateCustomerLabel(customerLabel);
+            }else {
+                customerLabel.setCreateBy(createBy);
+                customerLabel.setCreateTime(new Date());
+                customerLabel.setDelFlag("0");
+                customerLabel.setLabelId(labelId);
+                labelService.insertCustomerLabel(customerLabel);
+            }
+            resultData = ResultData.success(CodeMsg.SUCCESS);
+        }catch (Exception e){
+            logger.info("用户扫码进标签错误信息: "+  e.getMessage());
+            resultData = ResultData.error(CodeMsg.YEWU_FAIL);
+        }
+        return gson.toJson(resultData);
+    }
+}

+ 31 - 22
YijiaRestful/src/main/java/com/platform/yijia/controller/PayOrderController.java

@@ -257,33 +257,42 @@ public class PayOrderController {
             payOrderResultInfo = this.calculateLngGroupStaDiscount(params);
 
         }else {
-            //按照正常优惠计算
             CustomerLabel customerLabel = new CustomerLabel();
             customerLabel.setPhone(payOrderRequest.getCustomerPhone());
             customerLabel.setStationId(payOrderRequest.getStationId());
-            CustomerLabel customerLabelInfo = labelService.getCustomerLabel(customerLabel); //获取该用户是否在标签组内
-            if(payOrderRequest.getLabelFlag() !=null && payOrderRequest.getLabelFlag().equals("1") && customerLabelInfo !=null){
-                //表示此用户为标签用户,计算标签用户优惠
-                params.put("labelId", customerLabelInfo.getLabelId());
+            //扫码进标签优惠:一码一签
+            if(payOrderRequest.getLabelId() !=null){
+                //如果前端传来labelId,则表示一码一签;
+                params.put("labelId", payOrderRequest.getLabelId());
                 payOrderResultInfo = this.calculateLabelDiscount(params);
+                //只要走次标签码,则不管该用户在何标签组,都将强行拉入此标签组;
+                labelService.updateCustomerLabel(customerLabel);
             }else {
-                //不为标签用户时
-                switch (discountSetting){
-                    case "0":   //不执营销方案时 计算等级优惠
-                        payOrderResultInfo = this.calculateGradeDiscount(params);
-                        break;
-                    case "1":    //满减方案
-                        payOrderResultInfo = this.calculateManJianDiscount(params);
-                        break;
-                    case "2":    //立减方案
-                        payOrderResultInfo = this.calculateLiJianDiscount(params);
-                        break;
-                    case "3":    //独立直降
-                        payOrderResultInfo = this.calculateZhiJiangDiscount(params);
-                        break;
-                    case "4":    //计算阶梯直降
-                        payOrderResultInfo = this.calculateJieTiZhiJiangDiscount(params);
-                        break;
+                //按照正常优惠计算
+                CustomerLabel customerLabelInfo = labelService.getCustomerLabel(customerLabel); //获取该用户是否在标签组内
+                if(payOrderRequest.getLabelFlag() !=null && payOrderRequest.getLabelFlag().equals("1") && customerLabelInfo !=null){
+                    //表示此用户为标签用户,计算标签用户优惠
+                    params.put("labelId", customerLabelInfo.getLabelId());
+                    payOrderResultInfo = this.calculateLabelDiscount(params);
+                }else {
+                    //不为标签用户时
+                    switch (discountSetting){
+                        case "0":   //不执营销方案时 计算等级优惠
+                            payOrderResultInfo = this.calculateGradeDiscount(params);
+                            break;
+                        case "1":    //满减方案
+                            payOrderResultInfo = this.calculateManJianDiscount(params);
+                            break;
+                        case "2":    //立减方案
+                            payOrderResultInfo = this.calculateLiJianDiscount(params);
+                            break;
+                        case "3":    //独立直降
+                            payOrderResultInfo = this.calculateZhiJiangDiscount(params);
+                            break;
+                        case "4":    //计算阶梯直降
+                            payOrderResultInfo = this.calculateJieTiZhiJiangDiscount(params);
+                            break;
+                    }
                 }
             }
         }

+ 6 - 0
YijiaRestful/src/main/java/com/platform/yijia/dao/LabelMapper.java

@@ -13,4 +13,10 @@ public interface LabelMapper {
     //获取油站标签用户列
     CustomerLabel getCustomerLabel(CustomerLabel customerLabel);
 
+    //更新用户新标签组
+    void updateCustomerLabel(CustomerLabel customerLabel);
+
+    //新增标签用户
+    void insertCustomerLabel(CustomerLabel customerLabel);
+
 }

+ 1 - 1
YijiaRestful/src/main/java/com/platform/yijia/pojo/CustomerLabel.java

@@ -15,7 +15,7 @@ public class CustomerLabel {
     private Integer stationId;        //油站ID
     private String createBy;          //创建人
     private Date createTime;          //创建时间
-    private String update_by;         //修改人
+    private String updateBy;         //修改人
     private Date updateTime;          //修改人
     private String delFlag;           //删除 1是 0否
 }

+ 6 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/LabelService.java

@@ -14,4 +14,10 @@ public interface LabelService {
     //获取油站标签用户列
     CustomerLabel getCustomerLabel(CustomerLabel customerLabel);
 
+    //更新用户新标签组
+    void updateCustomerLabel(CustomerLabel customerLabel);
+
+    //新增标签用户
+    void insertCustomerLabel(CustomerLabel customerLabel);
+
 }

+ 12 - 0
YijiaRestful/src/main/java/com/platform/yijia/service/impl/LabelServiceImpl.java

@@ -20,6 +20,18 @@ public class LabelServiceImpl implements LabelService {
         return labelMapper.getLabelRuleList(labelRule);
     }
 
+    //新增标签用户
+    @Override
+    public void insertCustomerLabel(CustomerLabel customerLabel) {
+        labelMapper.insertCustomerLabel(customerLabel);
+    }
+
+    //更新用户新标签组
+    @Override
+    public void updateCustomerLabel(CustomerLabel customerLabel) {
+        labelMapper.updateCustomerLabel(customerLabel);
+    }
+
     //获取标签用户信息
     @Override
     public CustomerLabel getCustomerLabel(CustomerLabel customerLabel) {

+ 1 - 1
YijiaRestful/src/main/resources/application.yml

@@ -28,7 +28,7 @@ yijia:
 
 # swagger2
 swagger2:
-    swagger-ui-open: false
+    swagger-ui-open: true
 
 # swagger2 UI登录密码
 #security:

+ 74 - 0
YijiaRestful/src/main/resources/mapper/LabelMapper.xml

@@ -7,6 +7,7 @@
         <result column="station_id"       jdbcType="INTEGER" property="stationId" />
         <result column="phone"            jdbcType="VARCHAR" property="phone" />
         <result column="label_id"         jdbcType="VARCHAR" property="labelId" />
+        <result column="create_by"        jdbcType="VARCHAR" property="createBy" />
         <result column="create_time"      jdbcType="DATE"    property="createTime" />
         <result column="update_by"        jdbcType="VARCHAR" property="updateBy" />
         <result column="update_time"      jdbcType="DATE"    property="updateTime" />
@@ -89,7 +90,80 @@
             <if test="phone !=null and phone !=''">
                 AND phone = #{phone}
             </if>
+            <if test="labelId !=null and labelId !=''">
+                AND label_id = #{labelId}
+            </if>
         </where>
     </select>
 
+    <!--更新用户新标签组-->
+    <update id="updateCustomerLabel" parameterType="com.platform.yijia.pojo.CustomerLabel">
+        UPDATE customer_label
+        <set>
+            <if test="labelId !=null">
+                label_id = #{labelId},
+            </if>
+            <if test="updateBy !=null">
+                update_by = #{updateBy},
+            </if>
+            <if test="updateTime !=null">
+                update_time = #{updateTime}
+            </if>
+        </set>
+        <where>
+            del_flag = "0"
+            <if test="stationId !=null and stationId !=''">
+                AND station_id = #{stationId}
+            </if>
+            <if test="phone !=null and phone !=''">
+                AND phone = #{phone}
+            </if>
+        </where>
+    </update>
+
+    <!--标签插入新的用户-->
+    <insert id="insertCustomerLabel" parameterType="com.platform.yijia.pojo.CustomerLabel">
+        INSERT INTO customer_label
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="labelId !=null">
+                label_id,
+            </if>
+            <if test="stationId !=null">
+                station_id,
+            </if>
+            <if test="phone !=null">
+                phone,
+            </if>
+            <if test="delFlag !=null">
+                del_flag,
+            </if>
+            <if test="createTime !=null">
+                create_time,
+            </if>
+            <if test="createBy !=null">
+                create_by,
+            </if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="labelId !=null">
+                #{labelId},
+            </if>
+            <if test="stationId !=null">
+                #{stationId},
+            </if>
+            <if test="phone !=null">
+                #{phone},
+            </if>
+            <if test="delFlag !=null">
+                #{delFlag},
+            </if>
+            <if test="createTime !=null">
+                #{createTime},
+            </if>
+            <if test="createBy !=null">
+                #{createBy},
+            </if>
+        </trim>
+    </insert>
+
 </mapper>