init: 项目初始代码
This commit is contained in:
133
app/api/controller/v1/Platform.php
Normal file
133
app/api/controller/v1/Platform.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\Platform as PlatformModel;
|
||||
use app\api\validate\Platform as PlatformValidate;
|
||||
|
||||
/**
|
||||
* 平台类
|
||||
* Class Platform
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Platform extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->validate = new PlatformValidate();
|
||||
$this->model = new PlatformModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
$result = $this->model->getAllList($inputData,$this->simple,$this->focus,$this->order);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 语言列表
|
||||
*/
|
||||
public function languageList():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$this->field = ['id','name','code','icon','status'];
|
||||
$result = $this->model->getLanguageList($this->field,['status'=>0]);
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function create():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->addData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
// 已经注册的平台,如果被使用,则不允许修改品牌名
|
||||
//TODO::暂时限制不能更改品牌名称
|
||||
$isExist = $this->model->hasUserPlatform($inputData);
|
||||
if (count($isExist) >= 1) {
|
||||
unset($inputData['name']);
|
||||
}
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->editData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
public function read():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->getInfo($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
} else {
|
||||
return $this->msg(504,'获取列表失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del():\think\response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
//删除前检测
|
||||
$isExist = $this->model->hasUserPlatform($inputData);
|
||||
if (count($isExist) >= 1) {
|
||||
return $this->msg(504,"平台被使用,不能删除");
|
||||
}
|
||||
$result = $this->model->delData($inputData);
|
||||
if ($result) {
|
||||
return $this->msg(200,"删除成功");
|
||||
} else {
|
||||
return $this->msg(504,"删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user