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
ae267073
Commit
ae267073
authored
Dec 10, 2019
by
郭勇志
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
o2o配送导入(未完成)
parent
8688737a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
128 additions
and
57 deletions
+128
-57
urlmanager.php
backend/config/urlmanager.php
+1
-0
O2oDeliveryController.php
backend/controllers/v1/transport/O2oDeliveryController.php
+39
-47
ShopBranch.php
backend/models/v1/branch/ShopBranch.php
+1
-1
ShopCityDistributionSetting.php
backend/models/v1/branch/ShopCityDistributionSetting.php
+9
-9
ScdsImport.php
backend/models/v1/transport/ScdsImport.php
+78
-0
o2o_delivery_import.xls
template/o2o_delivery_import.xls
+0
-0
No files found.
backend/config/urlmanager.php
View file @
ae267073
...
...
@@ -261,6 +261,7 @@ return [
'PUT,OPTIONS o2o-delivery-update'
=>
'o2o-delivery-update'
,
'GET,OPTIONS o2o-delivery-export'
=>
'o2o-delivery-export'
,
'GET,OPTIONS o2o-delivery-view'
=>
'o2o-delivery-view'
,
'POST,OPTIONS o2o-delivery-import'
=>
'o2o-delivery-import'
,
],
],
//配送方式
...
...
backend/controllers/v1/transport/O2oDeliveryController.php
View file @
ae267073
...
...
@@ -11,6 +11,7 @@ use yii\web\HttpException;
use
backend\helpers\UploadFiles
;
use
yii\web\UploadedFile
;
use
yidas\phpSpreadsheet\Helper
;
use
app\models\v1\transport\ScdsImport
;
class
O2oDeliveryController
extends
BaseController
{
...
...
@@ -244,6 +245,7 @@ class O2oDeliveryController extends BaseController
*/
public
function
actionO2oDeliveryImport
()
{
$scdsImport
=
new
ScdsImport
();
$model
=
new
UploadFiles
();
if
(
Yii
::
$app
->
request
->
isPost
)
{
//多文件用getInstances
...
...
@@ -254,63 +256,53 @@ class O2oDeliveryController extends BaseController
if
(
$fileInfo
[
'CODE'
]
==
200
)
{
$rows
=
Helper
::
newSpreadsheet
(
$fileInfo
[
'INFO'
][
0
])
->
getRows
();
$tempArr
=
array_slice
(
$rows
,
2
);
$scdrModel
=
new
ShopCityDistributionRegion
();
$scdsModel
=
new
$this
->
modelClass
();
$scdsModel
->
scenario
=
'o2o_import'
;
//判断用户等级
$rbacModel
=
new
ShopRbacUser
();
$userGuid
=
Yii
::
$app
->
user
->
identity
->
GUID
;
$userInfo
=
$rbacModel
->
getRbacUserInfo
(
$userGuid
);
switch
(
$userInfo
[
'ROLE_ID'
])
{
case
USER_ROLE_HEADQUARTERS_ADMIN
:
break
;
case
USER_ROLE_REGION_ADMIN
:
break
;
case
USER_ROLE_STORE_ADMIN
:
break
;
$codeArr
=
[];
$scdsImport
->
scenario
=
'o2o_update'
;
foreach
(
$tempArr
as
$keyA
=>
$valueA
)
{
$codeArr
[]
=
$valueA
[
0
];
}
$transaction
=
$scdsModel
->
getDb
()
->
beginTransaction
();
$scdsImport
->
branchCodeArr
=
$codeArr
;
if
(
!
$scdsImport
->
validate
()){
return
$scdsImport
->
errors
;
}
$transaction
=
$scdsImport
->
getDb
()
->
beginTransaction
();
$orgGuid
=
Yii
::
$app
->
user
->
identity
->
ORG_GUID
;
try
{
foreach
(
$tempArr
as
$key
=>
$value
)
{
$_scdsModel
=
$scdsModel
::
find
()
->
where
([
'BRANCH_GUID'
=>
Yii
::
$app
->
user
->
identity
->
ORG_GUID
.
'-'
.
$value
[
0
],
'SETTING_TYPE'
=>
O2O_FLAG
]);
if
(
$_scdsModel
===
null
)
{
$_scdsModel
=
clone
$scdsModel
;
}
$_scdsModel
->
BRANCH_CODE
=
$value
[
0
];
$_scdsModel
->
REGION_TYPE
=
$value
[
1
];
$_scdsModel
->
DELIVERY_PRICE
=
$value
[
2
];
$_scdsModel
->
REGION_DISTR_DISTANCE
=
$value
[
3
];
$_scdsModel
->
REGION_DISTR_PRICE
=
$value
[
4
];
$_scdsModel
->
INCREASE_DISTANCE
=
$value
[
5
];
$_scdsModel
->
INCREASE_PRICE
=
$value
[
6
];
if
(
$_scdsModel
->
REGION_TYPE
==
1
)
{
$_scdrModel
=
$scdrModel
::
find
()
->
where
([
'$_scdsModel'
=>
$_scdsModel
->
GUID
]);
if
(
$_scdrModel
===
null
)
{
$_scdrModel
=
clone
$scdrModel
;
}
// $_scdrModel ->
if
(
!
$_scdsModel
->
save
()
||
$_scdrModel
->
save
(
false
))
{
$transaction
->
rollBack
();
$returnInfo
=
[
(
$key
+
1
)
=>
$_scdsModel
->
errors
];
@
unlink
(
$fileInfo
[
'INFO'
][
0
]);
Yii
::
$app
->
response
->
statusCode
=
422
;
return
$returnInfo
;
# code...
foreach
(
$tempArr
as
$key
=>
$valueB
)
{
$scdsImport
->
branchCode
=
$valueB
[
0
];
$scdsImport
->
REGION_TYPE
=
$valueB
[
1
];
$scdsImport
->
DELIVERY_PRICE
=
$valueB
[
2
];
$scdsImport
->
REGION_DISTR_DISTANCE
=
$valueB
[
3
];
$scdsImport
->
REGION_DISTR_PRICE
=
$valueB
[
4
];
$scdsImport
->
INCREASE_DISTANCE
=
$valueB
[
5
];
$scdsImport
->
INCREASE_PRICE
=
$valueB
[
6
];
if
(
!
$scdsImport
->
validate
()){
$returnInfo
=
[
(
$key
+
1
)
=>
$scdsImport
->
errors
];
@
unlink
(
$fileInfo
[
'INFO'
][
0
]);
Yii
::
$app
->
response
->
statusCode
=
422
;
return
$returnInfo
;
}
else
{
if
(
$scdsImport
->
REGION_TYPE
==
REGION_TYPE_REGION
)
{
//区域更新shop_city_distribution_setting和shop_city_distribution_region俩表
// $scdsImport->update();
$scdsImport
::
updateAll
([
'status'
=>
1
],
[
'status'
=>
$orgGuid
.
'-'
.
$scdsImport
->
branchCode
,
'SETTING_TYPE'
=>
O2O_FLAG
]);
}
elseif
(
$scdsImport
->
REGION_TYPE
==
REGION_TYPE_DISTANCE
){
//距离更新shop_city_distribution_setting表
}
}
elseif
(
$_scdsModel
->
REGION_TYPE
==
2
){
}
}
$transaction
->
commit
();
@
unlink
(
$fileInfo
[
'INFO'
][
0
]);
throw
new
HttpException
(
"200"
,
'导入成功'
);
}
catch
(
\Throwable
$e
)
{
$transaction
->
rollBack
();
@
unlink
(
$fileInfo
[
'INFO'
][
0
]);
throw
$e
;
}
}
else
{
return
$fileInfo
[
'INFO'
];
}
...
...
backend/models/v1/branch/ShopBranch.php
View file @
ae267073
...
...
@@ -50,7 +50,7 @@ use app\models\v1\rbacuser\ShopRbacUser;
* @property string $TRANSFERS_OPENID 收款人openid
* @property int $IS_SHELVE 是否营业
* @property string $LICENCE_DATE 营业执照到期时间
* @property int $BRANCH_TYPE 部门类型,0:总部 1:省级DC分公司 2:
区域 3:
门店
* @property int $BRANCH_TYPE 部门类型,0:总部 1:省级DC分公司 2:门店
* @property string $SUPPORT_SEND_PLATFORM 支持配送的平台:(1.达达,2蜂鸟,3美团) 按顺序逗号分隔
* @property string $TRANSPORT_TYPE 快递类型
* @property int $IS_DELIVERY_CODECHAIN_GOODS 1:支持冷链配送,0:不支持
...
...
backend/models/v1/branch/ShopCityDistributionSetting.php
View file @
ae267073
...
...
@@ -62,17 +62,17 @@ class ShopCityDistributionSetting extends BaseModel
[[
'ORG_GUID'
,
'GUID'
,
'BRANCH_GUID'
,
'REGION_TYPE'
,
'SETTING_TYPE'
],
'required'
,
'on'
=>
[
'insert'
,
'update'
]],
[[
'STATUS'
],
'boolean'
],
[[
'REGION_TYPE'
,
'SETTING_TYPE'
],
'in'
,
'range'
=>
[
1
,
2
],
'on'
=>
[
'insert'
,
'update'
]
],
[[
'REGION_TYPE'
,
'SETTING_TYPE'
],
'in'
,
'range'
=>
[
1
,
2
],
'on'
=>
[
'insert'
,
'update'
,
'o2o_update'
],
'message'
=>
'{attribute}只能为1或2'
],
[[
'BRANCH_GUID'
],
'exist'
,
'skipOnError'
=>
true
,
'targetClass'
=>
ShopBranch
::
className
(),
'targetAttribute'
=>
[
'BRANCH_GUID'
=>
'GUID'
]],
[[
'BRANCH_INFO'
],
'match'
,
'pattern'
=>
'/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u'
,
'message'
=>
'只能包含中文汉字,字母,数字'
,
'on'
=>
'search'
],
[[
'
GUID'
,
'REGION_TYPE'
],
'required'
,
'on'
=>
[
'o2o_update'
],
'message'
=>
'{attribute}不能为空'
],
[[
'REGION_DISTR_DISTANCE'
,
'REGION_DISTR_PRICE'
,
'INCREASE_DISTANCE'
,
'INCREASE_PRICE'
,
'DELIVERY_PRICE'
],
'double'
,
'on'
=>
[
'o2o_update'
]],
[[
'REGION_DISTR_DISTANCE'
,
'REGION_DISTR_PRICE'
,
'INCREASE_DISTANCE'
,
'INCREASE_PRICE'
],
'required'
,
'when'
=>
function
(
$model
)
{
[[
'BRANCH_INFO'
],
'match'
,
'pattern'
=>
'/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u'
,
'message'
=>
'只能包含中文汉字,字母,数字'
,
'on'
=>
'search'
],
[[
'
REGION_TYPE'
],
'required'
,
'on'
=>
[
'o2o_update'
],
'message'
=>
'{attribute}不能为空'
],
[[
'REGION_DISTR_DISTANCE'
,
'REGION_DISTR_PRICE'
,
'INCREASE_DISTANCE'
,
'INCREASE_PRICE'
,
'DELIVERY_PRICE'
],
'double'
,
'on'
=>
[
'o2o_update'
]],
[[
'REGION_DISTR_DISTANCE'
,
'REGION_DISTR_PRICE'
,
'INCREASE_DISTANCE'
,
'INCREASE_PRICE'
],
'required'
,
'when'
=>
function
(
$model
)
{
return
$model
->
REGION_TYPE
==
'2'
;
},
'message'
=>
'{attribute}不能为空'
,
'on'
=>
[
'o2o_update'
]],
[[
'DELIVERY_PRICE'
],
'required'
,
'when'
=>
function
(
$model
)
{
},
'message'
=>
'费用类型为2时,{attribute}不能为空'
,
'on'
=>
[
'o2o_update'
]],
[[
'DELIVERY_PRICE'
],
'required'
,
'when'
=>
function
(
$model
)
{
return
$model
->
REGION_TYPE
==
'1'
;
},
'message'
=>
'{attribute}不能为空'
,
'on'
=>
[
'o2o_update'
]],
},
'message'
=>
'费用类型为1时,{attribute}不能为空'
,
'on'
=>
[
'o2o_update'
]],
];
}
...
...
@@ -90,7 +90,7 @@ class ShopCityDistributionSetting extends BaseModel
'IS_OTHER_DISTR'
=>
'Is Other Distr'
,
'WORK_TYPE'
=>
'Work Type'
,
'IS_DADA_DISTR'
=>
'Is Dada Distr'
,
'REGION_TYPE'
=>
'
配送
类型'
,
'REGION_TYPE'
=>
'
费用
类型'
,
'SIMPLE_DISTR_NOTES'
=>
'Simple Distr Notes'
,
'SIMPLE_DISTR_PIC'
=>
'Simple Distr Pic'
,
'SIMPLE_DISTR_INITIAL_PRICE'
=>
'Simple Distr Initial Price'
,
...
...
backend/models/v1/transport/ScdsImport.php
0 → 100644
View file @
ae267073
<?php
namespace
app\models\v1\transport
;
use
app\models\v1\rbacuser\ShopRbacUser
;
use
Yii
;
use
app\models\v1\branch\ShopCityDistributionSetting
;
use
yii\web\HttpException
;
class
ScdsImport
extends
ShopCityDistributionSetting
{
//用来导入数据时使用
public
$branchCodeArr
=
[];
//门店code数组
public
$branchCode
=
''
;
//门店code
/**
* {@inheritdoc}
*/
public
function
rules
()
{
$sonRules
=
[
[[
'branchCodeArr'
],
'validateEffective'
],
[[
'branchCode'
],
'required'
,
'message'
=>
'{attribute}不能为空'
],
];
return
array_merge
(
parent
::
rules
(),
$sonRules
);
}
public
function
attributeLabels
()
{
$sonAttri
=
[
'branchCode'
=>
'门店编码'
];
return
array_merge
(
parent
::
attributeLabels
(),
$sonAttri
);
}
//验证用户有没有权限修改导入门店电子围栏信息
public
function
validateEffective
(
$attribute
)
{
$rbacUserModel
=
new
ShopRbacUser
();
$userGuid
=
Yii
::
$app
->
user
->
identity
->
GUID
;
$userInfo
=
$rbacUserModel
->
getRbacUserInfo
(
$userGuid
);
switch
(
$userInfo
[
'BRANCH_TYPE'
])
{
case
BRANCH_TYPE_HEADQUARTERS
://
总部
$branchGuid
=
''
;
$parentGuid
=
''
;
break
;
case
BRANCH_TYPE_REGION
://
省级
/
分公司
$branchGuid
=
$userInfo
[
'BRANCH_GUID'
];
$parentGuid
=
$userInfo
[
'BRANCH_GUID'
];
break
;
case
BRANCH_TYPE_STORE
://
门店
$branchGuid
=
$userInfo
[
'BRANCH_GUID'
];
$parentGuid
=
''
;
break
;
default
:
throw
new
HttpException
(
500
,
'不存在的门店等级'
);
break
;
}
$codeArr
=
$this
::
find
()
->
select
(
'CODE'
)
->
from
(
'SHOP_BRANCH'
)
->
where
([
'CODE'
=>
$this
->
branchCodeArr
])
->
andFilterWhere
([
'or'
,[
'GUID'
=>
$branchGuid
],[
'PARENT_GUID'
=>
$parentGuid
]])
->
asArray
()
->
all
();
$tempArr
=
[];
foreach
(
$codeArr
as
$value
)
{
$tempArr
[]
=
$value
[
'CODE'
];
}
$diff
=
array_diff
(
$this
->
branchCodeArr
,
$tempArr
);
if
(
!
empty
(
$diff
))
{
$this
->
addError
(
$attribute
,
'门店编码为'
.
implode
(
','
,
$diff
)
.
'的门店不存在或者您没有权限操作此门店.'
);
}
}
}
template/o2o_delivery_import.xls
View file @
ae267073
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