Order.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace addons\Alitopay\common\models;
  3. use common\models\base\BaseActiveRecord;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_atp_order}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property string|null $batch_sn 批次号
  11. * @property string|null $order_sn 订单号
  12. * @property string|null $account 收款人
  13. * @property string|null $name 姓名
  14. * @property int $type 1提现打款2手动转账
  15. * @property float $money 打款金额
  16. * @property int $status 1待打款2打款中3打款成功4打款失败5打款超时
  17. * @property int $is_delete 是否删除
  18. * @property int $created_at 创建时间
  19. * @property int $updated_at 更新时间
  20. * @property int $source_id 来源ID
  21. * @property string $source_sn 来源单号
  22. * @property string $form_html
  23. * @property string $msg
  24. * @property string $order_id
  25. * @property string $file_id
  26. * @property string $download_url
  27. */
  28. class Order extends BaseActiveRecord
  29. {
  30. const TYPE_WITHDRAWAL = 1;
  31. const TYPE_MANUAL = 2;
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public static function tableName()
  36. {
  37. return '{{%addons_atp_order}}';
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function rules()
  43. {
  44. return [
  45. [['type', 'status','mall_id', 'is_delete', 'created_at', 'updated_at', 'source_id'], 'integer'],
  46. [['money'], 'number'],
  47. [['batch_sn', 'order_sn'], 'string', 'max' => 64],
  48. [['source_sn','name','account'], 'string', 'max' => 32],
  49. [['order_id'], 'string', 'max' => 255],
  50. [['file_id'], 'string', 'max' => 200],
  51. [['download_url'], 'string', 'max' => 1000],
  52. [['form_html','msg'],"safe"]
  53. ];
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function attributeLabels()
  59. {
  60. return [
  61. 'id' => 'ID',
  62. 'mall_id' => 'ID',
  63. 'batch_sn' => '批次号',
  64. 'order_sn' => '订单号',
  65. 'type' => '1提现打款2手动转账',
  66. 'money' => '打款金额',
  67. 'status' => '1待打款2打款中3打款成功4打款失败5打款超时',
  68. 'is_delete' => '是否删除',
  69. 'created_at' => '创建时间',
  70. 'updated_at' => '更新时间',
  71. 'source_id' => '来源ID',
  72. 'source_sn' => '来源单号',
  73. 'msg' => '来源单号',
  74. 'order_id' => '支付宝转账单据号',
  75. 'file_id' => '文件申请号file_id信息',
  76. 'download_url' => '电子回单下载url',
  77. ];
  78. }
  79. /**
  80. * 批量插入
  81. *
  82. * @param array $insert_data
  83. * @return int
  84. */
  85. public static function batchInsert(array $insert_data)
  86. {
  87. return \Yii::$app->db
  88. ->createCommand()
  89. ->batchInsert(static::tableName(), array_keys($insert_data[0]), $insert_data)
  90. ->execute();
  91. }
  92. /**
  93. * 打款成功
  94. *
  95. * @param integer $source_id
  96. * @param string $order_sn
  97. * @return void
  98. */
  99. public static function paySuccessBySourceIdAndOrderSn(
  100. int $source_id,
  101. string $order_sn,
  102. string $order_id,
  103. string $msg = '成功'
  104. )
  105. {
  106. static::updateAll(
  107. ['status' => 3, 'updated_at' => time(), 'msg' => $msg,'order_id'=>$order_id],
  108. ['source_id' => $source_id, 'order_sn' => $order_sn]
  109. );
  110. // 打款成功
  111. $cash = WithdrawLog::getLogById($source_id);
  112. WithdrawLog::remit_success($cash);
  113. }
  114. /**
  115. * 打款失败
  116. *
  117. * @param integer $source_id
  118. * @param string $order_sn
  119. * @param string $msg
  120. * @return void
  121. */
  122. public static function payFialBySourceIdAndOrderSn(
  123. int $source_id,
  124. string $order_sn,
  125. string $msg = ''
  126. )
  127. {
  128. static::updateAll(
  129. ['status' => 4, 'updated_at' => time(), 'msg' => $msg],
  130. ['source_id' => $source_id, 'order_sn' => $order_sn]
  131. );
  132. // 打款失败
  133. $cash = WithdrawLog::getLogById($source_id);
  134. WithdrawLog::remit_fail($cash, $msg);
  135. }
  136. /**
  137. * 给这批提现订单设置一个批次号
  138. *
  139. * @param string $batch_no
  140. * @param array $order_sns
  141. * @return int
  142. */
  143. public static function setOutBatchNoByOrderSn(string $batch_no, array $order_sns)
  144. {
  145. return static::updateAll(
  146. ['batch_sn' => $batch_no],
  147. ['order_sn' => $order_sns]
  148. );
  149. }
  150. }