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

View File

@ -1,9 +1,9 @@
<?php
namespace app\admin\controller\Teachers_strength;
namespace app\admin\controller\Teachers_Strength;
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 think\Validate;
use think\exception\ValidateException;

View File

@ -3,7 +3,7 @@
namespace app\api\controller\Teachers;
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 think\Validate;
use think\exception\ValidateException;

View File

@ -3,7 +3,7 @@
namespace app\api\controller\Subject;
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 think\Validate;
use think\exception\ValidateException;

View File

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

View File

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

View File

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

View File

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