浏览代码

用户行为优化1.0.5

huangzhiguo 1 年之前
父节点
当前提交
5224df0b48

+ 10 - 6
src/main/java/com/caimei365/order/components/WeChatService.java

@@ -416,7 +416,7 @@ public class WeChatService {
      * @param remarkText 备注
      * @param pagePath 跳转链接
      */
-    public void sendTemplateMsgy(String accessToken, String openid, String title, String orderno,String time, String company, String companyno,String remarkText, String pagePath) {
+    public void sendTemplateMsgy(String accessToken, String openid, String title, String orderno, String time, String company, String companyno,String remarkText, String pagePath) {
         JSONObject first = new JSONObject();
         first.put("value", title);
         first.put("color", "#000000");
@@ -459,8 +459,8 @@ public class WeChatService {
         log.info(">>>>>>>>推送微信模板消息:" + jsonString);
         try {
             // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
-              String requestUrl =  "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN";
-//            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
+//              String requestUrl =  "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN";
+            String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
             // 发送请求
             String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
             log.info(">>>>>>>>推送结果:" + result);
@@ -520,9 +520,13 @@ public class WeChatService {
         try {
             // https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN
             String requestUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+accessToken;
-            // 发送请求
-            String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
-            log.info(">>>>>>>>推送结果:" + result);
+            /**
+             * 发送请求
+             * todo 订单详情改变,取消推送
+             */
+
+            // String result = RequestUtil.httpRequest(requestUrl, "POST", jsonString);
+            // log.info(">>>>>>>>推送结果:" + result);
         } catch (Exception e) {
             log.error("推送微信模板消息失败:", e);
         }

+ 20 - 0
src/main/java/com/caimei365/order/mapper/ShipMapper.java

@@ -334,4 +334,24 @@ public interface ShipMapper {
      * @param note
      */
     void deleteShopOrder(@Param("shopOrderId") Integer shopOrderId, @Param("note") String note);
+
+    /**
+     * 订单unionId
+     * @param orderId
+     * @return
+     */
+    String FromUnionId(Integer orderId);
+
+    /**
+     * openId
+     * @param unionid
+     * @return
+     */
+    List<String> getOpenidListByPermission(@Param("unionid") String unionid);
+    /**
+     * 子订单信息 发货
+     * @param shopOrderId
+     * @return
+     */
+    ShopOrderVo getShopOrderMsgy(@Param("shopOrderId") Integer shopOrderId);
 }

+ 4 - 0
src/main/java/com/caimei365/order/model/vo/MessageCenter.java

@@ -50,6 +50,10 @@ public class MessageCenter implements Serializable {
      * 订单ID
      */
     private Integer orderID;
+    /**
+     * 子订单Id
+     */
+    private Integer shopOrderId;
     /**
      *交易物流1.下单成功通知  2.订单支付完成 3.退款/货成功通知 4.订单取消通知 5.订单发货通知 6.自动收货通知
      */

+ 23 - 0
src/main/java/com/caimei365/order/service/impl/ShipServiceImpl.java

@@ -893,6 +893,7 @@ public class ShipServiceImpl implements ShipService {
             messageCenter.setMessageType(1);
             messageCenter.setOrderMessageType(5);
             messageCenter.setOrderID(logisticsBatch.getOrderId());
+            messageCenter.setShopOrderId(logisticsBatch.getShopOrderId());
             messageCenter.setContent(null);
             messageCenter.setTime(curDateStr);
             orderClubMapper.addMessageCenter(messageCenter);
@@ -909,6 +910,28 @@ public class ShipServiceImpl implements ShipService {
             logisticsInformation.setUpdateDate(date);
             // 保存 物流跟踪信息
             shipMapper.insertLogisticsInformation(logisticsInformation);
+            try {
+                ShopOrderVo shopOrder = shipMapper.getShopOrderMsgy(logisticsBatch.getShopOrderId());
+                Integer orderId = shopOrder.getOrderId();
+                String unionid = shipMapper.FromUnionId(orderId);
+                List<String> openidList = shipMapper.getOpenidListByPermission(unionid);
+                log.info("userid>>>>>>>>>>>>>>>" + orderId + "unionid》》》》》》》》》》" + unionid + "openid》》》》》》》》》" + openidList);
+                String accessToken = weChatService.getAccessToken();
+                String shopOrderNo = shopOrder.getShopOrderNo();
+                String title = "尊敬的采美客户,您购买的订单已经发货啦~";
+                String time = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
+                // 快递公司
+                String company = logisticsCompanyName;
+                // 快递单号
+                String companyno = number;
+                String remarkText = "收到货后请记得确认收货哟~";
+                String pagePath = "pages/user/order/order-details?type=share&shopOrderId=" + shopOrder.getShopOrderId();
+                for (String openid : openidList) {
+                    weChatService.sendTemplateMsgy(accessToken, openid, title, shopOrderNo, time, company, companyno, remarkText, pagePath);
+                }
+            } catch (Exception e) {
+                log.error("【订单发货通知】获取微信公众号access_token异常!", e);
+            }
         }
         logisticsBatch.setId(logisticsBatchDto.getLogisticsBatchId());
         logisticsBatch.setRemarkImage(logisticsBatchDto.getRemarkImage());

+ 2 - 2
src/main/resources/mapper/OrderClubMapper.xml

@@ -1031,9 +1031,9 @@
 
 
     <insert id="addMessageCenter">
-        INSERT INTO message_center (shopID, clubID, userType, messageType, content, time, orderMessageType, orderID,
+        INSERT INTO message_center (shopID, clubID, userType, messageType, content, time, orderMessageType, orderID, shopOrderId,
                                     accountType)
-        VALUES (#{shopID}, #{clubID}, #{userType}, #{messageType}, #{content}, #{time}, #{orderMessageType}, #{orderID},
+        VALUES (#{shopID}, #{clubID}, #{userType}, #{messageType}, #{content}, #{time}, #{orderMessageType}, #{orderID}, #{shopOrderId}
                 #{accountType})
     </insert>
 

+ 113 - 0
src/main/resources/mapper/ShipMapper.xml

@@ -678,4 +678,117 @@
             note = #{note}
         WHERE shopOrderID = #{shopOrderId}
     </update>
+
+    <select id="FromUnionId" resultType="java.lang.String">
+        SELECT unionID
+        FROM `cm_order`
+        WHERE orderID = #{orderId}
+    </select>
+
+    <select id="getOpenidListByPermission" resultType="java.lang.String">
+        SELECT openid
+        FROM `wechat_user`
+        WHERE unionid = #{unionid}
+    </select>
+
+    <select id="getShopOrderMsgy" resultType="com.caimei365.order.model.vo.ShopOrderVo">
+        select
+        co.rebateFee as rebateFee,
+        co.userBeans as userBeans,
+        a.shopOrderID AS shopOrderID,
+        a.shopStatus AS status,
+        a.shopPostFlag AS shopPostFlag,
+        a.orderID AS orderID,
+        a.organizeID AS organizeID,
+        a.shopOrderNo AS  shopOrderNo,
+        a.orderNo AS  orderNo,
+        a.userID  AS userID,
+        a.shopID  AS shopID,
+        a.isColdChina  AS isColdChina,
+        a.itemCount  AS itemCount,
+        a.townID  AS townID,
+        a.productAmount  AS productAmount,
+        a.discountAmount AS  discountAmount,
+        a.accountAmount AS  accountAmount,
+        a.totalAmount AS  totalAmount,
+        a.payFlag  AS payFlag,
+        a.payTime  AS payTime,
+        a.finishTime AS finishTime,
+        a.refundStatus AS  refundStatus,
+        a.needPayAmount AS  needPayAmount,
+        a.splitCode,
+        ifnull(a.realPay, a.needPayAmount) AS realPay,
+        a.eachDiscount AS eachDiscount,
+        IFNULL((SELECT SUM(cror.associateAmount)
+                FROM cm_receipt_order_relation cror
+                         LEFT JOIN cm_discern_receipt cdr ON cror.receiptID = cdr.id
+                WHERE cror.shopOrderId = a.shopOrderId
+                  AND cror.relationType = '2'
+                  AND cdr.receiptType = 1
+                  AND cdr.delFlag = 0
+                  AND cror.delFlag = 0
+                  AND cdr.receiptStatus IN (2, 3)
+                  AND cdr.payWay != 3)
+            , 0) AS receiptAmount,
+        (ifnull(a.realPay,a.needPayAmount) - ifnull(a.receiptAmount,0)) as restAmount,
+        a.receiptStatus as shopReceiptStatus,
+        a.receiptStatus as ReceiptStatus,
+        a.canRefundAmount AS  canRefundAmount,
+        a.refundAmount AS  refundAmount,
+        a.clubID  AS clubID,
+        a.spID AS  spID,
+        a.mainSpID  AS mainSpID,
+        a.orderBeanAmount AS  orderBeanAmount,
+        a.useBeanAmount AS  useBeanAmount,
+        a.useBeanFlag AS  useBeanFlag,
+        a.canRefundFlag AS  canRefundFlag,
+        a.useBalanceFlag  AS useBalanceFlag,
+        a.canRefundBeans AS  canRefundBeans,
+        a.freePostageFee AS  freePostageFee,
+        a.freePostageTicketID  AS freePostageTicketID,
+        a.brokerage  AS brokerage,
+        a.delFlag  AS delFlag,
+        a.refundsAmount  AS refundsAmount,
+        a.orderStatusFlag  AS orderStatusFlag,
+        a.buyStatus AS buyStatus,
+        a.orderSubmitType AS orderSubmitType,
+        a.orderType AS orderType,
+        a.orderTime AS orderTime,
+        a.deliveryTimeMills AS deliveryTimeMills,
+        a.presentNum AS presentNum,
+        a.preferential AS preferential,
+        a.outStoreNum AS outStoreNum,
+        IFNULL(a.outStoreTimes, 0) AS outStoreTimes,
+        a.splitFlag AS splitFlag,
+        a.autoReceiveTimeMills AS autoReceiveTimeMills,
+        a.autoOverTimeMills AS autoOverTimeMills,
+        a.receiveGoodsTime AS receiveGoodsTime,
+        a.totalAddedValueTax AS totalAddedValueTax,
+        a.note AS note,
+        a.payStatus AS payStatus,
+        a.sendOutStatus AS sendOutStatus,
+        a.shopProductAmount AS shopProductAmount,
+        ifnull(a.shopPostFee, 0) AS shopPostFee,
+        ifnull(a.shopTaxFee,0) AS shopTaxFee,
+        a.shouldPayShopAmount AS shouldPayShopAmount,
+        a.payedShopAmount AS payedShopAmount,
+        ifnull(a.shopOtherFee, 0) AS shopOtherFee,
+        a.paying AS paying,
+        a.costType AS costType,
+        a.settleStatus AS settleStatus,
+        a.modifyShouldPayNote AS modifyShouldPayNote,
+        a.orderPromotionsId AS orderPromotionsId,
+        a.differenceType AS differenceType,
+        a.differencePrice AS differencePrice,
+        a.proportional AS proportional,
+        ifnull(a.promotionFullReduction, 0) As promotionFullReduction,
+        ifnull(a.couponAmount, 0) As couponAmount,
+        a.zeroCostFlag AS zeroCostFlag,
+        ifnull(a.cmAccountType,0) as cmAccountType,
+        ifnull(a.rebateOrder,0) as rebateOrder,
+        ifnull(a.supplierFreight,0) as supplierFreight
+        from cm_shop_order a
+        left join cm_order co on co.orderID = a.orderID
+        where a.shopOrderID = #{shopOrderID}
+    </select>
 </mapper>