int
This commit is contained in:
parent
cec83457c5
commit
6ac26fe930
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app\admin\controller\infoArticle;
|
namespace app\admin\controller\ExaminationInformation\infoArticle;
|
||||||
|
|
||||||
use app\BaseController;
|
use app\BaseController;
|
||||||
use app\common\model\infoArticle\infoArticle as ModelinfoArticle;
|
use app\common\model\ExaminationInformation\infoArticle\infoArticle as ModelinfoArticle;
|
||||||
use app\Request;
|
use app\Request;
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app\admin\controller\infoArticleType;
|
namespace app\admin\controller\ExaminationInformation\infoArticleType;
|
||||||
|
|
||||||
use app\BaseController;
|
use app\BaseController;
|
||||||
use app\common\model\infoArticleType\infoArticleType as ModelinfoArticleType;
|
use app\common\model\ExaminationInformation\infoArticleType as ModelinfoArticleType;
|
||||||
use app\Request;
|
use app\Request;
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
@ -25,19 +25,22 @@ class Teacher extends BaseController
|
|||||||
$params = $request->param();
|
$params = $request->param();
|
||||||
$con = [];
|
$con = [];
|
||||||
|
|
||||||
$con = Tool::getOptionalQuery(['teacher_name', 'LIKE'], ['teacher_position', '='], ['subject_guid', '='],);
|
$con = Tool::getOptionalQuery(['teacher_name', 'LIKE'], ['teacher_position', 'LIKE'], ['a.subject_guid', '='],);
|
||||||
|
|
||||||
$query = ModelTeacher::where($con)
|
$query = ModelTeacher::where($con)
|
||||||
->field([
|
->field([
|
||||||
'teacher_id',
|
'a.teacher_id',
|
||||||
'teacher_guid',
|
'a.teacher_guid',
|
||||||
'teacher_name',
|
'a.teacher_name',
|
||||||
'teacher_position',
|
'a.teacher_position',
|
||||||
'teacher_img',
|
'a.teacher_img',
|
||||||
'subject_guid',
|
'a.subject_guid',
|
||||||
'teacher_intro',
|
'b.subject_name',
|
||||||
'teacher_order'
|
'a.teacher_intro',
|
||||||
|
'a.teacher_order'
|
||||||
])
|
])
|
||||||
|
->alias('a')
|
||||||
|
->leftJoin('subject b', 'a.subject_guid = b.subject_guid')
|
||||||
->order('teacher_update_time', 'desc');
|
->order('teacher_update_time', 'desc');
|
||||||
|
|
||||||
return msg("获取教师列表成功!", $query);
|
return msg("获取教师列表成功!", $query);
|
||||||
@ -48,27 +51,34 @@ class Teacher extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function editTeacher(Request $request): array
|
public function editTeacher(Request $request): array
|
||||||
{
|
{
|
||||||
$params = $request->param();
|
Db::startTrans();
|
||||||
$this->validate($params, [
|
try {
|
||||||
'teacher_name|教师名称' => 'require',
|
$params = $request->param();
|
||||||
'teacher_position|教师职位' => 'require',
|
$this->validate($params, [
|
||||||
'teacher_img|教师图片' => 'require',
|
'teacher_name|教师名称' => 'require',
|
||||||
'subject_guid|授课科目' => 'require',
|
'teacher_position|教师职位' => 'require',
|
||||||
'teacher_intro|教师简介' => 'require',
|
'teacher_img|教师图片' => 'require',
|
||||||
'teacher_order|教师排序' => 'require'
|
'subject_guid|授课科目' => 'require',
|
||||||
]);
|
'teacher_intro|教师简介' => 'require',
|
||||||
$model = ModelTeacher::where('teacher_guid', $params['teacher_guid'])->find();
|
'teacher_order|教师排序' => 'require'
|
||||||
if (!$model) throwErrorMsg("该教师不存在", 1);
|
]);
|
||||||
$model->allowField([
|
$model = ModelTeacher::where('teacher_guid', $params['teacher_guid'])->find();
|
||||||
'teacher_update_user_guid',
|
if (!$model) throwErrorMsg("该教师不存在", 1);
|
||||||
'teacher_name',
|
$model->allowField([
|
||||||
'teacher_position',
|
'teacher_update_user_guid',
|
||||||
'teacher_img',
|
'teacher_name',
|
||||||
'subject_guid',
|
'teacher_position',
|
||||||
'teacher_intro',
|
'teacher_img',
|
||||||
'teacher_order'
|
'subject_guid',
|
||||||
])->save($params);
|
'teacher_intro',
|
||||||
return msg('编辑成功!');
|
'teacher_order'
|
||||||
|
])->save($params);
|
||||||
|
Db::commit();
|
||||||
|
return msg('编辑成功!');
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Db::rollback();
|
||||||
|
throw $th;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,44 +86,57 @@ class Teacher extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function addTeacher(Request $request): array
|
public function addTeacher(Request $request): array
|
||||||
{
|
{
|
||||||
$params = $request->param();
|
Db::startTrans();
|
||||||
$this->validate($params, [
|
try {
|
||||||
'teacher_name|教师名称' => 'require',
|
$params = $request->param();
|
||||||
'teacher_position|教师职位' => 'require',
|
$this->validate($params, [
|
||||||
'teacher_img|教师图片' => 'require',
|
'teacher_name|教师名称' => 'require',
|
||||||
'subject_guid|授课科目' => 'require',
|
'teacher_position|教师职位' => 'require',
|
||||||
'teacher_intro|教师简介' => 'require',
|
'teacher_img|教师图片' => 'require',
|
||||||
'teacher_order|教师排序' => 'require'
|
'subject_guid|授课科目' => 'require',
|
||||||
]);
|
'teacher_intro|教师简介' => 'require',
|
||||||
$model = ModelTeacher::create($params, [
|
'teacher_order|教师排序' => 'require'
|
||||||
'teacher_guid',
|
]);
|
||||||
'teacher_create_user_guid',
|
$model = ModelTeacher::create($params, [
|
||||||
'teacher_update_user_guid',
|
'teacher_guid',
|
||||||
'teacher_name',
|
'teacher_create_user_guid',
|
||||||
'teacher_position',
|
'teacher_update_user_guid',
|
||||||
'teacher_img',
|
'teacher_name',
|
||||||
'subject_guid',
|
'teacher_position',
|
||||||
'teacher_intro',
|
'teacher_img',
|
||||||
'teacher_order'
|
'subject_guid',
|
||||||
]);
|
'teacher_intro',
|
||||||
return msg('添加成功!');
|
'teacher_order'
|
||||||
|
]);
|
||||||
|
Db::commit();
|
||||||
|
return msg('添加成功!');
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Db::rollback();
|
||||||
|
throw $th;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除教师
|
* 删除教师
|
||||||
*/
|
*/
|
||||||
public function deleteTeacher(Request $request): array
|
public function deleteTeacher(Request $request): array
|
||||||
{
|
{ Db::startTrans();
|
||||||
$params = $request->param();
|
try {
|
||||||
$this->validate($params, [
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
'teacher_guid' => 'require',
|
'teacher_guid' => 'require',
|
||||||
]);
|
]);
|
||||||
$teacher = ModelTeacher::where([
|
$teacher = ModelTeacher::where([
|
||||||
'teacher_guid' => explode(',', $params['teacher_guid'])
|
'teacher_guid' => explode(',', $params['teacher_guid'])
|
||||||
])->select();
|
])->select();
|
||||||
$teacher->delete();
|
$teacher->delete();
|
||||||
|
Db::commit();
|
||||||
return msg('删除成功!');
|
return msg('删除成功!');
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Db::rollback();
|
||||||
|
throw $th;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出Excel
|
* 导出Excel
|
||||||
@ -121,16 +144,8 @@ class Teacher extends BaseController
|
|||||||
public function exportExcel(Request $request)
|
public function exportExcel(Request $request)
|
||||||
{
|
{
|
||||||
$params = $request->param();
|
$params = $request->param();
|
||||||
$select = ModelTeacher::field([
|
$params['limit'] = 10000;
|
||||||
'teacher_name',
|
$select = self::getTeacherList($request)['data'];
|
||||||
'teacher_position',
|
|
||||||
'teacher_img',
|
|
||||||
'subject_guid',
|
|
||||||
'teacher_intro',
|
|
||||||
'teacher_order'
|
|
||||||
])
|
|
||||||
->order('teacher_update_time', 'desc')
|
|
||||||
->select();
|
|
||||||
return ModelTeacher::exportExcel($select);
|
return ModelTeacher::exportExcel($select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,8 @@ class Subject extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function editSubject(Request $request): array
|
public function editSubject(Request $request): array
|
||||||
{
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
$params = $request->param();
|
$params = $request->param();
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'subject_name|科目名字' => 'require',
|
'subject_name|科目名字' => 'require',
|
||||||
@ -56,14 +58,21 @@ class Subject extends BaseController
|
|||||||
'subject_name',
|
'subject_name',
|
||||||
'subject_sort'
|
'subject_sort'
|
||||||
])->save($params);
|
])->save($params);
|
||||||
|
Db::commit();
|
||||||
return msg('编辑成功!');
|
return msg('编辑成功!');
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Db::rollback();
|
||||||
|
throw $th;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加授课科目
|
* 添加授课科目
|
||||||
*/
|
*/
|
||||||
public function addSubject(Request $request): array
|
public function addSubject(Request $request): array
|
||||||
{
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
$params = $request->param();
|
$params = $request->param();
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'subject_name|科目名字' => 'require',
|
'subject_name|科目名字' => 'require',
|
||||||
@ -76,14 +85,20 @@ class Subject extends BaseController
|
|||||||
'subject_name',
|
'subject_name',
|
||||||
'subject_sort'
|
'subject_sort'
|
||||||
]);
|
]);
|
||||||
return msg('添加成功!');
|
Db::commit();
|
||||||
|
return msg('编辑成功!');
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Db::rollback();
|
||||||
|
throw $th;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 删除授课科目
|
* 删除授课科目
|
||||||
*/
|
*/
|
||||||
public function deleteSubject(Request $request): array
|
public function deleteSubject(Request $request): array
|
||||||
{
|
{
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
$params = $request->param();
|
$params = $request->param();
|
||||||
$this->validate($params, [
|
$this->validate($params, [
|
||||||
'subject_guid' => 'require',
|
'subject_guid' => 'require',
|
||||||
@ -92,9 +107,13 @@ class Subject extends BaseController
|
|||||||
'subject_guid' => explode(',', $params['subject_guid'])
|
'subject_guid' => explode(',', $params['subject_guid'])
|
||||||
])->select();
|
])->select();
|
||||||
$subject->delete();
|
$subject->delete();
|
||||||
return msg('删除成功!');
|
Db::commit();
|
||||||
|
return msg('编辑成功!');
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
Db::rollback();
|
||||||
|
throw $th;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 导出Excel
|
* 导出Excel
|
||||||
*/
|
*/
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app\api\controller\infoArticle;
|
namespace app\api\controller\ExaminationInformation\infoArticle;
|
||||||
|
|
||||||
use app\BaseController;
|
use app\BaseController;
|
||||||
use app\common\model\infoArticle\infoArticle as ModelinfoArticle;
|
use app\common\model\ExaminationInformation\infoArticle\infoArticle as ModelinfoArticle;
|
||||||
use app\Request;
|
use app\Request;
|
||||||
use think\Validate;
|
use think\Validate;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app\api\controller\infoArticleType;
|
namespace app\api\controller\ExaminationInformation\infoArticleType;
|
||||||
|
|
||||||
use app\BaseController;
|
use app\BaseController;
|
||||||
use app\common\model\infoArticleType\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;
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app\common\model\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;
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app\common\model\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;
|
@ -21,36 +21,36 @@ class Teacher extends BaseModel
|
|||||||
protected $disuse = [];
|
protected $disuse = [];
|
||||||
// 设置字段信息
|
// 设置字段信息
|
||||||
protected $schema = [
|
protected $schema = [
|
||||||
|
|
||||||
"teacher_id" => "int",
|
"teacher_id" => "int",
|
||||||
|
|
||||||
"teacher_guid" => "string",
|
"teacher_guid" => "string",
|
||||||
|
|
||||||
"teacher_name" => "string",
|
"teacher_name" => "string",
|
||||||
|
|
||||||
"teacher_position" => "int",
|
"teacher_position" => "string",
|
||||||
|
|
||||||
"teacher_img" => "string",
|
"teacher_img" => "string",
|
||||||
|
|
||||||
"subject_guid" => "string",
|
"subject_guid" => "string",
|
||||||
|
|
||||||
"teacher_intro" => "string",
|
"teacher_intro" => "string",
|
||||||
|
|
||||||
"teacher_order" => "int",
|
"teacher_order" => "int",
|
||||||
|
|
||||||
"teacher_create_time" => "datetime",
|
"teacher_create_time" => "datetime",
|
||||||
|
|
||||||
"teacher_create_user_guid" => "string",
|
"teacher_create_user_guid" => "string",
|
||||||
|
|
||||||
"teacher_update_time" => "datetime",
|
"teacher_update_time" => "datetime",
|
||||||
|
|
||||||
"teacher_update_user_guid" => "string",
|
"teacher_update_user_guid" => "string",
|
||||||
|
|
||||||
"teacher_delete_time" => "datetime",
|
"teacher_delete_time" => "datetime",
|
||||||
|
|
||||||
"teacher_delete_user_guid" => "string",
|
"teacher_delete_user_guid" => "string",
|
||||||
|
|
||||||
];
|
];
|
||||||
// 设置json类型字段
|
// 设置json类型字段
|
||||||
protected $json = [''];
|
protected $json = [''];
|
||||||
// 开启自动写入时间戳字段
|
// 开启自动写入时间戳字段
|
||||||
@ -60,25 +60,31 @@ class Teacher extends BaseModel
|
|||||||
// 修改时间
|
// 修改时间
|
||||||
protected $updateTime = 'teacher_update_time';
|
protected $updateTime = 'teacher_update_time';
|
||||||
|
|
||||||
|
|
||||||
// excel导入/下载模板表头
|
|
||||||
public const EXCELFIELD = [
|
|
||||||
'teacher_name' => '教师名称',
|
|
||||||
'teacher_position' => '教师职位',
|
|
||||||
'teacher_img' => '教师图片',
|
|
||||||
'subject_guid' => '授课科目',
|
|
||||||
'teacher_intro' => '教师简介',
|
|
||||||
'teacher_order' => '教师排序',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
|
// excel导入/下载模板表头
|
||||||
|
public const EXCELFIELD = [
|
||||||
|
'teacher_name' => '教师名称',
|
||||||
|
'teacher_position' => '教师职位',
|
||||||
|
'teacher_img' => '教师图片',
|
||||||
|
'subject_guid' => '授课科目',
|
||||||
|
'teacher_intro' => '教师简介',
|
||||||
|
'teacher_order' => '教师排序',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
//排序字段
|
||||||
|
public $order_field = 'teacher_order';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增前
|
* 新增前
|
||||||
*/
|
*/
|
||||||
public static function onBeforeInsert(self $model): void
|
public static function onBeforeInsert(self $model): void
|
||||||
{
|
{
|
||||||
// self::checkRepeatData($model);
|
Tool::sortInsertProc(
|
||||||
|
self::class,
|
||||||
|
$model->teacher_order,
|
||||||
|
['subject_guid' => $model->subject_guid]
|
||||||
|
);
|
||||||
$model->completeCreateField();
|
$model->completeCreateField();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +93,12 @@ class Teacher extends BaseModel
|
|||||||
*/
|
*/
|
||||||
public static function onBeforeUpdate(self $model): void
|
public static function onBeforeUpdate(self $model): void
|
||||||
{
|
{
|
||||||
// self::checkRepeatData($model);
|
Tool::sortEditProc(
|
||||||
|
self::class,
|
||||||
|
$model->teacher_guid,
|
||||||
|
$model->teacher_order,
|
||||||
|
['subject_guid' => $model->subject_guid]
|
||||||
|
);
|
||||||
$model->completeUpdateField();
|
$model->completeUpdateField();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,84 +107,89 @@ class Teacher extends BaseModel
|
|||||||
*/
|
*/
|
||||||
public static function onBeforeDelete(self $model): void
|
public static function onBeforeDelete(self $model): void
|
||||||
{
|
{
|
||||||
|
Tool::sortDeleteProc(self::class, $model->teacher_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['teacher_name'],
|
$val['teacher_name'],
|
||||||
$val['teacher_position'],
|
$val['teacher_position'],
|
||||||
Excel::ExportImgFiled($val['teacher_img']),
|
Excel::ExportImgFiled($val['teacher_img']),
|
||||||
$val['subject_guid'],
|
$val['subject_guid'],
|
||||||
$val['teacher_intro'],
|
$val['teacher_intro'],
|
||||||
$val['teacher_order'],
|
$val['teacher_order'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
$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)
|
||||||
{
|
{
|
||||||
$teacher_name = $value['teacher_name'];$teacher_position = $value['teacher_position'];$teacher_img = $value['teacher_img'];$subject_guid = $value['subject_guid'];$teacher_intro = $value['teacher_intro'];$teacher_order = $value['teacher_order'];
|
$teacher_name = $value['teacher_name'];
|
||||||
return self::create([
|
$teacher_position = $value['teacher_position'];
|
||||||
'teacher_name' => $teacher_name,
|
$teacher_img = $value['teacher_img'];
|
||||||
'teacher_position' => $teacher_position,
|
$subject_guid = $value['subject_guid'];
|
||||||
'teacher_img' => $teacher_img,
|
$teacher_intro = $value['teacher_intro'];
|
||||||
'subject_guid' => $subject_guid,
|
$teacher_order = $value['teacher_order'];
|
||||||
'teacher_intro' => $teacher_intro,
|
return self::create([
|
||||||
'teacher_order' => $teacher_order,
|
'teacher_name' => $teacher_name,
|
||||||
]);
|
'teacher_position' => $teacher_position,
|
||||||
}
|
'teacher_img' => $teacher_img,
|
||||||
|
'subject_guid' => $subject_guid,
|
||||||
|
'teacher_intro' => $teacher_intro,
|
||||||
|
'teacher_order' => $teacher_order,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,28 +21,28 @@ class Subject extends BaseModel
|
|||||||
protected $disuse = [];
|
protected $disuse = [];
|
||||||
// 设置字段信息
|
// 设置字段信息
|
||||||
protected $schema = [
|
protected $schema = [
|
||||||
|
|
||||||
"subject_id" => "int",
|
"subject_id" => "int",
|
||||||
|
|
||||||
"subject_guid" => "string",
|
"subject_guid" => "string",
|
||||||
|
|
||||||
"subject_name" => "string",
|
"subject_name" => "string",
|
||||||
|
|
||||||
"subject_sort" => "int",
|
"subject_sort" => "int",
|
||||||
|
|
||||||
"subject_create_time" => "datetime",
|
"subject_create_time" => "datetime",
|
||||||
|
|
||||||
"subject_create_user_guid" => "string",
|
"subject_create_user_guid" => "string",
|
||||||
|
|
||||||
"subject_update_time" => "datetime",
|
"subject_update_time" => "datetime",
|
||||||
|
|
||||||
"subject_update_user_guid" => "string",
|
"subject_update_user_guid" => "string",
|
||||||
|
|
||||||
"subject_delete_time" => "datetime",
|
"subject_delete_time" => "datetime",
|
||||||
|
|
||||||
"subject_delete_user_guid" => "string",
|
"subject_delete_user_guid" => "string",
|
||||||
|
|
||||||
];
|
];
|
||||||
// 设置json类型字段
|
// 设置json类型字段
|
||||||
protected $json = [''];
|
protected $json = [''];
|
||||||
// 开启自动写入时间戳字段
|
// 开启自动写入时间戳字段
|
||||||
@ -52,14 +52,15 @@ class Subject extends BaseModel
|
|||||||
// 修改时间
|
// 修改时间
|
||||||
protected $updateTime = 'subject_update_time';
|
protected $updateTime = 'subject_update_time';
|
||||||
|
|
||||||
|
|
||||||
// excel导入/下载模板表头
|
|
||||||
public const EXCELFIELD = [
|
|
||||||
'subject_name' => '科目名字',
|
|
||||||
'subject_sort' => '排序',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
|
// excel导入/下载模板表头
|
||||||
|
public const EXCELFIELD = [
|
||||||
|
'subject_name' => '科目名字',
|
||||||
|
'subject_sort' => '排序',
|
||||||
|
];
|
||||||
|
|
||||||
|
//排序字段
|
||||||
|
public $order_field = 'subject_sort';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增前
|
* 新增前
|
||||||
@ -67,6 +68,11 @@ class Subject extends BaseModel
|
|||||||
public static function onBeforeInsert(self $model): void
|
public static function onBeforeInsert(self $model): void
|
||||||
{
|
{
|
||||||
// self::checkRepeatData($model);
|
// self::checkRepeatData($model);
|
||||||
|
Tool::sortInsertProc(
|
||||||
|
self::class,
|
||||||
|
$model->subject_sort,
|
||||||
|
|
||||||
|
);
|
||||||
$model->completeCreateField();
|
$model->completeCreateField();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +81,14 @@ class Subject extends BaseModel
|
|||||||
*/
|
*/
|
||||||
public static function onBeforeUpdate(self $model): void
|
public static function onBeforeUpdate(self $model): void
|
||||||
{
|
{
|
||||||
|
|
||||||
// self::checkRepeatData($model);
|
// self::checkRepeatData($model);
|
||||||
|
Tool::sortEditProc(
|
||||||
|
self::class,
|
||||||
|
$model->subject_guid,
|
||||||
|
$model->subject_sort,
|
||||||
|
|
||||||
|
);
|
||||||
$model->completeUpdateField();
|
$model->completeUpdateField();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,72 +97,73 @@ class Subject extends BaseModel
|
|||||||
*/
|
*/
|
||||||
public static function onBeforeDelete(self $model): void
|
public static function onBeforeDelete(self $model): void
|
||||||
{
|
{
|
||||||
|
Tool::sortDeleteProc(self::class, $model->subject_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['subject_name'],
|
$val['subject_name'],
|
||||||
$val['subject_sort'],
|
$val['subject_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)
|
||||||
{
|
{
|
||||||
$subject_name = $value['subject_name'];$subject_sort = $value['subject_sort'];
|
$subject_name = $value['subject_name'];
|
||||||
return self::create([
|
$subject_sort = $value['subject_sort'];
|
||||||
'subject_name' => $subject_name,
|
return self::create([
|
||||||
'subject_sort' => $subject_sort,
|
'subject_name' => $subject_name,
|
||||||
]);
|
'subject_sort' => $subject_sort,
|
||||||
}
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user