feat:完成后台联系我们-在线报名模块

This commit is contained in:
xjh 2023-04-20 23:07:47 +08:00
parent 58e9909d1f
commit 2806277868
7 changed files with 309 additions and 15 deletions

View File

@ -0,0 +1,147 @@
<?php
namespace app\admin\controller\ContactUs;
use app\BaseController;
use app\common\model\ContactUs\Signup as ModelSignup;
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 Signup extends BaseController
{
/**
* 获取在线报名列表接口
*
* @param Request request
* @return array
* @date 2023-04-20
* @author xjh
* @since 1.0.0
*/
public function getSignupList(): array
{
$con = Tool::getOptionalQuery(
['signup.signup_user_name', 'LIKE'],
['signup.signup_user_phone', 'LIKE'],
['signup.signup_user_parents_phone', 'LIKE'],
['signup.signup_user_home_address', 'LIKE'],
['signup.signup_user_original_school', 'LIKE'],
['signup.signup_user_arrival_time', 'LIKE'],
['signup.signup_user_grad_type', '='],
['signup.signup_status', '='],
['signup.classes_guid', '='],
['signup.signup_create_time', 'BETWEEN', 'data_time'],
);
$query = ModelSignup::where($con)
->field([
'signup.signup_id',
'signup.signup_guid',
'signup.signup_user_name',
'signup.signup_user_phone',
'signup.signup_user_parents_phone',
'signup.signup_user_home_address',
'signup.signup_user_original_school',
'signup.signup_user_arrival_time',
'signup.classes_guid',
'signup.signup_user_grad_type',
'signup.signup_status',
'classes.classes_name',
'signup.signup_create_time',
])
->leftJoin('classes', 'classes.classes_guid = signup.classes_guid')
->order('signup_create_time', 'desc');
return msg("获取在线报名列表成功!", $query);
}
// /**
// * 添加在线报名
// */
// public function addSignup(Request $request): array
// {
// $params = $request->param();
// $this->validate($params, [
// 'signup_user_name|报名用户名称' => 'require',
// 'signup_user_phone|报名用户电话' => 'require',
// 'signup_user_parents_phone|报名用户家长电话' => 'require',
// 'signup_user_home_address|报名用户家庭地址' => 'require',
// 'signup_user_original_school|报名用户原就读学校' => 'require',
// 'signup_user_arrival_time|报名用户预计到校时间' => 'require',
// 'classes_guid|报名用户选择班级guid(外键)' => 'require',
// 'signup_user_grad_type|报名用户毕业类型(字典)' => 'require',
// 'signup_status|报名受理状态(字典)' => 'require'
// ]);
// $model = ModelSignup::create($params, [
// 'signup_guid',
// 'signup_create_user_guid',
// 'signup_update_user_guid',
// 'signup_user_name',
// 'signup_user_phone',
// 'signup_user_parents_phone',
// 'signup_user_home_address',
// 'signup_user_original_school',
// 'signup_user_arrival_time',
// 'classes_guid',
// 'signup_user_grad_type',
// 'signup_status'
// ]);
// return msg('添加成功!');
// }
/**
* 删除在线报名接口
*
* @param Request request
* @return array
* @date 2023-04-20
* @author xjh
* @since 1.0.0
*/
public function deleteSignup(Request $request): array
{
$params = $request->param();
$this->validate($params, [
'signup_guid' => 'require',
]);
$signup = ModelSignup::where([
'signup_guid' => explode(',', $params['signup_guid'])
])->select();
$signup->delete();
return msg('删除成功!');
}
/**
* 导出Excel接口
*
* @param Request request
* @return array
* @date 2023-04-20
* @author xjh
* @since 1.0.0
*/
public function exportExcel(Request $request): void
{
$params = $request->param();
$con = [
['classes.classes_delete_time', 'NULL', null],
];
if (isset($params['signup_guids']) && $params['signup_guids']) {
$con['signup.signup_guid'] = explode(',', $params['signup_guids']);
}
$select = ModelSignup::where($con)
->leftJoin('classes', 'classes.classes_guid = signup.classes_guid')
->order('signup_create_time', 'desc')
->select()
->toArray();
ModelSignup::exportExcel($select);
}
}

View File

@ -195,7 +195,7 @@ class Works extends BaseController
public function downloadTemplate(Request $request) public function downloadTemplate(Request $request)
{ {
$data = [ $data = [
array_values(ModelWorks::IMPORTEXCELFIELD), array_values(ModelWorks::IMPORT_EXCEL_FIELD),
['素描', '龙与虎', '张三', '色彩班', "0", "0"] ['素描', '龙与虎', '张三', '色彩班', "0", "0"]
]; ];
$excel = (new Excel())->exporTsheet($data); $excel = (new Excel())->exporTsheet($data);

View File

@ -27,7 +27,7 @@ class WorksType extends BaseController
* @author xjh * @author xjh
* @since 1.0.0 * @since 1.0.0
*/ */
public function getWorksTypeList(Request $request):array public function getWorksTypeList(Request $request): array
{ {
$con = Tool::getOptionalQuery(['works_type_name', 'LIKE']); $con = Tool::getOptionalQuery(['works_type_name', 'LIKE']);
$con[] = ['works_type_parent_guid', '=', "0"]; $con[] = ['works_type_parent_guid', '=', "0"];
@ -221,7 +221,7 @@ class WorksType extends BaseController
public function downloadTemplate(Request $request): void public function downloadTemplate(Request $request): void
{ {
$data = [ $data = [
array_values(ModelWorksType::EXCELFIELD), array_values(ModelWorksType::IMPORT_EXCEL_FIELD),
['', '素描', '1'] ['', '素描', '1']
]; ];
$excel = (new Excel())->exporTsheet($data); $excel = (new Excel())->exporTsheet($data);

View File

@ -0,0 +1,119 @@
<?php
namespace app\common\model\ContactUs;
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;
use app\common\model\Dictionary\Dictionary as ModelDictionary;
class Signup extends BaseModel
{
use SoftDelete;
// 删除字段
protected $deleteTime = 'signup_delete_time';
// 设置主键名
protected $pk = 'signup_guid';
// 设置废弃字段
protected $disuse = [];
// 设置字段信息
protected $schema = [
"signup_id" => "int",
"signup_guid" => "string",
"signup_user_name" => "string",
"signup_user_phone" => "string",
"signup_user_parents_phone" => "string",
"signup_user_home_address" => "string",
"signup_user_original_school" => "string",
"signup_user_arrival_time" => "datetime",
"classes_guid" => "string",
"signup_user_grad_type" => "int",
"signup_status" => "int",
"signup_create_time" => "datetime",
"signup_create_user_guid" => "string",
"signup_update_time" => "datetime",
"signup_update_user_guid" => "string",
"signup_delete_time" => "datetime",
"signup_delete_user_guid" => "string",
];
// 设置json类型字段
protected $json = [''];
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'datetime';
// 创建时间
protected $createTime = 'signup_create_time';
// 修改时间
protected $updateTime = 'signup_update_time';
// excel导出模板表头
public const EXPORT_EXCEL_FIELD = [
'signup_user_name' => '用户名称',
'signup_user_phone' => '用户电话',
'signup_user_parents_phone' => '家长电话',
'signup_user_home_address' => '家庭地址',
'signup_user_original_school' => '原就读学校',
'signup_user_arrival_time' => '预计到校时间',
'classes_name' => '所择班级',
'signup_user_grad_type' => '毕业类型',
'signup_status' => '报名受理状态',
'signup_create_time' => '报名时间',
];
/**
* 新增前
*/
public static function onBeforeInsert(self $model): void
{
$model->completeCreateField();
}
/**
* 更新前
*/
public static function onBeforeUpdate(self $model): void
{
$model->completeUpdateField();
}
/**
* 删除前
*/
public static function onBeforeDelete(self $model): void
{
$model->completeDeleteField();
}
/**
* 导出Excel
*
* @param array $select导出的数据集合
*/
public static function exportExcel(array $select): void
{
$processing_state_data = ModelDictionary::getDictionaryData('processing_state');
$graduation_type_data = ModelDictionary::getDictionaryData('graduation_type');
$export_excel_fields = self::EXPORT_EXCEL_FIELD;
$data = [array_values($export_excel_fields)];
foreach ($select as $key => $val) {
foreach (array_keys($export_excel_fields) as $field_name) {
$value = $val[$field_name];
switch ($field_name) {
case 'signup_status': //毕业类型
$value = ModelDictionary::getDataDictionaryName($processing_state_data, $value);
break;
case 'signup_user_grad_type': //报名受理状态
$value = ModelDictionary::getDataDictionaryName($graduation_type_data, $value);
break;
}
$data[$key + 1][$field_name] = $value;
}
}
$excel = (new Excel())->exporTsheet($data);
$excel->save('在线报名.xlsx');
}
}

View File

@ -157,12 +157,11 @@ class Dictionary extends BaseModel
public static function importInit($value) public static function importInit($value)
{ {
// 上级判断 // 上级判断
if(isset($value['dictionary_parent_name']) && $value['dictionary_parent_name']){ if (isset($value['dictionary_parent_name']) && $value['dictionary_parent_name']) {
$dictionary = self::where('dictionary_name', $value['dictionary_parent_name'])->find(); $dictionary = self::where('dictionary_name', $value['dictionary_parent_name'])->find();
if (!$dictionary) throwErrorMsg("{$value['dictionary_parent_name']} 上级字典不存在"); if (!$dictionary) throwErrorMsg("{$value['dictionary_parent_name']} 上级字典不存在");
$value['dictionary_parent_guid'] = $dictionary->dictionary_guid; $value['dictionary_parent_guid'] = $dictionary->dictionary_guid;
} } else {
else{
$value['dictionary_parent_guid'] = 0; $value['dictionary_parent_guid'] = 0;
} }
@ -236,8 +235,37 @@ class Dictionary extends BaseModel
Db::rollback(); Db::rollback();
throw $th; throw $th;
} }
} }
/**
* 获取字典数据(二级)
*
* @param string $dictionary_value 字典模块字段值
* @param array $field 字段筛选
*/
public static function getDictionaryData(string $dictionary_value, array $field = ['dictionary_name', 'dictionary_value']): array
{
$dictionary = self::where('dictionary_value', $dictionary_value)->find();
if (!$dictionary) throwErrorMsg("字典数据不存在dictionary_value值为{$dictionary_value}的数据!");
return self::field($field)->where('dictionary_parent_guid', $dictionary->dictionary_guid)->select()->toArray();
}
/**
* 获取字典集合(二级)指定字典值的名称
*
* @param array $dictionary_data 字典集合
* @param string $dictionary_value 字典值
* @return string|null
*/
public static function getDataDictionaryName(array $dictionary_data, string $dictionary_value)
{
$dictionary_name = null;
foreach ($dictionary_data as $dictionary) {
if ($dictionary['dictionary_value'] == $dictionary_value) {
$dictionary_name = $dictionary['dictionary_name'];
break;
}
};
return $dictionary_name;
}
} }

View File

@ -53,7 +53,7 @@ class Works extends BaseModel
public $order_field = 'works_order'; public $order_field = 'works_order';
// excel导出模板表头 // excel导出模板表头
public const EXPORTEXCELFIELD = [ public const EXPORT_EXCEL_FIELD = [
'works_type_name' => '作品类型', 'works_type_name' => '作品类型',
'works_img' => '作品图片', 'works_img' => '作品图片',
'works_name' => '作品名称', 'works_name' => '作品名称',
@ -62,7 +62,7 @@ class Works extends BaseModel
'works_likes_count' => '点赞数', 'works_likes_count' => '点赞数',
]; ];
// excel导入/下载模板表头 // excel导入/下载模板表头
public const IMPORTEXCELFIELD = [ public const IMPORT_EXCEL_FIELD = [
'works_type_name' => '*作品类型', 'works_type_name' => '*作品类型',
'works_name' => '*作品名称', 'works_name' => '*作品名称',
'works_author' => '*作品作者', 'works_author' => '*作品作者',
@ -105,9 +105,9 @@ class Works extends BaseModel
*/ */
public static function exportExcel(array $select): void public static function exportExcel(array $select): void
{ {
$data = [array_values(self::EXPORTEXCELFIELD)]; $data = [array_values(self::EXPORT_EXCEL_FIELD)];
foreach ($select as $key => $val) { foreach ($select as $key => $val) {
foreach (array_keys(self::EXPORTEXCELFIELD) as $field_name) { foreach (array_keys(self::EXPORT_EXCEL_FIELD) as $field_name) {
$value = $val[$field_name]; $value = $val[$field_name];
if ($field_name == 'works_img') $value = Excel::ExportImgFiled($value); if ($field_name == 'works_img') $value = Excel::ExportImgFiled($value);
$data[$key + 1][$field_name] = $value; $data[$key + 1][$field_name] = $value;
@ -130,7 +130,7 @@ class Works extends BaseModel
try { try {
$excel = new Excel($file); $excel = new Excel($file);
$data = $excel->parseExcel( $data = $excel->parseExcel(
Tool::getExcelRule(self::IMPORTEXCELFIELD), Tool::getExcelRule(self::IMPORT_EXCEL_FIELD),
['titleLine' => [1]] ['titleLine' => [1]]
); );
if (!$data) throwErrorMsg('excel无数据', 1); if (!$data) throwErrorMsg('excel无数据', 1);

View File

@ -52,7 +52,7 @@ class WorksType extends BaseModel
public $ancestors_guid_field = 'works_type_ancestors_guid'; public $ancestors_guid_field = 'works_type_ancestors_guid';
// excel导入/下载模板表头 // excel导入/下载模板表头
public const EXCELFIELD = [ public const IMPORT_EXCEL_FIELD = [
'works_type_parent_name' => '上级类型名称', 'works_type_parent_name' => '上级类型名称',
'works_type_name' => '*作品类型名称', 'works_type_name' => '*作品类型名称',
'works_type_order' => '作品类型排序', 'works_type_order' => '作品类型排序',
@ -109,7 +109,7 @@ class WorksType extends BaseModel
*/ */
public static function exportExcel(array $select): void public static function exportExcel(array $select): void
{ {
$data = [array_values(self::EXCELFIELD)]; $data = [array_values(self::IMPORT_EXCEL_FIELD)];
foreach ($select as $key => $val) { foreach ($select as $key => $val) {
$data[] = [ $data[] = [
$val['works_type_parent_name'] ?? "", $val['works_type_parent_name'] ?? "",
@ -134,7 +134,7 @@ class WorksType extends BaseModel
try { try {
$excel = new Excel($file); $excel = new Excel($file);
$data = $excel->parseExcel( $data = $excel->parseExcel(
Tool::getExcelRule(self::EXCELFIELD), Tool::getExcelRule(self::IMPORT_EXCEL_FIELD),
['titleLine' => [1]] ['titleLine' => [1]]
); );
if (!$data) throwErrorMsg('excel无数据', 1); if (!$data) throwErrorMsg('excel无数据', 1);