123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- declare (strict_types = 1);
- namespace app\store\controller;
- use app\common\model\Provider as ProviderModel;
- /**
- * 供应商
- * Class Provider
- * @package app\store\controller
- */
- class Provider extends Controller
- {
- /**
- * 列表
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function list()
- {
- $model = new ProviderModel;
- $list = $model->getList($this->request->param());
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 获取所有记录
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function all()
- {
- $model = new ProviderModel;
- $list = $model->getAll();
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 删除
- * @param $providerId
- * @return array
- * @throws \Exception
- */
- public function delete(int $providerId)
- {
- // 详情
- $model = ProviderModel::detail($providerId);
- if (!$model->delete()) {
- return $this->renderError($model->getError() ?: '删除失败');
- }
- return $this->renderSuccess('删除成功');
- }
- /**
- * 详情记录
- * @param int $providerId
- * @return array
- */
- public function detail(int $providerId)
- {
- $detail = ProviderModel::detail($providerId);
- return $this->renderSuccess(compact('detail'));
- }
- /**
- * 添加
- * @return array|string
- */
- public function add()
- {
- // 新增记录
- $model = new ProviderModel;
- if ($model->add($this->postForm())) {
- return $this->renderSuccess('添加成功');
- }
- return $this->renderError($model->getError() ?: '添加失败');
- }
- /**
- * 编辑
- * @param int $providerId
- * @return mixed
- */
- public function edit(int $providerId)
- {
- // 详情
- $model = ProviderModel::detail($providerId);
- // 更新记录
- if ($model->edit($this->postForm())) {
- return $this->renderSuccess('更新成功');
- }
- return $this->renderError($model->getError() ?: '更新失败');
- }
- }
|