Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
newShopBack
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
newshop
newShopBack
Commits
618c02dc
Commit
618c02dc
authored
Nov 28, 2019
by
张晓林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
证照批量上传
parent
f24e3f62
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
10 deletions
+62
-10
BranchLicenceController.php
backend/controllers/v1/branch/BranchLicenceController.php
+59
-8
BranchLicence.php
backend/models/v1/branch/BranchLicence.php
+3
-2
No files found.
backend/controllers/v1/branch/BranchLicenceController.php
View file @
618c02dc
...
@@ -4,12 +4,13 @@
...
@@ -4,12 +4,13 @@
use
Yii
;
use
Yii
;
use
yii\data\ArrayDataProvider
;
use
yii\data\ArrayDataProvider
;
use
backend\models\v1\branch\BranchLicence
;
use
backend\models\v1\branch\BranchLicence
;
use
app\models\v1\branch\ShopBranch
;
use
backend\controllers\v1\BaseController
;
use
backend\controllers\v1\BaseController
;
use
backend\helpers\Func
;
use
backend\helpers\Func
;
use
backend\helpers\UploadFiles
;
use
backend\helpers\UploadFiles
;
use
yii\web\UploadedFile
;
use
yii\web\UploadedFile
;
use
yii\web\HttpException
;
use
yii\web\HttpException
;
use
yidas\phpSpreadsheet\Helper
;
use
\
yidas\phpSpreadsheet\Helper
;
class
BranchLicenceController
extends
BaseController
{
class
BranchLicenceController
extends
BaseController
{
public
$modelClass
=
'backend\models\v1\branch\BranchLicence'
;
public
$modelClass
=
'backend\models\v1\branch\BranchLicence'
;
...
@@ -88,7 +89,7 @@ class BranchLicenceController extends BaseController{
...
@@ -88,7 +89,7 @@ class BranchLicenceController extends BaseController{
*/
*/
public
function
actionLicenceImgUpload
(){
public
function
actionLicenceImgUpload
(){
//多文件时依赖注入参数参考UploadFiles类
//多文件时依赖注入参数参考UploadFiles类
$model
=
new
UploadFiles
([
'png'
,
'jpg'
,
'jpeg'
]);
$model
=
new
UploadFiles
([
'png'
,
'jpg'
,
'jpeg'
]
,
$maxFiles
=
1
,
$minFiles
=
0
,
$minSize
=
null
,
$maxSize
=
200
*
1024
);
if
(
Yii
::
$app
->
request
->
isPost
)
{
if
(
Yii
::
$app
->
request
->
isPost
)
{
//多文件用getInstances
//多文件用getInstances
$model
->
uploadFiles
=
UploadedFile
::
getInstance
(
$model
,
'uploadFile'
);
$model
->
uploadFiles
=
UploadedFile
::
getInstance
(
$model
,
'uploadFile'
);
...
@@ -133,22 +134,72 @@ class BranchLicenceController extends BaseController{
...
@@ -133,22 +134,72 @@ class BranchLicenceController extends BaseController{
* )
* )
* )
* )
*/
*/
public
function
actionLicenceExcelUpload
(){
public
function
actionLicenceExcelUpload
(){
//多文件时依赖注入参数参考UploadFiles类
//多文件时依赖注入参数参考UploadFiles类
$model
=
new
UploadFiles
([
'
jpg'
,
'xls'
]
);
$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
();
//多文件用getInstances
//多文件用getInstances
$model
->
uploadFiles
=
UploadedFile
::
getInstance
(
$model
,
'uploadFile'
);
$model
->
uploadFiles
=
UploadedFile
::
getInstance
(
$model
,
'uploadFile'
);
$fileInfo
=
$model
->
upload
();
$fileInfo
=
$model
->
upload
();
$file
=
$fileInfo
[
'INFO'
];
$file
=
$fileInfo
[
'INFO'
][
0
];
Helper
::
getRow
();
return
$file
;
if
(
$fileInfo
[
'CODE'
]
==
200
)
{
if
(
$fileInfo
[
'CODE'
]
==
200
)
{
// 文件上传成功
// 文件上传成功
throw
new
HttpException
(
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
)){
$licenceInfo
=
$licenceModel
::
findOne
([
'BRANCH_CODE'
=>
$licenceValues
[
0
],
'LICENCE_CODE'
=>
$licenceValues
[
2
]]);
if
(
empty
(
$licenceInfo
)){
$licenceInfo
=
clone
$licenceModel
;
$licenceInfo
->
GUID
=
Func
::
create_guid
();
$licenceInfo
->
BRANCH_CODE
=
$licenceValues
[
0
];
$licenceInfo
->
LICENCE_CODE
=
$licenceValues
[
2
];
}
$licenceInfo
->
scenario
=
'excelUpload'
;
$licenceInfo
->
LICENCE_NAME
=
$licenceValues
[
3
];
$licenceInfo
->
LICENCE_CONTENT
=
$licenceValues
[
6
];
$licenceInfo
->
UPDATE_TIME
=
date
(
'Y-m-d H:i:s'
,
time
());
$licenceInfo
->
LICENCE_GRADE
=
$licenceValues
[
1
];
$licenceInfo
->
LICENCE_IMG_URL
=
$licenceValues
[
4
];
$licenceInfo
->
LICENCE_EXPIRY_DATE
=
$licenceValues
[
5
];
$licenceInfo
->
IS_SHOW
=
$licenceValues
[
7
];
if
(
!
$licenceInfo
->
save
()){
$transaction
->
rollBack
();
unlink
(
$file
);
$returnInfo
=
[
$rows
=>
$licenceInfo
->
errors
];
throw
new
HttpException
(
"422"
,
json_encode
(
$returnInfo
));
}
$transaction
->
commit
();
unlink
(
$file
);
throw
new
HttpException
(
"200"
,
'导入成功'
);
}
else
{
$transaction
->
rollBack
();
unlink
(
$file
);
return
[
'CODE'
=>
200
,
'MESSAGE'
=>
'第'
.
$rows
.
'行的门店不存在'
];
}
}
}
else
{
}
else
{
$transaction
->
rollBack
();
throw
new
HttpException
(
422
);
throw
new
HttpException
(
422
);
}
}
}
else
{
$transaction
->
rollBack
();
return
[
'CODE'
=>
200
,
'MESSAGE'
=>
'请求方式不符合'
];
}
}
}
}
/**
/**
...
...
backend/models/v1/branch/BranchLicence.php
View file @
618c02dc
...
@@ -16,9 +16,10 @@ class BranchLicence extends ActiveRecord{
...
@@ -16,9 +16,10 @@ class BranchLicence extends ActiveRecord{
return
[
return
[
[
'GUID'
,
'required'
,
'on'
=>
[
'licenceDetail'
,
'licenceInsert'
],
'message'
=>
'缺少参数GUID'
],
[
'GUID'
,
'required'
,
'on'
=>
[
'licenceDetail'
,
'licenceInsert'
],
'message'
=>
'缺少参数GUID'
],
[
'GUID'
,
'unique'
,
'on'
=>
'licenceInsert'
,
'message'
=>
'GUID不能重复'
],
[
'GUID'
,
'unique'
,
'on'
=>
'licenceInsert'
,
'message'
=>
'GUID不能重复'
],
[[
'LICENCE_CODE'
,
'LICENCE_NAME'
,
'LICENCE_EXPIRY_DATE'
,
'BRANCH_CODE'
,
'LICENCE_CONTENT'
,
'LICENCE_
IMG_URL'
],
'trim'
,
'on'
=>
'licenceInsert'
],
[[
'LICENCE_CODE'
,
'LICENCE_NAME'
,
'LICENCE_EXPIRY_DATE'
,
'BRANCH_CODE'
,
'LICENCE_CONTENT'
,
'LICENCE_
GRADE'
,
'LICENCE_IMG_URL'
],
'trim'
,
'on'
=>
[
'licenceInsert'
,
'excelUpload'
]
],
[[
'GUID'
,
'LICENCE_CODE'
,
'LICENCE_NAME'
,
'LICENCE_EXPIRY_DATE'
,
'BRANCH_CODE'
],
'required'
,
'on'
=>
'licenceInsert'
,
'message'
=>
'缺少参数'
],
[[
'GUID'
,
'LICENCE_CODE'
,
'LICENCE_NAME'
,
'LICENCE_EXPIRY_DATE'
,
'BRANCH_CODE'
],
'required'
,
'on'
=>
[
'licenceInsert'
,
'excelUpload'
]
,
'message'
=>
'缺少参数'
],
[[
'LICENCE_CONTENT'
,
'LICENCE_IMG_URL'
,
'LICENCE_GRADE'
],
'default'
,
'value'
=>
''
,
'on'
=>
'licenceInsert'
],
[[
'LICENCE_CONTENT'
,
'LICENCE_IMG_URL'
,
'LICENCE_GRADE'
],
'default'
,
'value'
=>
''
,
'on'
=>
'licenceInsert'
],
[[
'LICENCE_GRADE'
],
'default'
,
'value'
=>
0
,
'on'
=>
'excelUpload'
],
[[
'LICENCE_CODE'
,
'LICENCE_NAME'
],
'string'
,
'max'
=>
20
,
'on'
=>
'licenceInsert'
],
[[
'LICENCE_CODE'
,
'LICENCE_NAME'
],
'string'
,
'max'
=>
20
,
'on'
=>
'licenceInsert'
],
[[
'IS_FROM'
,
'IS_SHOW'
],
'default'
,
'value'
=>
1
],
[[
'IS_FROM'
,
'IS_SHOW'
],
'default'
,
'value'
=>
1
],
[[
'LICENCE_EXPIRY_DATE'
],
'datetime'
,
'format'
=>
'Y-m-d'
,
'on'
=>
'licenceInsert'
],
[[
'LICENCE_EXPIRY_DATE'
],
'datetime'
,
'format'
=>
'Y-m-d'
,
'on'
=>
'licenceInsert'
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment