feat:Tool类新增封装方法、后台+前台招生问答模块接口修改
This commit is contained in:
parent
e89105dd88
commit
b59bd41817
@ -47,23 +47,31 @@ class EnrolAq extends BaseController
|
||||
*/
|
||||
public function editEnrolAq(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
]);
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$params['enrol_aq_answer_status'] = 2;
|
||||
$params = $request->param();
|
||||
$this->validate($params, []);
|
||||
|
||||
$model = ModelEnrolAq::where('enrol_aq_guid', $params['enrol_aq_guid'])->find();
|
||||
if (!$model) throwErrorMsg("该招生问答不存在", 1);
|
||||
$model->allowField([
|
||||
'enrol_aq_update_user_guid',
|
||||
'enrol_aq_question',
|
||||
'enrol_aq_answer',
|
||||
'enrol_aq_sort',
|
||||
'enrol_aq_status',
|
||||
'enrol_aq_answer_status'
|
||||
])->save($params);
|
||||
return msg('编辑成功!');
|
||||
$params['enrol_aq_answer_status'] = 2;
|
||||
|
||||
$model = ModelEnrolAq::where('enrol_aq_guid', $params['enrol_aq_guid'])->find();
|
||||
if (!$model) throwErrorMsg("该招生问答不存在", 1);
|
||||
$model->allowField([
|
||||
'enrol_aq_update_user_guid',
|
||||
'enrol_aq_question',
|
||||
'enrol_aq_answer',
|
||||
'enrol_aq_sort',
|
||||
'enrol_aq_status',
|
||||
'enrol_aq_answer_status'
|
||||
])->save($params);
|
||||
|
||||
Db::commit();
|
||||
return msg('编辑成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,15 +79,23 @@ class EnrolAq extends BaseController
|
||||
*/
|
||||
public function deleteEnrolAq(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'enrol_aq_guid' => 'require',
|
||||
]);
|
||||
$enrol_aq = ModelEnrolAq::where([
|
||||
'enrol_aq_guid' => explode(',', $params['enrol_aq_guid'])
|
||||
])->select();
|
||||
$enrol_aq->delete();
|
||||
return msg('删除成功!');
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'enrol_aq_guid' => 'require',
|
||||
]);
|
||||
$enrol_aq = ModelEnrolAq::where([
|
||||
'enrol_aq_guid' => explode(',', $params['enrol_aq_guid'])
|
||||
])->select();
|
||||
$enrol_aq->delete();
|
||||
|
||||
Db::commit();
|
||||
return msg('删除成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,8 +37,8 @@ class EnrolAq extends BaseController
|
||||
'enrol_aq_status',
|
||||
'enrol_aq_answer_status'
|
||||
])
|
||||
->where('enrol_aq_status',2)
|
||||
->where('enrol_aq_answer_status',2)
|
||||
->where('enrol_aq_status', 2)
|
||||
->where('enrol_aq_answer_status', 2)
|
||||
->order('enrol_aq_sort', 'asc');
|
||||
|
||||
|
||||
@ -52,25 +52,28 @@ class EnrolAq extends BaseController
|
||||
*/
|
||||
public function addEnrolAq(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'enrol_aq_question|问题' => 'require',
|
||||
]);
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'enrol_aq_question|问题' => 'require',
|
||||
]);
|
||||
|
||||
// $params['enrol_aq_sort'] = 0;
|
||||
// $params['enrol_aq_status'] = 1;
|
||||
// $params['enrol_aq_answer_status'] = 1;
|
||||
ModelEnrolAq::create($params, [
|
||||
'enrol_aq_guid',
|
||||
'enrol_aq_create_user_guid',
|
||||
'enrol_aq_update_user_guid',
|
||||
'enrol_aq_question',
|
||||
'enrol_aq_sort',
|
||||
'enrol_aq_status',
|
||||
'enrol_aq_answer_status'
|
||||
]);
|
||||
|
||||
$model = ModelEnrolAq::create($params, [
|
||||
'enrol_aq_guid',
|
||||
'enrol_aq_create_user_guid',
|
||||
'enrol_aq_update_user_guid',
|
||||
'enrol_aq_question',
|
||||
'enrol_aq_sort',
|
||||
'enrol_aq_status',
|
||||
'enrol_aq_answer_status'
|
||||
]);
|
||||
return msg('添加成功!');
|
||||
Db::commit();
|
||||
return msg('添加成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ class Tool
|
||||
|
||||
/**
|
||||
* 祖级guid构建
|
||||
* @param string 模型层对象
|
||||
* @param string $model 模型层命名空间地址
|
||||
* @param string $parent_guid 父级guid
|
||||
* @param string $first_parent 首父级值 默认"0"
|
||||
*/
|
||||
@ -458,4 +458,17 @@ class Tool
|
||||
if (!$parent) throwErrorMsg('该父级数据不存在!');
|
||||
return $parent[$ancestors_guid_field] . ',' . $parent_guid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化模型字段值
|
||||
*
|
||||
* @param \think\Model &$model 模型层对象(引用传递)
|
||||
* @param array $field_values 初始化字段信息 例: ['user_name'=>'张三',...]
|
||||
*/
|
||||
public static function initModelFieldValue(\think\Model &$model, array $field_values): void
|
||||
{
|
||||
foreach ($field_values as $field => $value) {
|
||||
$model[$field] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,11 @@ class EnrolAq extends BaseModel
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
BaseModel::setUserGuid(false);
|
||||
self::createFieldInit($model);
|
||||
Tool::initModelFieldValue($model, [
|
||||
'enrol_aq_sort' => 0,
|
||||
'enrol_aq_status' => 1,
|
||||
'enrol_aq_answer_status' => 1,
|
||||
]);
|
||||
Tool::sortInsertProc(
|
||||
self::class,
|
||||
$model->enrol_aq_sort,
|
||||
@ -122,14 +126,4 @@ class EnrolAq extends BaseModel
|
||||
$excel = (new Excel())->exporTsheet($data);
|
||||
$excel->save('招生问答.xlsx');
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增前字段初始化
|
||||
*/
|
||||
public static function createFieldInit(self &$model): void
|
||||
{
|
||||
$model->enrol_aq_sort = 1;
|
||||
$model->enrol_aq_status = 1;
|
||||
$model->enrol_aq_answer_status = 1;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user