diff --git a/superadmin/application/admin/controller/Firm.php b/superadmin/application/admin/controller/Firm.php index fd6c710..56de036 100755 --- a/superadmin/application/admin/controller/Firm.php +++ b/superadmin/application/admin/controller/Firm.php @@ -113,4 +113,53 @@ class Firm extends Backend } return ['res'=>true,'data'=>$data]; } + + /** 导入基础管理(企业为1的导入其中) + * @param + * @return void + */ + public function importBasic($ids = null) + { + $firmstoreData = Db::table('fa_firmstore')->where('firm_id',$ids)->select(); + 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(); + $firmdutyMore = []; + foreach ($firmdutyData as $key=>&$val){ + $data = []; + $data['firm_id'] = $ids; + $data['name'] = $val['name']; + foreach ($firmstoreData as &$v){ + $data['firmstore_id'] = $v['id']; + $firmdutyMore[] = $data; + } + } + $firmbigcategoryResult = false; + $firmcustomerorigiResult = false; + $firmdutyResult = 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); + Db::commit(); + }catch(ValidateException|PDOException|Exception $e){ + return json(['code'=>201,'msg'=>$e->getMessage()]); + } + if (!$firmbigcategoryResult || !$firmcustomerorigiResult || !$firmdutyResult){ + return json(['code'=>201,'msg'=>'导入失败']); + } + return json(['code'=>200,'msg'=>'导入成功']); + } } diff --git a/superadmin/public/assets/js/backend/firm.js b/superadmin/public/assets/js/backend/firm.js index ad6ed27..1996db3 100755 --- a/superadmin/public/assets/js/backend/firm.js +++ b/superadmin/public/assets/js/backend/firm.js @@ -31,7 +31,25 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, {field: 'aicustomerservice_ids', title: __('Aicustomerservice_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, - {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, + buttons: [ + { + name: 'importBasic', + text: '导入基础管理', + title: '导入基础管理', + confirm:'确定导入【基础管理】中的【大类,客户来源,职务】吗?', + classname: 'btn btn-xs btn-primary btn-ajax', + icon: 'fa fa-list', + url: 'firm/importBasic', + success: function (row) { + if (row.code == 200) { + Layer.msg("导入成功"); + } else { + Layer.msg(row.msg); + } + } + }, + ]} ] ] });