Authored by Lixiaodi

提交商家充值

@@ -14,4 +14,11 @@ public interface EntrySellerRechargeOrderMapper { @@ -14,4 +14,11 @@ public interface EntrySellerRechargeOrderMapper {
14 int updateByPrimaryKeySelective(EntrySellerRechargeOrder record); 14 int updateByPrimaryKeySelective(EntrySellerRechargeOrder record);
15 15
16 int updateByPrimaryKey(EntrySellerRechargeOrder record); 16 int updateByPrimaryKey(EntrySellerRechargeOrder record);
  17 +
  18 + void updateByOrderCode(EntrySellerRechargeOrder order);
  19 +
  20 + EntrySellerRechargeOrder selectByOrderCodeUid(long orderCode, int uid);
  21 +
  22 + EntrySellerRechargeOrder selectByOrderCode(long orderCode);
  23 +
17 } 24 }
@@ -54,4 +54,6 @@ public interface OrdersPayMapper { @@ -54,4 +54,6 @@ public interface OrdersPayMapper {
54 * @mbggenerated 54 * @mbggenerated
55 */ 55 */
56 int updateByPrimaryKey(OrdersPay record); 56 int updateByPrimaryKey(OrdersPay record);
  57 +
  58 + int addMoney(OrdersPay record);
57 } 59 }
1 package com.yohoufo.dal.order; 1 package com.yohoufo.dal.order;
2 2
  3 +import org.apache.ibatis.annotations.Param;
  4 +
3 import com.yohoufo.dal.order.model.SellerWallet; 5 import com.yohoufo.dal.order.model.SellerWallet;
4 6
5 public interface SellerWalletMapper { 7 public interface SellerWalletMapper {
@@ -14,4 +16,11 @@ public interface SellerWalletMapper { @@ -14,4 +16,11 @@ public interface SellerWalletMapper {
14 int updateByPrimaryKeySelective(SellerWallet record); 16 int updateByPrimaryKeySelective(SellerWallet record);
15 17
16 int updateByPrimaryKey(SellerWallet record); 18 int updateByPrimaryKey(SellerWallet record);
  19 +
  20 + SellerWallet selectByUidAndType(@Param("uid") Integer uid, @Param("type") int type);
  21 +
  22 + int addMoney(SellerWallet sw);
  23 +
  24 + int returnMoney(SellerWallet sw);
  25 +
17 } 26 }
@@ -9,9 +9,9 @@ public class SellerWallet { @@ -9,9 +9,9 @@ public class SellerWallet {
9 9
10 private BigDecimal amount; 10 private BigDecimal amount;
11 11
12 - private Byte status; 12 + private Integer status;
13 13
14 - private Byte type; 14 + private Integer type;
15 15
16 private Integer createTime; 16 private Integer createTime;
17 17
@@ -41,19 +41,19 @@ public class SellerWallet { @@ -41,19 +41,19 @@ public class SellerWallet {
41 this.amount = amount; 41 this.amount = amount;
42 } 42 }
43 43
44 - public Byte getStatus() { 44 + public Integer getStatus() {
45 return status; 45 return status;
46 } 46 }
47 47
48 - public void setStatus(Byte status) { 48 + public void setStatus(Integer status) {
49 this.status = status; 49 this.status = status;
50 } 50 }
51 51
52 - public Byte getType() { 52 + public Integer getType() {
53 return type; 53 return type;
54 } 54 }
55 55
56 - public void setType(Byte type) { 56 + public void setType(Integer type) {
57 this.type = type; 57 this.type = type;
58 } 58 }
59 59
@@ -13,7 +13,7 @@ public class SellerWalletDetail { @@ -13,7 +13,7 @@ public class SellerWalletDetail {
13 13
14 private BigDecimal amount; 14 private BigDecimal amount;
15 15
16 - private Byte type; 16 + private Integer type;
17 17
18 private Integer createTime; 18 private Integer createTime;
19 19
@@ -59,11 +59,11 @@ public class SellerWalletDetail { @@ -59,11 +59,11 @@ public class SellerWalletDetail {
59 this.amount = amount; 59 this.amount = amount;
60 } 60 }
61 61
62 - public Byte getType() { 62 + public Integer getType() {
63 return type; 63 return type;
64 } 64 }
65 65
66 - public void setType(Byte type) { 66 + public void setType(Integer type) {
67 this.type = type; 67 this.type = type;
68 } 68 }
69 69
@@ -138,4 +138,34 @@ @@ -138,4 +138,34 @@
138 update_time = #{updateTime,jdbcType=INTEGER} 138 update_time = #{updateTime,jdbcType=INTEGER}
139 where id = #{id,jdbcType=INTEGER} 139 where id = #{id,jdbcType=INTEGER}
140 </update> 140 </update>
  141 +
  142 + <update id="updateByOrderCode" parameterType="com.yohoufo.dal.order.model.BuyerOrder">
  143 + update entry_seller_recharge_order
  144 + set
  145 + <if test="status != null">
  146 + status = #{status,jdbcType=INTEGER},
  147 + </if>
  148 + <if test="payment != null">
  149 + payment = #{payment,jdbcType=INTEGER},
  150 + </if>
  151 + update_time = #{updateTime,jdbcType=INTEGER}
  152 + where order_code = #{orderCode,jdbcType=BIGINT}
  153 + </update>
  154 +
  155 + <select id="selectByOrderCodeUid" resultMap="BaseResultMap">
  156 + select
  157 + <include refid="Base_Column_List" />
  158 + from entry_seller_recharge_order
  159 + where order_code = #{orderCode,jdbcType=BIGINT}
  160 + and uid = #{uid,jdbcType=INTEGER}
  161 + limit 1
  162 + </select>
  163 + <select id="selectByOrderCode" resultMap="BaseResultMap">
  164 + select
  165 + <include refid="Base_Column_List" />
  166 + from entry_seller_recharge_order
  167 + where order_code = #{orderCode,jdbcType=BIGINT}
  168 + limit 1
  169 + </select>
  170 +
141 </mapper> 171 </mapper>
@@ -188,4 +188,9 @@ @@ -188,4 +188,9 @@
188 create_time = #{createTime,jdbcType=INTEGER} 188 create_time = #{createTime,jdbcType=INTEGER}
189 where id = #{id,jdbcType=INTEGER} 189 where id = #{id,jdbcType=INTEGER}
190 </update> 190 </update>
  191 +
  192 + <update id="addMoney" parameterType="com.yohoufo.dal.order.model.OrdersPay" >
  193 + update orders_pay set amount = amount + #{amount,jdbcType=DECIMAL},update_time = #{updateTime,jdbcType=INTEGER} where order_code = #{orderCode,jdbcType=BIGINT}
  194 + and uid = #{uid,jdbcType=INTEGER} and amount + #{amount,jdbcType=DECIMAL} &gt;= 0
  195 + </update>
191 </mapper> 196 </mapper>
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 delete from seller_wallet_detail 24 delete from seller_wallet_detail
25 where id = #{id,jdbcType=INTEGER} 25 where id = #{id,jdbcType=INTEGER}
26 </delete> 26 </delete>
27 - <insert id="insert" parameterType="com.yohoufo.dal.order.model.SellerWalletDetail" > 27 + <insert id="insert" parameterType="com.yohoufo.dal.order.model.SellerWalletDetail" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
28 insert into seller_wallet_detail (id, wallet_id, uid, 28 insert into seller_wallet_detail (id, wallet_id, uid,
29 order_code, amount, type, 29 order_code, amount, type,
30 create_time, update_time) 30 create_time, update_time)
@@ -32,7 +32,7 @@ @@ -32,7 +32,7 @@
32 #{orderCode,jdbcType=BIGINT}, #{amount,jdbcType=DECIMAL}, #{type,jdbcType=TINYINT}, 32 #{orderCode,jdbcType=BIGINT}, #{amount,jdbcType=DECIMAL}, #{type,jdbcType=TINYINT},
33 #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER}) 33 #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
34 </insert> 34 </insert>
35 - <insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.SellerWalletDetail" > 35 + <insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.SellerWalletDetail" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
36 insert into seller_wallet_detail 36 insert into seller_wallet_detail
37 <trim prefix="(" suffix=")" suffixOverrides="," > 37 <trim prefix="(" suffix=")" suffixOverrides="," >
38 <if test="id != null" > 38 <if test="id != null" >
@@ -5,8 +5,8 @@ @@ -5,8 +5,8 @@
5 <id column="id" property="id" jdbcType="INTEGER" /> 5 <id column="id" property="id" jdbcType="INTEGER" />
6 <result column="uid" property="uid" jdbcType="INTEGER" /> 6 <result column="uid" property="uid" jdbcType="INTEGER" />
7 <result column="amount" property="amount" jdbcType="DECIMAL" /> 7 <result column="amount" property="amount" jdbcType="DECIMAL" />
8 - <result column="status" property="status" jdbcType="TINYINT" />  
9 - <result column="type" property="type" jdbcType="TINYINT" /> 8 + <result column="status" property="status" jdbcType="INTEGER" />
  9 + <result column="type" property="type" jdbcType="INTEGER" />
10 <result column="create_time" property="createTime" jdbcType="INTEGER" /> 10 <result column="create_time" property="createTime" jdbcType="INTEGER" />
11 <result column="update_time" property="updateTime" jdbcType="INTEGER" /> 11 <result column="update_time" property="updateTime" jdbcType="INTEGER" />
12 </resultMap> 12 </resultMap>
@@ -23,15 +23,15 @@ @@ -23,15 +23,15 @@
23 delete from seller_wallet 23 delete from seller_wallet
24 where id = #{id,jdbcType=INTEGER} 24 where id = #{id,jdbcType=INTEGER}
25 </delete> 25 </delete>
26 - <insert id="insert" parameterType="com.yohoufo.dal.order.model.SellerWallet" > 26 + <insert id="insert" parameterType="com.yohoufo.dal.order.model.SellerWallet" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
27 insert into seller_wallet (id, uid, amount, 27 insert into seller_wallet (id, uid, amount,
28 status, type, create_time, 28 status, type, create_time,
29 update_time) 29 update_time)
30 values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{amount,jdbcType=DECIMAL}, 30 values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER}, #{amount,jdbcType=DECIMAL},
31 - #{status,jdbcType=TINYINT}, #{type,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER}, 31 + #{status,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER},
32 #{updateTime,jdbcType=INTEGER}) 32 #{updateTime,jdbcType=INTEGER})
33 </insert> 33 </insert>
34 - <insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.SellerWallet" > 34 + <insert id="insertSelective" parameterType="com.yohoufo.dal.order.model.SellerWallet" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
35 insert into seller_wallet 35 insert into seller_wallet
36 <trim prefix="(" suffix=")" suffixOverrides="," > 36 <trim prefix="(" suffix=")" suffixOverrides="," >
37 <if test="id != null" > 37 <if test="id != null" >
@@ -67,10 +67,10 @@ @@ -67,10 +67,10 @@
67 #{amount,jdbcType=DECIMAL}, 67 #{amount,jdbcType=DECIMAL},
68 </if> 68 </if>
69 <if test="status != null" > 69 <if test="status != null" >
70 - #{status,jdbcType=TINYINT}, 70 + #{status,jdbcType=INTEGER},
71 </if> 71 </if>
72 <if test="type != null" > 72 <if test="type != null" >
73 - #{type,jdbcType=TINYINT}, 73 + #{type,jdbcType=INTEGER},
74 </if> 74 </if>
75 <if test="createTime != null" > 75 <if test="createTime != null" >
76 #{createTime,jdbcType=INTEGER}, 76 #{createTime,jdbcType=INTEGER},
@@ -90,10 +90,10 @@ @@ -90,10 +90,10 @@
90 amount = #{amount,jdbcType=DECIMAL}, 90 amount = #{amount,jdbcType=DECIMAL},
91 </if> 91 </if>
92 <if test="status != null" > 92 <if test="status != null" >
93 - status = #{status,jdbcType=TINYINT}, 93 + status = #{status,jdbcType=INTEGER},
94 </if> 94 </if>
95 <if test="type != null" > 95 <if test="type != null" >
96 - type = #{type,jdbcType=TINYINT}, 96 + type = #{type,jdbcType=INTEGER},
97 </if> 97 </if>
98 <if test="createTime != null" > 98 <if test="createTime != null" >
99 create_time = #{createTime,jdbcType=INTEGER}, 99 create_time = #{createTime,jdbcType=INTEGER},
@@ -108,10 +108,25 @@ @@ -108,10 +108,25 @@
108 update seller_wallet 108 update seller_wallet
109 set uid = #{uid,jdbcType=INTEGER}, 109 set uid = #{uid,jdbcType=INTEGER},
110 amount = #{amount,jdbcType=DECIMAL}, 110 amount = #{amount,jdbcType=DECIMAL},
111 - status = #{status,jdbcType=TINYINT},  
112 - type = #{type,jdbcType=TINYINT}, 111 + status = #{status,jdbcType=INTEGER},
  112 + type = #{type,jdbcType=INTEGER},
113 create_time = #{createTime,jdbcType=INTEGER}, 113 create_time = #{createTime,jdbcType=INTEGER},
114 update_time = #{updateTime,jdbcType=INTEGER} 114 update_time = #{updateTime,jdbcType=INTEGER}
115 where id = #{id,jdbcType=INTEGER} 115 where id = #{id,jdbcType=INTEGER}
116 </update> 116 </update>
  117 + <select id="selectByUidAndType" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  118 + select
  119 + <include refid="Base_Column_List" />
  120 + from seller_wallet
  121 + where uid = #{uid,jdbcType=INTEGER} and type = #{type,jdbcType=INTEGER}
  122 + </select>
  123 +
  124 + <update id="addMoney" parameterType="com.yohoufo.dal.order.model.SellerWallet" >
  125 + update seller_wallet set amount = amount + #{amount,jdbcType=DECIMAL},update_time = #{updateTime,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} and amount + #{amount,jdbcType=DECIMAL} &gt;= 0 and status=1
  126 + </update>
  127 +
  128 + <update id="returnMoney" parameterType="com.yohoufo.dal.order.model.SellerWallet" >
  129 + update seller_wallet set amount = 0 ,status = 0,update_time = #{updateTime,jdbcType=INTEGER} where id = #{id,jdbcType=INTEGER} and amount = #{amount,jdbcType=DECIMAL} and status=1
  130 + </update>
  131 +
117 </mapper> 132 </mapper>
1 package com.yohoufo.order.common; 1 package com.yohoufo.order.common;
2 2
3 public enum Payment { 3 public enum Payment {
  4 + WALLET(11, "wallet", "钱包"),
4 MINIAPP(3, "miniapp", "微信小程序"), 5 MINIAPP(3, "miniapp", "微信小程序"),
5 ALIPAY(2, "alipay", "支付宝"), 6 ALIPAY(2, "alipay", "支付宝"),
6 WECHAT(1, "wechat", "微信"); 7 WECHAT(1, "wechat", "微信");
  1 +package com.yohoufo.order.service;
  2 +
  3 +import java.math.BigDecimal;
  4 +import java.util.Arrays;
  5 +import java.util.List;
  6 +
  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.JSONObject;
  13 +import com.yoho.core.common.utils.DateUtil;
  14 +import com.yoho.error.ServiceError;
  15 +import com.yoho.error.exception.ServiceException;
  16 +import com.yohobuy.ufo.model.order.bo.OrderInfo;
  17 +import com.yohobuy.ufo.model.order.common.OrderCodeType;
  18 +import com.yohobuy.ufo.model.order.common.OrderStatus;
  19 +import com.yohobuy.ufo.model.order.common.TabType;
  20 +import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
  21 +import com.yohoufo.common.utils.TimeUtils;
  22 +import com.yohoufo.dal.order.EntrySellerRechargeOrderMapper;
  23 +import com.yohoufo.dal.order.OrdersPayMapper;
  24 +import com.yohoufo.dal.order.SellerWalletDetailMapper;
  25 +import com.yohoufo.dal.order.SellerWalletMapper;
  26 +import com.yohoufo.dal.order.model.EntrySellerRechargeOrder;
  27 +import com.yohoufo.dal.order.model.OrdersPay;
  28 +import com.yohoufo.dal.order.model.SellerWallet;
  29 +import com.yohoufo.dal.order.model.SellerWalletDetail;
  30 +import com.yohoufo.order.common.Payment;
  31 +import com.yohoufo.order.model.request.PaymentRequest;
  32 +import com.yohoufo.order.model.response.PrepayResponse;
  33 +import com.yohoufo.order.service.cache.CacheCleaner;
  34 +import com.yohoufo.order.service.cache.CacheKeyBuilder;
  35 +
  36 +@Service
  37 +public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
  38 +
  39 + private final Logger logger = LoggerFactory.getLogger(getClass());
  40 + private static final int TYPE_FIRST_RECHARGE = 1;
  41 +
  42 + @Autowired
  43 + SellerWalletMapper sellerWalletMapper;
  44 +
  45 + @Autowired
  46 + SellerWalletDetailMapper sellerWalletDetailMapper;
  47 +
  48 + @Autowired
  49 + EntrySellerRechargeOrderMapper entrySellerRechargeOrderMapper;
  50 +
  51 + @Autowired
  52 + OrdersPayMapper ordersPayDao;
  53 +
  54 + @Autowired
  55 + private CacheCleaner cacheCleaner;
  56 +
  57 + /**
  58 + * 更新订单状态
  59 + * @param orderInfo
  60 + */
  61 + public void updateOrderStatusPaid(OrderInfo orderInfo) {
  62 + EntrySellerRechargeOrder order = new EntrySellerRechargeOrder();
  63 + order.setOrderCode(orderInfo.getOrderCode());
  64 + order.setStatus(OrderStatus.HAS_PAYED.getCode());
  65 + order.setUpdateTime(DateUtil.getCurrentTimeSecond());
  66 + // order.setPayment(orderInfo.getPayment());
  67 + entrySellerRechargeOrderMapper.updateByOrderCode(order);
  68 + orderInfo.setStatus(OrderStatus.HAS_PAYED.getCode());
  69 + }
  70 +
  71 + @Override
  72 + public void processAfterPay(OrderInfo orderInfo) {
  73 + // 首次充值,调用认证成功接口
  74 + if (orderInfo.getType() == TYPE_FIRST_RECHARGE) {
  75 + // TODO
  76 + }
  77 + BigDecimal amount = orderInfo.getAmount();
  78 + SellerWallet sw = sellerWalletMapper.selectByUidAndType(orderInfo.getUid(), 1);
  79 + if (orderInfo.getType() == TYPE_FIRST_RECHARGE) {
  80 + if (sw != null) {
  81 + logger.error("首次充值保证金余额{},发现钱包已存在,uid={}", amount, orderInfo.getUid());
  82 + CommonAlarmEventPublisher.publish("首次充值保证金余额失败", "ufo.order.recharge", "钱包已存在:uid=" + orderInfo.getUid() + ",充值订单号为:" + orderInfo.getOrderCode()+", 充值金额为:"+amount);
  83 + return;
  84 + }
  85 + // 首次充值,创建钱包信息
  86 + sw = new SellerWallet();
  87 + sw.setUid(orderInfo.getUid());
  88 + sw.setAmount(orderInfo.getAmount());
  89 + sw.setStatus(1);
  90 + sw.setType(1);
  91 + sw.setCreateTime(TimeUtils.getTimeStampSecond());
  92 + sw.setUpdateTime(0);
  93 + sellerWalletMapper.insert(sw);
  94 + } else {
  95 + // 修改钱包余额
  96 + if (sw == null) {
  97 + logger.error("充值保证金余额{},钱包不存在,uid={}", amount, orderInfo.getUid());
  98 + CommonAlarmEventPublisher.publish("充值保证金余额失败", "ufo.order.recharge", "钱包不存在uid=" + orderInfo.getUid() + ",充值订单号为:" + orderInfo.getOrderCode()+", 充值金额为:"+amount);
  99 + return;
  100 + }
  101 + if (sw.getStatus() == null || sw.getStatus() == 0) {
  102 + logger.error("充值保证金余额{},钱包不可用,uid={}", amount, orderInfo.getUid());
  103 + CommonAlarmEventPublisher.publish("充值保证金余额失败", "ufo.order.recharge", "钱包不可用uid=" + orderInfo.getUid() + ",充值订单号为:" + orderInfo.getOrderCode()+", 充值金额为:"+amount);
  104 + return;
  105 + }
  106 +
  107 + sw.setAmount(orderInfo.getAmount());
  108 + sw.setUpdateTime(TimeUtils.getTimeStampSecond());
  109 + if (sellerWalletMapper.addMoney(sw) == 0) {
  110 + logger.error("充值保证金余额{},更新表返回0,uid={}", amount, orderInfo.getUid());
  111 + CommonAlarmEventPublisher.publish("充值保证金余额失败", "ufo.order.recharge", "更新表返回0,uid=" + orderInfo.getUid() + ",充值订单号为:" + orderInfo.getOrderCode()+", 充值金额为:"+amount);
  112 + return;
  113 + }
  114 + }
  115 +
  116 + // 增加充值记录
  117 + SellerWalletDetail swd = new SellerWalletDetail();
  118 + swd.setOrderCode(orderInfo.getOrderCode());
  119 + swd.setType(1);
  120 + swd.setUid(orderInfo.getUid());
  121 + swd.setWalletId(sw.getId());
  122 + swd.setAmount(orderInfo.getAmount());
  123 + swd.setCreateTime(TimeUtils.getTimeStampSecond());
  124 + sellerWalletDetailMapper.insert(swd);
  125 +
  126 + cacheCleaner.delete(Arrays.asList(
  127 + CacheKeyBuilder.orderListKey(orderInfo.getUid(), TabType.BUY.getValue()),
  128 + CacheKeyBuilder.orderDetailKey(orderInfo.getUid(), TabType.BUY.getValue(), orderInfo.getOrderCode())));
  129 + }
  130 +
  131 +
  132 + /**
  133 + * 订单是否是待支付状态
  134 + * @param orderInfo
  135 + * @return
  136 + */
  137 + public boolean isOrderWaitingPay(OrderInfo orderInfo){
  138 +
  139 + if (orderInfo.getStatus() != null && orderInfo.getStatus().intValue() == OrderStatus.WAITING_PAY.getCode()){
  140 + return true;
  141 + }
  142 +
  143 + return false;
  144 + }
  145 +
  146 +
  147 + /**
  148 + * 订单是 已支付的订单
  149 + * @param orderInfo
  150 + * @return
  151 + */
  152 + public boolean isOrderPaid(OrderInfo orderInfo){
  153 +
  154 + if (orderInfo.getStatus() != null && orderInfo.getStatus().intValue() == OrderStatus.HAS_PAYED.getCode()){
  155 + return true;
  156 + }
  157 +
  158 + return false;
  159 + }
  160 +
  161 + final static List<Integer> canRefundStatusList = Arrays.asList(OrderStatus.SELLER_CANCEL_AFTER_PAY.getCode(),
  162 + OrderStatus.SEND_OUT_TIMEOUT.getCode(), OrderStatus.CHECKING_FAKE.getCode());
  163 +
  164 + @Override
  165 + public boolean canRefund(OrderInfo orderInfo) {
  166 + if (orderInfo.getStatus() != null && canRefundStatusList.contains(orderInfo.getStatus().intValue())){
  167 + return true;
  168 + }
  169 + return false;
  170 + }
  171 +
  172 +
  173 + /**
  174 + * 保存前回预支付结果
  175 + * @param orderInfo
  176 + * @param response
  177 + */
  178 + public void saveAppPayRequest(OrderInfo orderInfo, PrepayResponse response) {
  179 + }
  180 +
  181 +
  182 + /**
  183 + * 获取前回的访问结果
  184 + * @param request
  185 + * @return
  186 + */
  187 + public PrepayResponse getAppPayRequest(PaymentRequest request) {
  188 + return null;
  189 + }
  190 +
  191 +
  192 + /**
  193 + * 检查状态
  194 + * @param orderInfo
  195 + */
  196 + public void checkOrderStatus(OrderInfo orderInfo){
  197 + // 订单不是未付款的状态
  198 + if (orderInfo.getStatus() == null || orderInfo.getStatus().intValue() != OrderStatus.WAITING_PAY.getCode()){
  199 + logger.warn("payment status not allow {}, orderCode is {}, uid is {}", orderInfo.getStatus(),
  200 + orderInfo.getOrderCode(), orderInfo.getUid());
  201 + throw new ServiceException(ServiceError.ORDER_PAY_NOT_ALLOW);
  202 + }
  203 + }
  204 +
  205 +
  206 + /**
  207 + * 预支付方式更新
  208 + * @param orderInfo
  209 + */
  210 + public void updatePayment(OrderInfo orderInfo, int payment){
  211 +
  212 + EntrySellerRechargeOrder order = new EntrySellerRechargeOrder();
  213 + order.setOrderCode(orderInfo.getOrderCode());
  214 + order.setUid(orderInfo.getUid());
  215 + // 更新预支付方式
  216 + order.setPayment(payment);
  217 + order.setUpdateTime(DateUtil.getCurrentTimeSecond());
  218 + entrySellerRechargeOrderMapper.updateByOrderCode(order);
  219 + }
  220 +
  221 +
  222 + /**
  223 + * 获取订单情报
  224 + * @param orderCode
  225 + * @param uid
  226 + * @return
  227 + */
  228 + public OrderInfo getOrderInfo(long orderCode, int uid) {
  229 +
  230 + EntrySellerRechargeOrder order = entrySellerRechargeOrderMapper.selectByOrderCodeUid(orderCode, uid);
  231 +
  232 + if (order == null){
  233 + logger.warn("getOrderInfo order not exist, orderCode is {}, uid is {}", orderCode, uid);
  234 + throw new ServiceException(ServiceError.ORDER_NULL);
  235 + }
  236 +
  237 + return buildOrderInfo(order);
  238 + }
  239 +
  240 + private OrderInfo buildOrderInfo(EntrySellerRechargeOrder order) {
  241 + OrderInfo orderInfo = OrderInfo.builder()
  242 + .id(order.getId())
  243 + .uid(order.getUid())
  244 + .orderCode(order.getOrderCode())
  245 + .payment(order.getPayment())
  246 + .status(order.getStatus())
  247 + .amount(order.getAmount())
  248 + .createTime(order.getCreateTime())
  249 + .orderCodeType(OrderCodeType.BUYER_TYPE)
  250 + .sourceStatus(order.getStatus())
  251 + .type(order.getType())
  252 + .build();
  253 +
  254 + return orderInfo;
  255 + }
  256 +
  257 + /**
  258 + * 获取订单情报
  259 + * @param orderCode
  260 + * @return
  261 + */
  262 + public OrderInfo getOrderInfo(long orderCode) {
  263 + EntrySellerRechargeOrder buyerOrder = entrySellerRechargeOrderMapper.selectByOrderCode(orderCode);
  264 + if (buyerOrder == null){
  265 + logger.warn("getOrderInfo order not exist, orderCode is {}", orderCode);
  266 + throw new ServiceException(ServiceError.ORDER_NULL);
  267 + }
  268 + return buildOrderInfo(buyerOrder);
  269 + }
  270 +
  271 + // 支付保证金:总账修改
  272 + public SellerWallet useEarnest(Integer uid, BigDecimal money) {
  273 + return changeEarnest(uid, money, "支付保证金");
  274 + }
  275 +
  276 + // 修改价格保证金差价:总账修改
  277 + public SellerWallet changePriceUseEarnest(Integer uid, BigDecimal money) {
  278 + return changeEarnest(uid, money, "支付保证金(修改价格)");
  279 + }
  280 +
  281 + // 退还保证金:总账修改
  282 + public SellerWallet cancelRefundEarnest(Integer uid, BigDecimal money) {
  283 + return changeEarnest(uid, money, "退还保证金");
  284 + }
  285 +
  286 + // 支付保证金:明细
  287 + public void addUseEarnestDetail(SellerWallet sw, BigDecimal money) {
  288 + long orderCode = 0;
  289 + BigDecimal amount = null;
  290 + Integer uid = sw.getId();
  291 + SellerWalletDetail swd = new SellerWalletDetail();
  292 + swd.setOrderCode(orderCode);
  293 + swd.setType(2);
  294 + swd.setUid(uid);
  295 + swd.setWalletId(sw.getId());
  296 + swd.setAmount(amount);
  297 + swd.setCreateTime(TimeUtils.getTimeStampSecond());
  298 + sellerWalletDetailMapper.insert(swd);
  299 + }
  300 +
  301 + // 退还保证金
  302 + public void refundEarnestDetail(SellerWallet sw, long orderCode, BigDecimal amount) {
  303 + SellerWalletDetail swd = new SellerWalletDetail();
  304 + swd.setOrderCode(orderCode);
  305 + swd.setType(3); // 单笔退还
  306 + swd.setUid(sw.getUid());
  307 + swd.setWalletId(sw.getId());
  308 + swd.setAmount(amount);
  309 + swd.setCreateTime(TimeUtils.getTimeStampSecond());
  310 + sellerWalletDetailMapper.insert(swd);
  311 + }
  312 +
  313 + // 退出入驻:归还所有保证金 总账+明细
  314 + public BigDecimal returnEarnest(Integer uid, long orderCode) {
  315 + SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
  316 +
  317 + if (sw == null) {
  318 + logger.error("退还所有保证金,钱包不存在,uid={}", uid);
  319 + CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.recharge", "钱包不存在uid=" + uid);
  320 + return null;
  321 + }
  322 + BigDecimal amount = sw.getAmount();
  323 +
  324 + if (sw.getStatus() == null || sw.getStatus() == 0) {
  325 + logger.error("退还所有保证金{},钱包不可用,uid={}", amount, uid);
  326 + CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.recharge", "钱包不可用uid=" + uid+", 退还金额为:"+amount);
  327 + return null;
  328 + }
  329 +
  330 + sw.setAmount(amount);
  331 + sw.setUpdateTime(TimeUtils.getTimeStampSecond());
  332 + if (sellerWalletMapper.returnMoney(sw) == 0) {
  333 + logger.error("退还所有证金失败,更新表返回0,uid={}", uid);
  334 + CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.recharge", "更新表返回0,uid=" + uid + ", 退还金额为:"+ amount);
  335 + return null;
  336 + }
  337 +
  338 + // 增加充值记录
  339 + SellerWalletDetail swd = new SellerWalletDetail();
  340 + swd.setOrderCode(orderCode);
  341 + swd.setType(5);// 退还所有保证金
  342 + swd.setUid(uid);
  343 + swd.setWalletId(sw.getId());
  344 + swd.setAmount(amount);
  345 + swd.setCreateTime(TimeUtils.getTimeStampSecond());
  346 + sellerWalletDetailMapper.insert(swd);
  347 +
  348 + return amount;
  349 + }
  350 +
  351 + private SellerWallet changeEarnest(Integer uid, BigDecimal money, String message) {
  352 + // 使用钱包余额,支付保证金
  353 + SellerWallet sw = sellerWalletMapper.selectByUidAndType(uid, 1);
  354 +
  355 + if (sw == null) {
  356 + logger.error(message + "失败,钱包不存在,uid={}", uid);
  357 + CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.recharge", "钱包不存在uid=" + uid+", 金额为:"+money);
  358 + return null;
  359 + }
  360 + if (sw.getStatus() == null || sw.getStatus() == 0) {
  361 + logger.error(message + "{}失败,钱包不可用,uid={}", money, uid);
  362 + CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.recharge", "钱包不可用uid=" + uid+", 金额为:"+money);
  363 + return null;
  364 + }
  365 + if (sw.getAmount().compareTo(money) < 0) {
  366 + logger.error(message + "{}失败,钱包余额不足,uid={}", money, uid);
  367 + CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.recharge", "钱包余额不足uid=" + uid+", 金额为:"+money+", 账户余额为:"+sw.getAmount());
  368 + return null;
  369 + }
  370 +
  371 + sw.setAmount(money.multiply(new BigDecimal("-1")));
  372 + sw.setUpdateTime(TimeUtils.getTimeStampSecond());
  373 + if (sellerWalletMapper.addMoney(sw) == 0) {
  374 + logger.error(message + "失败,(并发)更新表返回0,uid={}", uid);
  375 + CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.recharge", "(并发)更新表返回0,uid=" + uid + ", 金额为:"+ money);
  376 + return null;
  377 + }
  378 + return sw;
  379 + }
  380 +
  381 + public void addOrdersPay(SellerWalletDetail swd) {
  382 + // 增加支付记录
  383 + OrdersPay ordersPay = new OrdersPay();
  384 + ordersPay.setOrderCode(swd.getOrderCode());
  385 + ordersPay.setUid(swd.getUid());
  386 + ordersPay.setPayment(Payment.WALLET.getCode());
  387 + ordersPay.setAmount(swd.getAmount());
  388 + ordersPay.setPayOrderCode(String.valueOf(swd.getOrderCode()));
  389 + ordersPay.setSerialNo(Integer.toString(swd.getId()));
  390 + ordersPay.setCreateTime(TimeUtils.getTimeStampSecond());
  391 +
  392 + JSONObject attach = new JSONObject();
  393 + attach.put("order_type", OrderCodeType.SELLER_TYPE.getType());
  394 + ordersPay.setAttach(attach.toJSONString());
  395 + ordersPayDao.insertSelective(ordersPay);
  396 + }
  397 +
  398 + public void changePriceUpdateOrdersPay(SellerWalletDetail swd) {
  399 + // 增加支付记录
  400 + OrdersPay ordersPay = new OrdersPay();
  401 + ordersPay.setOrderCode(swd.getOrderCode());
  402 + ordersPay.setUid(swd.getUid());
  403 + ordersPay.setAmount(swd.getAmount());
  404 + String message = "修改保证金order_pay记录金额";
  405 + if (ordersPayDao.addMoney(ordersPay) == 0) {
  406 + logger.error(message + "{}失败,修改DB返回记录数为0,orderCode={}", swd.getAmount(), swd.getOrderCode());
  407 + CommonAlarmEventPublisher.publish(message + "失败", "ufo.order.changePriceOrdersPay", "修改DB返回记录数为0,orderCode=" + swd.getOrderCode()+", 金额为:"+swd.getAmount());
  408 + }
  409 + }
  410 +
  411 +}
@@ -29,10 +29,12 @@ import com.yohoufo.order.model.response.PrepayResponse; @@ -29,10 +29,12 @@ import com.yohoufo.order.model.response.PrepayResponse;
29 import com.yohoufo.order.service.AbstractOrderPaymentService; 29 import com.yohoufo.order.service.AbstractOrderPaymentService;
30 import com.yohoufo.order.service.BuyerOrderPaymentService; 30 import com.yohoufo.order.service.BuyerOrderPaymentService;
31 import com.yohoufo.order.service.IPaymentService; 31 import com.yohoufo.order.service.IPaymentService;
  32 +import com.yohoufo.order.service.MerchantOrderPaymentService;
32 import com.yohoufo.order.service.SellerOrderPaymentService; 33 import com.yohoufo.order.service.SellerOrderPaymentService;
33 import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler; 34 import com.yohoufo.order.service.handler.BuyerCancelCompensateComputeHandler;
34 import com.yohoufo.order.service.pay.AbstractPayService; 35 import com.yohoufo.order.service.pay.AbstractPayService;
35 import com.yohoufo.order.service.pay.alipay.AlipayOuyinService; 36 import com.yohoufo.order.service.pay.alipay.AlipayOuyinService;
  37 +import com.yohoufo.order.service.pay.wallet.WalletPayService;
36 import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService; 38 import com.yohoufo.order.service.pay.weixin.WeixinMiniappPayService;
37 import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService; 39 import com.yohoufo.order.service.pay.weixin.WeixinPayUFORealAppService;
38 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; 40 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
@@ -76,6 +78,9 @@ public class PaymentServiceImpl implements IPaymentService { @@ -76,6 +78,9 @@ public class PaymentServiceImpl implements IPaymentService {
76 SellerOrderPaymentService sellerOrderPaymentService; 78 SellerOrderPaymentService sellerOrderPaymentService;
77 79
78 @Autowired 80 @Autowired
  81 + MerchantOrderPaymentService merchantOrderPaymentService;
  82 +
  83 + @Autowired
79 OrderCodeGenerator orderCodeGenerator; 84 OrderCodeGenerator orderCodeGenerator;
80 85
81 @Autowired 86 @Autowired
@@ -109,6 +114,9 @@ public class PaymentServiceImpl implements IPaymentService { @@ -109,6 +114,9 @@ public class PaymentServiceImpl implements IPaymentService {
109 WeixinMiniappPayService weixinMiniappPayService; 114 WeixinMiniappPayService weixinMiniappPayService;
110 115
111 @Autowired 116 @Autowired
  117 + WalletPayService walletPayService;
  118 +
  119 + @Autowired
112 BuyerOrderMapper buyerOrderMapper; 120 BuyerOrderMapper buyerOrderMapper;
113 121
114 @Autowired 122 @Autowired
@@ -144,8 +152,7 @@ public class PaymentServiceImpl implements IPaymentService { @@ -144,8 +152,7 @@ public class PaymentServiceImpl implements IPaymentService {
144 }else if(codeMeta.getType() == OrderCodeType.SELLER_TYPE.getType()){ 152 }else if(codeMeta.getType() == OrderCodeType.SELLER_TYPE.getType()){
145 paymentService = this.sellerOrderPaymentService; 153 paymentService = this.sellerOrderPaymentService;
146 }else if(codeMeta.getType() == OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType()){ 154 }else if(codeMeta.getType() == OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType()){
147 - // TODO  
148 - paymentService = this.sellerOrderPaymentService; 155 + paymentService = this.merchantOrderPaymentService;
149 } 156 }
150 157
151 return paymentService; 158 return paymentService;
@@ -173,6 +180,8 @@ public class PaymentServiceImpl implements IPaymentService { @@ -173,6 +180,8 @@ public class PaymentServiceImpl implements IPaymentService {
173 payService = alipayService; 180 payService = alipayService;
174 }else if(payment == Payment.MINIAPP){ 181 }else if(payment == Payment.MINIAPP){
175 payService = weixinMiniappPayService; 182 payService = weixinMiniappPayService;
  183 + }else if(payment == Payment.WALLET){
  184 + payService = walletPayService;
176 } 185 }
177 186
178 return payService; 187 return payService;
@@ -283,7 +292,7 @@ public class PaymentServiceImpl implements IPaymentService { @@ -283,7 +292,7 @@ public class PaymentServiceImpl implements IPaymentService {
283 292
284 ordersPayDao.insertSelective(ordersPay); 293 ordersPayDao.insertSelective(ordersPay);
285 294
286 - // 支付方式适配 295 + // 流水记录表支付方式适配
287 Integer recordPayment = orderInfo.getPayment(); 296 Integer recordPayment = orderInfo.getPayment();
288 if (recordPayment != null && recordPayment == 1) { 297 if (recordPayment != null && recordPayment == 1) {
289 if (recordPayment == 1) { 298 if (recordPayment == 1) {
@@ -300,7 +309,10 @@ public class PaymentServiceImpl implements IPaymentService { @@ -300,7 +309,10 @@ public class PaymentServiceImpl implements IPaymentService {
300 } 309 }
301 addPayBuyRecord(orderInfo.getUid(), orderInfo.getSellerUid(), goods.getSkup(), orderCode, recordPayment, 310 addPayBuyRecord(orderInfo.getUid(), orderInfo.getSellerUid(), goods.getSkup(), orderCode, recordPayment,
302 ordersPay.getAmount()); 311 ordersPay.getAmount());
303 - } else { 312 + } else if (codeMeta.getType() == OrderCodeType.SELLER_TYPE.getType()) {
  313 + addPayEnsureRecord(orderInfo.getUid(), orderInfo.getSkup(), orderCode, recordPayment,
  314 + ordersPay.getAmount());
  315 + } else if (codeMeta.getType() == OrderCodeType.SELLER_RECHARGE_EARNEST_TYPE.getType()) {
304 addPayEnsureRecord(orderInfo.getUid(), orderInfo.getSkup(), orderCode, recordPayment, 316 addPayEnsureRecord(orderInfo.getUid(), orderInfo.getSkup(), orderCode, recordPayment,
305 ordersPay.getAmount()); 317 ordersPay.getAmount());
306 } 318 }