Selaa lähdekoodia

Merge remote-tracking branch 'origin/developerB' into developer

chao 4 vuotta sitten
vanhempi
commit
ed68c19faf

+ 8 - 1
base-module/src/main/java/com/caimei/module/base/entity/po/CmOrder.java

@@ -255,6 +255,11 @@ public class CmOrder implements Serializable {
      */
     private BigDecimal freight;
 
+    /**
+     * 采美豆抵扣运费数量(100:1)
+     */
+    private Integer userBeans;
+
     /**
      * 订单状态 0 有效  其它无效
      */
@@ -302,6 +307,8 @@ public class CmOrder implements Serializable {
      */
     private String rebateFlag;
 
-    /** 订单0成本标识*/
+    /**
+     * 订单0成本标识
+     */
     private Integer zeroCostFlag;
 }

+ 1 - 1
base-module/src/main/java/com/caimei/module/base/entity/po/Product.java

@@ -495,7 +495,7 @@ public class Product implements Serializable {
     private Date downlineTime;
 
     /**
-     * 是否包邮 0包邮 1到付
+     * 是否包邮 0包邮 1到付 2默认(遵循运费规则)
      */
     private String freePostFlag;
 

+ 54 - 0
base-module/src/main/java/com/caimei/module/base/entity/po/UserBeansHistoryPo.java

@@ -0,0 +1,54 @@
+package com.caimei.module.base.entity.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * user_beans_history
+ *
+ * @author
+ */
+@Data
+public class UserBeansHistoryPo implements Serializable {
+    private Integer id;
+
+    /**
+     * 用户id
+     */
+    private Integer userId;
+
+    /**
+     * 收支类型:1收入,2支出
+     */
+    private Integer type;
+
+    /**
+     * 采美豆类型:1注册机构,2升级会员机构,3普通机构完善资料,4会员机构完善资料,5下单,
+     * 6线上支付订单,7确认收货,8系统发放,9抵用退回,10抵用运费,11退款回收
+     */
+    private Integer beansType;
+
+    /**
+     * 主订单id
+     */
+    private Integer orderId;
+
+    /**
+     * 采美豆数量
+     */
+    private Integer num;
+
+    /**
+     * 推送状态:0未推送,1已推送
+     */
+    private Integer pushStatus;
+
+    /**
+     * 添加时间
+     */
+    private Date addTime;
+
+    private static final long serialVersionUID = 1L;
+}

+ 47 - 0
pay/src/main/java/com/caimei/module/pay/dao/PayDao.java

@@ -1,6 +1,7 @@
 package com.caimei.module.pay.dao;
 
 import com.caimei.module.base.entity.po.SeconHandProduct;
+import com.caimei.module.base.entity.po.UserBeansHistoryPo;
 import com.caimei.module.base.entity.vo.*;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -159,4 +160,50 @@ public interface PayDao {
      * @param payStatus
      */
     void updateOrderByPayStatus(@Param("orderId") Integer orderId, @Param("payStatus") String payStatus);
+
+    /**
+     * 保存采美豆记录
+     *
+     * @param beansHistory
+     */
+    void insertBeansHistory(UserBeansHistoryPo beansHistory);
+
+    /**
+     * @param orderId
+     * @return
+     */
+    Integer findPromotionsOrder(Long orderId);
+
+    /**
+     * 修改采美豆数量
+     *
+     * @param userId
+     * @param userBeans
+     */
+    void updateUserBeans(@Param("userId") Long userId, @Param("userBeans") int userBeans);
+
+    /**
+     * 查询短链接是否存在
+     *
+     * @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);
 }

+ 75 - 3
pay/src/main/java/com/caimei/module/pay/service/impl/PayServiceImpl.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.caimei.module.base.entity.bo.JsonModel;
 import com.caimei.module.base.entity.bo.Payment;
 import com.caimei.module.base.entity.po.SeconHandProduct;
+import com.caimei.module.base.entity.po.UserBeansHistoryPo;
 import com.caimei.module.base.entity.vo.*;
 import com.caimei.module.pay.dao.PayDao;
 import com.caimei.module.pay.service.PayService;
@@ -490,7 +491,8 @@ public class PayServiceImpl implements PayService {
             payDao.updateOrderPayLink(orderPayLink);
         }
         //保存收款记录
-        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date());
+        Date date = new Date();
+        String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
         DiscernReceiptVo discernReceipt = new DiscernReceiptVo();
         discernReceipt.setPayWay("1");
         discernReceipt.setPayType(payType);
@@ -517,13 +519,83 @@ public class PayServiceImpl implements PayService {
         relation.setSplitStatus("0");
         payDao.insertOrderRelation(relation);
         log.info(">>>>>>>>>>>>>>>>>>>>>>>保存付款金额到收款记录," + amount);
-        //修改分账付款状态
-        //payDao.updateSplitAccountByPay(mbOrderId);
         //判断是否是充值商品
         getRechargeGoods(order, amount);
+        //线上支付与自主下单送豆
+        UserVo user = payDao.findUser(order.getUserID());
+        if (user != null && "3".equals(order.getReceiptStatus()) && "0".equals(order.getSecondHandOrderFlag())) {
+            int userBeans = user.getUserBeans() == null ? 0 : user.getUserBeans();
+            //线上支付送100采美豆
+            UserBeansHistoryPo beansHistory = new UserBeansHistoryPo();
+            beansHistory.setUserId(order.getUserID().intValue());
+            beansHistory.setOrderId(order.getOrderID().intValue());
+            beansHistory.setBeansType(6);
+            beansHistory.setType(1);
+            beansHistory.setNum(100);
+            beansHistory.setPushStatus(0);
+            beansHistory.setAddTime(date);
+            payDao.insertBeansHistory(beansHistory);
+            userBeans = userBeans + 100;
+
+            //自主下单且没有促销活动送豆
+            Integer id = payDao.findPromotionsOrder(order.getOrderID());
+            if (1 == order.getOrderType() && id == null) {
+                BigDecimal payTotalFee = order.getPayTotalFee();
+                int num = 0;
+                if (MathUtil.compare(1000, payTotalFee) > -1) {
+                    num = 10;
+                } else if (MathUtil.compare(5000, payTotalFee) > -1) {
+                    num = 20;
+                } else if (MathUtil.compare(10000, payTotalFee) > -1) {
+                    num = 50;
+                } else if (MathUtil.compare(25000, payTotalFee) > -1) {
+                    num = 100;
+                } else if (MathUtil.compare(100000, payTotalFee) > -1) {
+                    num = 150;
+                } else if (MathUtil.compare(250000, payTotalFee) > -1) {
+                    num = 200;
+                } else if (MathUtil.compare(500000, payTotalFee) > -1) {
+                    num = 250;
+                } else {
+                    num = 400;
+                }
+                beansHistory.setBeansType(5);
+                beansHistory.setNum(num);
+                payDao.insertBeansHistory(beansHistory);
+                userBeans = userBeans + num;
+            }
+            payDao.updateUserBeans(order.getUserID(), userBeans);
+        }
+        //已支付短信推送
+        if (user != null && StringUtils.isNotBlank(user.getBindMobile()) && user.getBindMobile().length() == 11 && "3".equals(order.getReceiptStatus())) {
+            String shortLink = getShortLink(8, 6, "https://www.caimei365.com/user/order/detail.html?orderId=" + order.getOrderID());
+            String content = "您已成功支付订单(订单编号:" + order.getOrderNo() + ")全部款项,支付总金额¥" + order.getPayTotalFee() + ",采美平台将立即安排发货。您可关注采美公众号或者访问采美微信小程序和网站查看订单。" +
+                    "平台公众号:微信搜索“采美365网”; 微信小程序:微信搜索“采美采购商城”;网址:www.caimei365.com/t/" + shortLink;
+            Map<String, String> map = new HashMap<>(2);
+            map.put("content", content);
+            map.put("mobile", user.getBindMobile());
+            String result = HttpRequest.sendPost("https://core.caimei365.com/tools/sms/send", map);
+            JSONObject parseObject = JSONObject.parseObject(result);
+            Integer code = parseObject.getInteger("code");
+            if (code != 0) {
+                log.info("已支付短信推送失败,订单id>>>>" + order.getOrderID());
+            }else {
+                payDao.updateSendNum(6, 1);
+            }
+        }
         return "SUCCESS";
     }
 
+    public String getShortLink(int length, int markId, String url) {
+        String shortLink = RandomCodeGenerator.generateShortLink(length);
+        Integer id = payDao.findBYShortLink(shortLink);
+        if (id != null && id > 0) {
+            getShortLink(length, markId, url);
+        }
+        payDao.insertShortLink(markId, shortLink, url);
+        return shortLink;
+    }
+
     /**
      * 判断是否是充值商品
      *

+ 240 - 0
pay/src/main/java/com/caimei/module/pay/util/HttpRequest.java

@@ -0,0 +1,240 @@
+package com.caimei.module.pay.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * HTTP 请求工具
+ */
+public class HttpRequest {
+    /**
+     * 向指定URL发送GET方法的请求
+     *
+     * @param url   发送请求的URL
+     * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
+     * @return URL 所代表远程资源的响应结果
+     * @throws Exception
+     */
+    @SuppressWarnings("unused")
+    public static String sendGetWithParameter(String url, String param) throws Exception {
+        StringBuffer result=new StringBuffer();
+        BufferedReader in = null;
+        try {
+            String urlNameString = url + "?" + param;
+            URL realUrl = new URL(urlNameString);
+            // 打开和URL之间的连接
+            URLConnection connection = realUrl.openConnection();
+            // 设置通用的请求属性
+            connection.setRequestProperty("accept", "*/*");
+            connection.setRequestProperty("connection", "Keep-Alive");
+            connection.setRequestProperty("Accept-Charset", "utf-8");
+            connection.setRequestProperty("contentType", "utf-8");
+            connection.setConnectTimeout(5000);
+            // 建立实际的连接
+            connection.connect();
+            // 获取所有响应头字段
+            Map<String, List<String>> map = connection.getHeaderFields();
+            // 遍历所有的响应头字段
+            for (String key : map.keySet()) {
+                // System.out.println(key + "--->" + map.get(key)); //关闭响应头的输出
+            }
+            // 定义 BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(new InputStreamReader(
+                    connection.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result.append(line);
+            }
+        } catch (Exception e) {
+            throw e;
+        }
+        // 使用finally块来关闭输入流
+        finally {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            } catch (Exception e2) {
+                throw e2;
+            }
+        }
+        return result.toString();
+    }
+
+
+    @SuppressWarnings("unused")
+    public static String sendGet(String url) throws Exception {
+        StringBuffer result=new StringBuffer();
+        BufferedReader in = null;
+        try {
+
+            URL realUrl = new URL(url);
+            // 打开和URL之间的连接
+            URLConnection connection = realUrl.openConnection();
+            // 设置通用的请求属性
+            connection.setRequestProperty("accept", "*/*");
+            connection.setRequestProperty("connection", "Keep-Alive");
+            connection.setRequestProperty("Accept-Charset", "utf-8");
+            connection.setRequestProperty("contentType", "utf-8");
+            connection.setConnectTimeout(5000);
+            // 建立实际的连接
+            connection.connect();
+            // 获取所有响应头字段
+            Map<String, List<String>> map = connection.getHeaderFields();
+            // 遍历所有的响应头字段
+            for (String key : map.keySet()) {
+                //  System.out.println(key + "--->" + map.get(key));
+            }
+            // 定义 BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(new InputStreamReader(
+                    connection.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result.append(line);
+            }
+        } catch (Exception e) {
+            throw e;
+        }
+        // 使用finally块来关闭输入流
+        finally {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            } catch (Exception e2) {
+                throw e2;
+            }
+        }
+        return result.toString();
+    }
+
+    /**
+     * 向指定 URL 发送POST方法的请求
+     *
+     * @param url   发送请求的 URL
+     * @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
+     * @return 所代表远程资源的响应结果
+     * @throws Exception
+     */
+    public static String sendPost(String url, String param) throws Exception {
+        PrintWriter out = null;
+        BufferedReader in = null;
+        StringBuffer result=new StringBuffer();
+        try {
+            URL realUrl = new URL(url);
+            // 打开和URL之间的连接
+            URLConnection conn = realUrl.openConnection();
+            // 设置通用的请求属性
+            conn.setRequestProperty("accept", "*/*");
+            conn.setRequestProperty("connection", "Keep-Alive");
+            conn.setRequestProperty("Accept-Charset", "utf-8");
+            conn.setRequestProperty("contentType", "utf-8");
+            conn.setConnectTimeout(5000);
+            // 发送POST请求必须设置如下两行
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            // 获取URLConnection对象对应的输出流
+            out = new PrintWriter(conn.getOutputStream());
+            // 发送请求参数
+            out.print(param);
+            // flush输出流的缓冲
+            out.flush();
+            // 定义BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(
+                    new InputStreamReader(conn.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result.append(line);
+            }
+        } catch (Exception e) {
+            throw e;
+        }
+        //使用finally块来关闭输出流、输入流
+        finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+                if (in != null) {
+                    in.close();
+                }
+            } catch (Exception ex) {
+                throw ex;
+            }
+        }
+        return result.toString();
+    }
+
+
+    /**
+     * 向指定 URL 发送POST方法的请求
+     *
+     * @param url 发送请求的 URL
+     * @param paramMap 请求参数
+     * @return 所代表远程资源的响应结果
+     */
+    public static String sendPost(String url, Map<String, ?> paramMap) throws Exception{
+        PrintWriter out = null;
+        BufferedReader in = null;
+        String result = "";
+
+        String param = "";
+        Iterator<String> it = paramMap.keySet().iterator();
+
+        while(it.hasNext()) {
+            String key = it.next();
+            param += key + "=" + paramMap.get(key) + "&";
+        }
+
+        try {
+            URL realUrl = new URL(url);
+            // 打开和URL之间的连接
+            URLConnection conn = realUrl.openConnection();
+            // 设置通用的请求属性
+            conn.setRequestProperty("accept", "*/*");
+            conn.setRequestProperty("connection", "Keep-Alive");
+            conn.setRequestProperty("Accept-Charset", "utf-8");
+            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+            // 发送POST请求必须设置如下两行
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            // 获取URLConnection对象对应的输出流
+            out = new PrintWriter(conn.getOutputStream());
+            // 发送请求参数
+            out.print(param);
+            // flush输出流的缓冲
+            out.flush();
+            // 定义BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result += line;
+            }
+        } catch (Exception e) {
+            throw e;
+        }
+        //使用finally块来关闭输出流、输入流
+        finally{
+            try{
+                if(out!=null){
+                    out.close();
+                }
+                if(in!=null){
+                    in.close();
+                }
+            }
+            catch(IOException ex){
+               throw ex;
+            }
+        }
+        return result;
+    }
+
+}

+ 19 - 0
pay/src/main/java/com/caimei/module/pay/util/RandomCodeGenerator.java

@@ -28,6 +28,25 @@ public class RandomCodeGenerator {
 	};
 //	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();

+ 40 - 0
pay/src/main/resources/com-caimei-module-pay/PayMapper.xml

@@ -584,4 +584,44 @@
         WHERE
           orderID = #{orderId}
     </update>
+
+    <insert id="insertBeansHistory">
+        INSERT INTO `user_beans_history` (
+          `userId`, `type`, `beansType`, `orderId`,
+          `num`, `pushStatus`, `addTime`, delFlag
+        )
+        VALUES
+          (
+            #{userId}, #{type}, #{beansType}, #{orderId},
+            #{num}, #{pushStatus}, #{addTime}, 0
+          )
+    </insert>
+
+    <select id="findPromotionsOrder" resultType="integer">
+        SELECT id FROM cm_organize_promotions_order WHERE orderId = #{orderId} LIMIT 1
+    </select>
+
+    <update id="updateUserBeans">
+        UPDATE user SET userBeans = #{userBeans} WHERE userID = #{userId}
+    </update>
+
+    <select id="findBYShortLink" resultType="integer">
+        SELECT id FROM cm_short_link WHERE shortLink = #{shortLink}
+    </select>
+
+    <insert id="insertShortLink">
+    INSERT INTO `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>