JK 4 år sedan
förälder
incheckning
eaa2c77ad9

+ 22 - 0
YijiaRestful/src/main/java/com/platform/yijia/dao/PayOrderMapper.java

@@ -1,5 +1,6 @@
 package com.platform.yijia.dao;
 
+import com.platform.yijia.pojo.CustomerManage;
 import com.platform.yijia.pojo.PayOrder;
 import com.platform.yijia.pojo.PayOrderExample;
 import java.util.List;
@@ -14,6 +15,27 @@ public interface PayOrderMapper {
      */
     int updateOrderStatus(PayOrder payOrder);
 
+    /*
+     * 查询客户是否已存在
+     * @param customerManage
+     * @return
+     */
+    CustomerManage isExistCustomer(CustomerManage customerManage);
+
+    /*
+     *  插入客户
+     * @param customerManage
+     * @return
+     */
+    void insertCustomer(CustomerManage customerManage);
+
+    /*
+     *  生成订单时更新客户表
+     * @param customerManage
+     * @return
+     */
+    void updateCustomer(CustomerManage customerManage);
+
     /***
      * 根据油品名称和油站查询油品调价信息
      * @param map

+ 23 - 1
YijiaRestful/src/main/java/com/platform/yijia/service/impl/PayOrderServiceImpl.java

@@ -3,6 +3,7 @@ package com.platform.yijia.service.impl;
 import com.platform.yijia.dao.PayOrderMapper;
 import com.platform.yijia.param.request.PayOrderRequest;
 import com.platform.yijia.pojo.AppUserInfo;
+import com.platform.yijia.pojo.CustomerManage;
 import com.platform.yijia.pojo.PayOrder;
 
 import com.platform.yijia.pojo.PayOrderExample;
@@ -144,17 +145,38 @@ public class PayOrderServiceImpl implements PayOrderService {
         //返回订单号
         ordNo= payOrderList.get(0).getOrderNo();
 
-//        //向客户表中插入数据
+        //向客户表中插入数据
 //        AppUserInfo appUserInfo = new AppUserInfo();
+//        CustomerManage customerManage = new CustomerManage();
 //        appUserInfo.setUserType(payOrderRequest.getUserType());
 //        if(payOrderRequest.getUserType().equals("1")){
 //            //1 是公众号
 //            appUserInfo.setBlogOpenid(payOrderRequest.getToken());
+//            customerManage.setBlogOpenid(payOrderRequest.getToken());
 //        }else if(payOrderRequest.getUserType().equals("2")){
 //            //2是小程序
 //            appUserInfo.setMinaOpenid(payOrderRequest.getToken());
+//            customerManage.setMinaOpenid(payOrderRequest.getToken());
 //        }
+//
 //        List<AppUserInfo> userInfos = appUserInfoService.Authentication(appUserInfo);
+//        //判断该用户是否已存在
+//        customerManage.setStationId(payOrderRequest.getStationId());
+//        CustomerManage existCustomer = payOrderMapper.isExistCustomer(customerManage);
+//        if(existCustomer != null){
+//            //已存在更新
+//            customerManage.setCustomerName(userInfos.get(0).getBlogNickName());
+//            //Double oilLiters = Double.valueOf(payOrder.getOrderLiters() + customerManage.getCyLiters());
+//            customerManage.setCyLiters(BigDecimal.valueOf(Double.valueOf(payOrder.getOrderLiters())));
+//            payOrderMapper.updateCustomer(customerManage);
+//        }else{
+//
+//            //不存在时从客户信息表查询插入
+//
+//            //customerManage.setMemberId();
+//            //customerManage.setCustomerName(userInfos.get(0).getBlogNickName());
+//            payOrderMapper.insertCustomer(customerManage);
+//        }
 
         return ordNo;
     }

+ 217 - 0
YijiaRestful/src/main/resources/mapper/PayOrderMapper.xml

@@ -671,6 +671,223 @@
     </where>
   </update>
 
+  <!-- 判断客户表是否已存在-->
+  <select id="isExistCustomer" parameterType="com.platform.yijia.pojo.CustomerManage" resultType="com.platform.yijia.pojo.CustomerManage">
+    SELECT
+        id              AS id,
+        member_id       AS memberId,
+        member_grade    AS memberGrade,
+        phone_number    AS phoneNumber,
+        regtime         AS regtime,
+        station_name    AS stationName,
+        cy_liters       AS cyLiters,
+        qy_liters       AS qyLiters,
+        cy_amt          AS cyAmt,
+        qy_amt          AS qyAmt
+    FROM
+        customer_manage
+    <where>
+      <if test="blogOpenid !=null and blogOpenid !='' ">
+        blog_openid = #{blogOpenid}
+      </if>
+      <if test="minaOpenid !=null and minaOpenid !='' ">
+        AND mina_openid = #{minaOpenid}
+      </if>
+      <if test="stationId !=null and stationId !='' ">
+        AND station_id = #{stationId}
+      </if>
+    </where>
+  </select>
+
+  <!-- 更新客户表 -->
+  <update id="updateCustomer" parameterType="com.platform.yijia.pojo.CustomerManage">
+    UPDATE
+        customer_manage
+    <set>
+        <if test="memberGrade !=null ">
+          member_grade = #{memberGrade},
+        </if>
+        <if test="phoneNumber !=null ">
+          phone_number = #{phoneNumber},
+        </if>
+        <if test="regtime !=null ">
+          regtime = #{regtime},
+        </if>
+        <if test="stationName !=null ">
+          station_name = #{stationName},
+        </if>
+        <if test="cyLiters !=null ">
+          cy_liters = #{cyLiters},
+        </if>
+        <if test="qyLiters !=null ">
+          qy_liters = #{qyLiters},
+        </if>
+    </set>
+    <where>
+      <if test="blogOpenid !=null and blogOpenid !='' ">
+        blog_openid = #{blogOpenid}
+      </if>
+      <if test="minaOpenid !=null and minaOpenid !='' ">
+        AND mina_openid = #{minaOpenid}
+      </if>
+      <if test="stationId !=null and stationId !='' ">
+        AND station_id = #{stationId}
+      </if>
+    </where>
+  </update>
+
+  <!-- 插入客户表 -->
+  <insert id="insertCustomer" parameterType="com.platform.yijia.pojo.CustomerManage">
+    INSERT INTO
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+          <if test="memberId !=null ">
+            member_id,
+          </if>
+          <if test="customerName !=null ">
+            customer_name,
+          </if>
+          <if test="commendMan !=null ">
+            commend_man,
+          </if>
+          <if test="memberGrade !=null ">
+            member_grade,
+          </if>
+          <if test="phoneNumber !=null ">
+            phone_number,
+          </if>
+
+          <if test="carNumber !=null ">
+            car_number,
+          </if>
+          <if test="balance !=null ">
+            balance,
+          </if>
+          <if test="integral !=null ">
+            integral,
+          </if>
+          <if test="specialCarType !=null ">
+            specialCarType,
+          </if>
+
+          <if test="regtime !=null ">
+            regtime,
+          </if>
+          <if test="stationId !=null ">
+            station_id,
+          </if>
+          <if test="stationName !=null ">
+            station_name,
+          </if>
+
+          <if test="cyGrade !=null ">
+            cy_grade,
+          </if>
+          <if test="qyGrade !=null ">
+            qy_grade,
+          </if>
+
+
+          <if test="cyLiters !=null ">
+            cy_liters,
+          </if>
+          <if test="qyLiters !=null ">
+            qy_liters
+          </if>
+
+          <if test="cyAmt !=null ">
+            cy_amt,
+          </if>
+          <if test="qyAmt !=null ">
+            qy_amt,
+          </if>
+          <if test="blogOpenid !=null ">
+            blog_openid,
+          </if>
+          <if test="minaOpenid !=null ">
+            mina_openid,
+          </if>
+          <if test="blogUserId !=null ">
+            blog_user_id,
+          </if>
+          <if test="minaUserId !=null ">
+            mina_user_id
+          </if>
+
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+
+          <if test="memberId !=null ">
+            #{memberId},
+          </if>
+          <if test="customerName !=null ">
+            #{customerName},
+          </if>
+          <if test="commendMan !=null ">
+            #{commendMan},
+          </if>
+          <if test="memberGrade !=null ">
+            #{memberGrade},
+          </if>
+          <if test="phoneNumber !=null ">
+            #{phoneNumber},
+          </if>
+          <if test="carNumber !=null ">
+            #{carNumber},
+          </if>
+          <if test="balance !=null ">
+            #{balance},
+          </if>
+          <if test="integral !=null ">
+            #{integral},
+          </if>
+          <if test="specialCarType !=null ">
+            #{specialCarType},
+          </if>
+
+          <if test="regtime !=null ">
+            #{regtime},
+          </if>
+          <if test="stationId !=null ">
+            #{stationId},
+          </if>
+          <if test="stationName !=null ">
+            #{stationName},
+          </if>
+
+          <if test="cyGrade !=null ">
+            #{cyGrade},
+          </if>
+          <if test="qyGrade !=null ">
+            #{qyGrade},
+          </if>
+          <if test="cyLiters !=null ">
+            #{cyLiters},
+          </if>
+          <if test="qyLiters !=null ">
+            #{qyLiters},
+          </if>
+
+          <if test="cyAmt !=null ">
+            #{cyAmt},
+          </if>
+          <if test="qyAmt !=null ">
+            #{qyAmt},
+          </if>
+          <if test="blogOpenid !=null ">
+            #{blogOpenid},
+          </if>
+          <if test="minaOpenid !=null ">
+            #{minaOpenid},
+          </if>
+          <if test="blogUserId !=null ">
+            #{blogUserId},
+          </if>
+          <if test="minaUserId !=null ">
+            #{minaUserId}
+          </if>
+        </trim>
+  </insert>
+
 
   <update id="updateByExample" parameterType="map">
     <!--