PaymentTypeHelper.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace common\helpers;
  3. use common\enums\PayTypeEnum;
  4. use common\models\common\PaymentTradeGroupOrder;
  5. use common\models\common\PaymentTradeOrder;
  6. class PaymentTypeHelper
  7. {
  8. /**
  9. * 获取订单支付方式
  10. * @param string $order_no
  11. * @param int $payment_type
  12. * @return array
  13. */
  14. public static function getPaymentTypes(string $order_no, int $payment_type)
  15. {
  16. $pay_types = PayTypeEnum::getMap();
  17. $payment_types = [];
  18. if ($payment_type == PayTypeEnum::MIXED) {
  19. /**
  20. * @var $each PaymentTradeGroupOrder
  21. */
  22. foreach (PaymentTradeGroupOrder::find()->where(['order_no' => $order_no])->each() as $each) {
  23. $payment_types[] = [
  24. 'title' => $pay_types[$each->pay_type] ?? '未知支付',
  25. 'pay_money' => bcmul($each->pay_fee, 1, 2)
  26. ];
  27. }
  28. } else {
  29. $payment_types[] = [
  30. 'title' => $pay_types[$payment_type] ?? '未知支付',
  31. 'pay_money' => bcmul((float) PaymentTradeOrder::find()->where(['order_no' => $order_no])
  32. ->select('pay_fee')->scalar(), 1, 2)
  33. ];
  34. }
  35. return $payment_types;
  36. }
  37. }