136 lines
4.3 KiB
PHP
136 lines
4.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace app\api\controller\v1;
|
|
|
|
use app\api\model\Brand as BrandModel;
|
|
use app\api\validate\Brand as BrandValidate;
|
|
|
|
/**
|
|
* 文章新闻模块
|
|
* Class Brand
|
|
* @package app\api\controller
|
|
*/
|
|
class Brand extends Base
|
|
{
|
|
public function initialize()
|
|
{
|
|
parent::initialize();
|
|
$this->validate = new BrandValidate();
|
|
$this->model = new BrandModel();
|
|
}
|
|
|
|
/**
|
|
* 列表
|
|
*/
|
|
public function index():\think\Response\Json
|
|
{
|
|
$inputData = $this->request->param();
|
|
$inputData['platform_id'] = $this->platformId;
|
|
|
|
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
|
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
|
unset($inputData['language_id']);
|
|
}
|
|
|
|
if (isset($inputData['Brand_type_id']) && $inputData['Brand_type_id'] != '' && $inputData['Brand_type_id'] != 0) {
|
|
$this->focus['Brand_type_id'] = $inputData['Brand_type_id'];
|
|
}
|
|
|
|
if (isset($inputData['title']) && $inputData['title'] != '') {
|
|
$this->simple['title'] = $inputData['title'];
|
|
}
|
|
|
|
$this->order['create_time'] = 'desc';
|
|
|
|
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 create():\think\Response\Json
|
|
{
|
|
$detail = $this->request->param('detail','','htmlspecialchars');
|
|
$inputData = $this->request->param();
|
|
$inputData['detail'] = $detail;
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (isset($inputData['create_time']) && !$inputData['create_time']) {
|
|
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
|
} else {
|
|
unset($inputData['create_time']);
|
|
}
|
|
unset($inputData['update_time']);
|
|
|
|
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
|
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
|
}
|
|
|
|
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
|
|
{
|
|
$detail = $this->request->param('detail','','htmlspecialchars');
|
|
$inputData = $this->request->param();
|
|
$inputData['detail'] = $detail;
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (isset($inputData['create_time'])) {
|
|
$inputData['create_time'] = intval($inputData['create_time']) / 1000;
|
|
} else {
|
|
unset($inputData['create_time']);
|
|
}
|
|
unset($inputData['update_time']);
|
|
|
|
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
|
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
|
}
|
|
|
|
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();
|
|
$inputData['platform_id'] = $this->platformId;
|
|
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
|
return $this->msg(-1,$this->validate->getError());
|
|
}
|
|
$result = $this->model->changeStatus($inputData);
|
|
if ($result) {
|
|
return $this->msg(200,'更改成功');
|
|
} else {
|
|
return $this->msg(504,'更改失败');
|
|
}
|
|
}
|
|
|
|
}
|