Commit e4b7691d authored by 张晓林's avatar 张晓林

证照批量上传优化

parent e02a486d
...@@ -137,21 +137,21 @@ class BranchLicenceController extends BaseController{ ...@@ -137,21 +137,21 @@ class BranchLicenceController extends BaseController{
public function actionLicenceExcelUpload(){ public function actionLicenceExcelUpload(){
//多文件时依赖注入参数参考UploadFiles类 //多文件时依赖注入参数参考UploadFiles类
$model = new UploadFiles(['xlsx','xls'],$maxFiles = 1 ,$minFiles = 0 ,$minSize = null ,$maxSize = 7*1024*1024); $model = new UploadFiles(['xlsx','xls'],$maxFiles = 1 ,$minFiles = 0 ,$minSize = null ,$maxSize = 7*1024*1024);
if (Yii::$app->request->isPost) { if (Yii::$app->request->isPost) {
$bracnModel = new ShopBranch(); $bracnModel = new ShopBranch();
//多文件用getInstances //多文件用getInstances
$model->uploadFiles = UploadedFile::getInstance($model,'uploadFile'); $model->uploadFiles = UploadedFile::getInstance($model,'uploadFile');
$fileInfo = $model->upload(); $fileInfo = $model->upload();
$file = $fileInfo['INFO'][0]; $file = $fileInfo['INFO'][0];
if ($fileInfo['CODE']==200) { if ($fileInfo['CODE']==200) {
// 文件上传成功 // 文件上传成功
$helper = Helper::newSpreadsheet($file); $helper = Helper::newSpreadsheet($file);
$data = $helper->getRows(true,['rowOffset' =>2,'columns'=>8]); $data = $helper->getRows(true,['rowOffset' =>2,'columns'=>8]);
$licenceModel = new BranchLicence(); $licenceModel = new BranchLicence();
$transaction=$licenceModel->getDb()->beginTransaction(); $transaction=$licenceModel->getDb()->beginTransaction();
foreach($data as $key=>$licenceValues){ foreach($data as $key=>$licenceValues){
$rows = 3+$key; // 第几行 $rows = 3+$key; // 第几行
// $bracnModel::find()->select(['GUID'])->where(['CODE'=>$licenceValues[0],'ORG_GUID'=>Yii::$app->user->identity->ORG_GUID])->one(); // $bracnModel::find()->select(['GUID'])->where(['CODE'=>$licenceValues[0],'ORG_GUID'=>Yii::$app->user->identity->ORG_GUID])->one();
$branInfo = $bracnModel::find()->select(['GUID'])->where(['CODE'=>$licenceValues[0]])->one(); $branInfo = $bracnModel::find()->select(['GUID'])->where(['CODE'=>$licenceValues[0]])->one();
if(!empty($branInfo)){ if(!empty($branInfo)){
...@@ -170,6 +170,7 @@ class BranchLicenceController extends BaseController{ ...@@ -170,6 +170,7 @@ class BranchLicenceController extends BaseController{
$licenceInfo->LICENCE_IMG_URL = $licenceValues[4]; $licenceInfo->LICENCE_IMG_URL = $licenceValues[4];
$licenceInfo->LICENCE_EXPIRY_DATE = $licenceValues[5]; $licenceInfo->LICENCE_EXPIRY_DATE = $licenceValues[5];
$licenceInfo->IS_SHOW = $licenceValues[7]; $licenceInfo->IS_SHOW = $licenceValues[7];
unset($data[$key]);
if(!$licenceInfo->save()){ if(!$licenceInfo->save()){
$transaction->rollBack(); $transaction->rollBack();
unlink($file); unlink($file);
...@@ -178,29 +179,29 @@ class BranchLicenceController extends BaseController{ ...@@ -178,29 +179,29 @@ class BranchLicenceController extends BaseController{
]; ];
throw new HttpException("422", json_encode($returnInfo)); throw new HttpException("422", json_encode($returnInfo));
} }
$transaction->commit();
unlink($file);
throw new HttpException("200", '导入成功');
}else{ }else{
$transaction->rollBack(); $transaction->rollBack();
unlink($file); unlink($file);
return [ return [
'CODE'=>200, 'CODE'=>200,
'MESSAGE'=>'第'.$rows.'行的门店不存在' 'MESSAGE'=>'第'.$rows.'行的门店不存在'
]; ];
} }
} }
}else{ $transaction->commit();
$transaction->rollBack(); unlink($file);
throw new HttpException(422); throw new HttpException("200", '导入成功');
} }else{
}else{ throw new HttpException(422);
$transaction->rollBack(); }
return [ }else{
'CODE'=>200, $transaction->rollBack();
'MESSAGE'=>'请求方式不符合' return [
]; 'CODE'=>200,
} 'MESSAGE'=>'请求方式不符合'
];
}
} }
/** /**
* @OA\GET( * @OA\GET(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment