|
|
|
<?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
|
|
|
|
* @throws DataNotFoundException
|
|
|
|
* @throws DbException
|
|
|
|
* @throws ModelNotFoundException
|
|
|
|
* @author: wanghousheng
|
|
|
|
*/
|
|
|
|
public function dealerList(): Json
|
|
|
|
{
|
|
|
|
$where['type'] = IdentityEnum::DEALER;
|
|
|
|
$model = new IdentityModel();
|
|
|
|
$list = $model->getList($where);
|
|
|
|
return $this->renderSuccess(compact('list'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @notes:新增
|
|
|
|
* @return Json
|
|
|
|
* @author: wanghousheng
|
|
|
|
*/
|
|
|
|
public function addDealer(): Json
|
|
|
|
{
|
|
|
|
$data = $this->postForm();
|
|
|
|
if (!$data) {
|
|
|
|
return $this->renderError('缺少必要参数');
|
|
|
|
}
|
|
|
|
$model = new IdentityModel();
|
|
|
|
$data['type'] = IdentityEnum::DEALER;
|
|
|
|
if ($model->add($data)) {
|
|
|
|
return $this->renderSuccess('添加成功');
|
|
|
|
}
|
|
|
|
return $this->renderError($model->getError() ?: '添加失败');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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'));
|
|
|
|
}
|
|
|
|
}
|