YS:换货流程

es
yangsai@163.com 7 months ago
parent 7e90bd19a7
commit 93551f4dfc
  1. 11
      app/api/controller/Refund.php
  2. 38
      app/store/model/OrderRefund.php

@ -12,6 +12,7 @@ declare (strict_types=1);
namespace app\api\controller;
use app\common\enum\order\refund\RefundType as RefundTypeEnum;
use think\response\Json;
use app\api\model\OrderRefund as OrderRefundModel;
@ -91,8 +92,14 @@ class Refund extends Controller
{
// 售后单详情
$model = OrderRefundModel::getDetail($orderRefundId, false);
if ($model->delivery($this->postForm())) {
return $this->renderSuccess([], '操作成功');
if($model['type']==RefundTypeEnum::EXCHANGE){
if ($model->huanhuo($this->postForm())) {
return $this->renderSuccess([], '操作成功');
}
}else{
if ($model->delivery($this->postForm())) {
return $this->renderSuccess([], '操作成功');
}
}
return $this->renderError($model->getError() ?: '提交失败');
}

@ -13,7 +13,9 @@ declare (strict_types=1);
namespace app\store\model;
use app\api\service\User as UserService;
use app\common\enum\order\DeliveryStatus as DeliveryStatusEnum;
use app\common\enum\order\DeliveryType;
use app\common\enum\order\OrderStatus as OrderStatusEnum;
use app\common\enum\order\refund\AuditStatus as AuditStatusEnum;
use app\common\enum\order\refund\RefundStatus as RefundStatusEnum;
use app\common\enum\order\refund\RefundType as RefundTypeEnum;
@ -22,6 +24,7 @@ use app\common\model\OrderRefund as OrderRefundModel;
use app\common\service\Message as MessageService;
use app\common\service\order\Refund as RefundService;
use app\store\model\User as UserModel;
use app\store\model\Order as OrderModel;
/**
* 售后单模型
@ -199,7 +202,7 @@ class OrderRefund extends OrderRefundModel
// 拒绝申请, 标记售后单状态为已拒绝
$data['audit_status'] == AuditStatusEnum::REJECTED && $data['status'] = RefundStatusEnum::REJECTED;
// 同意换货申请, 标记售后单状态为已完成
$data['audit_status'] == AuditStatusEnum::REVIEWED && $this['type'] == RefundTypeEnum::EXCHANGE && $data['status'] = RefundStatusEnum::COMPLETED;
// $data['audit_status'] == AuditStatusEnum::REVIEWED && $this['type'] == RefundTypeEnum::EXCHANGE && $data['status'] = RefundStatusEnum::COMPLETED;
// 更新售后单状态
$this->save($data);
// 同意售后申请, 记录退货地址
@ -291,7 +294,40 @@ class OrderRefund extends OrderRefundModel
});
return true;
}
/**
* 确认收货并更改换货状态
* @param array $data
* @return bool
*/
public function huanhuo(array $data): bool
{
// 订单详情
$order = Order::detail($this['order_id']);
$data['refund_money'] = empty($data['refund_money'])?0:$data['refund_money'];
// 事务处理
$this->transaction(function () use ($order, $data) {
// 更新售后单状态
$this->save([
'refund_money' => $data['refund_money'],
'is_receipt' => 1,
'status' => RefundStatusEnum::COMPLETED
]);
// 条件:判断订单是否已结算
if ($order['is_settled']) {
(new UserModel)->setDecUserExpend($order['user_id'], $data['refund_money']);
}
// 更新主订单状态为未发货
(new OrderModel)->save(['order_status'=>OrderStatusEnum::NORMAL,'delivery_status'=>DeliveryStatusEnum::NOT_DELIVERED,'order_id'=>$order['order_id']]);
// 发送消息通知
MessageService::send('order.refund', [
'refund' => $this, // 售后单信息
'order_no' => $order['order_no'], // 订单信息
], $this['store_id']);
});
return true;
}
/**
* 获取待处理售后单数量
* @return int

Loading…
Cancel
Save