Authored by Lixiaodi

增加退款验证

@@ -32,5 +32,7 @@ public interface EntrySellerRechargeOrderMapper { @@ -32,5 +32,7 @@ public interface EntrySellerRechargeOrderMapper {
32 EntrySellerRechargeOrder selectByOrderCodeUid(@Param("orderCode")long orderCode, @Param("uid")int uid); 32 EntrySellerRechargeOrder selectByOrderCodeUid(@Param("orderCode")long orderCode, @Param("uid")int uid);
33 33
34 EntrySellerRechargeOrder selectByOrderCode(@Param("orderCode")long orderCode); 34 EntrySellerRechargeOrder selectByOrderCode(@Param("orderCode")long orderCode);
  35 +
  36 + EntrySellerRechargeOrder selectAllRechargeByUid(@Param("uid") Integer uid);
35 37
36 } 38 }
@@ -22,4 +22,7 @@ public interface SellerWalletDetailMapper { @@ -22,4 +22,7 @@ public interface SellerWalletDetailMapper {
22 int selectUserDetailCount(@Param("uid") Integer uid); 22 int selectUserDetailCount(@Param("uid") Integer uid);
23 23
24 List<SellerWalletDetail> selectUserDetail(@Param("uid") Integer uid, @Param("start") Integer start, @Param("count") Integer count); 24 List<SellerWalletDetail> selectUserDetail(@Param("uid") Integer uid, @Param("start") Integer start, @Param("count") Integer count);
  25 +
  26 + SellerWalletDetail selectUserPunishAmount(@Param("uid") Integer uid);
  27 +
25 } 28 }
@@ -200,5 +200,12 @@ @@ -200,5 +200,12 @@
200 order by id desc 200 order by id desc
201 limit #{start,jdbcType=INTEGER},#{limit,jdbcType=INTEGER} 201 limit #{start,jdbcType=INTEGER},#{limit,jdbcType=INTEGER}
202 </select> 202 </select>
  203 +
  204 + <select id="selectAllRechargeByUid" resultMap="BaseResultMap">
  205 + select
  206 + uid, sum(amount) as amount
  207 + from entry_seller_recharge_order
  208 + where status = 1 and uid = #{uid,jdbcType=INTEGER} and type in(1,2)
  209 + </select>
203 210
204 </mapper> 211 </mapper>
@@ -194,5 +194,11 @@ @@ -194,5 +194,11 @@
194 where uid = #{uid,jdbcType=INTEGER} and is_batch = 0 and type in (1,31,32,33,61) order by id desc limit #{start},#{count} 194 where uid = #{uid,jdbcType=INTEGER} and is_batch = 0 and type in (1,31,32,33,61) order by id desc limit #{start},#{count}
195 </select> 195 </select>
196 196
  197 + <select id="selectUserPunishAmount" resultMap="BaseResultMap" >
  198 + select
  199 + uid, sum(amount) as amount
  200 + from seller_wallet_detail
  201 + where uid = #{uid,jdbcType=INTEGER} and is_batch = 0 and type in (31,32,33)
  202 + </select>
197 203
198 </mapper> 204 </mapper>
@@ -388,8 +388,8 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { @@ -388,8 +388,8 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
388 388
389 // 处罚保证金:总账修改 389 // 处罚保证金:总账修改
390 // 卖家取消、鉴定失败 390 // 卖家取消、鉴定失败
391 - public SellerWallet punishEarnest(Integer uid, BigDecimal money, MerchantOrderAttachInfo attach, SellerWalletDetail.Type type) {  
392 - return changeEarnest(uid, money, 0L, attach, type); 391 + public SellerWallet punishEarnest(Integer uid, BigDecimal money, MerchantOrderAttachInfo attach, long orderCode, SellerWalletDetail.Type type) {
  392 + return changeEarnest(uid, money, orderCode, attach, type);
393 } 393 }
394 394
395 // 支付保证金:明细记录+orders_pay记录 395 // 支付保证金:明细记录+orders_pay记录
@@ -454,6 +454,16 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { @@ -454,6 +454,16 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
454 CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.changeEarnest", "钱包不可用uid=" + uid+", 退还金额为:"+amount); 454 CommonAlarmEventPublisher.publish("退还所有保证金失败", "ufo.order.changeEarnest", "钱包不可用uid=" + uid+", 退还金额为:"+amount);
455 return null; 455 return null;
456 } 456 }
  457 +
  458 + //////////////////////////////////////
  459 + // 核算总账
  460 + BigDecimal checkMoney = checkMoney(sw,0);
  461 + if (checkMoney == null) {
  462 + logger.info("uid={}退出入驻账目简要核对,结果失败", uid);
  463 + return null;
  464 + }
  465 + // 查询充值表,查询明细表
  466 + //////////////////////////////////////
457 467
458 sw.setUpdateTime(TimeUtils.getTimeStampSecond()); 468 sw.setUpdateTime(TimeUtils.getTimeStampSecond());
459 if (sellerWalletMapper.returnMoney(sw) == 0) { 469 if (sellerWalletMapper.returnMoney(sw) == 0) {
@@ -482,6 +492,40 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService { @@ -482,6 +492,40 @@ public class MerchantOrderPaymentService extends AbstractOrderPaymentService {
482 return amount; 492 return amount;
483 } 493 }
484 494
  495 + private BigDecimal checkMoney(SellerWallet sw, Integer uid0) {
  496 + if(sw==null) {
  497 + sw = sellerWalletMapper.selectByUidAndType(uid0, 1);
  498 + }
  499 + Integer uid = sw.getUid();
  500 + logger.info("uid={}退出入驻账目简要核对", uid);
  501 + logger.info("uid={}退出入驻账目简要核对,保证金余额={},锁定余额={}", uid, sw.getAmount(), sw.getLockAmount());
  502 + if (sw.getLockAmount().compareTo(BigDecimal.ZERO) != 0) {
  503 + logger.error("uid={}退出入驻账目简要核对,锁定余额{}不为0", uid, sw.getLockAmount());
  504 + return null;
  505 + }
  506 + EntrySellerRechargeOrder recharge = entrySellerRechargeOrderMapper.selectAllRechargeByUid(uid);
  507 + if (recharge == null) {
  508 + logger.error("uid={}退出入驻账目简要核对,未找到充值订单");
  509 + return null;
  510 + }
  511 +
  512 + BigDecimal allMoney = recharge.getAmount();
  513 + logger.info("uid={}退出入驻账目简要核对,保证金充值总额为={}", uid, recharge.getAmount());
  514 + SellerWalletDetail punish = sellerWalletDetailMapper.selectUserPunishAmount(uid);
  515 + if (punish != null) {
  516 + logger.info("uid={}退出入驻账目简要核对,处罚总额为={}", uid, punish.getAmount().abs());
  517 + allMoney = allMoney.subtract(punish.getAmount().abs());
  518 + } else {
  519 + logger.info("uid={}退出入驻账目简要核对,无处罚记录", uid);
  520 + }
  521 + if (allMoney.compareTo(sw.getAmount()) != 0) {
  522 + logger.error("uid={}退出入驻账目简要核对,总账-处罚={},与余额{}不一致", uid, allMoney, sw.getAmount());
  523 + return null;
  524 + }
  525 + logger.info("uid={}退出入驻账目简要核对,保证金余额={},核对成功", uid, sw.getAmount());
  526 + return sw.getAmount();
  527 + }
  528 +
485 // 增加:明细 529 // 增加:明细
486 private SellerWalletDetail addWalletDetail(SellerWallet sw, long orderCode, BigDecimal amount, SellerWalletDetail.Type type) { 530 private SellerWalletDetail addWalletDetail(SellerWallet sw, long orderCode, BigDecimal amount, SellerWalletDetail.Type type) {
487 Integer uid = sw.getUid(); 531 Integer uid = sw.getUid();