136 lines
4.1 KiB
PHP
136 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\Home\Highlights;
|
|
|
|
use app\BaseController;
|
|
use app\common\model\Home\Highlights\Highlights as ModelHighlights;
|
|
use app\Request;
|
|
use think\Validate;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Filesystem;
|
|
use app\common\arw\adjfut\src\Excel;
|
|
use app\common\arw\adjfut\src\UploadFile;
|
|
use app\common\exception\Tool;
|
|
use think\facade\Db;
|
|
use think\facade\Env;
|
|
|
|
|
|
class Highlights extends BaseController
|
|
{
|
|
/**
|
|
* 获取亮点列表
|
|
*/
|
|
public function getHighlightsList(Request $request, $isExport = false): array
|
|
{
|
|
$params = $request->param();
|
|
$con = [];
|
|
|
|
$con = Tool::getOptionalQuery(['a.i18n_lang_type_guid', '='], ['highlights_title', 'LIKE'],);
|
|
|
|
$query = ModelHighlights::where($con)
|
|
->alias('a')
|
|
->leftjoin('i18n_lang_type c', 'a.i18n_lang_type_guid = c.i18n_lang_type_guid')
|
|
->field([
|
|
'a.highlights_id',
|
|
'a.highlights_guid',
|
|
'c.i18n_lang_type_code',
|
|
'a.i18n_lang_type_guid',
|
|
'a.highlights_title',
|
|
'a.highlights_sort'
|
|
])
|
|
->order('highlights_sort', 'asc');
|
|
|
|
return $isExport ? $query->select()->toArray() : msg("获取亮点列表成功!", $query);
|
|
}
|
|
|
|
/**
|
|
* 添加亮点
|
|
*/
|
|
public function addHighlights(Request $request): array
|
|
{
|
|
Db::startTrans();
|
|
Tool::adminLockTableWrite('highlights');
|
|
try {
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'i18n_lang_type_guid|语言类型guid' => 'require',
|
|
'highlights_title|标题' => 'require',
|
|
// 'highlights_sort|排序' => 'require'
|
|
]);
|
|
$model = ModelHighlights::create($params, [
|
|
'i18n_lang_type_guid',
|
|
'highlights_title',
|
|
'highlights_sort',
|
|
'highlights_guid',
|
|
'highlights_create_user_guid',
|
|
'highlights_update_user_guid'
|
|
]);
|
|
Db::commit();
|
|
Tool::unlockTable();
|
|
return msg('添加成功!');
|
|
} catch (\Throwable $th) {
|
|
Db::rollback();
|
|
Tool::unlockTable();
|
|
throw $th;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 编辑亮点
|
|
*/
|
|
public function editHighlights(Request $request): array
|
|
{
|
|
Db::startTrans();
|
|
Tool::adminLockTableWrite('highlights');
|
|
try {
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'i18n_lang_type_guid|语言类型guid' => 'require',
|
|
'highlights_title|标题' => 'require',
|
|
'highlights_sort|排序' => 'require'
|
|
]);
|
|
$model = ModelHighlights::where('highlights_guid', $params['highlights_guid'])->find();
|
|
if (!$model) throwErrorMsg("该亮点不存在", 1);
|
|
$model->allowField([
|
|
'i18n_lang_type_guid',
|
|
'highlights_title',
|
|
'highlights_sort',
|
|
'highlights_update_user_guid'
|
|
])->save($params);
|
|
Db::commit();
|
|
Tool::unlockTable();
|
|
return msg('编辑成功!');
|
|
} catch (\Throwable $th) {
|
|
Db::rollback();
|
|
Tool::unlockTable();
|
|
throw $th;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除亮点
|
|
*/
|
|
public function deleteHighlights(Request $request): array
|
|
{
|
|
Db::startTrans();
|
|
Tool::adminLockTableWrite('highlights');
|
|
try {
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'highlights_guid' => 'require',
|
|
]);
|
|
$highlights = ModelHighlights::where([
|
|
'highlights_guid' => explode(',', $params['highlights_guid'])
|
|
])->select();
|
|
$highlights->delete();
|
|
Db::commit();
|
|
Tool::unlockTable();
|
|
return msg('删除成功!');
|
|
} catch (\Throwable $th) {
|
|
Db::rollback();
|
|
Tool::unlockTable();
|
|
throw $th;
|
|
}
|
|
}
|
|
}
|