Authored by Lixiaodi

Merge branch 'dev_order_transfer' into dev

# Conflicts:
#	dal/src/main/java/com/yohoufo/dal/order/TradeBillsMapper.java
#	dal/src/main/java/com/yohoufo/dal/order/model/TradeBills.java
#	dal/src/main/resources/META-INF/mybatis/order/TradeBillsMapper.xml
#	order/src/main/java/com/yohoufo/order/service/impl/PaymentServiceImpl.java
@@ -57,4 +57,6 @@ public interface CacheClient { @@ -57,4 +57,6 @@ public interface CacheClient {
57 57
58 public <T> T hashGet(String key, String field, Class<T> clazz); 58 public <T> T hashGet(String key, String field, Class<T> clazz);
59 59
  60 + boolean setNx(String key, int expireInSeconds, Object o);
  61 +
60 } 62 }
@@ -164,6 +164,24 @@ public class RedisGwCacheClient implements CacheClient { @@ -164,6 +164,24 @@ public class RedisGwCacheClient implements CacheClient {
164 } 164 }
165 return null; 165 return null;
166 } 166 }
  167 +
  168 + @Override
  169 + public boolean setNx(String key, int expireInSeconds, Object o) {
  170 + try {
  171 + RedisKeyBuilder keyB = RedisKeyBuilder.newInstance().appendFixed(key);
  172 + String compressStr = SnappyZipUtils.compress(JSON.toJSONString(o));
  173 + Boolean resu = this.valueOperations.setIfAbsent(keyB, compressStr);
  174 + if (resu != null && resu) {
  175 + redis.expire(keyB, expireInSeconds, TimeUnit.SECONDS);
  176 + return true;
  177 + }
  178 + return false;
  179 + } catch (Exception e) {
  180 + LOGGER.warn("setNx into redis failed!! key is :{} ,e is :{}", key, e);
  181 + return false;
  182 + }
  183 + }
  184 +
167 185
168 /** 186 /**
169 * 获取正负区间的一个随机数 187 * 获取正负区间的一个随机数
@@ -15,4 +15,6 @@ public interface OrdersPayTransferMapper { @@ -15,4 +15,6 @@ public interface OrdersPayTransferMapper {
15 int updateByPrimaryKeySelective(OrdersPayTransfer record); 15 int updateByPrimaryKeySelective(OrdersPayTransfer record);
16 16
17 int updateByPrimaryKey(OrdersPayTransfer record); 17 int updateByPrimaryKey(OrdersPayTransfer record);
  18 +
  19 + OrdersPayTransfer selectByBuyerOrderCode(long buyerOrderCode);
18 } 20 }
1 package com.yohoufo.dal.order; 1 package com.yohoufo.dal.order;
2 2
3 -import com.yohoufo.dal.order.model.TradeBills;  
4 -import org.apache.ibatis.annotations.Param;  
5 -  
6 -import java.math.BigDecimal;  
7 import java.util.List; 3 import java.util.List;
8 import java.util.Map; 4 import java.util.Map;
9 5
  6 +import org.apache.ibatis.annotations.Param;
  7 +
  8 +import com.yohoufo.dal.order.model.TradeBills;
  9 +
10 public interface TradeBillsMapper { 10 public interface TradeBillsMapper {
11 11
12 TradeBills selectByPrimaryKey(Integer id); 12 TradeBills selectByPrimaryKey(Integer id);
@@ -23,6 +23,13 @@ public interface TradeBillsMapper { @@ -23,6 +23,13 @@ public interface TradeBillsMapper {
23 23
24 //根据用户uid,获取用户总支出 24 //根据用户uid,获取用户总支出
25 List<Map<String, Object>> selectSpendAmountByUid(@Param("uid") Integer uid); 25 List<Map<String, Object>> selectSpendAmountByUid(@Param("uid") Integer uid);
26 - 26 +
  27 + int deleteByPrimaryKey(Integer id);
  28 +
  29 + int insertSelective(TradeBills record);
  30 +
  31 + int updateByPrimaryKeySelective(TradeBills record);
  32 +
  33 + int updateByPrimaryKey(TradeBills record);
27 34
28 } 35 }
@@ -5,9 +5,13 @@ import java.math.BigDecimal; @@ -5,9 +5,13 @@ import java.math.BigDecimal;
5 public class OrdersPayTransfer { 5 public class OrdersPayTransfer {
6 private Integer id; 6 private Integer id;
7 7
8 - private Long orderCode; 8 + private Long buyerOrderCode;
9 9
10 - private String orderId; 10 + private Long sellerOrderCode;
  11 +
  12 + private String alipayTradeId;
  13 +
  14 + private Integer transferType;
11 15
12 private Integer uid; 16 private Integer uid;
13 17
@@ -15,15 +19,13 @@ public class OrdersPayTransfer { @@ -15,15 +19,13 @@ public class OrdersPayTransfer {
15 19
16 private BigDecimal amount; 20 private BigDecimal amount;
17 21
18 - private Integer transferType;  
19 -  
20 - private Byte status; 22 + private Integer status;
21 23
22 private Integer createTime; 24 private Integer createTime;
23 25
24 private Integer updateTime; 26 private Integer updateTime;
25 27
26 - private String transferCode; 28 + private String alipayTradeResult;
27 29
28 public Integer getId() { 30 public Integer getId() {
29 return id; 31 return id;
@@ -33,20 +35,36 @@ public class OrdersPayTransfer { @@ -33,20 +35,36 @@ public class OrdersPayTransfer {
33 this.id = id; 35 this.id = id;
34 } 36 }
35 37
36 - public Long getOrderCode() {  
37 - return orderCode; 38 + public Long getBuyerOrderCode() {
  39 + return buyerOrderCode;
  40 + }
  41 +
  42 + public void setBuyerOrderCode(Long buyerOrderCode) {
  43 + this.buyerOrderCode = buyerOrderCode;
38 } 44 }
39 45
40 - public void setOrderCode(Long orderCode) {  
41 - this.orderCode = orderCode; 46 + public Long getSellerOrderCode() {
  47 + return sellerOrderCode;
42 } 48 }
43 49
44 - public String getOrderId() {  
45 - return orderId; 50 + public void setSellerOrderCode(Long sellerOrderCode) {
  51 + this.sellerOrderCode = sellerOrderCode;
46 } 52 }
47 53
48 - public void setOrderId(String orderId) {  
49 - this.orderId = orderId == null ? null : orderId.trim(); 54 + public String getAlipayTradeId() {
  55 + return alipayTradeId;
  56 + }
  57 +
  58 + public void setAlipayTradeId(String alipayTradeId) {
  59 + this.alipayTradeId = alipayTradeId == null ? null : alipayTradeId.trim();
  60 + }
  61 +
  62 + public Integer getTransferType() {
  63 + return transferType;
  64 + }
  65 +
  66 + public void setTransferType(Integer transferType) {
  67 + this.transferType = transferType;
50 } 68 }
51 69
52 public Integer getUid() { 70 public Integer getUid() {
@@ -73,19 +91,11 @@ public class OrdersPayTransfer { @@ -73,19 +91,11 @@ public class OrdersPayTransfer {
73 this.amount = amount; 91 this.amount = amount;
74 } 92 }
75 93
76 - public Integer getTransferType() {  
77 - return transferType;  
78 - }  
79 -  
80 - public void setTransferType(Integer transferType) {  
81 - this.transferType = transferType;  
82 - }  
83 -  
84 - public Byte getStatus() { 94 + public Integer getStatus() {
85 return status; 95 return status;
86 } 96 }
87 97
88 - public void setStatus(Byte status) { 98 + public void setStatus(Integer status) {
89 this.status = status; 99 this.status = status;
90 } 100 }
91 101
@@ -105,11 +115,11 @@ public class OrdersPayTransfer { @@ -105,11 +115,11 @@ public class OrdersPayTransfer {
105 this.updateTime = updateTime; 115 this.updateTime = updateTime;
106 } 116 }
107 117
108 - public String getTransferCode() {  
109 - return transferCode; 118 + public String getAlipayTradeResult() {
  119 + return alipayTradeResult;
110 } 120 }
111 121
112 - public void setTransferCode(String transferCode) {  
113 - this.transferCode = transferCode == null ? null : transferCode.trim(); 122 + public void setAlipayTradeResult(String alipayTradeResult) {
  123 + this.alipayTradeResult = alipayTradeResult == null ? null : alipayTradeResult.trim();
114 } 124 }
115 } 125 }
@@ -37,4 +37,6 @@ public class TradeBills { @@ -37,4 +37,6 @@ public class TradeBills {
37 private Integer tradeStatus; 37 private Integer tradeStatus;
38 38
39 private Integer createTime; 39 private Integer createTime;
40 -} 40 +
  41 +
  42 +}
@@ -3,24 +3,32 @@ @@ -3,24 +3,32 @@
3 <mapper namespace="com.yohoufo.dal.order.OrdersPayTransferMapper" > 3 <mapper namespace="com.yohoufo.dal.order.OrdersPayTransferMapper" >
4 <resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.OrdersPayTransfer" > 4 <resultMap id="BaseResultMap" type="com.yohoufo.dal.order.model.OrdersPayTransfer" >
5 <id column="id" property="id" jdbcType="INTEGER" /> 5 <id column="id" property="id" jdbcType="INTEGER" />
6 - <result column="order_code" property="orderCode" jdbcType="BIGINT" />  
7 - <result column="order_id" property="orderId" jdbcType="VARCHAR" /> 6 + <result column="buyer_order_code" property="buyerOrderCode" jdbcType="BIGINT" />
  7 + <result column="seller_order_code" property="sellerOrderCode" jdbcType="BIGINT" />
  8 + <result column="alipay_trade_id" property="alipayTradeId" jdbcType="VARCHAR" />
  9 + <result column="transfer_type" property="transferType" jdbcType="INTEGER" />
8 <result column="uid" property="uid" jdbcType="INTEGER" /> 10 <result column="uid" property="uid" jdbcType="INTEGER" />
9 <result column="alipay_account" property="alipayAccount" jdbcType="VARCHAR" /> 11 <result column="alipay_account" property="alipayAccount" jdbcType="VARCHAR" />
10 <result column="amount" property="amount" jdbcType="DECIMAL" /> 12 <result column="amount" property="amount" jdbcType="DECIMAL" />
11 - <result column="transfer_type" property="transferType" jdbcType="INTEGER" />  
12 - <result column="status" property="status" jdbcType="TINYINT" /> 13 + <result column="status" property="status" jdbcType="INTEGER" />
13 <result column="create_time" property="createTime" jdbcType="INTEGER" /> 14 <result column="create_time" property="createTime" jdbcType="INTEGER" />
14 <result column="update_time" property="updateTime" jdbcType="INTEGER" /> 15 <result column="update_time" property="updateTime" jdbcType="INTEGER" />
15 - <result column="transfer_code" property="transferCode" jdbcType="VARCHAR" /> 16 + </resultMap>
  17 + <resultMap id="ResultMapWithBLOBs" type="com.yohoufo.dal.order.model.OrdersPayTransfer" extends="BaseResultMap" >
  18 + <result column="alipay_trade_result" property="alipayTradeResult" jdbcType="LONGVARCHAR" />
16 </resultMap> 19 </resultMap>
17 <sql id="Base_Column_List" > 20 <sql id="Base_Column_List" >
18 - id, order_code, order_id, uid, alipay_account, amount, transfer_type, status, create_time,  
19 - update_time, transfer_code 21 + id, buyer_order_code, seller_order_code, alipay_trade_id, transfer_type, uid, alipay_account,
  22 + amount, status, create_time, update_time
20 </sql> 23 </sql>
21 - <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > 24 + <sql id="Blob_Column_List" >
  25 + alipay_trade_result
  26 + </sql>
  27 + <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
22 select 28 select
23 <include refid="Base_Column_List" /> 29 <include refid="Base_Column_List" />
  30 + ,
  31 + <include refid="Blob_Column_List" />
24 from orders_pay_transfer 32 from orders_pay_transfer
25 where id = #{id,jdbcType=INTEGER} 33 where id = #{id,jdbcType=INTEGER}
26 </select> 34 </select>
@@ -29,14 +37,16 @@ @@ -29,14 +37,16 @@
29 where id = #{id,jdbcType=INTEGER} 37 where id = #{id,jdbcType=INTEGER}
30 </delete> 38 </delete>
31 <insert id="insert" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" > 39 <insert id="insert" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
32 - insert into orders_pay_transfer (id, order_code, order_id,  
33 - uid, alipay_account, amount,  
34 - transfer_type, status, create_time,  
35 - update_time, transfer_code)  
36 - values (#{id,jdbcType=INTEGER}, #{orderCode,jdbcType=BIGINT}, #{orderId,jdbcType=VARCHAR},  
37 - #{uid,jdbcType=INTEGER}, #{alipayAccount,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL},  
38 - #{transferType,jdbcType=INTEGER}, #{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER},  
39 - #{updateTime,jdbcType=INTEGER}, #{transferCode,jdbcType=VARCHAR}) 40 + insert into orders_pay_transfer (id, buyer_order_code, seller_order_code,
  41 + alipay_trade_id, transfer_type, uid,
  42 + alipay_account, amount, status,
  43 + create_time, update_time, alipay_trade_result
  44 + )
  45 + values (#{id,jdbcType=INTEGER}, #{buyerOrderCode,jdbcType=BIGINT}, #{sellerOrderCode,jdbcType=BIGINT},
  46 + #{alipayTradeId,jdbcType=VARCHAR}, #{transferType,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER},
  47 + #{alipayAccount,jdbcType=VARCHAR}, #{amount,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER},
  48 + #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}, #{alipayTradeResult,jdbcType=LONGVARCHAR}
  49 + )
40 </insert> 50 </insert>
41 <insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" > 51 <insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
42 insert into orders_pay_transfer 52 insert into orders_pay_transfer
@@ -44,11 +54,17 @@ @@ -44,11 +54,17 @@
44 <if test="id != null" > 54 <if test="id != null" >
45 id, 55 id,
46 </if> 56 </if>
47 - <if test="orderCode != null" >  
48 - order_code, 57 + <if test="buyerOrderCode != null" >
  58 + buyer_order_code,
  59 + </if>
  60 + <if test="sellerOrderCode != null" >
  61 + seller_order_code,
49 </if> 62 </if>
50 - <if test="orderId != null" >  
51 - order_id, 63 + <if test="alipayTradeId != null" >
  64 + alipay_trade_id,
  65 + </if>
  66 + <if test="transferType != null" >
  67 + transfer_type,
52 </if> 68 </if>
53 <if test="uid != null" > 69 <if test="uid != null" >
54 uid, 70 uid,
@@ -59,9 +75,6 @@ @@ -59,9 +75,6 @@
59 <if test="amount != null" > 75 <if test="amount != null" >
60 amount, 76 amount,
61 </if> 77 </if>
62 - <if test="transferType != null" >  
63 - transfer_type,  
64 - </if>  
65 <if test="status != null" > 78 <if test="status != null" >
66 status, 79 status,
67 </if> 80 </if>
@@ -71,19 +84,25 @@ @@ -71,19 +84,25 @@
71 <if test="updateTime != null" > 84 <if test="updateTime != null" >
72 update_time, 85 update_time,
73 </if> 86 </if>
74 - <if test="transferCode != null" >  
75 - transfer_code, 87 + <if test="alipayTradeResult != null" >
  88 + alipay_trade_result,
76 </if> 89 </if>
77 </trim> 90 </trim>
78 <trim prefix="values (" suffix=")" suffixOverrides="," > 91 <trim prefix="values (" suffix=")" suffixOverrides="," >
79 <if test="id != null" > 92 <if test="id != null" >
80 #{id,jdbcType=INTEGER}, 93 #{id,jdbcType=INTEGER},
81 </if> 94 </if>
82 - <if test="orderCode != null" >  
83 - #{orderCode,jdbcType=BIGINT}, 95 + <if test="buyerOrderCode != null" >
  96 + #{buyerOrderCode,jdbcType=BIGINT},
  97 + </if>
  98 + <if test="sellerOrderCode != null" >
  99 + #{sellerOrderCode,jdbcType=BIGINT},
  100 + </if>
  101 + <if test="alipayTradeId != null" >
  102 + #{alipayTradeId,jdbcType=VARCHAR},
84 </if> 103 </if>
85 - <if test="orderId != null" >  
86 - #{orderId,jdbcType=VARCHAR}, 104 + <if test="transferType != null" >
  105 + #{transferType,jdbcType=INTEGER},
87 </if> 106 </if>
88 <if test="uid != null" > 107 <if test="uid != null" >
89 #{uid,jdbcType=INTEGER}, 108 #{uid,jdbcType=INTEGER},
@@ -94,11 +113,8 @@ @@ -94,11 +113,8 @@
94 <if test="amount != null" > 113 <if test="amount != null" >
95 #{amount,jdbcType=DECIMAL}, 114 #{amount,jdbcType=DECIMAL},
96 </if> 115 </if>
97 - <if test="transferType != null" >  
98 - #{transferType,jdbcType=INTEGER},  
99 - </if>  
100 <if test="status != null" > 116 <if test="status != null" >
101 - #{status,jdbcType=TINYINT}, 117 + #{status,jdbcType=INTEGER},
102 </if> 118 </if>
103 <if test="createTime != null" > 119 <if test="createTime != null" >
104 #{createTime,jdbcType=INTEGER}, 120 #{createTime,jdbcType=INTEGER},
@@ -106,19 +122,25 @@ @@ -106,19 +122,25 @@
106 <if test="updateTime != null" > 122 <if test="updateTime != null" >
107 #{updateTime,jdbcType=INTEGER}, 123 #{updateTime,jdbcType=INTEGER},
108 </if> 124 </if>
109 - <if test="transferCode != null" >  
110 - #{transferCode,jdbcType=VARCHAR}, 125 + <if test="alipayTradeResult != null" >
  126 + #{alipayTradeResult,jdbcType=LONGVARCHAR},
111 </if> 127 </if>
112 </trim> 128 </trim>
113 </insert> 129 </insert>
114 <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" > 130 <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
115 update orders_pay_transfer 131 update orders_pay_transfer
116 <set > 132 <set >
117 - <if test="orderCode != null" >  
118 - order_code = #{orderCode,jdbcType=BIGINT}, 133 + <if test="buyerOrderCode != null" >
  134 + buyer_order_code = #{buyerOrderCode,jdbcType=BIGINT},
  135 + </if>
  136 + <if test="sellerOrderCode != null" >
  137 + seller_order_code = #{sellerOrderCode,jdbcType=BIGINT},
119 </if> 138 </if>
120 - <if test="orderId != null" >  
121 - order_id = #{orderId,jdbcType=VARCHAR}, 139 + <if test="alipayTradeId != null" >
  140 + alipay_trade_id = #{alipayTradeId,jdbcType=VARCHAR},
  141 + </if>
  142 + <if test="transferType != null" >
  143 + transfer_type = #{transferType,jdbcType=INTEGER},
122 </if> 144 </if>
123 <if test="uid != null" > 145 <if test="uid != null" >
124 uid = #{uid,jdbcType=INTEGER}, 146 uid = #{uid,jdbcType=INTEGER},
@@ -129,11 +151,8 @@ @@ -129,11 +151,8 @@
129 <if test="amount != null" > 151 <if test="amount != null" >
130 amount = #{amount,jdbcType=DECIMAL}, 152 amount = #{amount,jdbcType=DECIMAL},
131 </if> 153 </if>
132 - <if test="transferType != null" >  
133 - transfer_type = #{transferType,jdbcType=INTEGER},  
134 - </if>  
135 <if test="status != null" > 154 <if test="status != null" >
136 - status = #{status,jdbcType=TINYINT}, 155 + status = #{status,jdbcType=INTEGER},
137 </if> 156 </if>
138 <if test="createTime != null" > 157 <if test="createTime != null" >
139 create_time = #{createTime,jdbcType=INTEGER}, 158 create_time = #{createTime,jdbcType=INTEGER},
@@ -141,24 +160,39 @@ @@ -141,24 +160,39 @@
141 <if test="updateTime != null" > 160 <if test="updateTime != null" >
142 update_time = #{updateTime,jdbcType=INTEGER}, 161 update_time = #{updateTime,jdbcType=INTEGER},
143 </if> 162 </if>
144 - <if test="transferCode != null" >  
145 - transfer_code = #{transferCode,jdbcType=VARCHAR}, 163 + <if test="alipayTradeResult != null" >
  164 + alipay_trade_result = #{alipayTradeResult,jdbcType=LONGVARCHAR},
146 </if> 165 </if>
147 </set> 166 </set>
148 where id = #{id,jdbcType=INTEGER} 167 where id = #{id,jdbcType=INTEGER}
149 </update> 168 </update>
150 - <update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" > 169 + <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
151 update orders_pay_transfer 170 update orders_pay_transfer
152 - set order_code = #{orderCode,jdbcType=BIGINT},  
153 - order_id = #{orderId,jdbcType=VARCHAR}, 171 + set buyer_order_code = #{buyerOrderCode,jdbcType=BIGINT},
  172 + seller_order_code = #{sellerOrderCode,jdbcType=BIGINT},
  173 + alipay_trade_id = #{alipayTradeId,jdbcType=VARCHAR},
  174 + transfer_type = #{transferType,jdbcType=INTEGER},
154 uid = #{uid,jdbcType=INTEGER}, 175 uid = #{uid,jdbcType=INTEGER},
155 alipay_account = #{alipayAccount,jdbcType=VARCHAR}, 176 alipay_account = #{alipayAccount,jdbcType=VARCHAR},
156 amount = #{amount,jdbcType=DECIMAL}, 177 amount = #{amount,jdbcType=DECIMAL},
157 - transfer_type = #{transferType,jdbcType=INTEGER},  
158 - status = #{status,jdbcType=TINYINT}, 178 + status = #{status,jdbcType=INTEGER},
159 create_time = #{createTime,jdbcType=INTEGER}, 179 create_time = #{createTime,jdbcType=INTEGER},
160 update_time = #{updateTime,jdbcType=INTEGER}, 180 update_time = #{updateTime,jdbcType=INTEGER},
161 - transfer_code = #{transferCode,jdbcType=VARCHAR} 181 + alipay_trade_result = #{alipayTradeResult,jdbcType=LONGVARCHAR}
  182 + where id = #{id,jdbcType=INTEGER}
  183 + </update>
  184 + <update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.OrdersPayTransfer" >
  185 + update orders_pay_transfer
  186 + set buyer_order_code = #{buyerOrderCode,jdbcType=BIGINT},
  187 + seller_order_code = #{sellerOrderCode,jdbcType=BIGINT},
  188 + alipay_trade_id = #{alipayTradeId,jdbcType=VARCHAR},
  189 + transfer_type = #{transferType,jdbcType=INTEGER},
  190 + uid = #{uid,jdbcType=INTEGER},
  191 + alipay_account = #{alipayAccount,jdbcType=VARCHAR},
  192 + amount = #{amount,jdbcType=DECIMAL},
  193 + status = #{status,jdbcType=INTEGER},
  194 + create_time = #{createTime,jdbcType=INTEGER},
  195 + update_time = #{updateTime,jdbcType=INTEGER}
162 where id = #{id,jdbcType=INTEGER} 196 where id = #{id,jdbcType=INTEGER}
163 </update> 197 </update>
164 </mapper> 198 </mapper>
@@ -62,4 +62,141 @@ @@ -62,4 +62,141 @@
62 62
63 63
64 64
  65 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  66 + delete from trade_bills
  67 + where id = #{id,jdbcType=INTEGER}
  68 + </delete>
  69 + <insert id="insert" parameterType="com.yohoufo.dal.order.model.TradeBills" >
  70 + insert into trade_bills (id, uid, order_code,
  71 + user_type, pay_type, trade_type,
  72 + income_outcome, amount, system_amount,
  73 + trade_status, create_time)
  74 + values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{orderCode,jdbcType=BIGINT},
  75 + #{userType,jdbcType=INTEGER}, #{payType,jdbcType=INTEGER}, #{tradeType,jdbcType=INTEGER},
  76 + #{incomeOutcome,jdbcType=INTEGER}, #{amount,jdbcType=DECIMAL}, #{systemAmount,jdbcType=DECIMAL},
  77 + #{tradeStatus,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER})
  78 + </insert>
  79 + <insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.TradeBills" >
  80 + insert into trade_bills
  81 + <trim prefix="(" suffix=")" suffixOverrides="," >
  82 + <if test="id != null" >
  83 + id,
  84 + </if>
  85 + <if test="uid != null" >
  86 + uid,
  87 + </if>
  88 + <if test="orderCode != null" >
  89 + order_code,
  90 + </if>
  91 + <if test="userType != null" >
  92 + user_type,
  93 + </if>
  94 + <if test="payType != null" >
  95 + pay_type,
  96 + </if>
  97 + <if test="tradeType != null" >
  98 + trade_type,
  99 + </if>
  100 + <if test="incomeOutcome != null" >
  101 + income_outcome,
  102 + </if>
  103 + <if test="amount != null" >
  104 + amount,
  105 + </if>
  106 + <if test="systemAmount != null" >
  107 + system_amount,
  108 + </if>
  109 + <if test="tradeStatus != null" >
  110 + trade_status,
  111 + </if>
  112 + <if test="createTime != null" >
  113 + create_time,
  114 + </if>
  115 + </trim>
  116 + <trim prefix="values (" suffix=")" suffixOverrides="," >
  117 + <if test="id != null" >
  118 + #{id,jdbcType=INTEGER},
  119 + </if>
  120 + <if test="uid != null" >
  121 + #{uid,jdbcType=INTEGER},
  122 + </if>
  123 + <if test="orderCode != null" >
  124 + #{orderCode,jdbcType=BIGINT},
  125 + </if>
  126 + <if test="userType != null" >
  127 + #{userType,jdbcType=INTEGER},
  128 + </if>
  129 + <if test="payType != null" >
  130 + #{payType,jdbcType=INTEGER},
  131 + </if>
  132 + <if test="tradeType != null" >
  133 + #{tradeType,jdbcType=INTEGER},
  134 + </if>
  135 + <if test="incomeOutcome != null" >
  136 + #{incomeOutcome,jdbcType=INTEGER},
  137 + </if>
  138 + <if test="amount != null" >
  139 + #{amount,jdbcType=DECIMAL},
  140 + </if>
  141 + <if test="systemAmount != null" >
  142 + #{systemAmount,jdbcType=DECIMAL},
  143 + </if>
  144 + <if test="tradeStatus != null" >
  145 + #{tradeStatus,jdbcType=INTEGER},
  146 + </if>
  147 + <if test="createTime != null" >
  148 + #{createTime,jdbcType=INTEGER},
  149 + </if>
  150 + </trim>
  151 + </insert>
  152 + <update id="updateByPrimaryKeySelective" parameterType="com.yohoufo.dal.order.model.TradeBills" >
  153 + update trade_bills
  154 + <set >
  155 + <if test="uid != null" >
  156 + uid = #{uid,jdbcType=INTEGER},
  157 + </if>
  158 + <if test="orderCode != null" >
  159 + order_code = #{orderCode,jdbcType=BIGINT},
  160 + </if>
  161 + <if test="userType != null" >
  162 + user_type = #{userType,jdbcType=INTEGER},
  163 + </if>
  164 + <if test="payType != null" >
  165 + pay_type = #{payType,jdbcType=INTEGER},
  166 + </if>
  167 + <if test="tradeType != null" >
  168 + trade_type = #{tradeType,jdbcType=INTEGER},
  169 + </if>
  170 + <if test="incomeOutcome != null" >
  171 + income_outcome = #{incomeOutcome,jdbcType=INTEGER},
  172 + </if>
  173 + <if test="amount != null" >
  174 + amount = #{amount,jdbcType=DECIMAL},
  175 + </if>
  176 + <if test="systemAmount != null" >
  177 + system_amount = #{systemAmount,jdbcType=DECIMAL},
  178 + </if>
  179 + <if test="tradeStatus != null" >
  180 + trade_status = #{tradeStatus,jdbcType=INTEGER},
  181 + </if>
  182 + <if test="createTime != null" >
  183 + create_time = #{createTime,jdbcType=INTEGER},
  184 + </if>
  185 + </set>
  186 + where id = #{id,jdbcType=INTEGER}
  187 + </update>
  188 + <update id="updateByPrimaryKey" parameterType="com.yohoufo.dal.order.model.TradeBills" >
  189 + update trade_bills
  190 + set uid = #{uid,jdbcType=INTEGER},
  191 + order_code = #{orderCode,jdbcType=BIGINT},
  192 + user_type = #{userType,jdbcType=INTEGER},
  193 + pay_type = #{payType,jdbcType=INTEGER},
  194 + trade_type = #{tradeType,jdbcType=INTEGER},
  195 + income_outcome = #{incomeOutcome,jdbcType=INTEGER},
  196 + amount = #{amount,jdbcType=DECIMAL},
  197 + system_amount = #{systemAmount,jdbcType=DECIMAL},
  198 + trade_status = #{tradeStatus,jdbcType=INTEGER},
  199 + create_time = #{createTime,jdbcType=INTEGER}
  200 + where id = #{id,jdbcType=INTEGER}
  201 + </update>
65 </mapper> 202 </mapper>
@@ -33,6 +33,11 @@ @@ -33,6 +33,11 @@
33 <groupId>com.yohoufo.fore</groupId> 33 <groupId>com.yohoufo.fore</groupId>
34 <artifactId>yohoufo-fore-product</artifactId> 34 <artifactId>yohoufo-fore-product</artifactId>
35 </dependency> 35 </dependency>
  36 +
  37 + <dependency>
  38 + <groupId>com.yohoufo.fore</groupId>
  39 + <artifactId>yohoufo-fore-user</artifactId>
  40 + </dependency>
36 41
37 <dependency> 42 <dependency>
38 <groupId>com.yoho.core</groupId> 43 <groupId>com.yoho.core</groupId>
@@ -3,18 +3,26 @@ package com.yohoufo.order.model.request; @@ -3,18 +3,26 @@ package com.yohoufo.order.model.request;
3 import lombok.AllArgsConstructor; 3 import lombok.AllArgsConstructor;
4 import lombok.Data; 4 import lombok.Data;
5 import lombok.NoArgsConstructor; 5 import lombok.NoArgsConstructor;
  6 +import lombok.ToString;
6 import lombok.experimental.Builder; 7 import lombok.experimental.Builder;
7 8
8 @Data 9 @Data
9 @Builder 10 @Builder
10 @AllArgsConstructor 11 @AllArgsConstructor
11 @NoArgsConstructor 12 @NoArgsConstructor
12 -public class CheckupRequest { 13 +@ToString
  14 +public class TransferMoneyRequest {
  15 +
  16 + private long buyerOrderCode;
13 17
14 - long orderCode; 18 + private long sellerOrderCode;
15 19
16 /** 20 /**
17 - * 鉴定结果 1:鉴定通过; 2:鉴定不通过 21 + * <pre>
  22 + * 1:鉴定通过(货款-->卖家);
  23 + * 2:鉴定不通过(保证金 --> 买家);
  24 + * 3:有买家时卖家不卖了(保证金 --> 买家)
  25 + * </pre>
18 */ 26 */
19 - int checkupResult; 27 + private int type;
20 } 28 }
1 package com.yohoufo.order.service.impl; 1 package com.yohoufo.order.service.impl;
2 2
  3 +import java.math.BigDecimal;
  4 +import java.util.Date;
  5 +
  6 +import org.apache.commons.lang3.StringUtils;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +import com.alibaba.fastjson.JSON;
3 import com.alibaba.fastjson.JSONObject; 13 import com.alibaba.fastjson.JSONObject;
4 -import com.yoho.core.common.utils.DateUtil;  
5 import com.yoho.error.ServiceError; 14 import com.yoho.error.ServiceError;
6 import com.yoho.error.exception.ServiceException; 15 import com.yoho.error.exception.ServiceException;
  16 +import com.yoho.tools.common.beans.ApiResponse;
  17 +import com.yohoufo.common.caller.UfoServiceCaller;
7 import com.yohoufo.common.utils.TimeUtils; 18 import com.yohoufo.common.utils.TimeUtils;
8 -import com.yohoufo.dal.order.*;  
9 -import com.yohoufo.dal.order.model.*;  
10 -import com.yohoufo.order.common.*;  
11 -import com.yohoufo.order.constants.OrderConstant;  
12 -import com.yohoufo.order.constants.RefundContant;  
13 -import com.yohoufo.order.model.*; 19 +import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
  20 +import com.yohoufo.dal.order.BuyerOrderMapper;
  21 +import com.yohoufo.dal.order.BuyerOrderMetaMapper;
14 import com.yohoufo.dal.order.OrdersPayMapper; 22 import com.yohoufo.dal.order.OrdersPayMapper;
  23 +import com.yohoufo.dal.order.OrdersPayRefundMapper;
  24 +import com.yohoufo.dal.order.OrdersPayTransferMapper;
  25 +import com.yohoufo.dal.order.SellerOrderMapper;
  26 +import com.yohoufo.dal.order.SellerOrderMetaMapper;
  27 +import com.yohoufo.dal.order.TradeBillsMapper;
  28 +import com.yohoufo.dal.order.model.BuyerOrder;
15 import com.yohoufo.dal.order.model.OrdersPay; 29 import com.yohoufo.dal.order.model.OrdersPay;
16 -import com.yohoufo.order.common.*; 30 +import com.yohoufo.dal.order.model.OrdersPayRefund;
  31 +import com.yohoufo.dal.order.model.OrdersPayTransfer;
  32 +import com.yohoufo.dal.order.model.SellerOrder;
  33 +import com.yohoufo.dal.order.model.SellerOrderMeta;
  34 +import com.yohoufo.dal.order.model.TradeBills;
  35 +import com.yohoufo.order.common.OrderCodeType;
  36 +import com.yohoufo.order.common.Payment;
  37 +import com.yohoufo.order.constants.OrderConstant;
  38 +import com.yohoufo.order.constants.RefundContant;
17 import com.yohoufo.order.model.OrderInfo; 39 import com.yohoufo.order.model.OrderInfo;
18 import com.yohoufo.order.model.PayQueryBo; 40 import com.yohoufo.order.model.PayQueryBo;
  41 +import com.yohoufo.order.model.PayRefundBo;
19 import com.yohoufo.order.model.PaymentData; 42 import com.yohoufo.order.model.PaymentData;
20 -import com.yohoufo.order.model.request.CheckupRequest;  
21 import com.yohoufo.order.model.request.PaymentRequest; 43 import com.yohoufo.order.model.request.PaymentRequest;
  44 +import com.yohoufo.order.model.request.TransferMoneyRequest;
22 import com.yohoufo.order.model.response.PaymentConfirmRsp; 45 import com.yohoufo.order.model.response.PaymentConfirmRsp;
23 import com.yohoufo.order.model.response.PrepayResponse; 46 import com.yohoufo.order.model.response.PrepayResponse;
24 import com.yohoufo.order.service.AbstractOrderPaymentService; 47 import com.yohoufo.order.service.AbstractOrderPaymentService;
@@ -27,18 +50,10 @@ import com.yohoufo.order.service.IPaymentService; @@ -27,18 +50,10 @@ import com.yohoufo.order.service.IPaymentService;
27 import com.yohoufo.order.service.SellerOrderPaymentService; 50 import com.yohoufo.order.service.SellerOrderPaymentService;
28 import com.yohoufo.order.service.pay.AbstractPayService; 51 import com.yohoufo.order.service.pay.AbstractPayService;
29 import com.yohoufo.order.service.pay.alipay.AlipayOuyinService; 52 import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
30 -import com.yohoufo.order.service.pay.weixin.WeixinPayAppService;  
31 -import com.yohoufo.order.service.pay.weixin.WeixinPayBlkAppService;  
32 import com.yohoufo.order.service.pay.weixin.WeixinPayUFOAppService; 53 import com.yohoufo.order.service.pay.weixin.WeixinPayUFOAppService;
33 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; 54 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
34 import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; 55 import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
35 -import org.slf4j.Logger;  
36 -import org.slf4j.LoggerFactory;  
37 -import org.springframework.beans.factory.annotation.Autowired;  
38 -import org.springframework.core.annotation.Order;  
39 -import org.springframework.stereotype.Service;  
40 -import java.math.BigDecimal;  
41 -import java.util.Date; 56 +import com.yohoufo.user.responseVO.AuthorizeResultRespVO;
42 57
43 58
44 @Service 59 @Service
@@ -78,6 +93,21 @@ public class PaymentServiceImpl implements IPaymentService { @@ -78,6 +93,21 @@ public class PaymentServiceImpl implements IPaymentService {
78 93
79 @Autowired 94 @Autowired
80 SellerOrderMapper sellerOrderMapper; 95 SellerOrderMapper sellerOrderMapper;
  96 +
  97 + @Autowired
  98 + SellerOrderMetaMapper sellerOrderMetaMapper;
  99 +
  100 + @Autowired
  101 + OrdersPayTransferMapper ordersPayTransferMapper;
  102 +
  103 + @Autowired
  104 + BuyerOrderMapper buyerOrderMapper;
  105 +
  106 + @Autowired
  107 + UfoServiceCaller ufoServiceCaller;
  108 +
  109 + @Autowired
  110 + TradeBillsMapper tradeBillsMapper;
81 111
82 /** 112 /**
83 * 获取主场的订单service 113 * 获取主场的订单service
@@ -355,89 +385,240 @@ public class PaymentServiceImpl implements IPaymentService { @@ -355,89 +385,240 @@ public class PaymentServiceImpl implements IPaymentService {
355 } 385 }
356 386
357 387
358 -  
359 - public void transferMon(CheckupRequest request){  
360 -  
361 - // 参数检查  
362 - if (request.getOrderCode() < 0  
363 - || request.getCheckupResult() <0){  
364 - logger.warn("transferMon request empty");  
365 - throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);  
366 - }  
367 -  
368 - // 未更新前,买家订单号的状态: 鉴定中  
369 - // 买家订单号信息  
370 - OrderInfo orderInfo = buyerOrderPaymentService.getOrderInfo(request.getOrderCode());  
371 -  
372 - if (orderInfo == null) {  
373 - logger.warn("getOrderInfo order not exist, orderCode is {}", request.getOrderCode());  
374 - throw new ServiceException(ServiceError.ORDER_NULL);  
375 - }  
376 -  
377 - // TODO 安全性校验:比如对转账的金额限额  
378 - // 保证金抽成 货款抽成 都在货款抽成  
379 - // 运费买家下单的时候 确定的  
380 -  
381 - // 鉴定通过: 1、保证金退款给卖家(参见退款接口) 2、打货款给卖家  
382 - if (request.getCheckupResult() == 1){  
383 -  
384 - // 根据买家订单号,查支付成功记录  
385 - OrdersPay ordersPay = ordersPayMapper.selectOrdersPay(orderInfo.getOrderCode(), orderInfo.getUid());  
386 - if (ordersPay == null){  
387 -  
388 - }  
389 -  
390 - // 实施转账  
391 -  
392 - }  
393 - // 鉴定不通过: 1、保证金赔款给买家  
394 - else if(request.getCheckupResult() == 2){  
395 - // 检查 保证金是否已经支付  
396 - // 1.根据买家订单号 获取 skup  
397 - BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(orderInfo.getUid(), orderInfo.getOrderCode());  
398 - if (buyerOrderGoods == null){  
399 -  
400 - }  
401 -  
402 - // 2.根据skup获取 卖家订单号  
403 - SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(buyerOrderGoods.getSkup());  
404 - if (sellerOrder == null){  
405 -  
406 - }  
407 -  
408 - // 3.根据卖家订单号,获取支付成功结果  
409 - OrdersPay ordersPay = ordersPayMapper.selectOrdersPay(sellerOrder.getOrderCode(), sellerOrder.getUid());  
410 - if (ordersPay == null){  
411 -  
412 - }  
413 -  
414 - // 根据用户uid,获取卖家支付宝账号  
415 - // 从meta中获取,取费用系数  
416 - String transferOrderCode = String.valueOf(request.getOrderCode()) + ordersPay.getId();  
417 - String alipayAccount = "";  
418 - // 算费  
419 - double transferAmount = 0;  
420 -  
421 - // TODO 下面转账的代码放入到提现接口  
422 - // 转账订单号必须唯一,所以一笔订单的一笔支付,只能转账一次  
423 - JSONObject jsonObject = alipayService.transferMoney(transferOrderCode, alipayAccount, transferAmount);  
424 - if (jsonObject.getInteger("code") == 10000){  
425 -  
426 - }  
427 -  
428 -  
429 - 388 + /**
  389 + * <pre>
  390 + * 1:鉴定通过(货款-->卖家);
  391 + * 2:鉴定不通过(保证金 --> 买家);
  392 + * 3:有买家时卖家不卖了(保证金 --> 买家)
  393 + * </pre>
  394 + *
  395 + * @param request 请求
  396 + */
  397 + public void transferMon(TransferMoneyRequest request){
  398 + logger.info("transferMon转账开始,request = {}", request);
  399 +
  400 + long buyerOrderCode = request.getBuyerOrderCode();
  401 + long sellerOrderCode = request.getBuyerOrderCode();
  402 + int transferType = request.getType();
  403 +
  404 + logger.info("transferMon参数检查");
  405 + // 订单号check
  406 + if (buyerOrderCode < 1 || sellerOrderCode < 1) {
  407 + logger.warn("transferMon orderCode empty");
  408 + throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
  409 + }
  410 + // 类型检查
  411 + if (transferType < 1 || transferType > 3) {
  412 + logger.warn("transferType invalid");
  413 + throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
  414 + }
  415 +
  416 + // 买家订单检查
  417 + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(buyerOrderCode);
  418 + if (buyerOrder == null) {
  419 + logger.warn("getOrderInfo buyer order not exist, orderCode is {}", buyerOrderCode);
  420 + throw new ServiceException(ServiceError.ORDER_NULL);
  421 + }
  422 +
  423 + // 卖家订单检查
  424 + SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCode(sellerOrderCode);
  425 + if (sellerOrder == null){
  426 + logger.warn("getOrderInfo seller order not exist, orderCode is {}", sellerOrderCode);
  427 + throw new ServiceException(ServiceError.ORDER_NULL);
430 } 428 }
431 -  
432 - // 记录转账记录到 orders_pay_transfer  
433 -  
434 -  
435 - // 更新订单状态  
436 -  
437 - 429 +
  430 + // 查看是否已经有转账记录
  431 + OrdersPayTransfer exist = ordersPayTransferMapper.selectByBuyerOrderCode(buyerOrderCode);
  432 + if (exist != null) {
  433 + logger.warn("getOrderInfo order not exist, orderCode is {}", buyerOrderCode);
  434 + throw new ServiceException(400, "订单已经处理过");
  435 + }
  436 +
  437 + Integer targetUid = transferType == 1 ? sellerOrder.getUid() : buyerOrder.getUid();
  438 +
  439 + if (targetUid == null || targetUid < 1) {
  440 + logger.warn("uid {} 不合法", targetUid);
  441 + throw new ServiceException(400, "uid[" + targetUid + "]不合法");
  442 + }
  443 + String alipayAccount = getAlipayAccount(targetUid);
  444 + if (StringUtils.isBlank(alipayAccount)) {
  445 + logger.warn("uid {} 没有获取到有效的支付宝账号", targetUid);
  446 + throw new ServiceException(400, "uid[" + targetUid + "]没有获取到有效的支付宝账号");
  447 + }
  448 + logger.info("transferMon参数检查成功!");
  449 +
  450 + int now = (int) (System.currentTimeMillis()/1000);
  451 +
  452 + OrdersPayTransfer transfer = new OrdersPayTransfer();
  453 + transfer.setBuyerOrderCode(buyerOrderCode);
  454 + transfer.setSellerOrderCode(sellerOrderCode);
  455 + transfer.setAlipayTradeId("");
  456 + transfer.setAlipayTradeResult("");
  457 + transfer.setTransferType(transferType);
  458 + transfer.setUid(targetUid);
  459 + transfer.setAlipayAccount(alipayAccount);
  460 + transfer.setAmount(BigDecimal.ZERO);
  461 + transfer.setCreateTime(now);
  462 + transfer.setStatus(0);
  463 +
  464 + try {
  465 + logger.info("transferMon插入初始化转账信息buyerOrderCode is {}", buyerOrderCode);
  466 + ordersPayTransferMapper.insert(transfer);
  467 + } catch (Exception e) {
  468 + logger.warn("insert ordersPayTransfer failed, orderCode is {}, msg is {}", buyerOrderCode, e.getMessage());
  469 + throw new ServiceException(400, "交易记录创建失败");
  470 + }
  471 +
  472 + logger.info("transferMon插入初始化转账信息成功,接下来计算费用");
  473 + // 算费
  474 + BigDecimal transferAmount = calcTransferAmount(sellerOrder.getUid(), sellerOrder.getSkup(), transferType);
  475 + logger.info("transferMon计算费用结果为 {}", transferAmount);
  476 + if (transferAmount == null || transferAmount.compareTo(new BigDecimal("0.1")) < 0) {
  477 + logger.warn("transferMon计算费用结果为 {}, 不合法的金额", transferAmount);
  478 + throw new ServiceException(400, "不合法的金额");
  479 + }
  480 + transfer.setAmount(transferAmount);
  481 +
  482 + // 转账
  483 + try {
  484 + logger.info("transferMon开始调用阿里接口参数buyerOrderCode={}, alipayAccount={}, transferAmount={}", buyerOrderCode, alipayAccount, transferAmount);
  485 + JSONObject jsonObject = alipayService.transferMoney(Long.toString(buyerOrderCode), alipayAccount, transferAmount);
  486 + if (jsonObject == null) {
  487 + logger.warn("转账失败 , orderCode is {}", buyerOrderCode);
  488 + transfer.setStatus(3);
  489 + throw new ServiceException(500, "转账失败");
  490 + }
  491 + transfer.setAlipayTradeResult(jsonObject.toJSONString());
  492 + // 成功
  493 + Integer code = null;
  494 + String orderId = null;
  495 + if (jsonObject.containsKey("code")
  496 + && (code = jsonObject.getInteger("code")) == 10000
  497 + && jsonObject.containsKey("order_id")
  498 + && StringUtils.isNotBlank(orderId = jsonObject.getString("order_id"))) {
  499 + logger.info("转账成功,targeAccount is {}, amount is {}", alipayAccount, transferAmount);
  500 + transfer.setAlipayTradeId(orderId);
  501 + transfer.setStatus(1);
  502 + } else {
  503 + logger.warn("返回code或者order_id不是成功状态,code={}, orderId={}", code, orderId);
  504 + transfer.setStatus(3);
  505 + }
  506 + } catch (Exception e) {
  507 + transfer.setStatus(3);
  508 + logger.warn("转账失败 , orderCode is {}, msg is {}", buyerOrderCode, e.getMessage());
  509 + throw new ServiceException(500, "转账失败");
  510 + } finally {
  511 + logger.info("transferMon最后更新状态 status= {}", transfer.getStatus());
  512 + transfer.setUpdateTime(now);
  513 + ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
  514 + logger.info("transferMon最后更新状态完成,转账结束, buyerOrderCode is {}!", buyerOrderCode);
  515 + }
  516 +
  517 + // 增加流水记录
  518 + TradeBills record = new TradeBills();
  519 + try {
  520 + record.setUid(targetUid);
  521 + record.setOrderCode(transferType == 1 ? sellerOrderCode : buyerOrderCode);
  522 + record.setUserType(transferType == 1 ? 2 : 1);
  523 + record.setPayType(1);
  524 + record.setTradeType(transferType == 1 ? 2 : 3);
  525 + record.setIncomeOutcome(1);
  526 + record.setAmount(transferAmount);
  527 + // 因为转账支付宝扣费累计计算,使用转账额
  528 + record.setSystemAmount(transferAmount.multiply(new BigDecimal("-1")));
  529 + record.setTradeStatus(1);
  530 + record.setCreateTime(now);
  531 + tradeBillsMapper.insert(record);
  532 + } catch (Exception e) {
  533 + logger.error("记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
  534 + }
  535 + }
  536 +
  537 + // 支付保证金流水记录
  538 + public void addPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payType, BigDecimal amount) {
  539 + // 增加流水记录
  540 + TradeBills record = new TradeBills();
  541 + try {
  542 + record.setUid(uid);
  543 + record.setOrderCode(orderCode);
  544 + record.setUserType(2);// 1:买家uid; 2:卖家uid
  545 + record.setPayType(payType);// 1:支付宝; 2:微信
  546 + record.setTradeType(1);//1:保证金;2:货款;3:补偿款
  547 + record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
  548 + record.setAmount(amount);
  549 + record.setSystemAmount(amount.multiply(new BigDecimal("-1")));// 有货收入
  550 + record.setTradeStatus(0);//0:订单未完结;1:订单完结
  551 + record.setCreateTime((int) (System.currentTimeMillis() / 1000));
  552 + tradeBillsMapper.insert(record);
  553 + } catch (Exception e) {
  554 + logger.error("记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
  555 + }
  556 + }
  557 +
  558 + // 支付货款流水记录
  559 + public void addPayBuyRecord(Integer uid, Long orderCode, Integer payType, BigDecimal amount) {
  560 + // 增加流水记录
  561 + TradeBills record = new TradeBills();
  562 + try {
  563 + record.setUid(uid);
  564 + record.setOrderCode(orderCode);
  565 + record.setUserType(1);// 1:买家uid; 2:卖家uid
  566 + record.setPayType(payType);// 1:支付宝; 2:微信
  567 + record.setTradeType(2);//1:保证金;2:货款;3:补偿款
  568 + record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
  569 + record.setAmount(amount);
  570 + record.setSystemAmount(amount.multiply(new BigDecimal("-1")));// 有货收入
  571 + record.setTradeStatus(0);//0:订单未完结;1:订单完结
  572 + record.setCreateTime((int) (System.currentTimeMillis() / 1000));
  573 + tradeBillsMapper.insert(record);
  574 + } catch (Exception e) {
  575 + logger.error("记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
  576 + }
438 } 577 }
439 578
440 - /** 579 + private BigDecimal calcTransferAmount(Integer sellerUid, Integer skup, int transferType) {
  580 + SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
  581 + if (meta == null) {
  582 + logger.warn("查询SellerOrderMeta无数据, sellerUid is {}, skup is {}", sellerUid, skup);
  583 + throw new ServiceException(500, "计费信息不完整");
  584 + }
  585 + if (StringUtils.isBlank(meta.getMetaValue())) {
  586 + logger.warn("查询SellerOrderMeta的MetaValue为空, sellerUid is {}, skup is {}", sellerUid, skup);
  587 + throw new ServiceException(500, "计费信息不完整");
  588 + }
  589 + try {
  590 + JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
  591 + // 交易成功的情况
  592 + if (transferType == 1) {
  593 + return metavalue.getBigDecimal("income");
  594 + }
  595 + // (1-Y)*A
  596 + // 保证金
  597 + BigDecimal ensure = metavalue.getBigDecimal("earnestMoney");
  598 + // 保证金抽成
  599 + BigDecimal ensureYohoRage = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("earnestMoney");
  600 + return ensure.multiply(BigDecimal.ONE.subtract(ensureYohoRage));
  601 + } catch (Exception e) {
  602 + logger.warn("计费信息不完整, sellerUid is {}, skup is {}, err is {}", sellerUid, skup, e.getMessage());
  603 + throw new ServiceException(500, "计费信息不完整");
  604 + }
  605 + }
  606 +
  607 +
  608 + @SuppressWarnings("unchecked")
  609 + private String getAlipayAccount(int targetUid) {
  610 + ApiResponse<AuthorizeResultRespVO> resp = ufoServiceCaller.call("ufo.user.aliPayAccountQuery", ApiResponse.class, targetUid);
  611 + if (resp != null) {
  612 + AuthorizeResultRespVO data = (AuthorizeResultRespVO) resp.getData();
  613 + if (data != null && data.getAlipayAccount() != null) {
  614 + return data.getAlipayAccount();
  615 + }
  616 + }
  617 + return null;
  618 + }
  619 +
  620 +
  621 + /**
441 * 支付 622 * 支付
442 * @param request 623 * @param request
443 * @return 624 * @return
@@ -140,12 +140,12 @@ public abstract class AlipayServiceAbstract extends AbstractPayService { @@ -140,12 +140,12 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
140 * @param transferAmount 140 * @param transferAmount
141 * @return 141 * @return
142 */ 142 */
143 - public JSONObject transferMoney(String transferOrderCode, String alipayAccount, double transferAmount){ 143 + public JSONObject transferMoney(String transferOrderCode, String alipayAccount, BigDecimal transferAmount){
144 144
145 Map<String, String> queryParams = buildTransferParams(transferOrderCode, alipayAccount, transferAmount); 145 Map<String, String> queryParams = buildTransferParams(transferOrderCode, alipayAccount, transferAmount);
146 String respTxt = sendOpenApiRequest(transferOrderCode, queryParams); 146 String respTxt = sendOpenApiRequest(transferOrderCode, queryParams);
147 147
148 - JSONObject result = new JSONObject(); 148 + JSONObject result = null;
149 149
150 if (StringUtils.isNotBlank(respTxt)){ 150 if (StringUtils.isNotBlank(respTxt)){
151 JSONObject json = JSON.parseObject(respTxt); 151 JSONObject json = JSON.parseObject(respTxt);
@@ -237,7 +237,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService { @@ -237,7 +237,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
237 * @param orderData 237 * @param orderData
238 * @return 238 * @return
239 */ 239 */
240 - private Map<String, String> buildTransferParams(String transferOrderCode, String alipayAccount, double transferAmount) { 240 + private Map<String, String> buildTransferParams(String transferOrderCode, String alipayAccount, BigDecimal transferAmount) {
241 Map<String, String> params = new HashMap<String, String>(); 241 Map<String, String> params = new HashMap<String, String>();
242 params.put("app_id", getAppId()); 242 params.put("app_id", getAppId());
243 params.put("method", "alipay.fund.trans.toaccount.transfer"); 243 params.put("method", "alipay.fund.trans.toaccount.transfer");
@@ -251,7 +251,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService { @@ -251,7 +251,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
251 bizJson.put("out_biz_no", transferOrderCode); // 商户转账唯一订单号 251 bizJson.put("out_biz_no", transferOrderCode); // 商户转账唯一订单号
252 bizJson.put("payee_type", "ALIPAY_LOGONID"); 252 bizJson.put("payee_type", "ALIPAY_LOGONID");
253 bizJson.put("payee_account", alipayAccount); // 支付宝账号 253 bizJson.put("payee_account", alipayAccount); // 支付宝账号
254 - bizJson.put("amount", transferAmount); 254 + bizJson.put("amount", transferAmount.toString());
255 255
256 256
257 params.put("biz_content", bizJson.toJSONString()); 257 params.put("biz_content", bizJson.toJSONString());