Authored by Lixiaodi

转账相关代码

@@ -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 }
@@ -165,6 +165,24 @@ public class RedisGwCacheClient implements CacheClient { @@ -165,6 +165,24 @@ public class RedisGwCacheClient implements CacheClient {
165 return null; 165 return null;
166 } 166 }
167 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 +
  185 +
168 /** 186 /**
169 * 获取正负区间的一个随机数 187 * 获取正负区间的一个随机数
170 * 188 *
@@ -385,7 +385,15 @@ public class PaymentServiceImpl implements IPaymentService { @@ -385,7 +385,15 @@ public class PaymentServiceImpl implements IPaymentService {
385 } 385 }
386 386
387 387
388 - 388 + /**
  389 + * <pre>
  390 + * 1:鉴定通过(货款-->卖家);
  391 + * 2:鉴定不通过(保证金 --> 买家);
  392 + * 3:有买家时卖家不卖了(保证金 --> 买家)
  393 + * </pre>
  394 + *
  395 + * @param request 请求
  396 + */
389 public void transferMon(TransferMoneyRequest request){ 397 public void transferMon(TransferMoneyRequest request){
390 logger.info("transferMon转账开始,request = {}", request); 398 logger.info("transferMon转账开始,request = {}", request);
391 399
@@ -419,7 +427,7 @@ public class PaymentServiceImpl implements IPaymentService { @@ -419,7 +427,7 @@ public class PaymentServiceImpl implements IPaymentService {
419 throw new ServiceException(ServiceError.ORDER_NULL); 427 throw new ServiceException(ServiceError.ORDER_NULL);
420 } 428 }
421 429
422 - // 查看是否已经有记录 430 + // 查看是否已经有转账记录
423 OrdersPayTransfer exist = ordersPayTransferMapper.selectByBuyerOrderCode(buyerOrderCode); 431 OrdersPayTransfer exist = ordersPayTransferMapper.selectByBuyerOrderCode(buyerOrderCode);
424 if (exist != null) { 432 if (exist != null) {
425 logger.warn("getOrderInfo order not exist, orderCode is {}", buyerOrderCode); 433 logger.warn("getOrderInfo order not exist, orderCode is {}", buyerOrderCode);
@@ -527,19 +535,40 @@ public class PaymentServiceImpl implements IPaymentService { @@ -527,19 +535,40 @@ public class PaymentServiceImpl implements IPaymentService {
527 } 535 }
528 536
529 // 支付保证金流水记录 537 // 支付保证金流水记录
530 - public void addPayEnsureRecord(Integer uid, Long orderCode, Integer payType, BigDecimal amount) { 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) {
531 // 增加流水记录 560 // 增加流水记录
532 TradeBills record = new TradeBills(); 561 TradeBills record = new TradeBills();
533 try { 562 try {
534 record.setUid(uid); 563 record.setUid(uid);
535 record.setOrderCode(orderCode); 564 record.setOrderCode(orderCode);
536 - record.setUserType(2);  
537 - record.setPayType(payType);  
538 - record.setTradeType(1);  
539 - record.setIncomeOutcome(2); 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:用户支出
540 record.setAmount(amount); 569 record.setAmount(amount);
541 - record.setSystemAmount(amount.multiply(new BigDecimal("-1")));  
542 - record.setTradeStatus(0); 570 + record.setSystemAmount(amount.multiply(new BigDecimal("-1")));// 有货收入
  571 + record.setTradeStatus(0);//0:订单未完结;1:订单完结
543 record.setCreateTime((int) (System.currentTimeMillis() / 1000)); 572 record.setCreateTime((int) (System.currentTimeMillis() / 1000));
544 tradeBillsMapper.insert(record); 573 tradeBillsMapper.insert(record);
545 } catch (Exception e) { 574 } catch (Exception e) {