diff --git a/app/api/controller/Recovery.php b/app/api/controller/Recovery.php index fec56b97..16f861e9 100644 --- a/app/api/controller/Recovery.php +++ b/app/api/controller/Recovery.php @@ -4,15 +4,70 @@ declare (strict_types=1); namespace app\api\controller; use app\api\model\RecoveryOrder; +use app\api\model\Server\RecoveryCategory; +use app\api\model\Server\ServerRecovery; use app\common\enum\RecoveryStatusEnum; use app\common\enum\RecoveryTypeEnum; use app\common\library\helper; use cores\exception\BaseException; +use think\db\exception\DataNotFoundException; use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; use think\response\Json; class Recovery extends Controller { + + /** + * @notes:分类列表 + * @return Json + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function categoryList(): Json + { + $model = new RecoveryCategory(); + $list = $model->list(); + if (!empty($list)) { + foreach ($list as $key => $value) { + unset($list[$key]['image']); + } + } + return $this->renderSuccess(compact('list')); + } + + /** + * @notes:服务列表页 + * @throws DbException + * @author: wanghousheng + */ + public function recoveryList(): Json + { + $recovery_name = $this->request->post('recovery_name'); + $category_id = intval($this->request->post('category_id')); + $where = []; + if ($recovery_name) { + $where[] = ['recovery.recovery_name', 'like', "%$recovery_name%"]; + } + if ($category_id) { + $where[] = ['recovery.category_id', '=', $category_id]; + } + $where[] = ['recovery.status', '=', 1]; + $model = new ServerRecovery(); + $list = $model->getList($where); + $data['list'] = $list->items(); + $data['total'] = $list->total(); + if (!$list->isEmpty()) { + foreach ($data['list'] as $key => $value) { + unset($data['list'][$key]['image']); + unset($data['list'][$key]['category']); + } + } + return $this->renderSuccess($data); + } + /** * @notes:用户回收订单列表 * @return Json @@ -20,7 +75,7 @@ class Recovery extends Controller * @throws DbException * @author: wanghousheng */ - public function list(): Json + public function orderList(): Json { $where = []; $order_status = intval($this->request->post('order_status')); @@ -59,7 +114,7 @@ class Recovery extends Controller * @throws BaseException * @author: wanghousheng */ - public function detail(): Json + public function orderDetail(): Json { $orderId = intval($this->request->post('order_id')); if (!$orderId) { @@ -89,7 +144,7 @@ class Recovery extends Controller * @throws BaseException * @author: wanghousheng */ - public function cancel(): Json + public function cancelOrder(): Json { $orderId = intval($this->request->post('order_id')); if (!$orderId) { @@ -109,7 +164,7 @@ class Recovery extends Controller * @throws BaseException * @author: wanghousheng */ - public function add(): Json + public function addOrder(): Json { $imageIds = $this->request->post('image_ids'); if ($imageIds) { @@ -123,6 +178,10 @@ class Recovery extends Controller if (!$shop_id) { return $this->renderError('门店不能为空'); } + $recovery_id = intval($this->request->post('recovery_id')); + if (!$recovery_id) { + return $this->renderError('缺少必要参数'); + } $recovery_type_arr = array_values(RecoveryStatusEnum::data()); $recovery_type_arr = array_column($recovery_type_arr, 'value'); $recovery_type = intval($this->request->post('recovery_type')); @@ -171,6 +230,7 @@ class Recovery extends Controller $express_id = intval($this->request->post('express_id')); $express_no = $this->request->post('express_no'); $data = [ + 'recovery_id' => $recovery_id, 'express_id' => $express_id, 'express_no' => $express_no, 'shipping_address' => $shipping_address, @@ -198,7 +258,7 @@ class Recovery extends Controller * @return Json * @author: wanghousheng */ - public function update(): Json + public function updateOrder(): Json { $order_id = intval($this->request->post('order_id')); if (!$order_id) { diff --git a/app/api/model/Server/RecoveryCategory.php b/app/api/model/Server/RecoveryCategory.php new file mode 100644 index 00000000..f0d87cb6 --- /dev/null +++ b/app/api/model/Server/RecoveryCategory.php @@ -0,0 +1,53 @@ +hasOne(UploadFile::class, 'file_id', 'image_id') + ->bind(['image_url' => 'preview_url']); + } + + /** + * @notes:获取全部记录 + * @return array + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author: wanghousheng + */ + public function list(): array + { + return $this->with(['image']) + ->where(['status' => 1]) + ->order(['sort', 'create_time']) + ->select() + ->toArray(); + } +} \ No newline at end of file diff --git a/app/api/model/Server/ServerRecovery.php b/app/api/model/Server/ServerRecovery.php new file mode 100644 index 00000000..602202da --- /dev/null +++ b/app/api/model/Server/ServerRecovery.php @@ -0,0 +1,21 @@ +