PaymentTradeOrder.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace addons\YunfastPay\common\models;
  3. use addons\YunfastPay\common\enums\YunfastPayEnum;
  4. use addons\YunfastPay\common\enums\YunfastPayTypeEnum;
  5. use common\models\common\PaymentTradeOrder as PaymentTradeOrderModel;
  6. use common\models\order\Order;
  7. /**
  8. * Mall PaymentTradeOrder
  9. * @package addons\YunfastPay\common\models
  10. */
  11. class PaymentTradeOrder extends PaymentTradeOrderModel
  12. {
  13. /**
  14. * 根据支付订单ID获取是否有门店相关信息
  15. *
  16. * @param integer $id
  17. * @return array
  18. */
  19. public static function getStoreInfoByTradeId(int $id)
  20. {
  21. return Order::find()
  22. ->where([
  23. 'pay_status' => 0,
  24. 'order_no' => PaymentTradeOrder::find()
  25. ->where(['trade_id' => $id])
  26. ->select('order_no')
  27. ->column(),
  28. ])
  29. ->select(['store_id', 'pay_money'])
  30. ->all();
  31. }
  32. /**
  33. * 通过收银台订单号查找支付订单
  34. *
  35. * @param string $order_no
  36. * @return int|null|false
  37. */
  38. public static function getPaymentIdByCashierOrderNo(string $order_no)
  39. {
  40. return static::getPaymentIdByOrderNo($order_no, YunfastPayEnum::CASHIER_ORDER);
  41. }
  42. /**
  43. * 通过商城订单号查找支付订单
  44. *
  45. * @param string $order_no
  46. * @param string $order_type
  47. * @return int|null|false
  48. */
  49. public static function getPaymentIdByMallOrderNo(string $order_no, string $order_type = YunfastPayEnum::MALL_ORDER)
  50. {
  51. return static::getPaymentIdByOrderNo($order_no, $order_type ?: YunfastPayEnum::MALL_ORDER);
  52. }
  53. /**
  54. * 通过订单号查找支付订单
  55. *
  56. * @param string $order_no
  57. * @return int|null|false
  58. */
  59. public static function getPaymentIdByOrderNo(string $order_no, string $order_type)
  60. {
  61. return static::find()
  62. ->where([
  63. 'order_no' => $order_no,
  64. 'is_pay' => 1,
  65. 'pay_type' => YunfastPayTypeEnum::YUNFAST_PAY_NUM,
  66. 'order_type' => $order_type,
  67. ])
  68. ->select('trade_id')
  69. ->scalar();
  70. }
  71. }