From 1dd8d6d86f331252032912c7454f47e456ee6f3a Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Mon, 4 Sep 2023 17:27:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=9C=8D=E5=85=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/CustomerService.php | 95 ++++++++++++++++++++++++++++++ app/model/CustomerService.php | 18 ++++++ app/validate/CustomerService.php | 35 +++++++++++ route/app.php | 5 ++ 4 files changed, 153 insertions(+) create mode 100644 app/controller/CustomerService.php create mode 100644 app/model/CustomerService.php create mode 100644 app/validate/CustomerService.php diff --git a/app/controller/CustomerService.php b/app/controller/CustomerService.php new file mode 100644 index 0000000..6a26622 --- /dev/null +++ b/app/controller/CustomerService.php @@ -0,0 +1,95 @@ +field($field)->where($where)->order('id desc')->paginate($limit); + + $list = $res->items(); + $total = $res->total(); + + return $this->renderSuccess('数据返回成功', ['list' => $list, 'total' => $total]); + } + + /** + * 保存新建的资源 + */ + public function save() + { + $param = Request::param(); + + try { + $id = $param['id'] ?? 0; + + if ($id) { + validate(CustomerServiceValidate::class)->scene('edit')->check($param); + $CustomerServiceModel = CustomerServiceModel::find($id); + $CustomerServiceModel->name = $param['name']; + $CustomerServiceModel->wx_number = $param['wx_number']; + $CustomerServiceModel->update_time = date("Y-m-d H:i:s",time()); + $CustomerServiceModel->save(); + } else { + validate(CustomerServiceValidate::class)->scene('add')->check($param); + + $CustomerService = new CustomerServiceModel(); + $CustomerService->save([ + 'name' => $param['name'], + 'wx_number' => $param['wx_number'], + 'create_time' => date("Y-m-d H:i:s",time()) + ]); + } + + return $this->renderSuccess($id ? '编辑成功' : '添加成功'); + } catch (ValidateException $validateException) { + return $this->renderError($validateException->getMessage()); + } catch (\Exception $e) { + return $this->renderError('操作失败'); + } + } + + /** + * 删除指定资源 + */ + public function delete() + { + $param = Request::param(); + + try { + + validate(CustomerServiceValidate::class)->scene('del')->check($param); + + $result = CustomerServiceModel::destroy($param['id']); + + if (!$result) throw new ValidateException('删除失败'); + + return $this->renderSuccess('已删除'); + } catch (ValidateException $validateException) { + return $this->renderError($validateException->getMessage()); + } catch (\Exception $e) { + return $this->renderError('操作失败'); + } + } +} diff --git a/app/model/CustomerService.php b/app/model/CustomerService.php new file mode 100644 index 0000000..633b59a --- /dev/null +++ b/app/model/CustomerService.php @@ -0,0 +1,18 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = [ + 'name|客服名称' => 'require', + 'wx_number|微信号码' => 'require|min:6|max:20|alphaDash', + 'id|客服id' => 'require|number', + ]; + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = []; + + protected $scene = [ + 'add' => ['name','wx_number'], + 'edit' => ['name','wx_number','id'], + 'del' => ['id'] + ]; +} diff --git a/route/app.php b/route/app.php index 3801230..cc46c80 100644 --- a/route/app.php +++ b/route/app.php @@ -87,6 +87,11 @@ Route::group('adminZoneManage',function() { Route::post('goodsParamDel','adminZoneManage/goodsParamDel')->middleware(CheckAdmin::class)->allowCrossDomain(); }); +Route::group('customerService',function() { + Route::post('list','customerService/list')->middleware(CheckAdmin::class)->allowCrossDomain(); + Route::post('save','customerService/save')->middleware(CheckAdmin::class)->allowCrossDomain(); + Route::post('delete','customerService/delete')->middleware(CheckAdmin::class)->allowCrossDomain(); +}); # 支付(待开发) //Route::group('pay',function (){ // Route::post('pay','pay/pay');