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

证照批量上传优化

parent e02a486d
......@@ -137,21 +137,21 @@ class BranchLicenceController extends BaseController{
public function actionLicenceExcelUpload(){
//多文件时依赖注入参数参考UploadFiles类
$model = new UploadFiles(['xlsx','xls'],$maxFiles = 1 ,$minFiles = 0 ,$minSize = null ,$maxSize = 7*1024*1024);
if (Yii::$app->request->isPost) {
$bracnModel = new ShopBranch();
//多文件用getInstances
$model->uploadFiles = UploadedFile::getInstance($model,'uploadFile');
$fileInfo = $model->upload();
$file = $fileInfo['INFO'][0];
if ($fileInfo['CODE']==200) {
// 文件上传成功
$helper = Helper::newSpreadsheet($file);
$data = $helper->getRows(true,['rowOffset' =>2,'columns'=>8]);
$licenceModel = new BranchLicence();
$transaction=$licenceModel->getDb()->beginTransaction();
foreach($data as $key=>$licenceValues){
$rows = 3+$key; // 第几行
$model = new UploadFiles(['xlsx','xls'],$maxFiles = 1 ,$minFiles = 0 ,$minSize = null ,$maxSize = 7*1024*1024);
if (Yii::$app->request->isPost) {
$bracnModel = new ShopBranch();
//多文件用getInstances
$model->uploadFiles = UploadedFile::getInstance($model,'uploadFile');
$fileInfo = $model->upload();
$file = $fileInfo['INFO'][0];
if ($fileInfo['CODE']==200) {
// 文件上传成功
$helper = Helper::newSpreadsheet($file);
$data = $helper->getRows(true,['rowOffset' =>2,'columns'=>8]);
$licenceModel = new BranchLicence();
$transaction=$licenceModel->getDb()->beginTransaction();
foreach($data as $key=>$licenceValues){
$rows = 3+$key; // 第几行
// $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();
if(!empty($branInfo)){
......@@ -170,6 +170,7 @@ class BranchLicenceController extends BaseController{
$licenceInfo->LICENCE_IMG_URL = $licenceValues[4];
$licenceInfo->LICENCE_EXPIRY_DATE = $licenceValues[5];
$licenceInfo->IS_SHOW = $licenceValues[7];
unset($data[$key]);
if(!$licenceInfo->save()){
$transaction->rollBack();
unlink($file);
......@@ -178,29 +179,29 @@ class BranchLicenceController extends BaseController{
];
throw new HttpException("422", json_encode($returnInfo));
}
$transaction->commit();
unlink($file);
throw new HttpException("200", '导入成功');
}else{
$transaction->rollBack();
unlink($file);
return [
$transaction->rollBack();
unlink($file);
return [
'CODE'=>200,
'MESSAGE'=>'第'.$rows.'行的门店不存在'
];
];
}
}
}else{
$transaction->rollBack();
throw new HttpException(422);
}
}else{
$transaction->rollBack();
return [
'CODE'=>200,
'MESSAGE'=>'请求方式不符合'
];
}
}
$transaction->commit();
unlink($file);
throw new HttpException("200", '导入成功');
}else{
throw new HttpException(422);
}
}else{
$transaction->rollBack();
return [
'CODE'=>200,
'MESSAGE'=>'请求方式不符合'
];
}
}
/**
* @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