fix:后台作品导入接口完善
This commit is contained in:
parent
3ddf42c795
commit
b140468669
@ -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');
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user