feat:新增后台轮播图,发展历程模块接口、Tool类排序换位封装修改
This commit is contained in:
parent
3c48c06400
commit
4e7da537b7
145
app/admin/controller/AboutUs/DevelopmentHistory.php
Normal file
145
app/admin/controller/AboutUs/DevelopmentHistory.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\AboutUs;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\AboutUs\DevelopmentHistory as ModelDevelopmentHistory;
|
||||
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 DevelopmentHistory extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取发展历程列表
|
||||
*/
|
||||
public function getDevelopmentHistoryList(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'sort|排序' => 'require',
|
||||
]);
|
||||
$query = ModelDevelopmentHistory::field([
|
||||
'development_history_id',
|
||||
'development_history_guid',
|
||||
'development_history_year',
|
||||
'development_history_title',
|
||||
'development_history_content'
|
||||
])
|
||||
->order('development_history_year', $params['sort']);
|
||||
|
||||
return msg("获取发展历程列表成功!", $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑发展历程
|
||||
*/
|
||||
public function editDevelopmentHistory(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'development_history_year|年份' => 'require',
|
||||
'development_history_title|标题' => 'require',
|
||||
'development_history_content|内容' => 'require'
|
||||
]);
|
||||
$model = ModelDevelopmentHistory::where('development_history_guid', $params['development_history_guid'])->find();
|
||||
if (!$model) throwErrorMsg("该发展历程不存在", 1);
|
||||
$model->allowField([
|
||||
'development_history_update_user_guid',
|
||||
'development_history_year',
|
||||
'development_history_title',
|
||||
'development_history_content'
|
||||
])->save($params);
|
||||
return msg('编辑成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加发展历程
|
||||
*/
|
||||
public function addDevelopmentHistory(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'development_history_year|年份' => 'require',
|
||||
'development_history_title|标题' => 'require',
|
||||
'development_history_content|内容' => 'require'
|
||||
]);
|
||||
$model = ModelDevelopmentHistory::create($params, [
|
||||
'development_history_guid',
|
||||
'development_history_create_user_guid',
|
||||
'development_history_update_user_guid',
|
||||
'development_history_year',
|
||||
'development_history_title',
|
||||
'development_history_content'
|
||||
]);
|
||||
return msg('添加成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除发展历程
|
||||
*/
|
||||
public function deleteDevelopmentHistory(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'development_history_guid' => 'require',
|
||||
]);
|
||||
$development_history = ModelDevelopmentHistory::where([
|
||||
'development_history_guid' => explode(',', $params['development_history_guid'])
|
||||
])->select();
|
||||
$development_history->delete();
|
||||
return msg('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出Excel
|
||||
*/
|
||||
public function exportExcel(Request $request): void
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'sort|排序' => 'require',
|
||||
]);
|
||||
$select = ModelDevelopmentHistory::field([
|
||||
'development_history_year',
|
||||
'development_history_title',
|
||||
'development_history_content'
|
||||
])
|
||||
->order('development_history_year', $params['sort'])
|
||||
->select();
|
||||
|
||||
ModelDevelopmentHistory::exportExcel($select);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载导入模板
|
||||
*/
|
||||
public function downloadTemplate(Request $request): void
|
||||
{
|
||||
$data = [
|
||||
array_values(ModelDevelopmentHistory::EXCELFIELD),
|
||||
[date('Y'), '公司成立', '公司成立']
|
||||
];
|
||||
$excel = (new Excel())->exporTsheet($data);
|
||||
$excel->save('发展历程导入模板.xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入excel
|
||||
*/
|
||||
public function importExcel(Request $request): array
|
||||
{
|
||||
$file = new UploadFile('uploads', 'fileExt:xlsx');
|
||||
$file->putFile('development_history');
|
||||
|
||||
$msg = ModelDevelopmentHistory::importExcel($file);
|
||||
return msg($msg);
|
||||
}
|
||||
}
|
99
app/admin/controller/Banner/Banner.php
Normal file
99
app/admin/controller/Banner/Banner.php
Normal file
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\Banner;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\Banner\Banner as ModelBanner;
|
||||
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 Banner extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取轮播图列表
|
||||
*/
|
||||
public function getBannerList(Request $request): array
|
||||
{
|
||||
$con = Tool::getOptionalQuery(['banner_location', '='],);
|
||||
|
||||
$query = ModelBanner::where($con)
|
||||
->field([
|
||||
'banner_id',
|
||||
'banner_img',
|
||||
'banner_location',
|
||||
'banner_order',
|
||||
'banner_guid'
|
||||
])
|
||||
->order('banner_order', 'asc');
|
||||
|
||||
return msg("获取轮播图列表成功!", $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑轮播图
|
||||
*/
|
||||
public function editBanner(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'banner_img|轮播图图片' => 'require',
|
||||
'banner_location|轮播图片位置(字典)' => 'require',
|
||||
'banner_order|排序' => 'require'
|
||||
]);
|
||||
$model = ModelBanner::where('banner_guid', $params['banner_guid'])->find();
|
||||
if (!$model) throwErrorMsg("该轮播图不存在", 1);
|
||||
$model->allowField([
|
||||
'banner_update_user_guid',
|
||||
'banner_img',
|
||||
'banner_location',
|
||||
'banner_order'
|
||||
])->save($params);
|
||||
return msg('编辑成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加轮播图
|
||||
*/
|
||||
public function addBanner(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'banner_img|轮播图图片' => 'require',
|
||||
'banner_location|轮播图片位置(字典)' => 'require',
|
||||
'banner_order|排序' => 'require'
|
||||
]);
|
||||
ModelBanner::create($params, [
|
||||
'banner_guid',
|
||||
'banner_create_user_guid',
|
||||
'banner_update_user_guid',
|
||||
'banner_img',
|
||||
'banner_location',
|
||||
'banner_order'
|
||||
]);
|
||||
return msg('添加成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除轮播图
|
||||
*/
|
||||
public function deleteBanner(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'banner_guid' => 'require',
|
||||
]);
|
||||
$banner = ModelBanner::where([
|
||||
'banner_guid' => explode(',', $params['banner_guid'])
|
||||
])->select();
|
||||
$banner->delete();
|
||||
return msg('删除成功!');
|
||||
}
|
||||
}
|
@ -353,7 +353,7 @@ class Tool
|
||||
* @param string $model 模型层命名空间地址
|
||||
* @param string $guid 主键
|
||||
* @param int $order 新排序号
|
||||
* @param array $extra_wheres 当前指定数据的额外查询条件(tp批量查询数组) 例:["xxx_type" => 1,...]
|
||||
* @param array $extra_wheres 关联类型 例:["xxx_type" => 1]
|
||||
*/
|
||||
public static function sortEditProc(string $model, string $guid, int $order, array $extra_wheres = []): void
|
||||
{
|
||||
@ -373,12 +373,17 @@ class Tool
|
||||
//已被占用,则将它们的排序号互换
|
||||
if ($model->where($order_field_name, $order)->where($guld_field, '<>', $guid)->where($extra_wheres)->find()) {
|
||||
$update_data = [$order_field_name => $original_oreder_find[$order_field_name]];
|
||||
if (isset($model->parent_guid_field)) {
|
||||
|
||||
//检查是否有父祖级主键,有则也加入互换
|
||||
if (isset($model->parent_guid_field) && isset($model->ancestors_guid_field)) {
|
||||
$update_data[$model->parent_guid_field] = $original_oreder_find[$model->parent_guid_field];
|
||||
}
|
||||
if (isset($model->ancestors_guid_field)) {
|
||||
$update_data[$model->ancestors_guid_field] = $original_oreder_find[$model->ancestors_guid_field];
|
||||
}
|
||||
|
||||
//关联类型也加入互换
|
||||
foreach ($extra_wheres as $key => $value) {
|
||||
$update_data[$key] = $original_oreder_find[$key];
|
||||
};
|
||||
Db::name($table_name)->where($order_field_name, $order)->where($extra_wheres)->update($update_data);
|
||||
}
|
||||
}
|
||||
@ -415,7 +420,7 @@ class Tool
|
||||
* 注意:使用该方法时候要启动事务!!
|
||||
* @param string $model 模型层命名空间地址
|
||||
* @param array $guid 主键
|
||||
* @param array $correl_fields 关联字段 例:["xxx_guid",...] 代表删除排序号时会根据这些字段来关联(例:所属xxx类型、所属xxx系列)来进行排序处理
|
||||
* @param array $correl_fields 关联类型字段 例:["xxx_guid",...] 代表删除排序号时会根据这些字段来关联(例:所属xxx类型、所属xxx系列)来进行排序处理
|
||||
*/
|
||||
public static function sortDeleteProc(string $model, string $guid, array $correl_fields = []): void
|
||||
{
|
||||
|
154
app/common/model/AboutUs/DevelopmentHistory.php
Normal file
154
app/common/model/AboutUs/DevelopmentHistory.php
Normal file
@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\AboutUs;
|
||||
|
||||
use app\common\arw\adjfut\src\Validate;
|
||||
use app\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\Request;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
|
||||
class DevelopmentHistory extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
// 删除字段
|
||||
protected $deleteTime = 'development_history_delete_time';
|
||||
// 设置主键名
|
||||
protected $pk = 'development_history_guid';
|
||||
// 设置废弃字段
|
||||
protected $disuse = [];
|
||||
// 设置字段信息
|
||||
protected $schema = [
|
||||
"development_history_id" => "int",
|
||||
"development_history_guid" => "string",
|
||||
"development_history_year" => "int",
|
||||
"development_history_title" => "string",
|
||||
"development_history_content" => "string",
|
||||
"development_history_create_time" => "datetime",
|
||||
"development_history_create_user_guid" => "string",
|
||||
"development_history_update_time" => "datetime",
|
||||
"development_history_update_user_guid" => "string",
|
||||
"development_history_delete_time" => "datetime",
|
||||
"development_history_delete_user_guid" => "string",
|
||||
];
|
||||
// 设置json类型字段
|
||||
protected $json = [''];
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
// 创建时间
|
||||
protected $createTime = 'development_history_create_time';
|
||||
// 修改时间
|
||||
protected $updateTime = 'development_history_update_time';
|
||||
|
||||
|
||||
// excel导入/下载模板表头
|
||||
public const EXCELFIELD = [
|
||||
'development_history_year' => '年份',
|
||||
'development_history_title' => '标题',
|
||||
'development_history_content' => '内容',
|
||||
];
|
||||
|
||||
/**
|
||||
* 新增前
|
||||
*/
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
Validate::unique(self::class, $model->development_history_guid, $model->getData(), [
|
||||
'development_history_year' => '年份',
|
||||
]);
|
||||
$model->completeCreateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新前
|
||||
*/
|
||||
public static function onBeforeUpdate(self $model): void
|
||||
{
|
||||
Validate::unique(self::class, $model->development_history_guid, $model->getData(), [
|
||||
'development_history_year' => '年份',
|
||||
]);
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前
|
||||
*/
|
||||
public static function onBeforeDelete(self $model): void
|
||||
{
|
||||
$model->completeDeleteField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出Excel
|
||||
*
|
||||
* @param array $select 导出的数据
|
||||
*/
|
||||
public static function exportExcel(array $select): void
|
||||
{
|
||||
$data = [
|
||||
['年份', '标题', '内容'],
|
||||
];
|
||||
foreach ($select as $key => $val) {
|
||||
$data[] = [
|
||||
$val['development_history_year'],
|
||||
$val['development_history_title'],
|
||||
$val['development_history_content'],
|
||||
];
|
||||
}
|
||||
$excel = (new Excel())->exporTsheet($data);
|
||||
$excel->save('发展历程.xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入excel
|
||||
*
|
||||
* @param \app\common\arw\adjfut\src\UploadFile $file excel
|
||||
*/
|
||||
public static function importExcel($file): string
|
||||
{
|
||||
$msg = [];
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$excel = new Excel($file);
|
||||
$data = $excel->parseExcel(
|
||||
Tool::getExcelRule(self::EXCELFIELD),
|
||||
['titleLine' => [1]]
|
||||
);
|
||||
if (!$data) throwErrorMsg('excel无数据', 1);
|
||||
$msg = [];
|
||||
foreach ($data as $line => $value) {
|
||||
try {
|
||||
self::importExcelInit($value);
|
||||
$msg[] = "{$line} <span style='color:#27af49'>新增成功!</span><br>";
|
||||
} catch (\Throwable $th) {
|
||||
$msg[] = "{$line} <span style='color:red'>{$th->getMessage()}</span><br>";
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
return implode(', ', $msg);
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入excel初始化
|
||||
*
|
||||
* @param array $value 每行数据
|
||||
*/
|
||||
public static function importExcelInit($value): string
|
||||
{
|
||||
$development_history_year = $value['development_history_year'];
|
||||
$development_history_title = $value['development_history_title'];
|
||||
$development_history_content = $value['development_history_content'];
|
||||
return self::create([
|
||||
'development_history_year' => $development_history_year,
|
||||
'development_history_title' => $development_history_title,
|
||||
'development_history_content' => $development_history_content,
|
||||
]);
|
||||
}
|
||||
}
|
@ -104,7 +104,7 @@ class TeachingEnvirType extends BaseModel
|
||||
/**
|
||||
* 导出Excel
|
||||
*
|
||||
* @param array $select导出的数据集合
|
||||
* @param array $select 导出的数据
|
||||
*/
|
||||
public static function exportExcel($select): void
|
||||
{
|
||||
|
74
app/common/model/Banner/Banner.php
Normal file
74
app/common/model/Banner/Banner.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\Banner;
|
||||
|
||||
use app\common\arw\adjfut\src\Validate;
|
||||
use app\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
use app\common\arw\adjfut\src\Excel;
|
||||
use app\Request;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Db;
|
||||
|
||||
class Banner extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
// 删除字段
|
||||
protected $deleteTime = 'banner_delete_time';
|
||||
// 设置主键名
|
||||
protected $pk = 'banner_guid';
|
||||
// 设置废弃字段
|
||||
protected $disuse = [];
|
||||
// 设置字段信息
|
||||
protected $schema = [
|
||||
"banner_id" => "int",
|
||||
"banner_img" => "string",
|
||||
"banner_location" => "string",
|
||||
"banner_order" => "int",
|
||||
"banner_guid" => "string",
|
||||
"banner_create_time" => "datetime",
|
||||
"banner_create_user_guid" => "string",
|
||||
"banner_update_time" => "datetime",
|
||||
"banner_update_user_guid" => "string",
|
||||
"banner_delete_time" => "datetime",
|
||||
"banner_delete_user_guid" => "string",
|
||||
];
|
||||
// 设置json类型字段
|
||||
protected $json = [''];
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
// 创建时间
|
||||
protected $createTime = 'banner_create_time';
|
||||
// 修改时间
|
||||
protected $updateTime = 'banner_update_time';
|
||||
|
||||
//排序字段
|
||||
public $order_field = 'banner_order';
|
||||
|
||||
/**
|
||||
* 新增前
|
||||
*/
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
Tool::sortInsertProc(self::class, $model->banner_order, ['banner_location' => $model->banner_location]);
|
||||
$model->completeCreateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新前
|
||||
*/
|
||||
public static function onBeforeUpdate(self $model): void
|
||||
{
|
||||
Tool::sortEditProc(self::class, $model->banner_guid, $model->banner_order, ['banner_location' => $model->banner_location]);
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前
|
||||
*/
|
||||
public static function onBeforeDelete(self $model): void
|
||||
{
|
||||
Tool::sortDeleteProc(self::class, $model->banner_guid, ["banner_location"]);
|
||||
$model->completeDeleteField();
|
||||
}
|
||||
}
|
@ -119,7 +119,7 @@ class Signup extends BaseModel
|
||||
/**
|
||||
* 导出Excel
|
||||
*
|
||||
* @param array $select导出的数据集合
|
||||
* @param array $select 导出的数据
|
||||
*/
|
||||
public static function exportExcel(array $select): void
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ class Works extends BaseModel
|
||||
/**
|
||||
* 导出Excel
|
||||
*
|
||||
* @param array $select导出的数据集合
|
||||
* @param array $select 导出的数据
|
||||
*/
|
||||
public static function exportExcel(array $select): void
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ class WorksType extends BaseModel
|
||||
/**
|
||||
* 导出Excel
|
||||
*
|
||||
* @param array $select导出的数据集合
|
||||
* @param array $select 导出的数据
|
||||
*/
|
||||
public static function exportExcel(array $select): void
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user