237 lines
8.3 KiB
PHP
237 lines
8.3 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
namespace app\api\controller\v1;
|
||
|
||
use app\api\model\SoftManual as SoftManualModel;
|
||
use app\api\validate\SoftManual as SoftManualValidate;
|
||
use think\facade\Env;
|
||
|
||
/**
|
||
* 驱动-文档手册类
|
||
* Class Download
|
||
* @package app\api\controller
|
||
*/
|
||
class SoftManual extends Base
|
||
{
|
||
public function initialize()
|
||
{
|
||
parent::initialize();
|
||
$this->validate = new SoftManualValidate();
|
||
$this->model = new SoftManualModel();
|
||
}
|
||
|
||
/**
|
||
* 列表
|
||
*/
|
||
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['file_type_id']) && $inputData['file_type_id'] != '' && $inputData['file_type_id'] != 0) {
|
||
$this->focus['file_type_id'] = $inputData['file_type_id'];
|
||
}
|
||
|
||
if (isset($inputData['name']) && $inputData['name'] != '') {
|
||
$this->simple['name'] = $inputData['name'];
|
||
}
|
||
|
||
$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
|
||
{
|
||
$introduce = $this->request->param('introduce','','htmlspecialchars');
|
||
$inputData = $this->request->param();
|
||
$inputData['introduce'] = $introduce;
|
||
$inputData['platform_id'] = $this->platformId;
|
||
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'];
|
||
unset($inputData['language_id']);
|
||
}
|
||
//验证是否提交按钮参数与链接
|
||
if (isset($inputData['softBtn']) && empty($inputData['softBtn'])) {
|
||
$this->msg(504,'还没有填写按钮信息,请检查!');
|
||
}
|
||
|
||
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
|
||
{
|
||
$introduce = $this->request->param('introduce','','htmlspecialchars');
|
||
$inputData = $this->request->param();
|
||
$inputData['introduce'] = $introduce;
|
||
$inputData['platform_id'] = $this->platformId;
|
||
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'];
|
||
unset($inputData['language_id']);
|
||
}
|
||
|
||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||
return $this->msg(-1,$this->validate->getError());
|
||
}
|
||
//验证是否提交按钮参数与链接
|
||
if (empty($inputData['softBtn'])) {
|
||
return $this->msg(504,'还没有填写按钮信息,请检查!');
|
||
}
|
||
|
||
$result = $this->model->editData($inputData);
|
||
if ($result) {
|
||
return $this->msg(200,'更改成功');
|
||
} else {
|
||
return $this->msg(504,'更改失败');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 更改排序
|
||
*/
|
||
public function changeSort():\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->changeSort($inputData);
|
||
if ($result) {
|
||
return $this->msg(200,'更改成功');
|
||
} else {
|
||
return $this->msg(504,'更改失败');
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 图片,ICON上传
|
||
*/
|
||
public function upload():\think\Response\Json
|
||
{
|
||
$files = $this->request->file();
|
||
if (!$files) {
|
||
return $this->msg(-1, "请选择上传的文件");
|
||
}
|
||
$field = array_keys($files)[0];
|
||
$data = [];
|
||
//兼容多图上传
|
||
if (is_array($files) && count($files) > 1 ) {
|
||
//不同字段文件名上传 image img ico
|
||
//上传到七牛
|
||
foreach ($files as $key => $fileSimple) {
|
||
// if (!$this->commonValidate(__FUNCTION__, [$key => $fileSimple])) {
|
||
// return $this->msg(200, $this->validate->getError());
|
||
// }
|
||
$result[$key] = $this->qn->uploadFile($key);
|
||
}
|
||
|
||
foreach ($result as $key => $item) {
|
||
$data[] = [
|
||
'cdn' => Env::get('QINIU.cdn'),
|
||
'origin_name' => $files[$key]->getOriginalName(),
|
||
'filename' => explode('/', $item['filename'])[count(explode('/', $item['filename'])) - 1],
|
||
'md5' => md5_file($files[$key]->getPathname()),
|
||
'url' => $item['remote_url'],
|
||
'relative_path' => $item['filename']
|
||
];
|
||
}
|
||
} elseif (is_array($files[$field]) && count($files[$field]) > 1) {
|
||
//同一名称的数组文件上传.image[0] image[1]
|
||
// foreach ($files as $key => $fileSimple) {
|
||
// if (!$this->commonValidate(__FUNCTION__, [$key => $fileSimple])) {
|
||
// return $this->msg(200, $this->validate->getError());
|
||
// }
|
||
// }
|
||
//上传到七牛
|
||
$result = $this->qn->uploadFile($field, true, count($files[$field]));
|
||
|
||
foreach ($result as $key => $item) {
|
||
$data[] = [
|
||
'cdn' => Env::get('QINIU.cdn'),
|
||
'origin_name' => $files[$field][$key]->getOriginalName(),
|
||
'filename' => explode('/', $item['filename'])[count(explode('/', $item['filename'])) - 1],
|
||
'md5' => md5_file($files[$field][$key]->getPathname()),
|
||
'url' => $item['remote_url'],
|
||
'relative_path' => $item['filename']
|
||
];
|
||
}
|
||
} else {
|
||
// if (!$this->commonValidate(__FUNCTION__,[$field=>$files])) {
|
||
// return $this->msg(200,$this->validate->getError());
|
||
// }
|
||
//上传到七牛
|
||
$result = $this->qn->uploadFile($field);
|
||
$data = [
|
||
'cdn' => Env::get('QINIU.cdn'),
|
||
'origin_name' => $files[$field]->getOriginalName(),
|
||
'filename' => explode('/',$result['filename'])[count(explode('/',$result['filename']))-1],
|
||
'md5' => md5_file($files[$field]->getPathname()),
|
||
'url' => $result['remote_url'],
|
||
'relative_path' => $result['filename']
|
||
];
|
||
}
|
||
|
||
return $this->msg(200, '上传成功', $data);
|
||
}
|
||
|
||
/**
|
||
* 删除
|
||
*/
|
||
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->getSoftManualUsed($inputData);
|
||
if ($hasUsed) {
|
||
return $this->msg(504,'已被使用,不能删除!');
|
||
}
|
||
$result = $this->model->delData($inputData);
|
||
if ($result) {
|
||
return $this->msg(200,"删除成功");
|
||
} else {
|
||
return $this->msg(504,"删除失败");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
}
|