| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace addons\QiJuhe\common\models;
- use addons\QiJuhe\common\enums\OrderRefundEnum;
- use common\models\goods\Goods;
- use common\models\order\OrderDetail;
- use common\models\order\OrderRefund;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%addons_qijuhe_order_refund}}".
- *
- * @property int $id
- * @property int|null $mall_id
- * @property int|null $supply_id 中台ID
- * @property int|null $order_id 订单ID
- * @property int|null $num 售后数量
- * @property string|null $order_no 商城订单编号
- * @property int|null $order_refund_id 商城售后订单ID
- * @property int|null $after_sales_id 中台售后ID
- * @property string|null $data 售后数据
- * @property int|null $status 是否推送售后
- * @property int|null $refund_status
- * @property int|null $shipping_address_id 中台退货地址ID
- * @property string|null $error_msg 错误信息
- * @property string|null $return_data
- * @property int|null $created_at
- * @property int|null $updated_at
- */
- class OrderRefundModel extends \yii\db\ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_qijuhe_order_refund}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['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'],
- [['data', 'return_data'], 'string'],
- [['order_no'], 'string', 'max' => 64],
- [['error_msg'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'supply_id' => 'Supply ID',
- 'order_id' => 'Order ID',
- 'num' => 'Num',
- 'order_no' => 'Order No',
- 'order_refund_id' => 'Order Refund ID',
- 'after_sales_id' => 'After sales ID',
- 'data' => 'Data',
- 'status' => 'Status',
- 'refund_status' => 'Refund Status',
- 'shipping_address_id' => 'Shipping Address ID',
- 'error_msg' => 'Error Msg',
- 'return_data' => 'Return Data',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 获取商品详情
- *
- * @return ActiveQueryInterface
- */
- public function getGoods()
- {
- return $this->hasOne(Goods::class, ['spu_id' => 'spu_id']);
- }
- /**
- * 获取订单详情
- *
- * @return ActiveQueryInterface
- */
- public function getDetail()
- {
- return $this->hasOne(OrderDetail::class, ['order_id' => 'order_id']);
- }
-
- /**
- * 获取订单信息
- *
- * @return ActiveQueryInterface
- */
- public function getOrder()
- {
- return $this->hasOne(MallOrderModel::class, ['id' => 'order_id']);
- }
- public function getRefund()
- {
- return $this->hasOne(OrderRefund::class, ['id' => 'order_refund_id']);
- }
- /**
- * 添加售后订单
- *
- * @param integer $user_id
- * @param integer $mall_id
- * @param integer $order_id
- * @param integer $order_detail_id
- * @param integer $order_refund_id
- * @param array $data
- * @return OrderRefundModel
- */
- public static function add($data)
- {
- $model = new self();
- $data['data'] = Json::encode($data['data']);
- if (!$model->load($data, '') || !$model->save()) throw new \Exception(current($model->errors)[0]);
- return $model;
- }
-
- /**
- * 推送成功
- *
- * @param array $data
- * @return void
- */
- public function pushOk($data)
- {
- $this->status = OrderRefundEnum::PUSHED;
- // $this->chain_refund_sn = $data['returnSn'];
- $this->return_data = Json::encode($data);
- $this->updated_at = time();
- $this->save();
- }
- /**
- * 审核中
- *
- * @return void
- */
- public function review()
- {
- $this->refund_status = 1;
- $this->save();
- }
- }
|