You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.4 KiB
97 lines
2.4 KiB
10 months ago
|
<?php
|
||
|
|
||
|
namespace app\store\controller\user;
|
||
|
|
||
|
use app\admin\controller\Controller;
|
||
|
use app\common\enum\user\IdentityEnum;
|
||
|
use app\store\model\user\Identity as IdentityModel;
|
||
|
use think\db\exception\DataNotFoundException;
|
||
|
use think\db\exception\DbException;
|
||
|
use think\db\exception\ModelNotFoundException;
|
||
|
use think\response\Json;
|
||
|
|
||
|
class Identity extends Controller
|
||
|
{
|
||
|
/**
|
||
|
* @notes:列表
|
||
|
* @return Json
|
||
|
* @throws DataNotFoundException
|
||
|
* @throws DbException
|
||
|
* @throws ModelNotFoundException
|
||
|
* @author: wanghousheng
|
||
|
*/
|
||
|
public function list(): Json
|
||
|
{
|
||
|
$where = [];
|
||
|
$type = $this->request->post('type');
|
||
|
if ($type) {
|
||
|
$where['type'] = $type;
|
||
|
}
|
||
|
$model = new IdentityModel();
|
||
|
$list = $model->getList($where);
|
||
|
return $this->renderSuccess(compact('list'));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @notes:新增
|
||
|
* @return Json
|
||
|
* @author: wanghousheng
|
||
|
*/
|
||
|
public function add(): Json
|
||
|
{
|
||
|
$data = $this->postForm();
|
||
|
if (!$data) {
|
||
|
return $this->renderError('缺少必要参数');
|
||
|
}
|
||
|
$model = new IdentityModel();
|
||
|
if ($model->add($data)) {
|
||
|
return $this->renderSuccess('添加成功');
|
||
|
}
|
||
|
return $this->renderError($model->getError() ?: '添加失败');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @notes:编辑
|
||
|
* @param int $identityId
|
||
|
* @return Json
|
||
|
* @author: wanghousheng
|
||
|
*/
|
||
|
public function edit(int $identityId): Json
|
||
|
{
|
||
|
$data = $this->postForm();
|
||
|
if (!$data) {
|
||
|
return $this->renderError('缺少必要参数');
|
||
|
}
|
||
|
$model = IdentityModel::detail($identityId);
|
||
|
if ($model->edit($data)) {
|
||
|
return $this->renderSuccess('编辑成功');
|
||
|
}
|
||
|
return $this->renderError($model->getError() ?: '编辑失败');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @notes:删除
|
||
|
* @param array $identityId
|
||
|
* @return Json
|
||
|
* @author: wanghousheng
|
||
|
*/
|
||
|
public function delete(array $identityId): Json
|
||
|
{
|
||
|
$model = new IdentityModel;
|
||
|
if ($model->remove($identityId)) {
|
||
|
return $this->renderSuccess('删除成功');
|
||
|
}
|
||
|
return $this->renderError('删除失败');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @notes:身份值
|
||
|
* @return Json
|
||
|
* @author: wanghousheng
|
||
|
*/
|
||
|
public function typeList(): Json
|
||
|
{
|
||
|
$list = array_values(IdentityEnum::data());
|
||
|
return $this->renderSuccess(compact('list'));
|
||
|
}
|
||
|
}
|