129 lines
3.8 KiB
PHP
129 lines
3.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace app\api\controller\v1;
|
|
|
|
use app\api\model\Language as LanguageModel;
|
|
use app\api\validate\Language as LanguageValidate;
|
|
/**
|
|
* 语言包类
|
|
* Class Language
|
|
* @package app\api\controller
|
|
*/
|
|
class Language extends Base
|
|
{
|
|
public function initialize()
|
|
{
|
|
parent::initialize();
|
|
$this->validate = new LanguageValidate();
|
|
$this->model = new LanguageModel();
|
|
}
|
|
|
|
/**
|
|
* 列表
|
|
*/
|
|
public function index():\think\response\Json
|
|
{
|
|
$inputData = $this->request->param();
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
if (isset($inputData['status']) && $inputData['status'] != '') {
|
|
$this->focus['status'] = $inputData['status'];
|
|
}
|
|
$this->field = ['id','name','code','icon','status'];
|
|
$result = $this->model->getIndexList($this->page,$this->size,$this->field,$this->simple,$this->focus,$this->order);
|
|
return $result ? $this->msg(200,'获取列表成功',$result) : $this->msg(504,'获取列表失败');
|
|
}
|
|
|
|
/**
|
|
* 新增
|
|
*/
|
|
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();
|
|
$inputData['platform_id'] = $this->platformId;
|
|
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 changeStatus():\think\response\Json
|
|
{
|
|
$inputData = $this->request->param(['id','status']);
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
//判断是否是否使用
|
|
$hasUsed = $this->model->getLanguageUse($inputData['id']);
|
|
if (!$hasUsed) {
|
|
$result = $this->model->changeStatus($inputData);
|
|
if ($result) {
|
|
return $this->msg(200,"操作成功");
|
|
} else {
|
|
return $this->msg(504,"操作失败");
|
|
}
|
|
} else {
|
|
return $this->msg(504,"此语言包已经被使用,不能启用/禁用");
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 删除
|
|
*/
|
|
public function del():\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());
|
|
}
|
|
//判断是否是否使用
|
|
$hasUsed = $this->model->getLanguageUse($inputData['id']);
|
|
if (!$hasUsed) {
|
|
$result = $this->model->delData($inputData);
|
|
if ($result) {
|
|
return $this->msg(200,"删除成功");
|
|
} else {
|
|
return $this->msg(504,"删除失败");
|
|
}
|
|
} else {
|
|
return $this->msg(504,"此语言包已经被使用,不能删除");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|