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.
yanzong/app/store/controller/user/Identity.php

147 lines
3.8 KiB

10 months ago
<?php
7 months ago
declare (strict_types=1);
10 months ago
namespace app\store\controller\user;
use app\common\enum\user\IdentityEnum;
7 months ago
use app\store\controller\Controller;
10 months ago
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;
5 months ago
use app\store\model\user\IdentityOrder;
10 months ago
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'));
}
5 months ago
/**
* @notes:分销商价格
* @return Json
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function identityOrderList(): Json
{
$model = new IdentityOrder();
$list = $model->getList($this->request->param());
return $this->renderSuccess(compact('list'));
}
8 months ago
/**
* @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() ?: '添加失败');
}
10 months ago
/**
* @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'));
}
}