RefundOrder.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace addons\YunfastPay\common\models;
  3. use addons\YunfastPay\common\enums\YunfastPayEnum;
  4. use common\models\order\OrderRefund;
  5. use Yii;
  6. /**
  7. * This is the model class for table "{{%addons_yunfast_pay_refund_order}}".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $user_id 会员ID
  12. * @property int $refund_id 退款订单ID
  13. * @property int $order_id 订单ID
  14. * @property string $order_no 退款订单号
  15. * @property float $refund_amount 退款金额
  16. * @property string|null $req_data 请求参数
  17. * @property string|null $res_data 返回参数
  18. * @property string|null $refund_params 退款参数
  19. * @property string $status 退款状态
  20. * @property int $updated_at
  21. * @property int $created_at
  22. * @property string $refund_source 退款订单来源
  23. */
  24. class RefundOrder extends ActiveRecord
  25. {
  26. protected static $json_fields = [
  27. 'req_data', 'res_data', 'refund_params'
  28. ];
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public static function tableName()
  33. {
  34. return '{{%addons_yunfast_pay_refund_order}}';
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function rules()
  40. {
  41. return [
  42. [['mall_id', 'user_id', 'refund_id', 'order_id', 'order_no'], 'required'],
  43. [['mall_id', 'user_id', 'refund_id', 'order_id', 'updated_at', 'created_at'], 'integer'],
  44. [['refund_amount'], 'number'],
  45. [['req_data', 'res_data', 'refund_params'], 'string'],
  46. [['order_no'], 'string', 'max' => 32],
  47. [['refund_source'], 'string', 'max' => 50],
  48. [['status'], 'string', 'max' => 10],
  49. ];
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function attributeLabels()
  55. {
  56. return [
  57. 'id' => 'ID',
  58. 'mall_id' => 'Mall ID',
  59. 'user_id' => 'User ID',
  60. 'refund_id' => 'Refund ID',
  61. 'order_id' => 'Order ID',
  62. 'order_no' => 'Order No',
  63. 'refund_amount' => 'Refund Amount',
  64. 'req_data' => 'Req Data',
  65. 'res_data' => 'Res Data',
  66. 'refund_params' => 'Refund Params',
  67. 'status' => 'Status',
  68. 'updated_at' => 'Updated At',
  69. 'created_at' => 'Created At',
  70. 'refund_source' => 'Refund Source',
  71. ];
  72. }
  73. /**
  74. * @return ActiveQueryInterface the relational query object.
  75. */
  76. public function getUser()
  77. {
  78. return $this->hasOne(User::class, ['id' => 'user_id']);
  79. }
  80. /**
  81. * @return ActiveQueryInterface the relational query object.
  82. */
  83. public function getRefund()
  84. {
  85. return $this->hasOne(OrderRefund::class, ['id' => 'refund_id']);
  86. }
  87. /**
  88. * 通过退款订单ID获取插件退款订单
  89. *
  90. * @param integer $refund_id
  91. * @param string $refund_source
  92. * @return static|null
  93. */
  94. public static function getOrderByRefundId(int $refund_id, string $refund_source = YunfastPayEnum::MALL_ORDER)
  95. {
  96. return static::find()
  97. ->where(['refund_id' => $refund_id, 'refund_source' => $refund_source])
  98. ->one();
  99. }
  100. /**
  101. * @return boolean
  102. */
  103. public function isRefundOk()
  104. {
  105. return $this->status == '100' ? true : false;
  106. }
  107. /**
  108. * 修改状态
  109. *
  110. * @param string $status
  111. * @return boolean
  112. */
  113. public function changeStatus(string $status)
  114. {
  115. $this->status = $status;
  116. return $this->save();
  117. }
  118. /**
  119. * 通过订单号获取订单
  120. *
  121. * @param integer $mall_id
  122. * @param string $order_no
  123. * @return static|null
  124. */
  125. public static function getOrderByNo(int $mall_id, string $order_no)
  126. {
  127. return static::find()
  128. ->where(['order_no' => $order_no])
  129. ->one();
  130. }
  131. }