| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
- <?php
- namespace addons\StarChain\common\models;
- use addons\JuheShop\common\models\MallOrderRefundModel;
- use addons\StarChain\common\enums\OrderRefundEnum;
- use common\enums\RefundStatusEnum;
- use common\logic\order\OrderRefundLogic;
- use common\models\order\OrderDetail;
- use common\models\order\OrderRefund as OrderOrderRefund;
- use Exception;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%addons_star_chain_order_refund}}".
- *
- * @property int $id
- * @property int|null $mall_id
- * @property int|null $user_id 用户ID
- * @property int|null $order_id 订单ID
- * @property string|null $spu_id 供应链商品ID
- * @property string|null $sku_id 供应链skuID
- * @property int|null $num 申请数量
- * @property int|null $order_refund_id 售后ID
- * @property string|null $chain_refund_sn 供应链端售后订单编号
- * @property string|null $data 推送数据
- * @property int|null $status 状态
- * @property int|null $refund_status 供应链售后状态
- * @property string|null $error_msg
- * @property string|null $return_data 返回数据
- * @property int|null $created_at
- * @property int|null $updated_at
- */
- class OrderRefund extends BaseModel
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_star_chain_order_refund}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'order_id', 'num', 'order_refund_id', 'status', 'refund_status', 'created_at', 'updated_at'], 'integer'],
- [['data', 'error_msg', 'return_data'], 'string'],
- [['spu_id', 'sku_id', 'chain_refund_sn'], 'string', 'max' => 64],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'order_id' => 'Order ID',
- 'spu_id' => 'Spu ID',
- 'sku_id' => 'Sku ID',
- 'num' => 'Num',
- 'order_refund_id' => 'Order Refund ID',
- 'chain_refund_sn' => 'Chain Refund Sn',
- 'data' => 'Data',
- 'status' => 'Status',
- 'refund_status' => 'Refund Status',
- '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(MallOrder::class, ['id' => 'order_id']);
- }
- public function getRefund()
- {
- return $this->hasOne(OrderOrderRefund::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 OrderRefund
- */
- public static function add($data)
- {
- $model = new self();
- $data['data'] = Json::encode($data['data']);
- $model->load($data, '');
-
- return $model->save() ? $model : false;
- }
-
- /**
- * 推送成功
- *
- * @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();
- }
-
- /**
- * 卖家拒绝退款
- *
- * @return void
- */
- public function refuseMoney()
- {
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_NEGATIVE_1
- ])) {
- $this->refund_status = 2;
- $this->save();
- return true;
- }
- throw new Exception('卖家拒绝退款');
- }
-
- /**
- * 退款成功
- *
- * @return void
- */
- public function success()
- {
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_6
- ])) {
- $this->refund_status = 3;
- $this->save();
- return true;
- }
-
- throw new Exception('退款成功');
- }
-
- /**
- * 卖家拒绝退货退款
- *
- * @return void
- */
- public function refuseMoneyAndProduct()
- {
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_NEGATIVE_1
- ])) {
- $this->refund_status = 4;
- $this->save();
- return true;
- }
- throw new Exception('卖家拒绝退货退款');
- }
-
- /**
- * 待买家退货
- *
- * @param array $refund_detail
- * @return void
- */
- public function waitBuyerSend($refund_detail)
- {
- // 退货地址
- $address = [
- 'consignee' => $refund_detail['userName'],
- 'mobile' => $refund_detail['userPhone'],
- 'address' => $refund_detail['userAddress']
- ];
- $logic = new OrderRefundLogic();
- if ($res = $logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'address' => $address,
- 'step_status' => RefundStatusEnum::STEP_2
- ])) {
- $this->refund_status = 5;
- $this->save();
- return true;
- }
- throw new Exception('卖家拒绝退货退款');
- }
-
- /**
- * 买家已退货,待卖家收货
- *
- * @return void
- */
- public function waitSellerReceive()
- {
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_3
- ])) {
- $this->refund_status = 6;
- $this->save();
- return true;
- }
- throw new Exception('卖家拒绝退货退款');
- }
-
- /**
- * 买家已退货,卖家拒绝收货
- *
- * @return void
- */
- public function sellerRefuseReceive()
- {
- $this->refund_status = 7;
- $this->save();
- }
-
- /**
- * 卖家已收货,待确认退款
- *
- * @return void
- */
- public function sellerReceiveOfWait()
- {
- $this->refund_status = 8;
- $this->save();
- }
-
- /**
- * 退货退款成功
- *
- * @return void
- */
- public function successMoneyAndProduct()
- {
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_4
- ])) {
- $this->refund_status = 9;
- $this->save();
- return true;
- }
- throw new Exception('退货退款成功');
- }
-
- /**
- * 卖家拒绝换货
- *
- * @return void
- */
- public function refuseExchange()
- {
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_NEGATIVE_1, // 拒绝售后
- ])) {
- $this->refund_status = 10;
- $this->save();
- return true;
- }
- throw new Exception('卖家拒绝退货退款');
- }
-
- /**
- * 买家已退货,待卖家换货
- *
- * @return void
- */
- public function waitSellerSend()
- {
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_7
- ])) {
- $this->refund_status = 11;
- $this->save();
- return true;
- }
-
- throw new Exception('买家已退货,待卖家换货');
- }
-
- /**
- * 卖家已换货,待买家收货
- *
- * @return void
- */
- public function waitBuyerReceive($refund_detail)
- {
- $express = [
- 'saler_express' => $refund_detail['sendDeliveryName'],
- 'saler_express_no' => $refund_detail['sendDeliverySn'],
- 'customer_name' => $refund_detail['receiveName'],
- ];
-
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_10,
- 'express' => $express,
- ])) {
- $this->refund_status = 12;
- $this->save();
- return true;
- }
- throw new Exception('卖家已换货,待买家收货');
- }
-
- /**
- * 换货成功
- *
- * @return void
- */
- public function successExchange()
- {
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_11
- ])) {
- $this->refund_status = 13;
- $this->save();
- return true;
- }
- throw new Exception('换货成功');
- }
-
- /**
- * 已关闭
- *
- * @return void
- */
- public function close()
- {
- $this->refund_status = 14;
- $this->save();
- }
-
- /**
- * 卖家同意退款
- *
- * @return void
- */
- public function adoptMoney()
- {
- $this->refund_status = 15;
- $this->save();
- }
-
- /**
- * 卖家同意仅退款
- *
- * @return void
- */
- public function adoptOnlyMoney()
- {
- $this->refund_status = 16;
- $this->save();
- }
-
- /**
- * 卖家拒绝仅退款
- *
- * @return void
- */
- public function refuseOnlyMoney()
- {
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_NEGATIVE_1
- ])) {
- $this->refund_status = 17;
- $this->save();
- return true;
- }
- throw new Exception('换货成功');
- }
-
- /**
- * 仅退款成功
- *
- * @return void
- */
- public function successOnlyMoney()
- {
- $logic = new OrderRefundLogic();
- if ($logic->execute($this->mall_id, [
- 'id' => $this->order_refund_id,
- 'step_status' => RefundStatusEnum::STEP_6
- ])) {
- $this->refund_status = 18;
- $this->save();
- return true;
- }
-
- throw new Exception('仅退款成功');
- }
- /**
- * 获取售后订单
- *
- * @param integer $mall_id
- * @param string $return_sn
- * @return static|null
- */
- public static function getOrderByReturnSn(int $mall_id, string $return_sn)
- {
- return static::find()->where(
- ['mall_id' => $mall_id, 'chain_refund_sn' => $return_sn]
- )->one();
- }
- }
|