Browse Source

短信推送

plf 3 years ago
parent
commit
c75cbbf91f

+ 25 - 0
src/main/java/com/caimei/modules/order/dao/NewOrderDao.java

@@ -112,4 +112,29 @@ public interface NewOrderDao extends CrudDao<NewOrder> {
      * @param ossName
      */
     void insertQualificationFile(@Param("recordId") Integer recordId, @Param("fileName") String fileName, @Param("ossName") String ossName);
+
+    /**
+     * 查询短链接是否存在
+     *
+     * @param shortLink
+     * @return
+     */
+    Integer findBYShortLink(String shortLink);
+
+    /**
+     * 保存短链接信息
+     *
+     * @param markId    短信类型
+     * @param shortLink 短链接
+     * @param url       跳转地址
+     */
+    void insertShortLink(@Param("markId") int markId, @Param("shortLink") String shortLink, @Param("url") String url);
+
+    /**
+     * 保存短信发送条数
+     *
+     * @param markId
+     * @param num
+     */
+    void updateSendNum(@Param("markId") int markId, @Param("num") int num);
 }

+ 4 - 4
src/main/java/com/caimei/modules/order/entity/NewShopOrder.java

@@ -138,7 +138,7 @@ public class NewShopOrder extends DataEntity<NewShopOrder> {
 
     private boolean modifyPayable = false; //是否线上支付
 
-    private boolean isPayShopOtherFee = true; //是否可以付第三方申请
+    private boolean payShopOtherFee = true; //是否可以付第三方申请
 
     public Integer getOrderPromotionsId() {
         return orderPromotionsId;
@@ -1095,11 +1095,11 @@ public class NewShopOrder extends DataEntity<NewShopOrder> {
         this.userBeans = userBeans;
     }
 
-    public boolean isPayShopOtherFee() {
-        return isPayShopOtherFee;
+    public boolean getPayShopOtherFee() {
+        return payShopOtherFee;
     }
 
     public void setPayShopOtherFee(boolean payShopOtherFee) {
-        isPayShopOtherFee = payShopOtherFee;
+        this.payShopOtherFee = payShopOtherFee;
     }
 }

+ 25 - 0
src/main/java/com/caimei/modules/order/service/CmReturnedPurchaseService.java

@@ -621,6 +621,31 @@ public class CmReturnedPurchaseService extends CrudService<CmReturnedPurchaseDao
                     cmUserDao.updateUserBeans(newOrder.getUserID(), userBeans);
                 }
             }
+            //退款短信推送
+            try {
+                if (user != null && StringUtils.isNotBlank(user.getBindMobile())) {
+                    String wwwServer = Global.getConfig("wwwServer");
+                    boolean sendSms = false;
+                    if ("1".equals(newOrder.getRefundType())) {
+                        //部分退
+                        String shortLink = newOrderService.getShortLink(8, 9, wwwServer + "user/order/detail.html?orderId=" + newOrder.getOrderID());
+                        String content = "订单(订单编号:" + newOrder.getOrderNo() + ")已部分退款成功,本次退款金额¥" + returnedPurchase.getRefundFee() + "。您可关注采美公众号或者访问采美微信小程序和网站查看订单。" +
+                                "平台公众号:微信搜索“采美365网”; 微信小程序:微信搜索“采美采购商城”;网址:www.caimei365.com/t/" + shortLink;
+                        sendSms = newOrderService.getSendSms(9, user.getBindMobile(), content);
+                    } else if ("2".equals(newOrder.getRefundType())) {
+                        //全部退
+                        String shortLink = newOrderService.getShortLink(8, 10, wwwServer + "user/order/detail.html?orderId=" + newOrder.getOrderID());
+                        String content = "订单(订单编号:" + newOrder.getOrderNo() + ")已全部退款成功,退款金额¥" + returnedPurchase.getRefundFee() + "。您可关注采美公众号或者访问采美微信小程序和网站查看订单。" +
+                                "平台公众号:微信搜索“采美365网”; 微信小程序:微信搜索“采美采购商城”;网址:www.caimei365.com/t/" + shortLink;
+                        sendSms = newOrderService.getSendSms(10, user.getBindMobile(), content);
+                    }
+                    if (!sendSms) {
+                        logger.info("退款短信推送失败,订单id>>>>" + newOrder.getOrderID());
+                    }
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         } else if (cmReturnedPurchase.getStatus().equals("3")) {//审核不通过
             cmReturnedPurchaseDao.update(cmReturnedPurchase);
             //解冻余额

+ 106 - 0
src/main/java/com/caimei/modules/order/service/NewOrderService.java

@@ -13,6 +13,7 @@ import com.caimei.modules.order.entity.*;
 import com.caimei.modules.order.utils.HttpClientUtils;
 import com.caimei.modules.order.utils.NewOrderStatus;
 import com.caimei.modules.order.utils.OrderUtil;
+import com.caimei.modules.order.utils.RandomCode;
 import com.caimei.modules.product.dao.CmPromotionDao;
 import com.caimei.modules.product.dao.CmSecondHandDetailDao;
 import com.caimei.modules.product.dao.ProductDao;
@@ -47,6 +48,8 @@ import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
@@ -351,6 +354,7 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
             newOrderProduct.setOrderID(newOrder.getOrderID());
             List<NewOrderProduct> dbOrderProducts = newOrderProductDao.findAllList(newOrderProduct);
 
+            StringBuilder productName = new StringBuilder();
             if (flag) {
                 //新增加的订单,那么删除原有的子订单 和订单商品信息
                 newOrderProductDao.deleteByOrderID(newOrder.getOrderID());
@@ -370,6 +374,7 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
                     double shopReducedPrice = 0d;
                     double needPayAmount = shopOrder.getNeedPayAmount();
                     for (NewOrderProduct orderProduct : shopOrder.getNewOrderProducts()) {
+                        productName.append(orderProduct.getName());
                         // 没有折扣时促销才生效
                         if (orderProduct.getDiscount() >= 100d) {
                             if (null != promotionsList && promotionsList.size() > 0) {
@@ -641,10 +646,68 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
             }
             newOrder.setShopOrderIDs(shopOrderIDs);
             newOrderDao.update(newOrder);
+
+            //下单短信推送
+            try {
+                if (flag) {
+                    CmUser user = cmUserDao.get(newOrder.getUserID().toString());
+                    if (user != null && StringUtils.isNotBlank(user.getBindMobile())) {
+                        String wwwServer = Global.getConfig("wwwServer");
+                        String shortLink = getShortLink(8, 3, wwwServer + "user/order/detail.html?orderId=" + newOrder.getOrderID());
+                        String name = productName.toString();
+                        if (name.length() > 10) {
+                            name = name.substring(0, 10);
+                        }
+                        String content = "您已成功下单“" + name + "...”等" + newOrder.getProductCount() + "件商品,订单编号:" + newOrder.getOrderNo() + ",订单等待支付,支付完成后采美将尽快安排发货。" +
+                                "您可关注采美公众号或者访问采美微信小程序和网站查看并支付订单。平台公众号:微信搜索“采美365网”; 微信小程序:微信搜索“采美采购商城”;网址:www.caimei365.com/t/" + shortLink;
+                        boolean sendSms = getSendSms(3, user.getBindMobile(), content);
+                        if (!sendSms) {
+                            logger.info("下单推送失败,orderId>>>>" + newOrder.getOrderID());
+                        }
+                    }
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
 
     }
 
+    public String getShortLink(int length, int markId, String url) {
+        String shortLink = RandomCode.generateShortLink(length);
+        Integer id = newOrderDao.findBYShortLink(shortLink);
+        if (id != null && id > 0) {
+            getShortLink(length, markId, url);
+        }
+        newOrderDao.insertShortLink(markId, shortLink, url);
+        return shortLink;
+    }
+
+    public boolean getSendSms(int markId, String mobile, String content) throws Exception {
+        if (org.apache.commons.lang.StringUtils.isNotBlank(mobile) && mobile.length() == 11) {
+            String regex = "^(1[3-9]\\d{9}$)";
+            Pattern pattern = Pattern.compile(regex);
+            Matcher matcher = pattern.matcher(mobile);
+            if (matcher.matches()) {
+                Map<String, Object> map = new HashMap<>(2);
+                map.put("content", content);
+                map.put("mobile", mobile);
+                String coreServer = Global.getConfig("caimei.core");
+                String url = coreServer + "/tools/sms/send";
+                String result = HttpRequest.sendPost(url, map);
+                JSONObject parseObject = JSONObject.parseObject(result);
+                Integer code = parseObject.getInteger("code");
+                if (code != 0) {
+                    logger.info("短信发送失败,手机号>>>>" + mobile);
+                } else {
+                    newOrderDao.updateSendNum(markId, 1);
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
     private void insertLadderPrice(NewOrderProduct orderProduct) {
         List<OrderProductLadderPrice> orderProductLadderPriceList = new ArrayList<>();
         if (orderProduct.getLadderPriceFlag() == 1) {
@@ -1175,6 +1238,21 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
             int userBeans = user.getUserBeans() + order.getUserBeans();
             cmUserDao.updateUserBeans(order.getUserID(), userBeans);
         }
+        //取消订单短信推送
+        try {
+            if (user != null && StringUtils.isNotBlank(user.getBindMobile())) {
+                String wwwServer = Global.getConfig("wwwServer");
+                String shortLink = getShortLink(8, 11, wwwServer + "user/order/detail.html?orderId=" + orderID);
+                String content = "您已成功取消订单(订单编号:" + order.getOrderNo() + "),订单金额¥" + order.getPayTotalFee() + "。您可关注采美公众号或者访问采美微信小程序和网站查看订单。" +
+                        "平台公众号:微信搜索“采美365网”; 微信小程序:微信搜索“采美采购商城”;网址:www.caimei365.com/t/" + shortLink;
+                boolean sendSms = getSendSms(11, user.getBindMobile(), content);
+                if (!sendSms) {
+                    logger.info("取消订单推送失败,订单id>>>>" + orderID);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -1260,6 +1338,7 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
         }
         //同步更新主订单的发货状态
         NewOrder order = newOrderDao.findByOrderID(orderID);
+        String sendOutStatus = order.getSendOutStatus();
         List<NewShopOrder> shopOrders = newShopOrderDao.findListByOrderID(order.getOrderID());
 
         String statusSuffix = "";
@@ -1333,6 +1412,33 @@ public class NewOrderService extends CrudService<NewOrderDao, NewOrder> {
                 logisticsInformationDao.insert(l);
             }
         }
+
+        try {
+            //发货短信推送
+            CmUser user = cmUserDao.get(order.getUserID().toString());
+            if (user != null && StringUtils.isNotBlank(user.getBindMobile())) {
+                String wwwServer = Global.getConfig("wwwServer");
+                boolean sendSms = false;
+                if ("2".equals(order.getSendOutStatus()) && "1".equals(sendOutStatus)) {
+                    //部分发货
+                    String shortLink = getShortLink(8, 7, wwwServer + "user/order/detail.html?orderId=" + order.getOrderID());
+                    String content = "您的订单(订单编号:" + order.getOrderNo() + ")已部分发货。您可关注采美公众号或者访问采美微信小程序和网站查看订单。平台公众号:微信搜索“采美365网”; " +
+                            "微信小程序:微信搜索“采美采购商城”;网址:www.caimei365.com/t/" + shortLink;
+                    sendSms = getSendSms(7, user.getBindMobile(), content);
+                } else if ("3".equals(order.getSendOutStatus())) {
+                    //已发货
+                    String shortLink = getShortLink(8, 8, wwwServer + "user/order/detail.html?orderId=" + order.getOrderID());
+                    String content = "您的订单(订单编号:" + order.getOrderNo() + ")已发货完毕。您可关注采美公众号或者访问采美微信小程序和网站查看订单。平台公众号:微信搜索“采美365网”; " +
+                            "微信小程序:微信搜索“采美采购商城”;网址:www.caimei365.com/t/" + shortLink;
+                    sendSms = getSendSms(8, user.getBindMobile(), content);
+                }
+                if (!sendSms) {
+                    logger.info("发货短信推送失败,订单id>>>>" + order.getOrderID());
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return lb.getId();
     }
 

+ 106 - 0
src/main/java/com/caimei/modules/order/utils/RandomCode.java

@@ -0,0 +1,106 @@
+package com.caimei.modules.order.utils;
+import java.util.Random;
+
+public class RandomCode {
+
+	// TODO 与WWW的RandomCodeGenerator是重复的,后续需要删除www的RandomCodeGenerator
+	private static char[] codeSequence = {
+			'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 
+			'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 
+			'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', 
+			'8', '9'
+		};
+	
+	private static char[] intSequence = {
+		'2', '3', '4', '5', '6', '7', 
+		'8', '9'
+	};
+	
+	private static char[] stringSequence = {
+		'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 
+		'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 
+		'W', 'X', 'Y', 'Z'
+	};
+
+	private static char[] newStringSequence = {
+			'A','a', 'B','b', 'D','d', 'E' ,'e', 'F','f', 'G','g', 'H','h',
+			'L', 'N','n', 'Q','q', 'R','r', 'T','t', 'Y','y'
+	};
+//	C,i,j,k,M,O,P,S,U,V,W,X,Z,l
+
+	private static char[] shortLink = {
+		'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
+		'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'O',
+		'W', 'X', 'Y', 'Z',
+		'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
+		'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'o',
+		'w', 'x', 'y', 'z' ,
+		'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'
+	};
+
+	public static String generateShortLink(int length) {
+		StringBuffer sb = new StringBuffer();
+		Random random = new Random();
+		for (int i = 0; i < shortLink.length && i < length; ++i) {
+			sb.append(shortLink[random.nextInt(shortLink.length)]);
+		}
+		return sb.toString();
+	}
+
+	public static String generateCode(int length) {
+		StringBuffer sb = new StringBuffer();
+		Random random = new Random();
+		for (int i = 0; i < codeSequence.length && i < length; ++i) {
+			sb.append(codeSequence[random.nextInt(codeSequence.length)]);
+		}
+		
+		return sb.toString();
+	}
+	
+	public static String generateCodeInt(int length) {
+		StringBuffer sb = new StringBuffer();
+		Random random = new Random();
+		for (int i = 0; i < intSequence.length && i < length; ++i) {
+			sb.append(intSequence[random.nextInt(intSequence.length)]);
+		}
+		
+		return sb.toString();
+	}
+	
+	public static String generateCodeString(int length) {
+		StringBuffer sb = new StringBuffer();
+		Random random = new Random();
+		for (int i = 0; i < stringSequence.length && i < length; ++i) {
+			sb.append(stringSequence[random.nextInt(stringSequence.length)]);
+		}
+		
+		return sb.toString();
+	}
+
+	public static String getRandomCharAndNumr(int length) {
+		String val = "";
+		Random random = new Random();
+		for (int i = 0; i < length; i++) {
+			// 输出字母还是数字
+			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
+			// 字符串
+			if ("char".equalsIgnoreCase(charOrNum)) {
+				// 取得大写字母还是小写字母
+				int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;
+				val += (char) (choice + random.nextInt(26));
+			} else if ("num".equalsIgnoreCase(charOrNum)) { // 数字
+				val += String.valueOf(random.nextInt(10));
+			}
+		}
+		return val;
+	}
+
+	public static String generateAccount(int length){
+		StringBuffer sb = new StringBuffer();
+		Random random = new Random();
+		for (int i = 0; i < newStringSequence.length && i < length; ++i) {
+			sb.append(newStringSequence[random.nextInt(newStringSequence.length)]);
+		}
+		return sb.toString();
+	}
+}

+ 20 - 0
src/main/resources/mappings/modules/order/OrderMapper.xml

@@ -838,4 +838,24 @@
             #{recordId}, #{fileName}, #{ossName}
           )
     </insert>
+
+	<select id="findBYShortLink" resultType="integer">
+        SELECT id FROM cm_short_link WHERE shortLink = #{shortLink}
+    </select>
+
+	<insert id="insertShortLink">
+    INSERT INTO `caimei`.`cm_short_link` (
+      `markId`, `shortLink`, `jumpLink`,
+      `createTime`
+    )
+    VALUES
+      (
+        #{markId}, #{shortLink}, #{url},
+        NOW()
+      )
+    </insert>
+
+	<update id="updateSendNum">
+        UPDATE cm_sms_statistics SET sendNum = (sendNum + #{num}) WHERE markId = #{markId}
+    </update>
 </mapper>

+ 3 - 3
src/main/webapp/WEB-INF/views/modules/order/cmPayShopList.jsp

@@ -373,10 +373,10 @@
                             </c:if>
                             <c:if test="${s.paying ne '1' && s.payStatus ne '3' }">
                                 <input type="checkbox" ${s.status eq 7 ?'disabled':''}
-                                       data-shoporderid="${s.shopOrderID}" data-shopid="${s.shopID}"/>
+                                       data-shoporderid="${s.shopOrderID}" data-shopid="${s.shopID}" data-isPayShopOtherFee="${s.payShopOtherFee}"/>
                             </c:if>
                         </c:if>
-                        <c:if test="${operatingMode == '2'}">
+<%--                        <c:if test="${operatingMode == '2'}">
                             <c:if test="${s.refunding == '1'}">
                                 退款中
                             </c:if>
@@ -390,7 +390,7 @@
                         </c:if>
                         <c:if test="${operatingMode == '3'}">
                             ${sIndex.index + 1}
-                        </c:if>
+                        </c:if>--%>
                     </th>
                     <th>子订单编号(ID)</th>
                     <th colspan="3">订单编号(ID)</th>