This commit is contained in:
ll 2023-04-27 19:52:58 +08:00
parent 8c55b39177
commit ac3520f826
9 changed files with 187 additions and 149 deletions

View File

@ -3,7 +3,7 @@
namespace app\admin\controller\ExaminationInformation\infoArticleType; namespace app\admin\controller\ExaminationInformation\infoArticleType;
use app\BaseController; use app\BaseController;
use app\common\model\ExaminationInformation\infoArticleType as ModelinfoArticleType; use app\common\model\ExaminationInformation\infoArticleType\infoArticleType as ModelinfoArticleType;
use app\Request; use app\Request;
use think\Validate; use think\Validate;
use think\exception\ValidateException; use think\exception\ValidateException;
@ -47,21 +47,28 @@ class infoArticleType extends BaseController
*/ */
public function editinfoArticleType(Request $request): array public function editinfoArticleType(Request $request): array
{ {
$params = $request->param(); Db::startTrans();
$this->validate($params, [ try {
'info_article_type_name|资讯类型名称' => 'require', $params = $request->param();
'info_article_type_sort|资讯类型排序' => 'require' $this->validate($params, [
]); 'info_article_type_name|资讯类型名称' => 'require',
$model = ModelinfoArticleType::where('info_article_type_guid', $params['info_article_type_guid'])->find(); 'info_article_type_sort|资讯类型排序' => 'require'
]);
$model = ModelinfoArticleType::where('info_article_type_guid', $params['info_article_type_guid'])->find();
if (!$model) throwErrorMsg("该资讯文章类型不存在", 1); if (!$model) throwErrorMsg("该资讯文章类型不存在", 1);
$model->allowField([ $model->allowField([
'info_article_type_update_user_guid', 'info_article_type_update_user_guid',
'info_article_type_name', 'info_article_type_name',
'info_article_type_sort' 'info_article_type_sort'
])->save($params); ])->save($params);
return msg('编辑成功!'); Db::commit();
return msg('编辑成功!');
} catch (\Throwable $th) {
Db::rollback();
throw $th;
}
} }
/** /**
@ -69,55 +76,73 @@ class infoArticleType extends BaseController
*/ */
public function addinfoArticleType(Request $request): array public function addinfoArticleType(Request $request): array
{ {
$params = $request->param(); Db::startTrans();
$this->validate($params, [ try {
'info_article_type_name|资讯类型名称' => 'require', $params = $request->param();
'info_article_type_sort|资讯类型排序' => 'require' $this->validate($params, [
]); 'info_article_type_name|资讯类型名称' => 'require',
'info_article_type_sort|资讯类型排序' => 'require'
$model = ModelinfoArticleType::create($params, [ ]);
'info_article_type_guid',
'info_article_type_create_user_guid',
'info_article_type_update_user_guid',
'info_article_type_name',
'info_article_type_sort'
]);
return msg('添加成功!');
}
$model = ModelinfoArticleType::create($params, [
'info_article_type_guid',
'info_article_type_create_user_guid',
'info_article_type_update_user_guid',
'info_article_type_name',
'info_article_type_sort'
]);
Db::commit();
return msg('编辑成功!');
} catch (\Throwable $th) {
Db::rollback();
throw $th;
}
}
/** /**
* 删除资讯文章类型 * 删除资讯文章类型
*/ */
public function deleteinfoArticleType(Request $request): array public function deleteinfoArticleType(Request $request): array
{ {
$params = $request->param(); Db::startTrans();
$this->validate($params, [ try {
'info_article_type_guid' => 'require', $params = $request->param();
]); $this->validate($params, [
$guids = explode(',', $params['info_article_type_guid']); 'info_article_type_guid' => 'require',
]);
$info_article_type = ModelinfoArticleType::where([ $guids = explode(',', $params['info_article_type_guid']);
'info_article_type_guid' => explode(',', $params['info_article_type_guid'])
])->select();
$info_article_type->delete();
return msg('删除成功!');
}
$info_article_type = ModelinfoArticleType::where([
'info_article_type_guid' => explode(',', $params['info_article_type_guid'])
])->select();
$info_article_type->delete();
Db::commit();
return msg('编辑成功!');
} catch (\Throwable $th) {
Db::rollback();
throw $th;
}
}
/** /**
* 导出Excel * 导出Excel
*/ */
public function exportExcel(Request $request) public function exportExcel(Request $request)
{ {
$params = $request->param(); Db::startTrans();
$select = ModelinfoArticleType::field([ try {
'info_article_type_name', $params = $request->param();
'info_article_type_sort' $select = ModelinfoArticleType::field([
]) 'info_article_type_name',
->order('info_article_type_update_time', 'desc') 'info_article_type_sort'
->select(); ])
return ModelinfoArticleType::exportExcel($select); ->order('info_article_type_update_time', 'desc')
->select();
Db::commit();
return msg('编辑成功!');
} catch (\Throwable $th) {
Db::rollback();
throw $th;
}
} }
/** /**
* 下载导入模板 * 下载导入模板
*/ */

View File

@ -1,9 +1,9 @@
<?php <?php
namespace app\admin\controller\Teachers_strength; namespace app\admin\controller\Teachers_Strength;
use app\BaseController; use app\BaseController;
use app\common\model\Teachers_strength\Teacher as ModelTeacher; use app\common\model\Teachers_Strength\Teacher as ModelTeacher;
use app\Request; use app\Request;
use think\Validate; use think\Validate;
use think\exception\ValidateException; use think\exception\ValidateException;

View File

@ -1,9 +1,9 @@
<?php <?php
namespace app\admin\controller\Teachers_strength; namespace app\admin\controller\Teachers_Strength;
use app\BaseController; use app\BaseController;
use app\common\model\Teachers_strength\Subject as ModelSubject; use app\common\model\Teachers_Strength\Subject as ModelSubject;
use app\Request; use app\Request;
use think\Validate; use think\Validate;
use think\exception\ValidateException; use think\exception\ValidateException;

View File

@ -3,7 +3,7 @@
namespace app\api\controller\Teachers; namespace app\api\controller\Teachers;
use app\BaseController; use app\BaseController;
use app\common\model\Teachers_strength\Teacher as ModelTeachers; use app\common\model\Teachers_Strength\Teacher as ModelTeachers;
use app\Request; use app\Request;
use think\Validate; use think\Validate;
use think\exception\ValidateException; use think\exception\ValidateException;

View File

@ -3,7 +3,7 @@
namespace app\api\controller\Subject; namespace app\api\controller\Subject;
use app\BaseController; use app\BaseController;
use app\common\model\Teachers_strength\Subject as ModelSubject; use app\common\model\Teachers_Strength\Subject as ModelSubject;
use app\Request; use app\Request;
use think\Validate; use think\Validate;
use think\exception\ValidateException; use think\exception\ValidateException;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace app\common\model\ExaminationInformation\infoArticle; namespace app\common\model\ExaminationInformation\InfoArticle;
use app\common\arw\adjfut\src\Validate; use app\common\arw\adjfut\src\Validate;
use app\BaseModel; use app\BaseModel;
@ -10,7 +10,7 @@ use app\Request;
use app\common\exception\Tool; use app\common\exception\Tool;
use think\facade\Db; use think\facade\Db;
class infoArticle extends BaseModel class InfoArticle extends BaseModel
{ {
use SoftDelete; use SoftDelete;
// 删除字段 // 删除字段

View File

@ -1,6 +1,6 @@
<?php <?php
namespace app\common\model\ExaminationInformation\infoArticleType; namespace app\common\model\ExaminationInformation\InfoArticleType;
use app\common\arw\adjfut\src\Validate; use app\common\arw\adjfut\src\Validate;
use app\BaseModel; use app\BaseModel;
@ -10,7 +10,7 @@ use app\Request;
use app\common\exception\Tool; use app\common\exception\Tool;
use think\facade\Db; use think\facade\Db;
class infoArticleType extends BaseModel class InfoArticleType extends BaseModel
{ {
use SoftDelete; use SoftDelete;
// 删除字段 // 删除字段
@ -21,28 +21,28 @@ class infoArticleType extends BaseModel
protected $disuse = []; protected $disuse = [];
// 设置字段信息 // 设置字段信息
protected $schema = [ protected $schema = [
"info_article_type_id" => "int", "info_article_type_id" => "int",
"info_article_type_guid" => "string", "info_article_type_guid" => "string",
"info_article_type_name" => "string", "info_article_type_name" => "string",
"info_article_type_sort" => "int", "info_article_type_sort" => "int",
"info_article_type_create_time" => "datetime", "info_article_type_create_time" => "datetime",
"info_article_type_create_user_guid" => "string", "info_article_type_create_user_guid" => "string",
"info_article_type_update_time" => "datetime", "info_article_type_update_time" => "datetime",
"info_article_type_update_user_guid" => "string", "info_article_type_update_user_guid" => "string",
"info_article_type_delete_time" => "datetime", "info_article_type_delete_time" => "datetime",
"info_article_type_delete_user_guid" => "string", "info_article_type_delete_user_guid" => "string",
]; ];
// 设置json类型字段 // 设置json类型字段
protected $json = ['']; protected $json = [''];
// 开启自动写入时间戳字段 // 开启自动写入时间戳字段
@ -52,20 +52,26 @@ class infoArticleType extends BaseModel
// 修改时间 // 修改时间
protected $updateTime = 'info_article_type_update_time'; protected $updateTime = 'info_article_type_update_time';
// excel导入/下载模板表头 // excel导入/下载模板表头
public const EXCELFIELD = [ public const EXCELFIELD = [
'info_article_type_name' => '资讯类型名称', 'info_article_type_name' => '资讯类型名称',
'info_article_type_sort' => '资讯类型排序', 'info_article_type_sort' => '资讯类型排序',
]; ];
//排序字段
public $order_field = 'info_article_type_sort';
/** /**
* 新增前 * 新增前
*/ */
public static function onBeforeInsert(self $model): void public static function onBeforeInsert(self $model): void
{ {
Tool::sortInsertProc(
self::class,
$model->info_article_type_order,
// ['subject_guid' => $model->subject_guid]
);
// self::checkRepeatData($model); // self::checkRepeatData($model);
$model->completeCreateField(); $model->completeCreateField();
} }
@ -75,6 +81,12 @@ class infoArticleType extends BaseModel
*/ */
public static function onBeforeUpdate(self $model): void public static function onBeforeUpdate(self $model): void
{ {
Tool::sortEditProc(
self::class,
$model->info_article_type_guid,
$model->info_article_type_sort,
// ['subject_guid' => $model->info_article_type_guid]
);
// self::checkRepeatData($model); // self::checkRepeatData($model);
$model->completeUpdateField(); $model->completeUpdateField();
} }
@ -84,72 +96,73 @@ class infoArticleType extends BaseModel
*/ */
public static function onBeforeDelete(self $model): void public static function onBeforeDelete(self $model): void
{ {
Tool::sortDeleteProc(self::class, $model->info_article_type_guid);
$model->completeDeleteField(); $model->completeDeleteField();
} }
/** /**
* 导出Excel * 导出Excel
*/ */
public static function exportExcel($select) public static function exportExcel($select)
{ {
$data = [[ $data = [[
'资讯类型名称', '资讯类型名称',
'资讯类型排序' '资讯类型排序'
]]; ]];
foreach ($select as $key => $val) { foreach ($select as $key => $val) {
$data[] = [ $data[] = [
$val['info_article_type_name'], $val['info_article_type_name'],
$val['info_article_type_sort'], $val['info_article_type_sort'],
]; ];
} }
$excel = (new Excel())->exporTsheet($data); $excel = (new Excel())->exporTsheet($data);
$excel->save('资讯文章类型.xlsx'); $excel->save('资讯文章类型.xlsx');
} }
/** /**
* 导入excel * 导入excel
*/ */
public static function importExcel($file) public static function importExcel($file)
{ {
$msg = []; $msg = [];
Db::startTrans(); Db::startTrans();
try { try {
$excel = new Excel($file); $excel = new Excel($file);
$data = $excel->parseExcel( $data = $excel->parseExcel(
Tool::getExcelRule(self::EXCELFIELD), Tool::getExcelRule(self::EXCELFIELD),
[ [
'titleLine' => [1] 'titleLine' => [1]
]); ]
if (!$data) throwErrorMsg('excel无数据', 1); );
$msg = []; if (!$data) throwErrorMsg('excel无数据', 1);
foreach ($data as $line => $value) { $msg = [];
try { foreach ($data as $line => $value) {
$model = self::importExcelInit($value); try {
$msg[] = "{$line} <span style='color:#27af49'>新增成功!</span><br>"; $model = self::importExcelInit($value);
} catch (\Throwable $th) { $msg[] = "{$line} <span style='color:#27af49'>新增成功!</span><br>";
$msg[] = "{$line} <span style='color:red'>{$th->getMessage()}</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;
}
} }
}
Db::commit();
return implode(', ', $msg);
} catch (\Throwable $th) {
Db::rollback();
throw $th;
}
}
/** /**
* 导入excel初始化 * 导入excel初始化
*/ */
public static function importExcelInit($value) public static function importExcelInit($value)
{ {
$info_article_type_name = $value['info_article_type_name'];$info_article_type_sort = $value['info_article_type_sort']; $info_article_type_name = $value['info_article_type_name'];
return self::create([ $info_article_type_sort = $value['info_article_type_sort'];
'info_article_type_name' => $info_article_type_name, return self::create([
'info_article_type_sort' => $info_article_type_sort, 'info_article_type_name' => $info_article_type_name,
]); 'info_article_type_sort' => $info_article_type_sort,
} ]);
}
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace app\common\model\Teachers_strength; namespace app\common\model\Teachers_Strength;
use app\common\arw\adjfut\src\Validate; use app\common\arw\adjfut\src\Validate;
use app\BaseModel; use app\BaseModel;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace app\common\model\Teachers_strength; namespace app\common\model\Teachers_Strength;
use app\common\arw\adjfut\src\Validate; use app\common\arw\adjfut\src\Validate;
use app\BaseModel; use app\BaseModel;