From 2806277868ae7b7827dcdcd640c132c2bdda771e Mon Sep 17 00:00:00 2001 From: xjh <2423579486@qq.com> Date: Thu, 20 Apr 2023 23:07:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AE=8C=E6=88=90=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E8=81=94=E7=B3=BB=E6=88=91=E4=BB=AC-=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E6=8A=A5=E5=90=8D=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/ContactUs/Signup.php | 147 +++++++++++++++++++++ app/admin/controller/Works/Works.php | 2 +- app/admin/controller/Works/WorksType.php | 4 +- app/common/model/ContactUs/Signup.php | 119 +++++++++++++++++ app/common/model/Dictionary/Dictionary.php | 36 ++++- app/common/model/Works/Works.php | 10 +- app/common/model/Works/WorksType.php | 6 +- 7 files changed, 309 insertions(+), 15 deletions(-) create mode 100644 app/admin/controller/ContactUs/Signup.php create mode 100644 app/common/model/ContactUs/Signup.php diff --git a/app/admin/controller/ContactUs/Signup.php b/app/admin/controller/ContactUs/Signup.php new file mode 100644 index 0000000..ea353bc --- /dev/null +++ b/app/admin/controller/ContactUs/Signup.php @@ -0,0 +1,147 @@ +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); + } +} diff --git a/app/admin/controller/Works/Works.php b/app/admin/controller/Works/Works.php index 2b14dae..a87536a 100644 --- a/app/admin/controller/Works/Works.php +++ b/app/admin/controller/Works/Works.php @@ -195,7 +195,7 @@ class Works extends BaseController public function downloadTemplate(Request $request) { $data = [ - array_values(ModelWorks::IMPORTEXCELFIELD), + array_values(ModelWorks::IMPORT_EXCEL_FIELD), ['素描', '龙与虎', '张三', '色彩班', "0", "0"] ]; $excel = (new Excel())->exporTsheet($data); diff --git a/app/admin/controller/Works/WorksType.php b/app/admin/controller/Works/WorksType.php index 60bcd0c..3c49b2a 100644 --- a/app/admin/controller/Works/WorksType.php +++ b/app/admin/controller/Works/WorksType.php @@ -27,7 +27,7 @@ class WorksType extends BaseController * @author xjh * @since 1.0.0 */ - public function getWorksTypeList(Request $request):array + public function getWorksTypeList(Request $request): array { $con = Tool::getOptionalQuery(['works_type_name', 'LIKE']); $con[] = ['works_type_parent_guid', '=', "0"]; @@ -221,7 +221,7 @@ class WorksType extends BaseController public function downloadTemplate(Request $request): void { $data = [ - array_values(ModelWorksType::EXCELFIELD), + array_values(ModelWorksType::IMPORT_EXCEL_FIELD), ['', '素描', '1'] ]; $excel = (new Excel())->exporTsheet($data); diff --git a/app/common/model/ContactUs/Signup.php b/app/common/model/ContactUs/Signup.php new file mode 100644 index 0000000..511a805 --- /dev/null +++ b/app/common/model/ContactUs/Signup.php @@ -0,0 +1,119 @@ + "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'); + } +} diff --git a/app/common/model/Dictionary/Dictionary.php b/app/common/model/Dictionary/Dictionary.php index abcfb51..06a8b4b 100644 --- a/app/common/model/Dictionary/Dictionary.php +++ b/app/common/model/Dictionary/Dictionary.php @@ -157,12 +157,11 @@ class Dictionary extends BaseModel 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(); if (!$dictionary) throwErrorMsg("{$value['dictionary_parent_name']} 上级字典不存在"); $value['dictionary_parent_guid'] = $dictionary->dictionary_guid; - } - else{ + } else { $value['dictionary_parent_guid'] = 0; } @@ -236,8 +235,37 @@ class Dictionary extends BaseModel Db::rollback(); 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; + } } diff --git a/app/common/model/Works/Works.php b/app/common/model/Works/Works.php index 132650d..0955dae 100644 --- a/app/common/model/Works/Works.php +++ b/app/common/model/Works/Works.php @@ -53,7 +53,7 @@ class Works extends BaseModel public $order_field = 'works_order'; // excel导出模板表头 - public const EXPORTEXCELFIELD = [ + public const EXPORT_EXCEL_FIELD = [ 'works_type_name' => '作品类型', 'works_img' => '作品图片', 'works_name' => '作品名称', @@ -62,7 +62,7 @@ class Works extends BaseModel 'works_likes_count' => '点赞数', ]; // excel导入/下载模板表头 - public const IMPORTEXCELFIELD = [ + public const IMPORT_EXCEL_FIELD = [ 'works_type_name' => '*作品类型', 'works_name' => '*作品名称', 'works_author' => '*作品作者', @@ -105,9 +105,9 @@ class Works extends BaseModel */ 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 (array_keys(self::EXPORTEXCELFIELD) as $field_name) { + foreach (array_keys(self::EXPORT_EXCEL_FIELD) as $field_name) { $value = $val[$field_name]; if ($field_name == 'works_img') $value = Excel::ExportImgFiled($value); $data[$key + 1][$field_name] = $value; @@ -130,7 +130,7 @@ class Works extends BaseModel try { $excel = new Excel($file); $data = $excel->parseExcel( - Tool::getExcelRule(self::IMPORTEXCELFIELD), + Tool::getExcelRule(self::IMPORT_EXCEL_FIELD), ['titleLine' => [1]] ); if (!$data) throwErrorMsg('excel无数据', 1); diff --git a/app/common/model/Works/WorksType.php b/app/common/model/Works/WorksType.php index c0a9ebc..6adedbc 100644 --- a/app/common/model/Works/WorksType.php +++ b/app/common/model/Works/WorksType.php @@ -52,7 +52,7 @@ class WorksType extends BaseModel public $ancestors_guid_field = 'works_type_ancestors_guid'; // excel导入/下载模板表头 - public const EXCELFIELD = [ + public const IMPORT_EXCEL_FIELD = [ 'works_type_parent_name' => '上级类型名称', 'works_type_name' => '*作品类型名称', 'works_type_order' => '作品类型排序', @@ -109,7 +109,7 @@ class WorksType extends BaseModel */ public static function exportExcel(array $select): void { - $data = [array_values(self::EXCELFIELD)]; + $data = [array_values(self::IMPORT_EXCEL_FIELD)]; foreach ($select as $key => $val) { $data[] = [ $val['works_type_parent_name'] ?? "无", @@ -134,7 +134,7 @@ class WorksType extends BaseModel try { $excel = new Excel($file); $data = $excel->parseExcel( - Tool::getExcelRule(self::EXCELFIELD), + Tool::getExcelRule(self::IMPORT_EXCEL_FIELD), ['titleLine' => [1]] ); if (!$data) throwErrorMsg('excel无数据', 1);