From 54157dc758726396365805a87b050a02b69763d0 Mon Sep 17 00:00:00 2001 From: Wayne <943146732@qq.com> Date: Sat, 24 Feb 2024 21:41:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8D=8F=E8=AE=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9B=B8=E5=85=B3=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/Agreement.php | 22 ++++++- app/store/controller/content/Agreement.php | 76 ++++++++++++++++++++++ app/store/model/Agreement.php | 71 ++++++++++++++++++++ 3 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 app/store/controller/content/Agreement.php create mode 100644 app/store/model/Agreement.php diff --git a/app/common/model/Agreement.php b/app/common/model/Agreement.php index 37af69a0..98cc481d 100644 --- a/app/common/model/Agreement.php +++ b/app/common/model/Agreement.php @@ -8,7 +8,7 @@ // +---------------------------------------------------------------------- // | Author: 萤火科技 // +---------------------------------------------------------------------- -declare (strict_types=1); +declare(strict_types=1); namespace app\common\model; @@ -16,6 +16,7 @@ use cores\BaseModel; use think\model\relation\HasMany; use think\model\relation\HasOne; use app\common\model\store\Shop; + /** * 用户协议模型类 * Class User @@ -29,5 +30,24 @@ class Agreement extends BaseModel // 定义主键 protected $pk = 'id'; + /** + * 获取列表记录 + * @return \think\Paginator + * @throws \think\db\exception\DbException + */ + public function getList(): \think\Paginator + { + return $this->paginate(); + } + /** + * 详情 + * @param int $agreementId + * @param array $with + * @return static|array|null + */ + public static function detail(int $agreementId, array $with = []) + { + return self::get($agreementId, $with); + } } diff --git a/app/store/controller/content/Agreement.php b/app/store/controller/content/Agreement.php new file mode 100644 index 00000000..624d7405 --- /dev/null +++ b/app/store/controller/content/Agreement.php @@ -0,0 +1,76 @@ +getList(); + return $this->renderSuccess(compact('list')); + } + + /** + * 添加协议 + * @return Json + */ + public function add(): Json + { + // 新增记录 + $model = new AgreementModel; + + if ($model->add($this->postForm())) { + return $this->renderSuccess('添加成功'); + } + return $this->renderError($model->getError() ?: '添加失败'); + } + + /** + * 更新协议 + * @param int $agreementId + * @return Json + */ + public function edit(int $agreementId): Json + { + // 协议详情 + $model = AgreementModel::detail($agreementId); + // 更新记录 + if ($model->edit($this->postForm())) { + return $this->renderSuccess('更新成功'); + } + return $this->renderError($model->getError() ?: '更新失败'); + } + + /** + * 删除协议 + * @param int $agreementId + * @return Json + */ + public function delete(int $agreementId): Json + { + // 协议详情 + $model = AgreementModel::detail($agreementId); + // 删除记录 + if ($model->setDelete()) { + return $this->renderSuccess('删除成功'); + } + return $this->renderError($model->getError() ?: '删除失败'); + } +} \ No newline at end of file diff --git a/app/store/model/Agreement.php b/app/store/model/Agreement.php new file mode 100644 index 00000000..556ac8f2 --- /dev/null +++ b/app/store/model/Agreement.php @@ -0,0 +1,71 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\store\model; + +use app\common\model\Agreement as AgreementModel; + +/** + * 模型类:帮助中心 + * Class Help + * @package app\store\model + */ +class Agreement extends AgreementModel +{ + + /** + * 新增记录 + * @param array $data + * @return bool|false + */ + public function add(array $data): bool + { + if (empty($data['type'])) { + $this->error = '请输入协议类型'; + return false; + } + if (empty($data['content'])) { + $this->error = '请输入协议内容'; + return false; + } + + $data['store_id'] = self::$storeId; + return $this->save($data); + } + + /** + * 更新记录 + * @param array $data + * @return bool + */ + public function edit(array $data): bool + { + if (empty($data['type'])) { + $this->error = '请输入协议类型'; + return false; + } + if (empty($data['content'])) { + $this->error = '请输入协议内容'; + return false; + } + return $this->save($data) !== false; + } + + /** + * 删除记录 + * @return bool + */ + public function setDelete(): bool + { + return $this->delete(); + } +}