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(); } }