作者 lyh

变更数据

@@ -110,32 +110,36 @@ class Extension3915ModuleController extends BaseController @@ -110,32 +110,36 @@ class Extension3915ModuleController extends BaseController
110 $moduleFieldModel = new ExtensionModuleField(); 110 $moduleFieldModel = new ExtensionModuleField();
111 $filedList = $moduleFieldModel->where(['module_id' => $this->param['module_id']])->pluck( 'id','field_name')->toArray(); 111 $filedList = $moduleFieldModel->where(['module_id' => $this->param['module_id']])->pluck( 'id','field_name')->toArray();
112 if(empty($filedList)){ 112 if(empty($filedList)){
113 - $this->response('请先设置字段,再添加数据'); 113 + $this->fail('请先设置字段,再添加数据');
114 } 114 }
115 $data = $this->param['data']; 115 $data = $this->param['data'];
116 $moduleValueModel = new ExtensionModuleValue(); 116 $moduleValueModel = new ExtensionModuleValue();
117 $key_filedId = []; 117 $key_filedId = [];
118 $resultData = []; 118 $resultData = [];
119 - foreach ($data as $k => $v){  
120 - foreach ($v as $k1 => $v1){  
121 - if($k == 0){  
122 - if(isset($filedList[$v1])){  
123 - $key_filedId[$k1] = $filedList[$v1]; 119 + try {
  120 + foreach ($data as $k => $v){
  121 + foreach ($v as $k1 => $v1){
  122 + if($k == 0){
  123 + if(isset($filedList[$v1])){
  124 + $key_filedId[$k1] = $filedList[$v1];
  125 + }
  126 + continue;
124 } 127 }
125 - continue; 128 + $resultData[] = [
  129 + 'uuid'=>$k + 1,
  130 + 'module_id'=>$this->param['module_id'],
  131 + 'field_id'=>$key_filedId[$k1],
  132 + 'value'=>$v1 ?? '',
  133 + ];
126 } 134 }
127 - $resultData[] = [  
128 - 'uuid'=>$k + 1,  
129 - 'module_id'=>$this->param['module_id'],  
130 - 'field_id'=>$key_filedId[$k1],  
131 - 'value'=>$v1 ?? '',  
132 - ];  
133 } 135 }
134 - }  
135 - if(!empty($resultData)){  
136 - //todo::优先截断表  
137 - $moduleValueModel->truncate();  
138 - $moduleValueModel->insertAll($resultData); 136 + if(!empty($resultData)){
  137 + //todo::优先截断表
  138 + $moduleValueModel->truncate();
  139 + $moduleValueModel->insertAll($resultData);
  140 + }
  141 + }catch (\Exception $e){
  142 + $this->fail('当前文件不能导入,请修改后再导入');
139 } 143 }
140 $this->response('success',Code::SUCCESS,$resultData); 144 $this->response('success',Code::SUCCESS,$resultData);
141 } 145 }