AgentOrder.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace addons\YunfastPay\common\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%addons_yunfast_pay_agent_order}}".
  6. *
  7. * @property int $id
  8. * @property int $mall_id mall_id
  9. * @property int $user_id 会员ID
  10. * @property int $type 1 提现订单 2 门店打款订单
  11. * @property int $withdraw_id 提现ID
  12. * @property string $order_no 订单号
  13. * @property float $trans_amount 交易金额
  14. * @property string $acct_number 收款卡号
  15. * @property string $acct_name 收款户名
  16. * @property int $acct_type 账户类型 1:对私 2:对公
  17. * @property string|null $req_data 请求参数
  18. * @property string|null $res_data 返回参数
  19. * @property string $status 100-支付成功(支付订单)或退款成功(退款订单) 101-待支付 102-支付失败(支付订单)或退款失败(退款订单) 103-订单处理中 104-已撤销
  20. * @property int $created_at 创建时间
  21. * @property int $updated_at 修改时间
  22. */
  23. class AgentOrder extends ActiveRecord
  24. {
  25. protected static $json_fields = [
  26. 'req_data', 'res_data'
  27. ];
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%addons_yunfast_pay_agent_order}}';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['mall_id', 'user_id', 'type', 'withdraw_id', 'acct_type', 'created_at', 'updated_at'], 'integer'],
  42. [['order_no', 'trans_amount'], 'required'],
  43. [['trans_amount'], 'number'],
  44. [['req_data', 'res_data'], 'string'],
  45. [['order_no'], 'string', 'max' => 32],
  46. [['acct_number', 'acct_name'], 'string', 'max' => 64],
  47. [['status'], 'string', 'max' => 5],
  48. ];
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function attributeLabels()
  54. {
  55. return [
  56. 'id' => 'ID',
  57. 'mall_id' => 'Mall ID',
  58. 'user_id' => 'User ID',
  59. 'type' => 'Type',
  60. 'withdraw_id' => 'Withdraw ID',
  61. 'order_no' => 'Order No',
  62. 'trans_amount' => 'Trans Amount',
  63. 'acct_number' => 'Acct Number',
  64. 'acct_name' => 'Acct Name',
  65. 'acct_type' => 'Acct Type',
  66. 'req_data' => 'Req Data',
  67. 'res_data' => 'Res Data',
  68. 'status' => 'Status',
  69. 'created_at' => 'Created At',
  70. 'updated_at' => 'Updated At',
  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', 'mall_id' => 'mall_id']);
  79. }
  80. /**
  81. * @return ActiveQueryInterface the relational query object.
  82. */
  83. public function getWithdrawLog()
  84. {
  85. return $this->hasOne(WithdrawLog::class, ['id' => 'withdraw_id']);
  86. }
  87. /**
  88. * @return ActiveQueryInterface the relational query object.
  89. */
  90. public function getSplitbillLog()
  91. {
  92. return $this->hasOne(SplitbillItem::class, ['id' => 'withdraw_id']);
  93. }
  94. /**
  95. * @return ActiveQueryInterface the relational query object.
  96. */
  97. public function getStore()
  98. {
  99. return $this->hasOne(Store::class, ['id' => 'user_id', 'mall_id' => 'mall_id']);
  100. }
  101. /**
  102. * @param integer $mall_id
  103. * @param string $order_no
  104. * @return static
  105. */
  106. public static function getOrderByNo(int $mall_id, string $order_no)
  107. {
  108. return static::find()
  109. ->where(['mall_id' => $mall_id, 'order_no' => $order_no])
  110. ->one();
  111. }
  112. /**
  113. * 修改状态为已审核
  114. *
  115. * @return void
  116. */
  117. public function agree(WithdrawLog $log, string $msg = '', $status = '102', array $notify_data = [])
  118. {
  119. $t = \Yii::$app->db->beginTransaction();
  120. try {
  121. $this->status = $status;
  122. $this->notify_data = json_encode($notify_data);
  123. $this->save();
  124. WithdrawLog::remit_fail($log, $msg);
  125. $t->commit();
  126. return true;
  127. } catch (\Exception $e) {
  128. $t->rollBack();
  129. return false;
  130. }
  131. }
  132. /**
  133. * 门店
  134. *
  135. * @param string $status
  136. * @return void
  137. */
  138. public function failByStore($status = '102', array $notify_data = [])
  139. {
  140. $this->status = $status;
  141. $this->notify_data = json_encode($notify_data);
  142. return $this->save();
  143. }
  144. /**
  145. * @param string $status
  146. * @return void
  147. */
  148. public function success(WithdrawLog $log, $status = '100', array $notify_data = [])
  149. {
  150. $t = \Yii::$app->db->beginTransaction();
  151. try {
  152. $this->status = $status;
  153. $this->notify_data = json_encode($notify_data);
  154. $this->save();
  155. WithdrawLog::remit_success($log);
  156. $t->commit();
  157. return true;
  158. } catch (\Exception $e) {
  159. $t->rollBack();
  160. return false;
  161. }
  162. }
  163. /**
  164. * 门店
  165. *
  166. * @param string $status
  167. * @return void
  168. */
  169. public function successByStore($status = '100', array $notify_data = [])
  170. {
  171. $this->status = $status;
  172. $this->notify_data = json_encode($notify_data);
  173. return $this->save();
  174. }
  175. }