导入基础类

This commit is contained in:
meimei
2025-04-18 15:58:01 +08:00
parent f20b865f4d
commit ee99adfb30
15 changed files with 90 additions and 19 deletions

View File

@@ -124,17 +124,20 @@ class Firm extends Backend
if (count($firmstoreData) == 0){
return json(['code'=>201,'msg'=>'请先添加门店']);
}
//大类
$firmbigcategoryData = Db::table('fa_firmbigcategory')->where('firm_id',1)->select();
foreach ($firmbigcategoryData as $key=>&$val){
unset($val['id']);
$val['firm_id'] = $ids;
}
//客户来源
$firmcustomeroriginData = Db::table('fa_firmcustomerorigin')->where('firm_id',1)->select();
foreach ($firmcustomeroriginData as $key=>&$val){
unset($val['id']);
$val['firm_id'] = $ids;
}
$firmdutyData = Db::table('fa_firmduty')->where('firm_id',1)->select();
//职务
$firmdutyData = Db::table('fa_firmduty')->where('firm_id',1)->where('firmstore_id',1)->select();
$firmdutyMore = [];
foreach ($firmdutyData as $key=>&$val){
$data = [];
@@ -145,19 +148,74 @@ class Firm extends Backend
$firmdutyMore[] = $data;
}
}
//标签
$firmtagsData = Db::table('fa_firmtags')->where('firm_id',1)->select();
foreach ($firmtagsData as $key=>&$val){
unset($val['id']);
$val['firm_id'] = $ids;
}
$firmbigcategoryResult = false;
$firmcustomerorigiResult = false;
$firmdutyResult = false;
$firmtagsResult = false;
Db::startTrans();
try {
$firmbigcategoryResult = Db::table('fa_firmbigcategory')->insertAll($firmbigcategoryData);
$firmcustomerorigiResult = Db::table('fa_firmcustomerorigin')->insertAll($firmcustomeroriginData);
$firmdutyResult = Db::table('fa_firmduty')->insertAll($firmdutyMore);
$firmtagsResult = Db::table('fa_firmtags')->insertAll($firmtagsData);
//店铺项目
$firmstoreprojectsoneData = Db::table('fa_firmstoreprojectsone')->where('firm_id',1)->where('firmstore_id',1)->select();
foreach ($firmstoreprojectsoneData as $key=>&$val){
foreach ($firmstoreData as &$v){
$data = [];
$data['firm_id'] = $ids;
$data['name'] = $val['name'];
$data['firmstore_id'] = $v['id'];
//添加一级店铺项目
$firmstoreprojectsone_id = Db::table('fa_firmstoreprojectsone')->insertGetId($data);
//查询二级店铺项目
$firmstoreprojectstwoData = Db::table('fa_firmstoreprojectstwo')->where('firm_id',1)
->where('firmstore_id',1)->where('firmstoreprojectsone_id',$val['id'])->select();
foreach ($firmstoreprojectstwoData as &$value){
$firmstoreprojectstwo_oldid = $value['id'];
unset($value['id']);
$value['firm_id'] = $ids;
$value['firmstore_id'] = $firmstoreprojectsone_id;
//添加二级店铺项目
$firmstoreprojectstwo_id = Db::table('fa_firmstoreprojectstwo')->insertGetId($value);
//查询事例模块
$mattertemplatecategorizationData = Db::table('fa_mattertemplatecategorization')->where('firm_id',1)
->where('firmstoreprojectsone_id',$val['id'])->where('firmstoreprojectstwo_id',$firmstoreprojectstwo_oldid)->find();
if ($mattertemplatecategorizationData){
$mtc_id = $mattertemplatecategorizationData['id'];
unset($mattertemplatecategorizationData['id']);
$mattertemplatecategorizationData['firm_id'] = $ids;
$mattertemplatecategorizationData['firmstoreprojectsone_id'] = $firmstoreprojectsone_id;
$mattertemplatecategorizationData['firmstoreprojectstwo_id'] = $firmstoreprojectstwo_id;
$mattertemplatecategorizationData['create_time'] = date('Y-m-d H:i:s');
$mattertemplatecategorizationData['update_time'] = date('Y-m-d H:i:s');
$mattertemplatecategorization_id = Db::table('fa_mattertemplatecategorization')->insertGetId($mattertemplatecategorizationData);
//事例模块具体内容
$fa_mattertemplatecategorizedcontent = Db::table('fa_mattertemplatecategorizedcontent')
->where('mattertemplatecategorization_id',$mtc_id)->select();
foreach ($fa_mattertemplatecategorizedcontent as &$values){
unset($values['id']);
$values['mattertemplatecategorization_id'] = $mattertemplatecategorization_id;
$values['create_time'] = date('Y-m-d H:i:s');
$values['update_time'] = date('Y-m-d H:i:s');
}
Db::table('fa_mattertemplatecategorizedcontent')->insertAll($fa_mattertemplatecategorizedcontent);
}
}
}
}
Db::commit();
}catch(ValidateException|PDOException|Exception $e){
return json(['code'=>201,'msg'=>$e->getMessage()]);
}
if (!$firmbigcategoryResult || !$firmcustomerorigiResult || !$firmdutyResult){
if (!$firmbigcategoryResult || !$firmcustomerorigiResult || !$firmdutyResult || !$firmtagsResult){
return json(['code'=>201,'msg'=>'导入失败']);
}
return json(['code'=>200,'msg'=>'导入成功']);