新增协议接口相关内容

pull/1/head
Wayne 11 months ago
parent e86bb22367
commit 54157dc758
  1. 22
      app/common/model/Agreement.php
  2. 76
      app/store/controller/content/Agreement.php
  3. 71
      app/store/model/Agreement.php

@ -8,7 +8,7 @@
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
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);
}
}

@ -0,0 +1,76 @@
<?php
declare(strict_types=1);
namespace app\store\controller\content;
use think\response\Json;
use app\store\controller\Controller;
use app\store\model\Agreement as AgreementModel;
/**
* 协议管理
* Class Agreement
* @package app\store\controller\content
*/
class Agreement extends Controller
{
/**
* 获取列表记录
* @return Json
* @throws \think\db\exception\DbException
*/
public function list(): Json
{
$model = new AgreementModel;
$list = $model->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() ?: '删除失败');
}
}

@ -0,0 +1,71 @@
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
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();
}
}
Loading…
Cancel
Save