// +---------------------------------------------------------------------- namespace app\controller\admin\system; use app\common\repositories\system\LhappRepository; use think\exception\ValidateException; use crmeb\basic\BaseController; use think\App; class Lhapp extends BaseController { /** * @var LhappRepository */ protected $repository; /** * CacheRepository constructor. * @param App $app */ public function __construct(App $app, LhappRepository $repository) { parent::__construct($app); $this->repository = $repository; } public function list() { [$page, $limit] = $this->getPage(); $where = $this->request->params(['type']); return app('json')->success($this->repository->getList($where, $page, $limit)); } public function create() { $this->repository->create($this->getValidParams()); return app('json')->success('添加成功'); } public function update($id) { if (!$this->repository->exists($id)) { return app('json')->fail('数据不存在'); } $this->repository->update($id, $this->getValidParams()); return app('json')->success('修改成功'); } public function detail($id) { $data = $this->repository->detail($id); return app('json')->success($data); } public function delete($id) { $res = $this->repository->delete($id); if ($res) { return app('json')->success('删除成功'); } else { return app('json')->fail('删除失败'); } } protected function getValidParams() { $data = $this->request->params(['title', 'content', 'type', 'phone_brand', 'version', 'dow_url', 'force', 'quiet']); if (empty($data['title'])) throw new ValidateException('title标题不能为空'); if (empty($data['content'])) throw new ValidateException('content内容不能为空'); if (empty($data['type'])) throw new ValidateException('type类型不能为空'); if (empty($data['version'])) throw new ValidateException('version版本号不能为空'); if (empty($data['dow_url'])) throw new ValidateException('dow_url下载地址不能为空'); return $data; } }