jk-GitHub-coder пре 4 година
родитељ
комит
3f9386900c

+ 80 - 0
YijiaRestful/src/main/java/com/platform/yijia/controller/AppUserInfoController.java

@@ -197,6 +197,7 @@ public class AppUserInfoController {
                 gzhAppId = m.get("gzhAppId");
                 gzhAppSecret = m.get("gzhAppSecret");
                 net.sf.json.JSONObject gzhAuthorizeInfo = WeiXinUserUtil.getGzhAuthorizeInfo(gzhAppId, gzhAppSecret, code);
+                logger.info("授权获取到信息:" + gzhAuthorizeInfo.toString());
                 resultData = ResultData.success(gzhAuthorizeInfo);
             }else {
                 resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
@@ -209,6 +210,85 @@ public class AppUserInfoController {
 
 
     /*
+     * 测试用来
+     * 获取公众号授权后的信息测试
+     * @param code
+     * @param stationId
+     * @return
+     */
+    @RequestMapping(value = "/getGzhAuthorizeInfoNew", method = RequestMethod.GET)
+    @ResponseBody
+    public String getGzhAuthorizeInfoNew(@RequestParam String code, Integer stationId){
+        logger.info("获取公众号授权后的信息前端传递参数:code:"+ code );
+        logger.info("获取公众号授权后的信息前端传递参数:stationId:" +stationId);
+        Gson gson =new Gson();
+        //返回结果集
+        ResultData resultData = null;
+        if(code != null && stationId !=null){
+            String gzhAppId ="";
+            String gzhAppSecret ="";
+            Map<String, String> m = stationService.getStationAppIdAndAppSecret(stationId);
+            if(m !=null && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
+                gzhAppId = m.get("gzhAppId");
+                gzhAppSecret = m.get("gzhAppSecret");
+                net.sf.json.JSONObject gzhAuthorizeInfo = WeiXinUserUtil.getGzhAuthorizeInfo(gzhAppId, gzhAppSecret, code);
+                logger.info("授权获取到信息:" + gzhAuthorizeInfo.toString());
+                if(gzhAuthorizeInfo.containsKey("openid")){
+                    String openId = gzhAuthorizeInfo.get("openid").toString();
+                    String accessToken  = this.getTokenByRedisCache(gzhAppId, gzhAppSecret);
+                    net.sf.json.JSONObject unionIdInfo = null;
+                    unionIdInfo= WeiXinUserUtil.getUnionIdInfo(accessToken, openId);
+                    if(unionIdInfo.containsKey("errcode")){
+                        //删除原来key
+                        redisCacheUtil.deleteObject(gzhAppId);
+                        String token = WeiXinUserUtil.getToken(gzhAppId, gzhAppSecret).getAccessToken();
+                        redisCacheUtil.setCacheObject(gzhAppId, token);
+                        redisCacheUtil.expire(gzhAppId, 7200, TimeUnit.SECONDS);
+                        unionIdInfo= WeiXinUserUtil.getUnionIdInfo(token, openId);
+                    }
+                    AppUserInfo appUserInfo = new AppUserInfo();
+                    if(unionIdInfo.containsKey("openid")){
+                        appUserInfo.setBlogOpenid(unionIdInfo.get("openid").toString());
+                    }
+                    if(unionIdInfo.containsKey("nickname")){
+                        appUserInfo.setBlogNickName(unionIdInfo.get("nickname").toString());
+                    }
+                    if(unionIdInfo.containsKey("sex")){
+                        appUserInfo.setSexFlag(unionIdInfo.get("sex").toString());
+                    }
+                    if(unionIdInfo.containsKey("headimgurl")){
+                        appUserInfo.setBlogProfilePhoto(unionIdInfo.get("headimgurl").toString());
+                    }
+                    if(unionIdInfo.containsKey("unionid")){
+                        appUserInfo.setUnionId(unionIdInfo.get("unionid").toString());
+                    }
+                    appUserInfo.setUserType("1");
+                    Map<String, Object> params = new HashMap<>();
+                    params.put("openId", openId);                   //注册用户openId
+                    params.put("userType", appUserInfo.getUserType());  //用户类型
+                    //判断该用户是否已存在
+                    int count = appUserInfoService.isExistAppUser(params);
+                    if(count > 0){
+                        appUserInfoService.updateAppUserInfo(appUserInfo);
+                    }else {
+                        appUserInfoService.AddAppUserInfo(appUserInfo);
+                    }
+                    resultData = ResultData.success(unionIdInfo);
+                }
+            }else {
+                resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
+            }
+        }else {
+            resultData = ResultData.error(CodeMsg.REQUEST_FAIL);
+        }
+        return gson.toJson(resultData);
+    }
+
+
+
+
+
+    /*
      * 获取公众号信息
      * @param openId
      * @param stationId

+ 37 - 4
YijiaRestful/src/main/java/com/platform/yijia/controller/ElectronicMembershipCardController.java

@@ -81,7 +81,6 @@ public class ElectronicMembershipCardController {
             if(stationCardEnabledFlag.equals("1")){
                 CustomerCardUseRecord customerCardUseRecord = new CustomerCardUseRecord();      //电子会员卡使用记录
                 CustomerCardSetting customerCardSetting = new CustomerCardSetting();        //电子卡优惠规则设置
-
                 customerCardSetting.setStationId(stationId);
                 customerCardSetting.setCardOilsType(cardOilsType);
                 customerCardSetting.setOrderBy("DESC");
@@ -96,7 +95,9 @@ public class ElectronicMembershipCardController {
                         dctime =new String[1];
                         dctime[0] = discountTime;
                     }
-                    String currentTime = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); //当前时间
+                    String currentTime =null;
+                    Calendar calendar = Calendar.getInstance();
+                    calendar.setTime(new Date());   //获取当前时间
                     //循环优惠规则明细
                     for (CustomerCardSettingDetail cardDetail : cardRechargeSettingList.get(0).getCustomerCardSettingDetailList()){
                         if(amt.compareTo(cardDetail.getDiscountAmtTerm()) ==1 || amt.compareTo(cardDetail.getDiscountAmtTerm()) ==0){
@@ -105,8 +106,24 @@ public class ElectronicMembershipCardController {
                             if(cardDetail.getSettingRuleType().equals("1")){ //按充值金额
                                 BigDecimal presentAmt = cardDetail.getPresentAmt(); //当前赠送金额
                                 if(cardRechargeSettingList.get(0).getDiscountTimeSetting().equals("1") && dctime !=null){
+                                    String discountTimeType = cardRechargeSettingList.get(0).getDiscountTimeType();     //获取日期类型
+                                    switch (discountTimeType){
+                                        case "1":   //  1.按周来
+                                            int day_Week = calendar.get(Calendar.DAY_OF_WEEK);
+                                            day_Week= day_Week-1;     //减一原因:数据库存的下标从零开始
+                                            currentTime = String.valueOf(day_Week);
+                                            break;
+                                        case "2":   //  2.每月的多少号
+                                            int day_month = calendar.get(Calendar.DAY_OF_MONTH);
+                                            day_month = day_month-1;        //减一原因:数据库存的下标从零开始
+                                            currentTime = String.valueOf(day_month); //当前时间
+                                            break;
+                                        case "3":   //  3.固定日期
+                                            currentTime =new SimpleDateFormat("yyyy-MM-dd").format(new Date());
+                                            break;
+                                    }
                                     for (String str : dctime){
-                                        if(str.contains(currentTime)){  //如果当前时间在会员日活动时间内
+                                        if(str.equals(currentTime)){  //如果当前时间在会员日活动时间内
                                             //计算会员日内的总赠送积分
                                             if(cardRechargeSettingList.get(0).getPresentScale() !=null){
                                                 presentAmt = presentAmt.multiply(new BigDecimal(cardRechargeSettingList.get(0).getPresentScale())).add(presentAmt);
@@ -120,8 +137,24 @@ public class ElectronicMembershipCardController {
                             }else if(cardDetail.getSettingRuleType().equals("2")){      //按充值金额的比例
                                 BigDecimal presentAmt = amt.multiply(cardDetail.getPresentAmt().divide(new BigDecimal(100))); //当前赠送金额比例的赠送积分
                                 if(cardRechargeSettingList.get(0).getDiscountTimeSetting().equals("1") && dctime !=null){
+                                    String discountTimeType = cardRechargeSettingList.get(0).getDiscountTimeType();     //获取日期类型
+                                    switch (discountTimeType){
+                                        case "1":   //  1.按周来
+                                            int day_Week = calendar.get(Calendar.DAY_OF_WEEK);
+                                            day_Week= day_Week-1;     //减一原因:数据库存的下标从零开始
+                                            currentTime = String.valueOf(day_Week);
+                                            break;
+                                        case "2":   //  2.每月的多少号
+                                            int day_month = calendar.get(Calendar.DAY_OF_MONTH);
+                                            day_month = day_month-1;        //减一原因:数据库存的下标从零开始
+                                            currentTime = String.valueOf(day_month); //当前时间
+                                            break;
+                                        case "3":   //  3.固定日期
+                                            currentTime =new SimpleDateFormat("yyyy-MM-dd").format(new Date());
+                                            break;
+                                    }
                                     for (String str : dctime){
-                                        if(str.contains(currentTime)){  //如果当前时间在会员日活动时间内
+                                        if(str.equals(currentTime)){  //如果当前时间在会员日活动时间内
                                             //计算会员日期内的总赠送积分
                                             if(cardRechargeSettingList.get(0).getPresentScale() !=null){
                                                 presentAmt = presentAmt.multiply(new BigDecimal(cardRechargeSettingList.get(0).getPresentScale())).add(presentAmt);

+ 52 - 9
YijiaRestful/src/main/java/com/platform/yijia/controller/PayController.java

@@ -566,6 +566,9 @@ public class PayController {
                             }else if(infoMap.containsKey("orderType") && infoMap.get("orderType").toString().equals("2")){
                                 calculateIntegral.setOilType(infoMap.get("orderType").toString());
                             }
+                            calculateIntegral.setUnionId(infoMap.get("unionId").toString());
+                            calculateIntegral.setNickName(infoMap.get("consumer").toString());
+                            calculateIntegral.setMobilePhone(infoMap.get("mobilePhone").toString());
                             calculateIntegral.setReceivableAmt(new BigDecimal(infoMap.get("receivableAmt").toString()));
                             //计算积分并推送
                             this.calculateIntegralAndPushIntegral(calculateIntegral, customerManage);
@@ -1045,23 +1048,30 @@ public class PayController {
                     }
                 }
             }
-            this.pushIntegral(calculateIntegral.getStationId(), integral, calculateIntegral.getOpenId());
+            calculateIntegral.setIntegral(integral);
+            this.pushIntegral(calculateIntegral);
         }
     }
 
     /*
-     * 公众号推送积分
+     * 更新积分并公众号推送积分
      * @param stationId 油站ID
      * @param integral  本次所得积分
      * @param openId    小程序用户openID
      */
-    public void pushIntegral(Integer stationId, int integral, String openId){
+    public void pushIntegral(CalculateIntegral calculateIntegral){
         String gzhAppId ="";
         String gzhAppSecret ="";
         String stationName = "";        //油站名称
         BigDecimal surplusIntegral=null;
-        String customerName =null;
-        if(StringUtils.isNotBlank(openId)){
+        String customerName =calculateIntegral.getNickName();       //客户昵称
+        String openId = calculateIntegral.getOpenId();      //客户小程序ID
+        Integer stationId = calculateIntegral.getStationId();   //油站ID
+        int integral = calculateIntegral.getIntegral();     //当前加油积分
+        String unionId = calculateIntegral.getUnionId();
+        String mobilePhone = calculateIntegral.getMobilePhone();
+        logger.info("客户小程序openId:" + openId);
+        if(StringUtils.isNotBlank(calculateIntegral.getOpenId())){
             Map<String, String> m = stationService.getStationAppIdAndAppSecret(stationId);
             if(m !=null && m.containsKey("stationName") && m.containsKey("gzhAppId") && m.containsKey("gzhAppSecret")){
                 stationName = m.get("stationName");
@@ -1069,10 +1079,13 @@ public class PayController {
                 gzhAppSecret = m.get("gzhAppSecret");
             }
             CustomerPoints customerPoints = new CustomerPoints();
-            customerPoints.setStationId(stationId);
+            customerPoints.setStationId(calculateIntegral.getStationId());
             customerPoints.setMinaOpenId(openId);
+            customerPoints.setUnionId(calculateIntegral.getUnionId());
             CustomerPoints customerPointsInfo = customerPointsService.getCustomerPointsInfoByMinaOpenId(customerPoints);
             if(customerPointsInfo !=null){
+                logger.info("当前存在客户:"+ customerPointsInfo.getMinaOpenId());
+                logger.info("当前客户原有剩余积分:"+ customerPointsInfo.getPoints().toString());
                 customerName =customerPointsInfo.getCustomerName();
                 surplusIntegral =new BigDecimal(customerPointsInfo.getPoints()).add(new BigDecimal(integral));
                 CustomerPointsRecord customerPointsRecord = new CustomerPointsRecord();
@@ -1084,10 +1097,15 @@ public class PayController {
                 customerPointsRecord.setUnionId(customerPointsInfo.getUnionId());
                 customerPointsRecord.setIntegral(integral);
                 customerPointsRecordService.insertCustomerPointsRecordInfo(customerPointsRecord);
-                customerPoints.setUnionId(customerPointsInfo.getUnionId());
+                //customerPoints.setUnionId(customerPointsInfo.getUnionId());
                 customerPoints.setPoints(surplusIntegral.intValue());
+                logger.info("本次加油后客户应有总积分:"+ customerPoints.getPoints().toString());
+                //用户已累积积分
+                BigDecimal add = new BigDecimal(customerPointsInfo.getAccumulatePoints()).add(new BigDecimal(integral));
+                customerPoints.setAccumulatePoints(add.intValue());
                 //更新客户积分
                 customerPointsService.updateCustomerPointsInfo(customerPoints);
+                logger.info("更新客户积分信息成功!");
                 String blogOpenId = customerPointsInfo.getBlogOpenId();     //公众号openId
                 if(blogOpenId !=null){
                     //推送模板
@@ -1099,8 +1117,6 @@ public class PayController {
                     wxMpTemplate.add(new WxMpTemplateData("From", stationName));
                     wxMpTemplate.add(new WxMpTemplateData("remark",
                             "截止至" + new SimpleDateFormat(" yyyy年MM月dd日HH时mm分").format(new Date())+",您在"+stationName+"的可用积分为 "+surplusIntegral.toString()+" 分"));
-//                    String templateId = "G9tN--a3tGM5BN3otqZr73b4ErQCYWISSgyshbTqLYc";  //积分兑换成功通知模板
-//                    wxPushUtil.push(gzhAppId, gzhAppSecret, templateId, blogOpenId, wxMpTemplate);  //oJR5R6r4EJhaORFcPap70r_mtFZo
                     GzhNewsTemplate gzhNewsTemplate = new GzhNewsTemplate();
                     gzhNewsTemplate.setStationId(stationId);
                     gzhNewsTemplate.setTemplateType("1");
@@ -1110,6 +1126,33 @@ public class PayController {
                     }
                 }
 
+            }else {
+                logger.info("当前系统不存在该客户积分信息");
+                //customerName =userName;
+                surplusIntegral =new BigDecimal(integral);
+                CustomerPointsRecord customerPointsRecord = new CustomerPointsRecord();
+                customerPointsRecord.setCreateTime(new Date());
+                customerPointsRecord.setCustomerName(customerName);
+                customerPointsRecord.setStationName(stationName);
+                customerPointsRecord.setStationId(stationId);
+                customerPointsRecord.setRecordType("+");
+                customerPointsRecord.setUnionId(unionId);
+                customerPointsRecord.setIntegral(integral);
+                customerPointsRecordService.insertCustomerPointsRecordInfo(customerPointsRecord);
+
+                customerPoints.setUnionId(unionId);
+                customerPoints.setPoints(surplusIntegral.intValue());
+                customerPoints.setPoints(integral);
+                customerPoints.setConsumptionPoints(0);
+                customerPoints.setMobilePhone(mobilePhone);
+                customerPoints.setCustomerName(customerName);
+                customerPoints.setStationName(stationName);
+                customerPoints.setAccumulatePoints(integral);
+                customerPoints.setInvalidPoints(0);
+                customerPoints.setCreateTime(new Date());
+                //新增客户积分
+                customerPointsService.insertCustomerPointsInfo(customerPoints);
+                logger.info("新增客户积分信息成功!");
             }
 
         }

+ 4 - 0
YijiaRestful/src/main/java/com/platform/yijia/pojo/CalculateIntegral.java

@@ -13,6 +13,10 @@ public class CalculateIntegral {
     private String oilName;     //油品名称
     private String oilType;     //油类:1.油品; 2.非油品
     private String openId;      //公众号Id
+    private String unionId;      // unionId
+    private String nickName;      //客户名
+    private String mobilePhone;      //客户手机号
+    private int integral;       //客户积分
     private BigDecimal amt;     //用户消费金额
     private BigDecimal oilLiters;       //用户加油的升数
     private BigDecimal receivableAmt;       //用户应收金额

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

@@ -13,6 +13,7 @@ public class CustomerCardSetting {
     private Integer id;
     private String cardOilsType;            //电子充值卡油类类型:1.柴油;2.汽油;
     private String discountTimeSetting;     //会员活动设置(0.禁用,1.启用)
+    private String discountTimeType;        //时间类型:1.周;2.每月多少号;3.具体日期;
     private String discountTime;        //会员日活动时间
     private String presentScale;          //赠送比例
     private String isDiscountCoupon;    //是否可以使用优惠券:0,否;1,是

+ 21 - 15
YijiaRestful/src/main/resources/mapper/CustomerPointsMapper.xml

@@ -46,8 +46,11 @@
     <include refid="Base_Column_List" />
     FROM customer_points
     <where>
-      <if test="minaOpenId !=null and minaOpenId !=''">
-        mina_openid = #{minaOpenId}
+<!--      <if test="minaOpenId !=null and minaOpenId !=''">-->
+<!--        mina_openid = #{minaOpenId}-->
+<!--      </if>-->
+      <if test="unionId !=null and unionId !=''">
+        union_id = #{unionId}
       </if>
       <if test="stationId !=null and stationId !=''">
         AND station_id = #{stationId}
@@ -192,15 +195,15 @@
       <if test="stationId !='' and stationId != null" >
         station_id = #{stationId}
       </if>
-<!--      <if test="unionId !=null and unionId !=''">-->
-<!--        AND union_id = #{unionId}-->
-<!--      </if>-->
-      <if test="blogOpenId !=null and blogOpenId !=''">
-        AND blog_openid = #{blogOpenId}
-      </if>
-      <if test="minaOpenId !=null and minaOpenId !=''">
-        AND mina_openid = #{minaOpenId}
+      <if test="unionId !=null and unionId !=''">
+        AND union_id = #{unionId}
       </if>
+<!--      <if test="blogOpenId !=null and blogOpenId !=''">-->
+<!--        AND blog_openid = #{blogOpenId}-->
+<!--      </if>-->
+<!--      <if test="minaOpenId !=null and minaOpenId !=''">-->
+<!--        AND mina_openid = #{minaOpenId}-->
+<!--      </if>-->
     </where>
   </update>
 
@@ -214,12 +217,15 @@
       <if test="stationId !='' and stationId != null" >
         station_id = #{stationId}
       </if>
-      <if test="blogOpenId !=null and blogOpenId !=''">
-        AND blog_openid = #{blogOpenId}
-      </if>
-      <if test="minaOpenId !=null and minaOpenId !=''">
-        AND mina_openid = #{minaOpenId}
+      <if test="unionId !=null and unionId !=''">
+        AND union_id = #{unionId}
       </if>
+<!--      <if test="blogOpenId !=null and blogOpenId !=''">-->
+<!--        AND blog_openid = #{blogOpenId}-->
+<!--      </if>-->
+<!--      <if test="minaOpenId !=null and minaOpenId !=''">-->
+<!--        AND mina_openid = #{minaOpenId}-->
+<!--      </if>-->
     </where>
   </select>
 

+ 15 - 13
YijiaRestful/src/main/resources/mapper/ElectronicMembershipCardMapper.xml

@@ -9,7 +9,7 @@
       <result column="mina_openid"             jdbcType="VARCHAR"   property="minaOpenid" />
       <result column="customer_no"             jdbcType="VARCHAR"   property="customerNo" />
       <result column="customer_name"           jdbcType="VARCHAR"   property="customerName" />
-      <result column="mobile_phone"           jdbcType="VARCHAR"   property="mobilePhone" />
+      <result column="mobile_phone"            jdbcType="VARCHAR"    property="mobilePhone" />
       <result column="amt"                     jdbcType="DECIMAL"   property="amt" />
       <result column="card_oils_type"          jdbcType="VARCHAR"   property="cardOilsType" />
       <result column="station_id"              jdbcType="INTEGER"   property="stationId" />
@@ -42,6 +42,7 @@
         <id     column="id"                         jdbcType="INTEGER"    property="id" />
         <result column="card_oils_type"             jdbcType="VARCHAR"    property="cardOilsType" />
         <result column="discount_time_setting"      jdbcType="VARCHAR"    property="discountTimeSetting" />
+        <result column="discount_time_type"         jdbcType="VARCHAR"    property="discountTimeType" />
         <result column="discount_time"              jdbcType="VARCHAR"    property="discountTime" />
         <result column="present_scale"              jdbcType="VARCHAR"    property="presentScale" />
         <result column="is_discount_coupon"         jdbcType="VARCHAR"    property="isDiscountCoupon" />
@@ -67,6 +68,7 @@
             T1.id,
             T1.card_oils_type,
             T1.discount_time_setting,
+            T1.discount_time_type,
             T1.discount_time,
             T1.present_scale,
             T1.is_discount_coupon,
@@ -402,12 +404,12 @@
             <if test="unionId !=null and unionId !=''">
                 AND union_id = #{unionId}
             </if>
-            <if test="blogOpenId !=null and blogOpenId !=''">
-                AND blog_openid = #{blogOpenId}
-            </if>
-            <if test="minaOpenId !=null and minaOpenId !=''">
-                AND mina_openid = #{minaOpenId}
-            </if>
+<!--            <if test="blogOpenid !=null and blogOpenid !=''">-->
+<!--                AND blog_openid = #{blogOpenid}-->
+<!--            </if>-->
+<!--            <if test="minaOpenid !=null and minaOpenid !=''">-->
+<!--                AND mina_openid = #{minaOpenid}-->
+<!--            </if>-->
             <if test="cardOilsType !=null and cardOilsType !=''">
                 AND card_oils_type = #{cardOilsType}
             </if>
@@ -502,12 +504,12 @@
             <if test="stationId !='' and stationId != null" >
                 station_id = #{stationId}
             </if>
-            <if test="blogOpenId !=null and blogOpenId !=''">
-                AND blog_openid = #{blogOpenId}
-            </if>
-            <if test="minaOpenId !=null and minaOpenId !=''">
-                AND mina_openid = #{minaOpenId}
-            </if>
+<!--            <if test="blogOpenid !=null and blogOpenid !=''">-->
+<!--                AND blog_openid = #{blogOpenid}-->
+<!--            </if>-->
+<!--            <if test="minaOpenid !=null and minaOpenid !=''">-->
+<!--                AND mina_openid = #{minaOpenid}-->
+<!--            </if>-->
             <if test="unionId !=null and unionId != ''">
                 AND union_id = #{unionId}
             </if>