From 6f6c8943ada582ff998cbcd02f3565c4ca994be8 Mon Sep 17 00:00:00 2001 From: wanghousheng Date: Wed, 31 Jan 2024 02:11:55 +0800 Subject: [PATCH] 1 --- app/api/controller/Recovery.php | 24 ++++++++++++++++++++++++ app/api/model/RecoveryOrder.php | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/app/api/controller/Recovery.php b/app/api/controller/Recovery.php index aead3fe2..08897916 100644 --- a/app/api/controller/Recovery.php +++ b/app/api/controller/Recovery.php @@ -68,6 +68,10 @@ class Recovery extends Controller $model = new RecoveryOrder(); $info = $model->getDetails($recoveryId); if ($info && !empty($info['images'])) { + $info['is_cancel'] = 0; + if ($info['order_status'] == RecoveryStatusEnum::ACCEPTED) { + $info['is_cancel'] = 1; + } $images_list = helper::getArrayColumn($info['images'], 'file'); $arr = []; foreach ($images_list as $image) { @@ -79,6 +83,26 @@ class Recovery extends Controller return $this->renderSuccess(['detail' => $info]); } + /** + * @notes:取消订单 + * @return Json + * @throws BaseException + * @author: wanghousheng + */ + public function cancel(): Json + { + $recoveryId = intval($this->request->post('recovery_id')); + if (!$recoveryId) { + return $this->renderError('缺少必要参数'); + } + $model = new RecoveryOrder(); + if ($model->cancel($recoveryId)) { + return $this->renderSuccess('操作成功'); + } + return $this->renderError('操作失败'); + + } + /** * @notes:新增记录 * @return Json diff --git a/app/api/model/RecoveryOrder.php b/app/api/model/RecoveryOrder.php index fc818034..83f6714d 100644 --- a/app/api/model/RecoveryOrder.php +++ b/app/api/model/RecoveryOrder.php @@ -3,6 +3,7 @@ namespace app\api\model; use app\api\service\User as UserService; +use app\common\enum\RecoveryStatusEnum; use app\common\model\RecoveryOrder as BaseRecoveryOrder; use app\common\service\Order as OrderService; use cores\exception\BaseException; @@ -100,4 +101,27 @@ class RecoveryOrder extends BaseRecoveryOrder } return false; } + + /** + * @notes:取消 + * @param int $recoveryId + * @return bool + * @throws BaseException + * @author: wanghousheng + */ + public function cancel(int $recoveryId): bool + { + $where['recovery_id'] = $recoveryId; + // 当前用户ID + $userId = UserService::getCurrentLoginUserId(); + if (!UserService::isStore()) { + $where['user_id'] = $userId; + } + $info = static::detail($where); + if (!$info->isEmpty() && $info['order_status'] == RecoveryStatusEnum::ACCEPTED) { + $this->where(['recovery_id' => $recoveryId])->save(['order_status' => RecoveryStatusEnum::CANCEL]); + return true; + } + return false; + } } \ No newline at end of file