OrderRefundModel.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace addons\QiJuhe\common\models;
  3. use addons\QiJuhe\common\enums\OrderRefundEnum;
  4. use common\models\goods\Goods;
  5. use common\models\order\OrderDetail;
  6. use common\models\order\OrderRefund;
  7. use Yii;
  8. use yii\helpers\Json;
  9. /**
  10. * This is the model class for table "{{%addons_qijuhe_order_refund}}".
  11. *
  12. * @property int $id
  13. * @property int|null $mall_id
  14. * @property int|null $supply_id 中台ID
  15. * @property int|null $order_id 订单ID
  16. * @property int|null $num 售后数量
  17. * @property string|null $order_no 商城订单编号
  18. * @property int|null $order_refund_id 商城售后订单ID
  19. * @property int|null $after_sales_id 中台售后ID
  20. * @property string|null $data 售后数据
  21. * @property int|null $status 是否推送售后
  22. * @property int|null $refund_status
  23. * @property int|null $shipping_address_id 中台退货地址ID
  24. * @property string|null $error_msg 错误信息
  25. * @property string|null $return_data
  26. * @property int|null $created_at
  27. * @property int|null $updated_at
  28. */
  29. class OrderRefundModel extends \yii\db\ActiveRecord
  30. {
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public static function tableName()
  35. {
  36. return '{{%addons_qijuhe_order_refund}}';
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function rules()
  42. {
  43. return [
  44. [['mall_id', 'supply_id', 'order_id', 'num', 'order_refund_id', 'after_sales_id', 'status', 'refund_status', 'shipping_address_id', 'created_at', 'updated_at','order_detail_id'], 'integer'],
  45. [['data', 'return_data'], 'string'],
  46. [['order_no'], 'string', 'max' => 64],
  47. [['error_msg'], 'string', 'max' => 255],
  48. ];
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function attributeLabels()
  54. {
  55. return [
  56. 'id' => 'ID',
  57. 'mall_id' => 'Mall ID',
  58. 'supply_id' => 'Supply ID',
  59. 'order_id' => 'Order ID',
  60. 'num' => 'Num',
  61. 'order_no' => 'Order No',
  62. 'order_refund_id' => 'Order Refund ID',
  63. 'after_sales_id' => 'After sales ID',
  64. 'data' => 'Data',
  65. 'status' => 'Status',
  66. 'refund_status' => 'Refund Status',
  67. 'shipping_address_id' => 'Shipping Address ID',
  68. 'error_msg' => 'Error Msg',
  69. 'return_data' => 'Return Data',
  70. 'created_at' => 'Created At',
  71. 'updated_at' => 'Updated At',
  72. ];
  73. }
  74. /**
  75. * 获取商品详情
  76. *
  77. * @return ActiveQueryInterface
  78. */
  79. public function getGoods()
  80. {
  81. return $this->hasOne(Goods::class, ['spu_id' => 'spu_id']);
  82. }
  83. /**
  84. * 获取订单详情
  85. *
  86. * @return ActiveQueryInterface
  87. */
  88. public function getDetail()
  89. {
  90. return $this->hasOne(OrderDetail::class, ['order_id' => 'order_id']);
  91. }
  92. /**
  93. * 获取订单信息
  94. *
  95. * @return ActiveQueryInterface
  96. */
  97. public function getOrder()
  98. {
  99. return $this->hasOne(MallOrderModel::class, ['id' => 'order_id']);
  100. }
  101. public function getRefund()
  102. {
  103. return $this->hasOne(OrderRefund::class, ['id' => 'order_refund_id']);
  104. }
  105. /**
  106. * 添加售后订单
  107. *
  108. * @param integer $user_id
  109. * @param integer $mall_id
  110. * @param integer $order_id
  111. * @param integer $order_detail_id
  112. * @param integer $order_refund_id
  113. * @param array $data
  114. * @return OrderRefundModel
  115. */
  116. public static function add($data)
  117. {
  118. $model = new self();
  119. $data['data'] = Json::encode($data['data']);
  120. if (!$model->load($data, '') || !$model->save()) throw new \Exception(current($model->errors)[0]);
  121. return $model;
  122. }
  123. /**
  124. * 推送成功
  125. *
  126. * @param array $data
  127. * @return void
  128. */
  129. public function pushOk($data)
  130. {
  131. $this->status = OrderRefundEnum::PUSHED;
  132. // $this->chain_refund_sn = $data['returnSn'];
  133. $this->return_data = Json::encode($data);
  134. $this->updated_at = time();
  135. $this->save();
  136. }
  137. /**
  138. * 审核中
  139. *
  140. * @return void
  141. */
  142. public function review()
  143. {
  144. $this->refund_status = 1;
  145. $this->save();
  146. }
  147. }