SplitBillTrans.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace addons\YunfastPay\common\services\trans\nocash;
  3. use addons\YunfastPay\common\services\trans\TransAbstract;
  4. /**
  5. * 分账trans
  6. * SplitBillTrans class
  7. * @package addons\YunfastPay\common\services\trans\nocash
  8. * @see https://yunfastpay.com/#/interface/fz
  9. */
  10. class SplitBillTrans extends TransAbstract
  11. {
  12. /**
  13. * @var string
  14. */
  15. protected $orgCd;
  16. /**
  17. * @var string
  18. */
  19. protected $outOrderId;
  20. /**
  21. * @var string
  22. */
  23. protected $oglOrdId;
  24. /**
  25. * 回调
  26. *
  27. * @var boolean
  28. */
  29. protected $hasNotify = false;
  30. /**
  31. * 实例化
  32. *
  33. * @param string $orgCd 组织机构代码
  34. * @param string $outOrderId 外部订单号
  35. * @param string $oglOrdId 原交易订单号
  36. */
  37. public function __construct(
  38. string $orgCd,
  39. string $outOrderId,
  40. string $oglOrdId
  41. )
  42. {
  43. $this->orgCd = $orgCd;
  44. $this->outOrderId = $outOrderId;
  45. $this->oglOrdId = $oglOrdId;
  46. }
  47. /**
  48. * 交易码,扫码支付固定:TRANS0105
  49. *
  50. * @return string
  51. */
  52. public function getTrscode() :string
  53. {
  54. return 'TRANS1133';
  55. }
  56. /**
  57. * 聚合:tran
  58. *
  59. * @return string
  60. */
  61. public function getProCd() :string
  62. {
  63. return 'tran';
  64. }
  65. /**
  66. * 费率通道
  67. *
  68. * @return integer
  69. */
  70. public function getChanelType() :int
  71. {
  72. return 1;
  73. }
  74. /**
  75. * @param string $mchtCd
  76. * @return array
  77. */
  78. public function getTransData(string $mchtCd) :array
  79. {
  80. return [
  81. 'trscode' => $this->getTrscode(),
  82. 'orgCd' => $this->orgCd,
  83. 'mchtCd' => $mchtCd,
  84. 'outOrderId' => $this->outOrderId,
  85. 'oglOrdId' => $this->oglOrdId,
  86. 'proCd' => $this->getProCd(),
  87. 'chanelType' => $this->getChanelType(),
  88. 'transAmt' => $this->getTotalAmount(),
  89. 'isSplitBill' => $this->getIsSplitBill(),
  90. 'itemsList' => $this->getSplitBill(),
  91. ];
  92. }
  93. /**
  94. * 获取分账总金额
  95. *
  96. * @return float
  97. */
  98. protected function getTotalAmount()
  99. {
  100. // func2
  101. $list = array_column(
  102. $this->getSplitBill(), 'item10'
  103. );
  104. $total = 0;
  105. foreach ($list as $item) {
  106. $total = bcadd($total, $item, 2);
  107. }
  108. return $total;
  109. // func1
  110. return array_sum(
  111. array_column(
  112. $this->getSplitBill(), 'item10'
  113. )
  114. );
  115. }
  116. }