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
19cc03d4
Commit
19cc03d4
authored
Dec 20, 2019
by
侯贺政
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
商品详情页模板,批量导入关联商品
Signed-off-by:
houhezheng
<
houhezheng@romens.cn
>
parent
ea1fd531
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
6 deletions
+90
-6
BranchScoreController.php
backend/controllers/v1/branch/BranchScoreController.php
+1
-0
DownTemplateController.php
backend/controllers/v1/common/DownTemplateController.php
+2
-1
GoodsDetailSettingController.php
...controllers/v1/shopgoods/GoodsDetailSettingController.php
+86
-5
ShopEmployeeController.php
backend/controllers/v1/shopuser/ShopEmployeeController.php
+1
-0
associated_goods_import.xls
template/associated_goods_import.xls
+0
-0
shop_branch_score_import.xls
template/shop_branch_score_import.xls
+0
-0
No files found.
backend/controllers/v1/branch/BranchScoreController.php
View file @
19cc03d4
...
...
@@ -423,6 +423,7 @@ class BranchScoreController extends BaseController
throw
$th
;
}
}
@
unlink
(
$fileInfo
[
'INFO'
][
0
]);
throw
new
BadRequestHttpException
(
'导入失败!'
);
}
}
backend/controllers/v1/common/DownTemplateController.php
View file @
19cc03d4
...
...
@@ -18,7 +18,8 @@ class DownTemplateController extends BaseController
* 门店导入模板(import_branch.xls);
* 员工信息导入模板(employee_import.xls);
* 门店服务评价打分模板(shop_branch_score_import.xls);
* o2o配送价格导入模板(o2o_delivery_import.xls)",
* o2o配送价格导入模板(o2o_delivery_import.xls);
* 批量关联模板(associated_goods_import.xls);",
* @OA\Parameter(name="ENG_NAME",in="query",required=true,description="模板名称",@OA\Schema(type="string")),
* @OA\Parameter(name="CN_NAME",in="query",required=true,description="模板中文名称",@OA\Schema(type="string")),
* @OA\Parameter(name="SUFFIX",in="query",description="excel后缀,默认xlsx,首字母大写",@OA\Schema(type="string")),
...
...
backend/controllers/v1/shopgoods/GoodsDetailSettingController.php
View file @
19cc03d4
...
...
@@ -5,9 +5,12 @@ namespace backend\controllers\v1\shopgoods;
use
app\models\v1\shopgoods\ShopGoods
;
use
Yii
;
use
backend\controllers\v1\BaseController
;
use
backend\helpers\UploadFiles
;
use
yidas\phpSpreadsheet\Helper
;
use
yii\web\BadRequestHttpException
;
use
yii\web\HttpException
;
use
yii\web\ServerErrorHttpException
;
use
yii\web\UploadedFile
;
class
GoodsDetailSettingController
extends
BaseController
{
...
...
@@ -232,8 +235,8 @@ class GoodsDetailSettingController extends BaseController
* @OA\GET(
* path="/backend/web/v1/shopgoods/goods-detail-settings/associated-goods-list",
* tags={"商品管理"},
* summary="
获取关联
商品列表(侯贺政)",
* description="注:如果不传pageSize字段默认分页,每页数据条数为后台默认条数
;
如果传pageSize字段则不分页,输出所有数据。pageSize值任意,字段存在不传值亦可获取所有数据。",
* summary="
商品详情页模板,获取已关联的
商品列表(侯贺政)",
* description="注:如果不传pageSize字段默认分页,每页数据条数为后台默认条数
;
如果传pageSize字段则不分页,输出所有数据。pageSize值任意,字段存在不传值亦可获取所有数据。",
* @OA\Parameter(name="page",in="query",description="分页页码",@OA\Schema(type="int")),
* @OA\Parameter(name="pageSize",in="query",description="每页条数(注意备注描述)",@OA\Schema(type="int")),
* @OA\Parameter(name="GUID",in="query",required=true,description="模板GUID",@OA\Schema(type="string")),
...
...
@@ -259,8 +262,8 @@ class GoodsDetailSettingController extends BaseController
* @OA\POST(
* path="/backend/web/v1/shopgoods/goods-detail-settings/associated-goods-add",
* tags={"商品管理"},
* summary="添加关联商品(侯贺政)",
* description="添加关联商品",
* summary="
商品详情页模板,
添加关联商品(侯贺政)",
* description="添加
模板
关联商品",
* @OA\RequestBody(
* required=true,
* description="",
...
...
@@ -295,7 +298,7 @@ class GoodsDetailSettingController extends BaseController
* @OA\DELETE(
* path="/backend/web/v1/shopgoods/goods-detail-settings/associated-goods-del",
* tags={"商品管理"},
* summary="删除单个关联商品(侯贺政)",
* summary="
商品详情页模板,
删除单个关联商品(侯贺政)",
* description="删除单个关联商品",
* @OA\Parameter(
* description="要删除的关联商品GUID",
...
...
@@ -326,4 +329,82 @@ class GoodsDetailSettingController extends BaseController
}
throw
new
HttpException
(
200
,
'删除成功'
);
}
/**
* @OA\POST(
* path="/backend/web/v1/shopgoods/goods-detail-settings/associated-goods-import",
* tags={"商品管理"},
* summary="商品详情页模板,批量导入关联商品(侯贺政)",
* description="批量导入关联商品",
* @OA\RequestBody(
* required=true,
* description="批量导入关联商品",
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(
* type="object",
* @OA\Property(
* property="uploadFile",
* type="string",
* format="binary"
* ),
* )
* )
* ),
* @OA\Response(
* response=200,
* description="导入成功",
* ),
* @OA\Response(
* response=422,
* description="导入失败,数据验证错误,返回错误数据行号及错误信息(数组)。",
* ),
* security={{"Authorization":{}}}
* )
*/
public
function
actionAssociatedGoodsImport
()
{
$upload_file
=
new
UploadFiles
([
'xlsx'
,
'xls'
]);
$upload_file
->
uploadFiles
=
UploadedFile
::
getInstance
(
$upload_file
,
'uploadFile'
);
$fileInfo
=
$upload_file
->
upload
();
if
(
$fileInfo
[
'CODE'
]
!=
'200'
)
{
Yii
::
$app
->
response
->
statusCode
=
422
;
if
(
$fileInfo
[
'INFO'
][
'uploadFiles'
][
0
]
==
"类型不对"
)
{
$fileInfo
[
'INFO'
][
'uploadFiles'
][
0
]
=
'文件类型要求97-2003工作簿 xls格式!'
;
}
return
$fileInfo
[
'INFO'
];
}
$data
=
Helper
::
newSpreadsheet
(
$fileInfo
[
'INFO'
][
0
])
->
getRows
(
true
,
[
'rowOffset'
=>
2
,
'columns'
=>
2
]);
$model
=
new
ShopGoods
();
$transaction
=
$model
->
getDb
()
->
beginTransaction
();
if
(
!
empty
(
$data
)
&&
is_array
(
$data
))
{
try
{
foreach
(
$data
as
$key
=>
$value
)
{
$_model
=
$model
::
findOne
([
'CODE'
=>
$value
[
0
]]);
if
(
$_model
!==
null
)
{
$_model
->
DETAIL_SETTING_GUID
=
$value
[
1
];
if
(
!
$_model
->
save
())
{
$transaction
->
rollBack
();
$returnInfo
=
[
(
$key
+
1
)
=>
$_model
->
errors
];
@
unlink
(
$fileInfo
[
'INFO'
][
0
]);
Yii
::
$app
->
response
->
statusCode
=
422
;
return
$returnInfo
;
}
}
}
$transaction
->
commit
();
@
unlink
(
$fileInfo
[
'INFO'
][
0
]);
throw
new
HttpException
(
"200"
,
'导入成功'
);
}
catch
(
\Throwable
$th
)
{
$transaction
->
rollBack
();
@
unlink
(
$fileInfo
[
'INFO'
][
0
]);
throw
$th
;
}
}
@
unlink
(
$fileInfo
[
'INFO'
][
0
]);
throw
new
BadRequestHttpException
(
'导入失败!'
);
}
}
backend/controllers/v1/shopuser/ShopEmployeeController.php
View file @
19cc03d4
...
...
@@ -200,6 +200,7 @@ class ShopEmployeeController extends BaseController
throw
$th
;
}
}
@
unlink
(
$fileInfo
[
'INFO'
][
0
]);
throw
new
BadRequestHttpException
(
'导入失败!'
);
}
...
...
template/associated_goods_import.xls
0 → 100644
View file @
19cc03d4
File added
template/shop_branch_score_import.xls
View file @
19cc03d4
No preview for this file type
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