feat:初始化招生问答模块
This commit is contained in:
parent
eb6f525c67
commit
601a5b9181
126
app/admin/controller/Enrol/EnrolAq.php
Normal file
126
app/admin/controller/Enrol/EnrolAq.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\Enrol;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\Enrol\EnrolAq as ModelEnrolAq;
|
||||
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 EnrolAq extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取招生问答列表
|
||||
*/
|
||||
public function getEnrolAqList(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$con = [];
|
||||
|
||||
$con = Tool::getOptionalQuery(['enrol_aq_question', 'LIKE'], ['enrol_aq_status', '='], ['enrol_aq_answer_status', '='],);
|
||||
|
||||
$query = ModelEnrolAq::where($con)
|
||||
->field([
|
||||
'enrol_aq_id',
|
||||
'enrol_aq_guid',
|
||||
'enrol_aq_question',
|
||||
'enrol_aq_answer',
|
||||
'enrol_aq_sort',
|
||||
'enrol_aq_status',
|
||||
'enrol_aq_answer_status'
|
||||
])
|
||||
->order('enrol_aq_sort', 'asc');
|
||||
|
||||
return msg("获取招生问答列表成功!", $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑招生问答
|
||||
*/
|
||||
public function editEnrolAq(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'enrol_aq_question|问题' => 'require',
|
||||
'enrol_aq_answer|答案' => 'require',
|
||||
'enrol_aq_sort|排序' => 'require'
|
||||
]);
|
||||
$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('编辑成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加招生问答
|
||||
*/
|
||||
public function addEnrolAq(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'enrol_aq_question|问题' => 'require',
|
||||
'enrol_aq_answer|答案' => 'require',
|
||||
'enrol_aq_sort|排序' => 'require'
|
||||
]);
|
||||
$model = ModelEnrolAq::create($params, [
|
||||
'enrol_aq_guid',
|
||||
'enrol_aq_create_user_guid',
|
||||
'enrol_aq_update_user_guid',
|
||||
'enrol_aq_question',
|
||||
'enrol_aq_answer',
|
||||
'enrol_aq_sort',
|
||||
'enrol_aq_status',
|
||||
'enrol_aq_answer_status'
|
||||
]);
|
||||
return msg('添加成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除招生问答
|
||||
*/
|
||||
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('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出Excel
|
||||
*/
|
||||
public function exportExcel(Request $request)
|
||||
{
|
||||
$params = $request->param();
|
||||
$select = ModelEnrolAq::field([
|
||||
'enrol_aq_question',
|
||||
'enrol_aq_answer',
|
||||
'enrol_aq_sort',
|
||||
'enrol_aq_status',
|
||||
'enrol_aq_answer_status'
|
||||
])
|
||||
->order('enrol_aq_sort', 'asc')
|
||||
->select();
|
||||
return ModelEnrolAq::exportExcel($select);
|
||||
}
|
||||
}
|
76
app/api/controller/Enrol/EnrolAq.php
Normal file
76
app/api/controller/Enrol/EnrolAq.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\Enrol;
|
||||
|
||||
use app\BaseController;
|
||||
use app\common\model\Enrol\EnrolAq as ModelEnrolAq;
|
||||
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 think\facade\Db;
|
||||
use app\common\exception\Tool;
|
||||
use think\facade\Env;
|
||||
|
||||
|
||||
class EnrolAq extends BaseController
|
||||
{
|
||||
/**
|
||||
* 获取招生问答列表
|
||||
*/
|
||||
public function getEnrolAqList(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$con = [];
|
||||
|
||||
$con = Tool::getOptionalQuery(['enrol_aq_question', 'LIKE'], ['enrol_aq_status', '='], ['enrol_aq_answer_status', '='],);
|
||||
|
||||
$query = ModelEnrolAq::where($con)
|
||||
->field([
|
||||
'enrol_aq_id',
|
||||
'enrol_aq_guid',
|
||||
'enrol_aq_question',
|
||||
'enrol_aq_answer',
|
||||
'enrol_aq_sort',
|
||||
'enrol_aq_status',
|
||||
'enrol_aq_answer_status'
|
||||
])
|
||||
->where('enrol_aq_status',2)
|
||||
->where('enrol_aq_answer_status',2)
|
||||
->order('enrol_aq_sort', 'asc');
|
||||
|
||||
|
||||
|
||||
return msg("获取招生问答列表成功!", $query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加招生问答
|
||||
*/
|
||||
public function addEnrolAq(Request $request): array
|
||||
{
|
||||
$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;
|
||||
|
||||
$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('添加成功!');
|
||||
}
|
||||
|
||||
}
|
120
app/common/model/Enrol/EnrolAq.php
Normal file
120
app/common/model/Enrol/EnrolAq.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model\Enrol;
|
||||
|
||||
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 EnrolAq extends BaseModel
|
||||
{
|
||||
use SoftDelete;
|
||||
// 删除字段
|
||||
protected $deleteTime = 'enrol_aq_delete_time';
|
||||
// 设置主键名
|
||||
protected $pk = 'enrol_aq_guid';
|
||||
// 设置废弃字段
|
||||
protected $disuse = [];
|
||||
// 设置字段信息
|
||||
protected $schema = [
|
||||
|
||||
"enrol_aq_id" => "int",
|
||||
|
||||
"enrol_aq_guid" => "string",
|
||||
|
||||
"enrol_aq_question" => "string",
|
||||
|
||||
"enrol_aq_answer" => "string",
|
||||
|
||||
"enrol_aq_sort" => "int",
|
||||
|
||||
"enrol_aq_status" => "int",
|
||||
|
||||
"enrol_aq_answer_status" => "int",
|
||||
|
||||
"enrol_aq_create_time" => "datetime",
|
||||
|
||||
"enrol_aq_create_user_guid" => "string",
|
||||
|
||||
"enrol_aq_update_time" => "datetime",
|
||||
|
||||
"enrol_aq_update_user_guid" => "string",
|
||||
|
||||
"enrol_aq_delete_time" => "datetime",
|
||||
|
||||
"enrol_aq_delete_user_guid" => "string",
|
||||
|
||||
];
|
||||
// 设置json类型字段
|
||||
protected $json = [''];
|
||||
// 开启自动写入时间戳字段
|
||||
protected $autoWriteTimestamp = 'datetime';
|
||||
// 创建时间
|
||||
protected $createTime = 'enrol_aq_create_time';
|
||||
// 修改时间
|
||||
protected $updateTime = 'enrol_aq_update_time';
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 新增前
|
||||
*/
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
// self::checkRepeatData($model);
|
||||
$model->completeCreateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新前
|
||||
*/
|
||||
public static function onBeforeUpdate(self $model): void
|
||||
{
|
||||
// self::checkRepeatData($model);
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前
|
||||
*/
|
||||
public static function onBeforeDelete(self $model): void
|
||||
{
|
||||
$model->completeDeleteField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出Excel
|
||||
*/
|
||||
public static function exportExcel($select)
|
||||
{
|
||||
$data = [[
|
||||
'问题',
|
||||
'答案',
|
||||
'排序',
|
||||
'是否展示',
|
||||
'回答状态'
|
||||
]];
|
||||
foreach ($select as $key => $val) {
|
||||
$data[] = [
|
||||
$val['enrol_aq_question'],
|
||||
$val['enrol_aq_answer'],
|
||||
$val['enrol_aq_sort'],
|
||||
$val['enrol_aq_status'],
|
||||
$val['enrol_aq_answer_status'],
|
||||
];
|
||||
}
|
||||
$excel = (new Excel())->exporTsheet($data);
|
||||
$excel->save('招生问答.xlsx');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user