From b140468669bee78ab7efe367045174c39df4d4ad Mon Sep 17 00:00:00 2001 From: "USER-20220207MB\\Administrator" <2423579486@qq.com> Date: Sat, 13 May 2023 17:02:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=90=8E=E5=8F=B0=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=8E=A5=E5=8F=A3=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/Works/Works.php | 4 +-- app/common/model/Works/Works.php | 39 ++++++++++++++++------------ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/admin/controller/Works/Works.php b/app/admin/controller/Works/Works.php index aa3d48c..89ee247 100644 --- a/app/admin/controller/Works/Works.php +++ b/app/admin/controller/Works/Works.php @@ -191,7 +191,7 @@ class Works extends BaseController { $data = [ array_values(ModelWorks::IMPORT_EXCEL_FIELD), - ['素描', '龙与虎', '张三', '色彩班', "0", "0"] + ['素描', '学生作品', '介绍', "0", "0"] ]; $excel = (new Excel())->exporTsheet($data); $excel->save('作品导入模板.xlsx'); @@ -209,7 +209,7 @@ class Works extends BaseController public function importExcel(Request $request) { Db::startTrans(); - Tool::adminLockTableWrite(['works','works_type']); + Tool::adminLockTableWrite(['works','works_type','dictionary']); try { $file = new UploadFile('uploads', 'fileExt:xlsx'); $file->putFile('works'); diff --git a/app/common/model/Works/Works.php b/app/common/model/Works/Works.php index 0af9514..cc41d92 100644 --- a/app/common/model/Works/Works.php +++ b/app/common/model/Works/Works.php @@ -63,9 +63,8 @@ class Works extends BaseModel // excel导入/下载模板表头 public const IMPORT_EXCEL_FIELD = [ 'works_type_name' => '*作品类型', - 'works_name' => '*作品名称', - 'works_author' => '*作品作者', - 'classes_name' => '*班型名称', + 'works_author_type' => '*作品作者类型', + 'works_intro' => '作品介绍', 'works_likes_count' => '作品点赞数', 'works_order' => '排序', ]; @@ -111,15 +110,15 @@ class Works extends BaseModel //业务内容处理 //作品图片 if ($field_name == 'works_img') { - $value = Excel::ExportImgFiled($value); + $value = Excel::ExportImgFiled($value); } //作品点赞数 if ($field_name == 'works_likes_count') { - $value = strval($value); + $value = strval($value); } //作品作者类型 if ($field_name == 'works_author_type') { - $value = ModelDictionary::getDataDictionaryName(ModelDictionary::getDictionaryData('works_author_type'), $value); + $value = ModelDictionary::getDataDictionaryName(ModelDictionary::getDictionaryData('works_author_type'), $value); } $data[$key + 1][$field_name] = $value; } @@ -142,7 +141,8 @@ class Works extends BaseModel Tool::getExcelRule(self::IMPORT_EXCEL_FIELD), ['titleLine' => [1]] ); - if (!$data) throwErrorMsg('excel无数据', 1); + if (!$data) + throwErrorMsg('excel无数据', 1); $msg = []; foreach ($data as $line => $value) { try { @@ -162,21 +162,26 @@ class Works extends BaseModel public static function importExcelInit($value): void { $works_type_name = $value['works_type_name']; - $works_name = $value['works_name']; - $works_author = $value['works_author']; - $classes_name = $value['classes_name']; - $works_likes_count = $value['works_likes_count'] ?? 0; - $works_order = $value['works_order'] ?? 0; + $works_author_type = $value['works_author_type']; + $works_likes_count = $value['works_likes_count'] ?? 0; + $works_order = $value['works_order']; + $works_intro = $value['works_intro']; $works_type = ModelWorksType::where("works_type_name", $works_type_name)->find(); - if (!$works_type) throwErrorMsg("作品类型不存在!"); + if (!$works_type)throwErrorMsg("作品类型不存在!"); + + $works_author_type_num = ModelDictionary::getDataDictionaryValue( + ModelDictionary::getDictionaryData('works_author_type'), + $works_author_type + ); + if (!$works_author_type_num)throwErrorMsg("作品作者类型不存在!"); self::create([ 'works_type_guid' => $works_type->works_type_guid, - 'works_name' => $works_name, - 'works_author' => $works_author, 'works_likes_count' => $works_likes_count, 'works_order' => $works_order, + 'works_author_type' => $works_author_type_num, + 'works_intro' => $works_intro, ]); } @@ -193,7 +198,7 @@ class Works extends BaseModel { $works_author_type = $data['works_author_type']; $dic_works_author_type = ModelDictionary::getDictionaryData('works_author_type'); - $works_author_type = ModelDictionary::getDataDictionaryName($dic_works_author_type, $works_author_type); + $works_author_type = ModelDictionary::getDataDictionaryName($dic_works_author_type, $works_author_type); return $works_author_type; } -} +} \ No newline at end of file