feat:完成后台关于我们-教学环境-环境列表模块的接口、作品类型、环境类型模型层修改
This commit is contained in:
parent
9df4463d7e
commit
33308f234e
140
app/admin/controller/AboutUs/TeachingEnvir/TeachingEnvir.php
Normal file
140
app/admin/controller/AboutUs/TeachingEnvir/TeachingEnvir.php
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\controller\AboutUs\TeachingEnvir;
|
||||||
|
|
||||||
|
use app\BaseController;
|
||||||
|
use app\common\model\AboutUs\TeachingEnvir\TeachingEnvir as ModelTeachingEnvir;
|
||||||
|
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 TeachingEnvir extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取教学环境列表接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @return array
|
||||||
|
* @date 2023-04-22
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getTeachingEnvirList(Request $request): array
|
||||||
|
{
|
||||||
|
$con = Tool::getOptionalQuery(
|
||||||
|
['teaching_envir', 'LIKE'],
|
||||||
|
['teaching_envir_intro', 'LIKE'],
|
||||||
|
['teaching_envir_details', 'LIKE'],
|
||||||
|
['teaching_envir.teaching_envir_type_guid', '='],
|
||||||
|
);
|
||||||
|
|
||||||
|
$query = ModelTeachingEnvir::where($con)
|
||||||
|
->field([
|
||||||
|
'teaching_envir_id',
|
||||||
|
'teaching_envir_guid',
|
||||||
|
'teaching_envir',
|
||||||
|
'teaching_envir_img',
|
||||||
|
'teaching_envir_intro',
|
||||||
|
'teaching_envir_details',
|
||||||
|
'teaching_envir.teaching_envir_type_guid',
|
||||||
|
'teaching_envir_type_name',
|
||||||
|
])
|
||||||
|
->leftJoin('teaching_envir_type', 'teaching_envir_type.teaching_envir_type_guid = teaching_envir.teaching_envir_type_guid')
|
||||||
|
->order('teaching_envir_update_time', 'desc');
|
||||||
|
|
||||||
|
return msg("获取教学环境列表成功!", $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑教学环境接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @return array
|
||||||
|
* @date 2023-04-22
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function editTeachingEnvir(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'teaching_envir|教学环境标题' => 'require',
|
||||||
|
'teaching_envir_img|教学环境图片' => 'require',
|
||||||
|
'teaching_envir_intro|教学环境简介' => 'require',
|
||||||
|
'teaching_envir_details|教学环境详情' => 'require',
|
||||||
|
'teaching_envir_type_guid|教学环境类型guid' => 'require',
|
||||||
|
]);
|
||||||
|
$model = ModelTeachingEnvir::where('teaching_envir_guid', $params['teaching_envir_guid'])->find();
|
||||||
|
if (!$model) throwErrorMsg("该教学环境不存在", 1);
|
||||||
|
$model->allowField([
|
||||||
|
'teaching_envir_update_user_guid',
|
||||||
|
'teaching_envir',
|
||||||
|
'teaching_envir_img',
|
||||||
|
'teaching_envir_intro',
|
||||||
|
'teaching_envir_type_guid',
|
||||||
|
'teaching_envir_details'
|
||||||
|
])->save($params);
|
||||||
|
return msg('编辑成功!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加教学环境接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @return array
|
||||||
|
* @date 2023-04-22
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function addTeachingEnvir(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'teaching_envir|教学环境标题' => 'require',
|
||||||
|
'teaching_envir_img|教学环境图片' => 'require',
|
||||||
|
'teaching_envir_intro|教学环境简介' => 'require',
|
||||||
|
'teaching_envir_details|教学环境详情' => 'require',
|
||||||
|
'teaching_envir_type_guid|教学环境类型guid' => 'require',
|
||||||
|
]);
|
||||||
|
ModelTeachingEnvir::create($params, [
|
||||||
|
'teaching_envir_guid',
|
||||||
|
'teaching_envir_create_user_guid',
|
||||||
|
'teaching_envir_update_user_guid',
|
||||||
|
'teaching_envir',
|
||||||
|
'teaching_envir_img',
|
||||||
|
'teaching_envir_type_guid',
|
||||||
|
'teaching_envir_intro',
|
||||||
|
'teaching_envir_details'
|
||||||
|
]);
|
||||||
|
return msg('添加成功!');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除教学环境接口
|
||||||
|
*
|
||||||
|
* @param Request request
|
||||||
|
* @return array
|
||||||
|
* @date 2023-04-22
|
||||||
|
* @author xjh
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function deleteTeachingEnvir(Request $request): array
|
||||||
|
{
|
||||||
|
$params = $request->param();
|
||||||
|
$this->validate($params, [
|
||||||
|
'teaching_envir_guid' => 'require',
|
||||||
|
]);
|
||||||
|
$teaching_envir = ModelTeachingEnvir::where([
|
||||||
|
'teaching_envir_guid' => explode(',', $params['teaching_envir_guid'])
|
||||||
|
])->select();
|
||||||
|
$teaching_envir->delete();
|
||||||
|
return msg('删除成功!');
|
||||||
|
}
|
||||||
|
}
|
77
app/common/model/AboutUs/TeachingEnvir/TeachingEnvir.php
Normal file
77
app/common/model/AboutUs/TeachingEnvir/TeachingEnvir.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\common\model\AboutUs\TeachingEnvir;
|
||||||
|
|
||||||
|
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 TeachingEnvir extends BaseModel
|
||||||
|
{
|
||||||
|
use SoftDelete;
|
||||||
|
// 删除字段
|
||||||
|
protected $deleteTime = 'teaching_envir_delete_time';
|
||||||
|
// 设置主键名
|
||||||
|
protected $pk = 'teaching_envir_guid';
|
||||||
|
// 设置废弃字段
|
||||||
|
protected $disuse = [];
|
||||||
|
// 设置字段信息
|
||||||
|
protected $schema = [
|
||||||
|
"teaching_envir_id" => "int",
|
||||||
|
"teaching_envir_guid" => "string",
|
||||||
|
"teaching_envir_type_guid" => "string",
|
||||||
|
"teaching_envir" => "string",
|
||||||
|
"teaching_envir_img" => "string",
|
||||||
|
"teaching_envir_intro" => "string",
|
||||||
|
"teaching_envir_details" => "string",
|
||||||
|
"teaching_envir_create_time" => "datetime",
|
||||||
|
"teaching_envir_create_user_guid" => "string",
|
||||||
|
"teaching_envir_update_time" => "datetime",
|
||||||
|
"teaching_envir_update_user_guid" => "string",
|
||||||
|
"teaching_envir_delete_time" => "datetime",
|
||||||
|
"teaching_envir_delete_user_guid" => "string",
|
||||||
|
];
|
||||||
|
// 设置json类型字段
|
||||||
|
protected $json = [''];
|
||||||
|
// 开启自动写入时间戳字段
|
||||||
|
protected $autoWriteTimestamp = 'datetime';
|
||||||
|
// 创建时间
|
||||||
|
protected $createTime = 'teaching_envir_create_time';
|
||||||
|
// 修改时间
|
||||||
|
protected $updateTime = 'teaching_envir_update_time';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增前
|
||||||
|
*/
|
||||||
|
public static function onBeforeInsert(self $model): void
|
||||||
|
{
|
||||||
|
Validate::unique(
|
||||||
|
self::class,
|
||||||
|
$model->teaching_envir_type_guid,
|
||||||
|
$model->getData(),
|
||||||
|
['teaching_envir_type_guid' => '环境类型',],
|
||||||
|
['teaching_envir_type_guid' => '一个教学环境类型只能拥有一个教学环境数据']
|
||||||
|
);
|
||||||
|
$model->completeCreateField();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新前
|
||||||
|
*/
|
||||||
|
public static function onBeforeUpdate(self $model): void
|
||||||
|
{
|
||||||
|
$model->completeUpdateField();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除前
|
||||||
|
*/
|
||||||
|
public static function onBeforeDelete(self $model): void
|
||||||
|
{
|
||||||
|
$model->completeDeleteField();
|
||||||
|
}
|
||||||
|
}
|
@ -81,8 +81,8 @@ class TeachingEnvirType extends BaseModel
|
|||||||
Validate::unique(self::class, $model->teaching_envir_type_guid, $model->getData(), [
|
Validate::unique(self::class, $model->teaching_envir_type_guid, $model->getData(), [
|
||||||
'teaching_envir_type_name' => '环境类型名称',
|
'teaching_envir_type_name' => '环境类型名称',
|
||||||
]);
|
]);
|
||||||
Tool::handleEthicalRel($model);
|
// Tool::handleEthicalRel($model);
|
||||||
Tool::buildAncestorsGuid($model);
|
Tool::buildAncestorsGuid($model, true);
|
||||||
Tool::sortEditProc(
|
Tool::sortEditProc(
|
||||||
self::class,
|
self::class,
|
||||||
$model->teaching_envir_type_guid,
|
$model->teaching_envir_type_guid,
|
||||||
|
@ -66,7 +66,7 @@ class WorksType extends BaseModel
|
|||||||
Validate::unique(self::class, $model->works_type_guid, $model->getData(), [
|
Validate::unique(self::class, $model->works_type_guid, $model->getData(), [
|
||||||
'works_type_name' => '作品类型名称',
|
'works_type_name' => '作品类型名称',
|
||||||
]);
|
]);
|
||||||
Tool::buildAncestorsGuid($model);
|
Tool::buildAncestorsGuid($model, true);
|
||||||
Tool::sortInsertProc(
|
Tool::sortInsertProc(
|
||||||
self::class,
|
self::class,
|
||||||
$model->works_type_order,
|
$model->works_type_order,
|
||||||
@ -83,8 +83,8 @@ class WorksType extends BaseModel
|
|||||||
Validate::unique(self::class, $model->works_type_guid, $model->getData(), [
|
Validate::unique(self::class, $model->works_type_guid, $model->getData(), [
|
||||||
'works_type_name' => '作品类型名称',
|
'works_type_name' => '作品类型名称',
|
||||||
]);
|
]);
|
||||||
Tool::handleEthicalRel($model);
|
// Tool::handleEthicalRel($model);
|
||||||
Tool::buildAncestorsGuid($model);
|
Tool::buildAncestorsGuid($model, true);
|
||||||
Tool::sortEditProc(
|
Tool::sortEditProc(
|
||||||
self::class,
|
self::class,
|
||||||
$model->works_type_guid,
|
$model->works_type_guid,
|
||||||
|
Loading…
Reference in New Issue
Block a user