Authored by mali

Merge branch 'dev'

@@ -447,15 +447,28 @@ public class PaymentServiceImpl implements IPaymentService { @@ -447,15 +447,28 @@ public class PaymentServiceImpl implements IPaymentService {
447 logger.warn("transferMonErr uid {} 不合法", targetUid); 447 logger.warn("transferMonErr uid {} 不合法", targetUid);
448 throw new ServiceException(400, "uid[" + targetUid + "]不合法"); 448 throw new ServiceException(400, "uid[" + targetUid + "]不合法");
449 } 449 }
  450 + int now = (int) (System.currentTimeMillis()/1000);
  451 +
  452 + // 增加流水记录
  453 + TradeBills record = new TradeBills();
  454 + record.setUid(targetUid);
  455 + record.setOrderCode(transferType == 1 ? sellerOrderCode : buyerOrderCode);
  456 + record.setUserType(transferType == 1 ? 2 : 1);
  457 + record.setPayType(1);
  458 + record.setTradeType(transferType == 1 ? 2 : 3);
  459 + record.setIncomeOutcome(1);
  460 + record.setTradeStatus(transferType == 1 ? 0 : 1);
  461 + record.setCreateTime(now);
  462 +
450 String alipayAccount = getAlipayAccount(targetUid); 463 String alipayAccount = getAlipayAccount(targetUid);
451 if (StringUtils.isBlank(alipayAccount)) { 464 if (StringUtils.isBlank(alipayAccount)) {
452 logger.warn("transferMonErr uid {} 没有获取到有效的支付宝账号", targetUid); 465 logger.warn("transferMonErr uid {} 没有获取到有效的支付宝账号", targetUid);
  466 + record.setTradeStatus(201);
  467 + addTradeBills(record);
453 throw new ServiceException(400, "uid[" + targetUid + "]没有获取到有效的支付宝账号"); 468 throw new ServiceException(400, "uid[" + targetUid + "]没有获取到有效的支付宝账号");
454 } 469 }
455 logger.info("transferMon参数检查成功!"); 470 logger.info("transferMon参数检查成功!");
456 471
457 - int now = (int) (System.currentTimeMillis()/1000);  
458 -  
459 OrdersPayTransfer transfer = new OrdersPayTransfer(); 472 OrdersPayTransfer transfer = new OrdersPayTransfer();
460 transfer.setBuyerOrderCode(buyerOrderCode); 473 transfer.setBuyerOrderCode(buyerOrderCode);
461 transfer.setSellerOrderCode(sellerOrderCode); 474 transfer.setSellerOrderCode(sellerOrderCode);
@@ -482,9 +495,14 @@ public class PaymentServiceImpl implements IPaymentService { @@ -482,9 +495,14 @@ public class PaymentServiceImpl implements IPaymentService {
482 logger.info("transferMon计算费用结果为 {}", transferAmount); 495 logger.info("transferMon计算费用结果为 {}", transferAmount);
483 if (transferAmount == null || transferAmount.compareTo(new BigDecimal("0.1")) < 0) { 496 if (transferAmount == null || transferAmount.compareTo(new BigDecimal("0.1")) < 0) {
484 logger.warn("transferMonErr transferMon计算费用结果为 {}, 不合法的金额", transferAmount); 497 logger.warn("transferMonErr transferMon计算费用结果为 {}, 不合法的金额", transferAmount);
485 - throw new ServiceException(400, "不合法的金额"); 498 + record.setTradeStatus(202);
  499 + addTradeBills(record);
  500 + throw new ServiceException(400, "不合法的金额:" + transferAmount);
486 } 501 }
487 transfer.setAmount(transferAmount); 502 transfer.setAmount(transferAmount);
  503 + record.setAmount(transferAmount);
  504 + // 因为转账支付宝扣费累计计算,使用转账额
  505 + record.setSystemAmount(transferAmount.multiply(new BigDecimal("-1")));
488 506
489 // 转账 507 // 转账
490 try { 508 try {
@@ -515,26 +533,18 @@ public class PaymentServiceImpl implements IPaymentService { @@ -515,26 +533,18 @@ public class PaymentServiceImpl implements IPaymentService {
515 logger.warn("transferMonErr 转账失败 , orderCode is {}, msg is {}", buyerOrderCode, e.getMessage()); 533 logger.warn("transferMonErr 转账失败 , orderCode is {}, msg is {}", buyerOrderCode, e.getMessage());
516 throw new ServiceException(500, "转账失败"); 534 throw new ServiceException(500, "转账失败");
517 } finally { 535 } finally {
518 - logger.info("transferMon最后更新状态 status= {}", transfer.getStatus()); 536 + logger.info("transferMon最后更新状态 status= {}", transfer.getStatus());
519 transfer.setUpdateTime(now); 537 transfer.setUpdateTime(now);
520 ordersPayTransferMapper.updateByPrimaryKeySelective(transfer); 538 ordersPayTransferMapper.updateByPrimaryKeySelective(transfer);
  539 + // 100:成功;201:没有支付宝账号;202:金额不合法;299:转账失败
  540 + record.setTradeStatus(transfer.getStatus() == 1 ? 100 : 299);
  541 + addTradeBills(record);
521 logger.info("transferMon最后更新状态完成,转账结束, buyerOrderCode is {}!", buyerOrderCode); 542 logger.info("transferMon最后更新状态完成,转账结束, buyerOrderCode is {}!", buyerOrderCode);
522 } 543 }
523 -  
524 - // 增加流水记录  
525 - TradeBills record = new TradeBills();  
526 - try {  
527 - record.setUid(targetUid);  
528 - record.setOrderCode(transferType == 1 ? sellerOrderCode : buyerOrderCode);  
529 - record.setUserType(transferType == 1 ? 2 : 1);  
530 - record.setPayType(1);  
531 - record.setTradeType(transferType == 1 ? 2 : 3);  
532 - record.setIncomeOutcome(1);  
533 - record.setAmount(transferAmount);  
534 - // 因为转账支付宝扣费累计计算,使用转账额  
535 - record.setSystemAmount(transferAmount.multiply(new BigDecimal("-1")));  
536 - record.setTradeStatus(transferType == 1 ? 0 : 1);  
537 - record.setCreateTime(now); 544 + }
  545 +
  546 + private void addTradeBills(TradeBills record) {
  547 + try {
538 tradeBillsMapper.insert(record); 548 tradeBillsMapper.insert(record);
539 } catch (Exception e) { 549 } catch (Exception e) {
540 logger.error("PayRecordErr记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record); 550 logger.error("PayRecordErr记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record);
@@ -550,29 +560,25 @@ public class PaymentServiceImpl implements IPaymentService { @@ -550,29 +560,25 @@ public class PaymentServiceImpl implements IPaymentService {
550 } 560 }
551 // 增加流水记录 561 // 增加流水记录
552 TradeBills record = new TradeBills(); 562 TradeBills record = new TradeBills();
  563 + record.setUid(uid);
  564 + record.setOrderCode(orderCode);
  565 + record.setUserType(2);// 1:买家uid; 2:卖家uid
  566 + record.setPayType(payType);// 1:支付宝; 2:微信
  567 + record.setTradeType(1);//1:保证金;2:货款;3:补偿款
  568 + record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
  569 + record.setAmount(amount);
553 try { 570 try {
554 - record.setUid(uid);  
555 - record.setOrderCode(orderCode);  
556 - record.setUserType(2);// 1:买家uid; 2:卖家uid  
557 - record.setPayType(payType);// 1:支付宝; 2:微信  
558 - record.setTradeType(1);//1:保证金;2:货款;3:补偿款  
559 - record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出  
560 - record.setAmount(amount);  
561 - try {  
562 - JSONObject metavalue = JSON.parseObject(meta.getMetaValue());  
563 - BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");  
564 - amount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);  
565 - } catch (Exception e) {  
566 - logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());  
567 - return;  
568 - }  
569 - record.setSystemAmount(amount);// 有货收入  
570 - record.setTradeStatus(0);//0:订单未完结;1:订单完结  
571 - record.setCreateTime((int) (System.currentTimeMillis() / 1000));  
572 - tradeBillsMapper.insert(record); 571 + JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
  572 + BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
  573 + amount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);
573 } catch (Exception e) { 574 } catch (Exception e) {
574 - logger.error("PayRecordErr记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record); 575 + logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
  576 + return;
575 } 577 }
  578 + record.setSystemAmount(amount);// 有货收入
  579 + record.setTradeStatus(0);//0:订单未完结;1:订单完结
  580 + record.setCreateTime((int) (System.currentTimeMillis() / 1000));
  581 + addTradeBills(record);
576 } 582 }
577 583
578 // 支付货款流水记录 584 // 支付货款流水记录
@@ -584,33 +590,29 @@ public class PaymentServiceImpl implements IPaymentService { @@ -584,33 +590,29 @@ public class PaymentServiceImpl implements IPaymentService {
584 } 590 }
585 // 增加流水记录 591 // 增加流水记录
586 TradeBills record = new TradeBills(); 592 TradeBills record = new TradeBills();
  593 + record.setUid(uid);
  594 + record.setOrderCode(orderCode);
  595 + record.setUserType(1);// 1:买家uid; 2:卖家uid
  596 + record.setPayType(payType);// 1:支付宝; 2:微信
  597 + record.setTradeType(2);//1:保证金;2:货款;3:补偿款
  598 + record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出
587 try { 599 try {
588 - record.setUid(uid);  
589 - record.setOrderCode(orderCode);  
590 - record.setUserType(1);// 1:买家uid; 2:卖家uid  
591 - record.setPayType(payType);// 1:支付宝; 2:微信  
592 - record.setTradeType(2);//1:保证金;2:货款;3:补偿款  
593 - record.setIncomeOutcome(2);// 1:用户收入; 2:用户支出  
594 - try {  
595 - JSONObject metavalue = JSON.parseObject(meta.getMetaValue());  
596 - BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");  
597 - amount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);  
598 - } catch (Exception e) {  
599 - logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());  
600 - return;  
601 - }  
602 - record.setAmount(amount);  
603 - record.setSystemAmount(amount);// 有货收入  
604 - record.setTradeStatus(0);//0:订单未完结;1:订单完结  
605 - record.setCreateTime((int) (System.currentTimeMillis() / 1000));  
606 - tradeBillsMapper.insert(record); 600 + JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
  601 + BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
  602 + amount = amount.multiply(BigDecimal.ONE.subtract(rate)).setScale(2, BigDecimal.ROUND_HALF_UP);
607 } catch (Exception e) { 603 } catch (Exception e) {
608 - logger.error("记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record); 604 + logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
  605 + return;
609 } 606 }
  607 + record.setAmount(amount);
  608 + record.setSystemAmount(amount);// 有货收入
  609 + record.setTradeStatus(0);//0:订单未完结;1:订单完结
  610 + record.setCreateTime((int) (System.currentTimeMillis() / 1000));
  611 + addTradeBills(record);
610 } 612 }
611 613
612 // 退保证金流水记录 614 // 退保证金流水记录
613 - public void backPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payType, BigDecimal amount) { 615 + public void backPayEnsureRecord(Integer uid, Integer skup, Long orderCode, Integer payType, BigDecimal amount, Integer tradeStatus) {
614 SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, "fee"); 616 SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(uid, skup, "fee");
615 if (meta == null) { 617 if (meta == null) {
616 logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup); 618 logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, uid = {}, skup={}", uid, skup);
@@ -618,33 +620,29 @@ public class PaymentServiceImpl implements IPaymentService { @@ -618,33 +620,29 @@ public class PaymentServiceImpl implements IPaymentService {
618 } 620 }
619 // 增加流水记录 621 // 增加流水记录
620 TradeBills record = new TradeBills(); 622 TradeBills record = new TradeBills();
  623 + record.setUid(uid);
  624 + record.setOrderCode(orderCode);
  625 + record.setUserType(2);// 1:买家uid; 2:卖家uid
  626 + record.setPayType(payType);// 1:支付宝; 2:微信
  627 + record.setTradeType(1);//1:保证金;2:货款;3:补偿款
  628 + record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
  629 + record.setAmount(amount);
621 try { 630 try {
622 - record.setUid(uid);  
623 - record.setOrderCode(orderCode);  
624 - record.setUserType(2);// 1:买家uid; 2:卖家uid  
625 - record.setPayType(payType);// 1:支付宝; 2:微信  
626 - record.setTradeType(1);//1:保证金;2:货款;3:补偿款  
627 - record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出  
628 - record.setAmount(amount);  
629 - try {  
630 - JSONObject metavalue = JSON.parseObject(meta.getMetaValue());  
631 - BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");  
632 - amount = amount.multiply(BigDecimal.ONE.subtract(rate)).multiply(new BigDecimal("-1")).setScale(2, BigDecimal.ROUND_HALF_UP);  
633 - } catch (Exception e) {  
634 - logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());  
635 - return;  
636 - }  
637 - record.setSystemAmount(amount);// 有货收入  
638 - record.setTradeStatus(1);//0:订单未完结;1:订单完结  
639 - record.setCreateTime((int) (System.currentTimeMillis() / 1000));  
640 - tradeBillsMapper.insert(record); 631 + JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
  632 + BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
  633 + amount = amount.multiply(BigDecimal.ONE.subtract(rate)).multiply(new BigDecimal("-1")).setScale(2, BigDecimal.ROUND_HALF_UP);
641 } catch (Exception e) { 634 } catch (Exception e) {
642 - logger.error("PayRecordErr记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record); 635 + logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
  636 + return;
643 } 637 }
  638 + record.setSystemAmount(amount);// 有货收入
  639 + record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
  640 + record.setCreateTime((int) (System.currentTimeMillis() / 1000));
  641 + addTradeBills(record);
644 } 642 }
645 643
646 // 退付货款流水记录 644 // 退付货款流水记录
647 - public void backPayBuyRecord(Integer uid, Integer sellerUid, Integer skup, Long orderCode, Integer payType, BigDecimal amount) { 645 + public void backPayBuyRecord(Integer uid, Integer sellerUid, Integer skup, Long orderCode, Integer payType, BigDecimal amount, Integer tradeStatus) {
648 SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee"); 646 SellerOrderMeta meta = sellerOrderMetaMapper.selectByMetaKey(sellerUid, skup, "fee");
649 if (meta == null) { 647 if (meta == null) {
650 logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, selleruid = {}, skup={}", sellerUid, skup); 648 logger.error("PayRecordErr记录交易到数据库出错 err=meta费率信息未查到, selleruid = {}, skup={}", sellerUid, skup);
@@ -652,29 +650,25 @@ public class PaymentServiceImpl implements IPaymentService { @@ -652,29 +650,25 @@ public class PaymentServiceImpl implements IPaymentService {
652 } 650 }
653 // 增加流水记录 651 // 增加流水记录
654 TradeBills record = new TradeBills(); 652 TradeBills record = new TradeBills();
  653 + record.setUid(uid);
  654 + record.setOrderCode(orderCode);
  655 + record.setUserType(1);// 1:买家uid; 2:卖家uid
  656 + record.setPayType(payType);// 1:支付宝; 2:微信
  657 + record.setTradeType(2);//1:保证金;2:货款;3:补偿款
  658 + record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出
655 try { 659 try {
656 - record.setUid(uid);  
657 - record.setOrderCode(orderCode);  
658 - record.setUserType(1);// 1:买家uid; 2:卖家uid  
659 - record.setPayType(payType);// 1:支付宝; 2:微信  
660 - record.setTradeType(2);//1:保证金;2:货款;3:补偿款  
661 - record.setIncomeOutcome(1);// 1:用户收入; 2:用户支出  
662 - try {  
663 - JSONObject metavalue = JSON.parseObject(meta.getMetaValue());  
664 - BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");  
665 - amount = amount.multiply(BigDecimal.ONE.subtract(rate)).multiply(new BigDecimal("-1")).setScale(2, BigDecimal.ROUND_HALF_UP);  
666 - } catch (Exception e) {  
667 - logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());  
668 - return;  
669 - }  
670 - record.setAmount(amount);  
671 - record.setSystemAmount(amount);// 有货收入  
672 - record.setTradeStatus(0);//0:订单未完结;1:订单完结  
673 - record.setCreateTime((int) (System.currentTimeMillis() / 1000));  
674 - tradeBillsMapper.insert(record); 660 + JSONObject metavalue = JSON.parseObject(meta.getMetaValue());
  661 + BigDecimal rate = metavalue.getJSONObject("serviceFeeRate").getBigDecimal("payChannelRate");
  662 + amount = amount.multiply(BigDecimal.ONE.subtract(rate)).multiply(new BigDecimal("-1")).setScale(2, BigDecimal.ROUND_HALF_UP);
675 } catch (Exception e) { 663 } catch (Exception e) {
676 - logger.error("记录交易到数据库出错 err={}, rec = {}", e.getMessage(), record); 664 + logger.error("PayRecordErr计费信息不完整, uid is {}, skup is {}, err is {}", uid, skup, e.getMessage());
  665 + return;
677 } 666 }
  667 + record.setAmount(amount);
  668 + record.setSystemAmount(amount);// 有货收入
  669 + record.setTradeStatus(tradeStatus);//0:订单未完结;1:订单完结
  670 + record.setCreateTime((int) (System.currentTimeMillis() / 1000));
  671 + addTradeBills(record);
678 } 672 }
679 673
680 private BigDecimal calcTransferAmount(Integer sellerUid, Integer skup, int transferType) { 674 private BigDecimal calcTransferAmount(Integer sellerUid, Integer skup, int transferType) {
@@ -93,6 +93,15 @@ @@ -93,6 +93,15 @@
93 93
94 94
95 <dependency> 95 <dependency>
  96 + <groupId>com.yoho.core</groupId>
  97 + <artifactId>yoho-core-rest-client-simple</artifactId>
  98 + </dependency>
  99 + <dependency>
  100 + <groupId>com.yoho.core</groupId>
  101 + <artifactId>yoho-core-rest-server</artifactId>
  102 + </dependency>
  103 +
  104 + <dependency>
96 <groupId>com.yohoufo.fore</groupId> 105 <groupId>com.yohoufo.fore</groupId>
97 <artifactId>yohoufo-fore-inboxclient</artifactId> 106 <artifactId>yohoufo-fore-inboxclient</artifactId>
98 </dependency> 107 </dependency>