Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
李洋
/
消息系统
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1a91bd70
authored
7 years ago
by
李洋
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
删除 多余controller文件
parent
cfe21d14
master
…
dev
leo_msg_tmp_classify_20190412
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
1763 deletions
app/Http/Controllers/FootStoneApiController.php
app/Http/Controllers/FootStoneController.php
app/Http/Controllers/FootStoneApiController.php
deleted
100644 → 0
View file @
cfe21d14
<?php
namespace
App\Http\Controllers
;
use
Illuminate\Http\Request
;
use
App\Http\Requests
;
use
DB
;
use
RedisDB
;
class
FootStoneApiController
extends
Controller
{
public
function
Entrance
(
Request
$request
,
$id
){
//统一入口
$this
->
$id
(
$request
,
$id
);
}
private
function
Export
(
$errcode
=
0
,
$errmsg
=
'成功'
,
$data
=
''
){
echo
json_encode
([
'errcode'
=>
$errcode
,
'errmsg'
=>
$errmsg
,
'data'
=>
$data
]);
exit
();
}
//获取猎芯品牌
private
function
liexinbrand
(
$request
,
$id
,
$limit
=
20
){
$map
=
strtoupper
(
$request
->
input
(
'brand_name'
));
$result
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand'
)
->
where
(
'status'
,
'='
,
1
);
if
(
$map
){
$result
=
$result
->
where
(
'brand_name'
,
'like'
,
'%'
.
$map
.
'%'
);
}
$content
=
$result
->
select
(
'brand_name'
,
'brand_id'
)
->
paginate
(
$limit
);
if
(
!
$content
){
$this
->
Export
(
11005
,
'没有查找到猎芯标准制造商'
);
}
if
(
$map
){
foreach
(
$content
as
$k
=>
$v
){
$content
[
$k
]
->
brand_name
=
str_ireplace
(
$map
,
'<span style="color: red">'
.
$map
.
'</span>'
,
$v
->
brand_name
);
}
}
$this
->
Export
(
0
,
'成功'
,
$content
);
}
//获取供应商品牌
private
function
supplier_brand
(
$request
,
$id
){
$map
=
strtoupper
(
$request
->
input
(
'supplier_brand_name'
));
$supplier_name
=
$request
->
input
(
'supplier_name'
);
$DB
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand_mapping'
)
->
where
(
'status'
,
'='
,
1
);
if
(
$map
){
$DB
=
$DB
->
where
(
'supplier_brand_name'
,
'like'
,
'%'
.
$map
.
'%'
);
}
if
(
$supplier_name
){
$DB
=
$DB
->
where
(
'supplier_name'
,
'='
,
$supplier_name
);
}
$DB
=
$DB
->
where
(
'status'
,
'='
,
1
)
->
where
(
'liexin_brand_id'
,
'='
,
0
);
$data
=
''
;
$content
=
$DB
->
select
(
'supplier_brand_name'
,
'id'
)
->
limit
(
1000
)
->
get
();
if
(
count
(
$content
)
>
0
){
foreach
(
$content
as
$k
=>
$v
){
$v
=
(
array
)
$v
;
$field
=
Getzimu
(
$v
[
'supplier_brand_name'
]);
if
((
$field
||
json_encode
(
$field
)
===
'null'
)){
$data
[
$field
][
$k
]
=
$v
;
}
else
{
$data
[
strtoupper
(
substr
(
$v
[
'supplier_brand_name'
],
0
,
1
))][
$k
]
=
$v
;
}
if
(
$map
){
$data
[
strtoupper
(
substr
(
$v
[
'supplier_brand_name'
],
0
,
1
))][
$k
][
'supplier_brand_name'
]
=
str_ireplace
(
$map
,
'<span style="color: red">'
.
$map
.
'</span>'
,
$data
[
strtoupper
(
substr
(
$v
[
'supplier_brand_name'
],
0
,
1
))][
$k
][
'supplier_brand_name'
]);
}
}
}
$content
=
null
;
$request
=
null
;
if
(
$data
){
ksort
(
$data
);
}
$this
->
Export
(
0
,
'成功'
,
$data
);
}
//品牌映射关联
private
function
binding_mapping
(
$request
){
$id
=
$request
->
input
(
'id'
);
$brand_id
=
$request
->
input
(
'brand_id'
);
if
(
empty
(
$id
)
||
!
is_array
(
$id
)
){
$this
->
Export
(
11001
,
'请选择需映射制造商'
,
''
);
}
if
(
empty
(
$brand_id
)){
$this
->
Export
(
11002
,
'请选择猎芯标准制造商'
,
''
);
}
$data
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand_mapping'
)
->
where
(
'status'
,
'='
,
1
)
->
where
(
'liexin_brand_id'
,
'='
,
0
)
->
lists
(
'supplier_brand_name'
,
'id'
);
foreach
(
$id
as
$k
=>
$v
){
if
(
!
$data
[
$v
]){
$this
->
Export
(
11003
,
"该制造商
{
$data
[
$v
]
}
暂时不能映射"
,
''
);
}
}
$errinfo
=
''
;
foreach
(
$id
as
$k
=>
$v
){
$add
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand_mapping'
)
->
where
(
'id'
,
$v
)
->
update
([
'liexin_brand_id'
=>
$brand_id
]);
if
(
!
$add
){
$errinfo
.=
','
.
$data
[
$v
];
}
}
if
(
$errinfo
){
$this
->
Export
(
11004
,
"制造商
{
$errinfo
}
映射失败"
,
''
);
}
$this
->
Export
();
}
//新增品牌
private
function
addbrand
(
$request
){
$data
=
$request
->
input
();
if
(
empty
(
$data
[
'brand_name'
])){
$this
->
Export
(
11010
,
'请输入制造商名称'
,
'brand_name'
);
}
if
(
empty
(
$data
[
'brand_logo'
])){
// $this->Export(11011,'制造商图标必须上传','brand_name');
}
$input_model
=
[];
$input_model
[
'brand_id'
]
=
$data
[
'brand_id'
];
$input_model
[
'brand_name'
]
=
$data
[
'brand_name'
];
$input_model
[
'brand_logo'
]
=
$data
[
'brand_logo'
];
$input_model
[
'brand_desc'
]
=
$data
[
'brand_desc'
];
$input_model
[
'status'
]
=
$data
[
'status'
];
$input_model
[
'main_product'
]
=
$data
[
'main_product'
];
$input_model
[
'brand_brief'
]
=
$data
[
'brand_brief'
];
if
(
isset
(
$data
[
'brand_area'
]))
{
$input_model
[
'brand_area'
]
=
$data
[
'brand_area'
];
}
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand'
);
if
(
!
empty
(
$input_model
[
'brand_id'
])){
$resurt
=
$db
->
where
(
'brand_id'
,
$input_model
[
'brand_id'
])
->
update
(
$input_model
);
if
(
!
$resurt
)
{
$this
->
Export
(
11011
,
'修改制造商失败'
,
'sql'
);
}
}
else
{
$find
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand'
)
->
where
(
'brand_name'
,
$input_model
[
'brand_name'
])
->
first
();
if
(
$find
){
$this
->
Export
(
11012
,
'当前品牌名字已经存在'
,
'brand_name'
);
}
$input_model
[
'create_time'
]
=
time
();
$resurt
=
$db
->
insert
(
$input_model
);
if
(
!
$resurt
)
{
$this
->
Export
(
11013
,
'新增制造商失败'
,
'sql'
);
}
}
$this
->
Export
(
0
,
empty
(
$input_model
[
'brand_id'
])
?
'新增成功'
:
'修改成功'
);
}
//获取类
private
function
Obtain_class
(
$request
){
$map
=
$request
->
input
(
'class_id'
)
?
$request
->
input
(
'class_id'
)
:
0
;
$list
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify'
)
->
where
(
'status'
,
1
)
->
where
(
'parent_id'
,
$map
)
->
get
();
$this
->
Export
(
0
,
''
,
$list
);
}
//批量下架SKU
private
function
off_shelf
(
$request
){
$map
=
$request
->
input
(
'spu_id'
);
if
(
empty
(
$map
)
||
!
is_array
(
$map
)){
$this
->
Export
(
14021
,
'请选择要操作的SPU'
,
'0'
);
}
$status
=
$request
->
input
(
'status'
);
$Redis
=
RedisDB
::
connection
();
switch
(
$status
){
case
'offshelf'
:
$updata
[
'status'
]
=
3
;
$errinfo
=
'成功下架'
;
break
;
case
'passed'
:
$errinfo
=
'成功上架'
;
$updata
[
'status'
]
=
1
;
break
;
case
'negative'
:
$updata
[
'status'
]
=
2
;
$errinfo
=
'审核不通过'
;
break
;
}
$i
=
0
;
foreach
(
$map
as
$k
=>
$v
){
$dbinfo
=
resolve
(
$v
);
$list
=
DB
::
connection
(
'spu'
)
->
table
(
$dbinfo
[
'table'
])
->
where
(
'spu_id'
,
$v
)
->
update
(
$updata
);
if
(
$list
){
$info
=
json_decode
(
$Redis
->
hget
(
'spu'
,
$v
),
true
);
$info
[
'status'
]
=
$updata
[
'status'
];
Handle_spu
(
$info
);
$i
++
;
}
}
$this
->
Export
(
0
,
$errinfo
.
$i
.
'件SPU'
,
$i
);
}
//生成分类归类信息redis
private
function
generate_class_redis
(){
$Redis
=
RedisDb
::
connection
();
$list
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify'
)
->
get
();
$class
=
tree_class
(
$list
);
foreach
(
$class
as
$k1
=>
$v1
){
$class
[
$k1
]
=
(
array
)
$class
[
$k1
];
foreach
(
$class
[
$k1
][
'lower'
]
as
$k2
=>
$v2
){
$data
=
[];
$class
[
$k1
][
'lower'
][
$k2
]
=
(
array
)
$class
[
$k1
][
'lower'
][
$k2
];
foreach
(
$class
[
$k1
][
'lower'
][
$k2
][
'lower'
]
as
$k3
=>
$v3
){
$class
[
$k1
][
'lower'
][
$k2
][
'lower'
][
$k3
]
=
(
array
)
$class
[
$k1
][
'lower'
][
$k2
][
'lower'
][
$k3
];
$value
=
$v1
->
class_id
.
','
.
$v2
->
class_id
;
$data
[
$v3
->
class_id
]
=
$value
;
}
$Redis
->
hmset
(
'class_ing'
,
$data
);
}
}
$list
=
$Redis
->
hget
(
'class_ing_'
.
'*'
);
dump
(
$list
);
}
//新增/编辑分类接口
private
function
addclassify
(
$request
){
$data
=
$request
->
input
();
if
(
empty
(
$data
[
'class_name'
])){
$this
->
Export
(
12010
,
'请输入分类名称'
,
'class_name'
);
}
//通过模型取出需要传递的数据,避免_url的出现
$input_model
=
[];
$input_model
[
'class_id'
]
=
$data
[
'class_id'
];
$input_model
[
'class_name'
]
=
$data
[
'class_name'
];
$input_model
[
'parent_id'
]
=
$data
[
'parent_id'
];
$input_model
[
'status'
]
=
$data
[
'status'
];
$input_model
[
'class_icon'
]
=
$data
[
'class_icon'
];
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify'
);
if
(
!
empty
(
$input_model
[
'class_id'
])){
$resurt
=
$db
->
where
(
'class_id'
,
$input_model
[
'class_id'
])
->
update
(
$input_model
);
if
(
!
$resurt
)
{
$this
->
Export
(
12011
,
'编辑分类失败'
,
'sql'
);
}
//清除class和tree_class缓存
$this
->
redisRemove
(
'class'
);
$this
->
redisRemove
(
'tree_class'
);
}
else
{
//同名&&同父级则重复
$isDuplicated
=
$this
->
isDuplicatedInSameLevel
(
$input_model
[
'class_name'
],
$input_model
[
'parent_id'
]);
if
(
$isDuplicated
){
$this
->
Export
(
12012
,
'当前分类名字已经存在'
,
'class_name'
);
}
$input_model
[
'create_time'
]
=
time
();
$result
=
$db
->
insert
(
$input_model
);
if
(
!
$result
)
{
$this
->
Export
(
12013
,
'新增分类失败'
,
'sql'
);
}
}
$this
->
Export
(
0
,
empty
(
$input_model
[
'class_id'
])
?
'新增成功'
:
'修改成功'
);
}
//新增/编辑供应商接口
private
function
addsupplier
(
$request
)
{
$data
=
$request
->
input
();
if
(
empty
(
$data
[
'supplier_name'
])){
$this
->
Export
(
15010
,
'请填写供应商'
);
}
if
(
empty
(
$data
[
'code'
]))
{
$this
->
Export
(
15011
,
'请选择供应商负责人'
);
}
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_supplier'
);
if
(
!
empty
(
$data
[
'supplier_id'
])){
$model_update
=
[];
$model_update
[
'type_id'
]
=
$data
[
'type_id'
];
$model_update
[
'supplier_name'
]
=
$data
[
'supplier_name'
];
$model_update
[
'code'
]
=
$data
[
'code'
];
$model_update
[
'status'
]
=
$data
[
'status'
];
$resurt
=
$db
->
where
(
'supplier_id'
,
$data
[
'supplier_id'
])
->
update
(
$model_update
);
if
(
!
$resurt
)
{
$this
->
Export
(
15012
,
'修改供应商失败'
,
'sql'
);
}
//清除class和tree_class缓存
$this
->
redisRemove
(
'supplier'
);
}
else
{
$find
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_supplier'
)
->
where
(
'supplier_name'
,
$data
[
'supplier_name'
])
->
select
(
'supplier_id'
)
->
first
();
if
(
$find
){
$this
->
Export
(
15013
,
'当前供应商名字已经存在'
,
'supplier_name'
);
}
$model_insert
=
[];
$model_insert
[
'type_id'
]
=
$data
[
'type_id'
];
$model_insert
[
'supplier_name'
]
=
$data
[
'supplier_name'
];
$model_insert
[
'code'
]
=
$data
[
'code'
];
$model_insert
[
'status'
]
=
$data
[
'status'
];
$model_insert
[
'create_time'
]
=
time
();
$resurt
=
$db
->
insert
(
$model_insert
);
if
(
!
$resurt
)
{
$this
->
Export
(
15014
,
'新增供应商失败'
,
'sql'
);
}
}
$this
->
Export
(
0
,
empty
(
$data
[
'supplier_id'
])
?
'新增成功'
:
'修改成功'
);
}
//点击变更供应商状态接口
private
function
operation_supplier_status
(
$request
)
{
$data
=
$request
->
input
();
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_supplier'
);
$supplier
=
$db
->
where
(
'supplier_id'
,
$data
[
'supplier_id'
])
->
first
();
$supplier
->
status
=
$data
[
'status'
];
$supplier
=
(
array
)
$supplier
;
$result
=
$db
->
where
(
'supplier_id'
,
$data
[
'supplier_id'
])
->
update
(
$supplier
);
if
(
!
$result
)
{
$this
->
Export
(
15015
,
'修改供应商状态失败'
);
}
$this
->
Export
(
0
,
"修改成功"
);
}
//新增/编辑SPU接口
private
function
addspu
(
$request
){
$data
=
$request
->
input
();
if
(
empty
(
$data
[
'class_id3'
])){
$this
->
Export
(
13010
,
'请选择分类名称'
,
'class_id3'
);
}
if
(
empty
(
$data
[
'class_id1'
])
||
empty
(
$data
[
'class_id2'
]))
{
$this
->
Export
(
13011
,
'提交分类名称有误'
);
}
if
(
empty
(
$data
[
'spu_name'
])){
$this
->
Export
(
13012
,
'请填写SPU型号'
,
'spu_name'
);
}
if
(
empty
(
$data
[
'brand_id'
])){
$this
->
Export
(
13013
,
'请选择制造商'
,
'brand_id'
);
}
//通过模型取出需要传递的数据,避免_url的出现
$input_model
=
[];
$input_model
[
'spu_id'
]
=
$data
[
'spu_id'
];
$input_model
[
'class_id1'
]
=
$data
[
'class_id1'
];
$input_model
[
'class_id2'
]
=
$data
[
'class_id2'
];
$input_model
[
'class_id3'
]
=
$data
[
'class_id3'
];
$input_model
[
'brand_id'
]
=
$data
[
'brand_id'
];
$input_model
[
'spu_name'
]
=
$data
[
'spu_name'
];
$input_model
[
'status'
]
=
$data
[
'status'
];
$input_model
[
'images_l'
]
=
$data
[
'images_l'
];
$input_model
[
'images_s'
]
=
$data
[
'images_s'
];
$input_model
[
'encap'
]
=
$data
[
'encap'
];
$input_model
[
'pdf'
]
=
$data
[
'pdf'
];
$input_model
[
'spu_brief'
]
=
$data
[
'spu_brief'
];
$input_model
[
'has_rohs'
]
=
$data
[
'has_rohs'
];
$input_model
[
'attrs'
]
=
$data
[
'attrs'
];
$input_model
[
'spu_detail'
]
=
$data
[
'spu_detail'
];
$input_model
[
'bussiness_area'
]
=
$data
[
'bussiness_area'
];
$collert
=
$input_model
[
'spu_id'
];
if
(
$collert
)
//编辑
{
$dt
=
resolve
(
$collert
);
$input_model
[
'update_time'
]
=
time
();
$result
=
DB
::
connection
(
$dt
[
'db'
])
->
table
(
$dt
[
'table'
])
->
where
(
'spu_id'
,
$input_model
[
'spu_id'
])
->
update
(
$input_model
);
if
(
!
$result
)
{
$this
->
Export
(
13014
,
'编辑SPU失败'
,
'sql'
);
}
//编辑成功,写入Redis
$info
=
DB
::
connection
(
$dt
[
'db'
])
->
table
(
$dt
[
'table'
])
->
where
(
'spu_id'
,
$input_model
[
'spu_id'
])
->
first
();
Handle_spu
(
$info
);
//写入mongo
$result_mongo
=
save_mongo_spu
(
$info
->
brand_id
,
$info
->
spu_name
,
$info
->
spu_id
);
// if(false == $result_mongo)
// {
// $this->Export(13017, '编辑时写入mongo失败', 'sql');
// }
}
else
//新增
{
//在同个品牌下不存在spu才能新增
if
(
!
only_judge_spu
(
$input_model
[
'brand_id'
],
$input_model
[
'spu_name'
]))
{
//添加到哪个库
$spu_id
=
structure
();
$dbinfo
=
resolve
(
$spu_id
);
$input_model
[
'create_time'
]
=
time
();
$input_model
[
'update_time'
]
=
time
();
$input_model
[
'sale_time'
]
=
time
();
$input_model
[
'spu_id'
]
=
$spu_id
;
$result
=
DB
::
connection
(
$dbinfo
[
'db'
])
->
table
(
$dbinfo
[
'table'
])
->
insert
(
$input_model
);
if
(
!
$result
)
{
$this
->
Export
(
13015
,
'新增SPU失败'
,
'sql'
);
}
//新增spu成功,写入Redis
$info
=
DB
::
connection
(
$dbinfo
[
'db'
])
->
table
(
$dbinfo
[
'table'
])
->
where
(
'spu_id'
,
$input_model
[
'spu_id'
])
->
first
();
Handle_spu
(
$info
);
//写入mongo
save_mongo_spu
(
$info
->
brand_id
,
$info
->
spu_name
,
$info
->
spu_id
);
}
else
{
$this
->
Export
(
13016
,
'新增SPU失败,该品牌中已存在同名SPU'
,
'sql'
);
}
}
//推送通知ES
Push_update
(
$input_model
[
'spu_id'
],
$type
=
'spu'
);
$this
->
Export
(
0
,
$collert
?
'编辑成功'
:
'新增成功'
);
}
//新增/编辑SKU接口
private
function
addsku
(
$request
){
$data
=
$request
->
input
();
if
(
empty
(
$data
[
'supplier_id'
]))
{
$this
->
Export
(
14011
,
'请选择供应商'
,
'supplier_id'
);
}
if
(
empty
(
$data
[
'goods_name'
]))
{
$this
->
Export
(
14012
,
'请选择SKU型号'
,
'goods_name'
);
}
if
(
empty
(
$data
[
'stock'
]))
{
$this
->
Export
(
14013
,
'请填写库存量'
,
'stock'
);
}
if
(
empty
(
$data
[
'moq'
]))
{
$this
->
Export
(
14014
,
'请填写起订量'
,
'moq'
);
}
if
(
empty
(
$data
[
'mpq'
]))
{
$this
->
Export
(
14015
,
'请填写标准包装量'
,
'mpq'
);
}
if
(
empty
(
$data
[
'hk_delivery_time'
]))
{
$this
->
Export
(
14016
,
'请填写香港货期'
,
'hk_delivery_time'
);
}
if
(
empty
(
$data
[
'cn_delivery_time'
]))
{
$this
->
Export
(
14017
,
'请填写大陆货期'
,
'cn_delivery_time'
);
}
//通过模型取出需要传递的数据,避免_url的出现
$input_model
=
[];
$input_model
[
'goods_id'
]
=
$data
[
'goods_id'
];
$input_model
[
'spu_id'
]
=
$data
[
'spu_id'
];
$input_model
[
'goods_name'
]
=
$data
[
'goods_name'
];
$input_model
[
'supplier_id'
]
=
$data
[
'supplier_id'
];
//新增的时候根据supplier_id查商品类型 编辑的时候带过来
if
(
isset
(
$data
[
'goods_type'
]))
{
$input_model
[
'goods_type'
]
=
$data
[
'goods_type'
];
}
else
{
$info
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_supplier'
)
->
where
(
'supplier_id'
,
$data
[
'supplier_id'
])
->
first
();
$input_model
[
'goods_type'
]
=
$info
->
type_id
;
}
$input_model
[
'goods_status'
]
=
$data
[
'goods_status'
];
if
(
isset
(
$data
[
'encoded'
]))
{
$input_model
[
'encoded'
]
=
$data
[
'encoded'
];
}
$input_model
[
'batch_sn'
]
=
$data
[
'batch_sn'
];
$input_model
[
'moq'
]
=
$data
[
'moq'
];
$input_model
[
'mpq'
]
=
$data
[
'mpq'
];
$input_model
[
'stock'
]
=
$data
[
'stock'
];
$input_model
[
'hk_delivery_time'
]
=
$data
[
'hk_delivery_time'
];
$input_model
[
'cn_delivery_time'
]
=
$data
[
'cn_delivery_time'
];
$input_model
[
'goods_details'
]
=
$data
[
'goods_details'
];
$input_model
[
'ladder_price'
]
=
$data
[
'ladder_price'
];
$input_model
[
'single_price'
]
=
$data
[
'single_price'
];
$input_model
[
'remark'
]
=
$data
[
'remark'
];
$input_model
[
'goods_images'
]
=
$data
[
'goods_images'
];
$collert
=
$input_model
[
'goods_id'
];
if
(
$collert
)
//编辑
{
$dt
=
resolve
(
$collert
);
$input_model
[
'update_time'
]
=
time
();
$result
=
DB
::
connection
(
$dt
[
'db'
])
->
table
(
$dt
[
'table'
])
->
where
(
'goods_id'
,
$input_model
[
'goods_id'
])
->
update
(
$input_model
);
if
(
!
$result
)
{
$this
->
Export
(
14018
,
'编辑SKU失败'
,
'sql'
);
}
else
{
//编辑成功,写入Redis
$info
=
DB
::
connection
(
$dt
[
'db'
])
->
table
(
$dt
[
'table'
])
->
where
(
'goods_id'
,
$input_model
[
'goods_id'
])
->
first
();
Handle_sku
(
$info
);
//写到mongo
save_mongo_sku
(
$info
->
spu_id
,
$info
->
supplier_id
,
$info
->
moq
,
$info
->
goods_id
);
}
}
else
//新增
{
if
(
!
only_judge_sku
(
$input_model
[
'spu_id'
],
$input_model
[
'supplier_id'
],
$input_model
[
'moq'
]))
{
//添加到哪个库
$sku_id
=
structure
(
'sku'
);
$dbinfo
=
resolve
(
$sku_id
);
$input_model
[
'create_time'
]
=
time
();
$input_model
[
'update_time'
]
=
time
();
$input_model
[
'goods_id'
]
=
$sku_id
;
$result
=
DB
::
connection
(
$dbinfo
[
'db'
])
->
table
(
$dbinfo
[
'table'
])
->
insert
(
$input_model
);
if
(
!
$result
)
{
$this
->
Export
(
14019
,
'新增SKU失败'
,
'sql'
);
}
else
{
//新增成功,写入Redis
$info
=
DB
::
connection
(
$dbinfo
[
'db'
])
->
table
(
$dbinfo
[
'table'
])
->
where
(
'goods_id'
,
$input_model
[
'goods_id'
])
->
first
();
Handle_sku
(
$info
);
//写到mongo
save_mongo_sku
(
$info
->
spu_id
,
$info
->
supplier_id
,
$info
->
moq
,
$info
->
goods_id
);
}
}
else
{
$this
->
Export
(
14020
,
'新增SKU失败,该品牌中已存在同名SKU'
,
'sql'
);
}
}
$push_result
=
Push_update
(
$input_model
[
'goods_id'
],
$type
=
'sku'
);
$this
->
Export
(
0
,
$collert
?
'编辑成功'
:
'新增成功'
);
}
//分类映射
private
function
classifymapping
(
$request
){
$map
=
$request
->
input
(
'cm_id'
);
$name
=
$request
->
input
(
'supplier_name'
);
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify_mapping'
)
->
where
(
'liexin_class_id'
,
0
);
if
(
$name
){
$db
=
$db
->
where
(
'supplier_name'
,
$name
);
}
$list
=
$db
->
where
(
'parent_id'
,
$map
)
->
select
(
'cm_id'
,
'cm_name'
,
'parent_id'
)
->
get
();
foreach
(
$list
as
$k
=>
$v
){
$result
=
''
;
$result
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify_mapping'
)
->
where
(
'liexin_class_id'
,
0
)
->
where
(
'parent_id'
,
$v
->
cm_id
)
->
select
(
'cm_id'
)
->
first
();
if
(
$result
){
$list
[
$k
]
->
lower
=
'1'
;
}
else
{
if
(
$map
==
0
){
unset
(
$list
[
$k
]);
}
}
}
$this
->
Export
(
0
,
'成功'
,
$list
);
}
//完成分类映射
private
function
complete_mapping
(
$request
){
$su_id
=
$request
->
input
(
'su_id'
);
$liexin_class_id
=
$request
->
input
(
'liexin_class_id'
);
if
(
empty
(
$su_id
)
||
!
is_array
(
$su_id
)){
$this
->
Export
(
12051
,
'请选择需映射的分类'
);
}
if
(
!
$liexin_class_id
){
$this
->
Export
(
12052
,
'请选择猎芯标准分类'
);
}
$map
[
'status'
]
=
1
;
$map
[
'liexin_class_id'
]
=
0
;
$save
[
'liexin_class_id'
]
=
$liexin_class_id
;
$i
=
0
;
foreach
(
$su_id
as
$k
=>
$v
){
$map
[
'cm_id'
]
=
$v
;
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify_mapping'
)
->
where
(
$map
);
$result
=
$db
->
update
(
$save
);
if
(
$result
){
$i
++
;
}
}
$this
->
Export
(
0
,
'成功关联'
.
$i
.
'个分类'
);
}
private
function
create_spu_mongo
()
{
set_time_limit
(
0
);
$starttime
=
explode
(
' '
,
microtime
());
$mongo
=
new
\MongoClient
(
env
(
'MONGO_HOST'
,
''
));
$mongodb
=
$mongo
->
ichunt
->
spu
;
$count
=
100
;
$db
=
DB
::
connection
(
'spu'
);
$i
=
0
;
for
(
$table
=
0
;
$table
<
10
;
$table
++
){
for
(
$p
=
1
;
$p
<
$count
+
1
;
$p
++
){
$data
=
[];
$list
=
$db
->
table
(
'lie_spu_'
.
$table
)
->
select
(
'spu_name'
,
'brand_id'
,
'spu_id'
)
->
paginate
(
1000
,[
'*'
],
''
,
$p
);
foreach
(
$list
as
$k
=>
$v
){
$data
[]
=
[
'spu_id'
=>
$v
->
spu_id
,
'spu_name'
=>
$v
->
spu_name
,
'brand_id'
=>
$v
->
brand_id
];
$i
++
;
}
$result
=
$mongodb
->
batchInsert
(
$data
);
$count
=
$list
->
lastPage
();
echo
$i
.
'->'
;
}
}
//程序运行时间
$endtime
=
explode
(
' '
,
microtime
());
$thistime
=
$endtime
[
0
]
+
$endtime
[
1
]
-
(
$starttime
[
0
]
+
$starttime
[
1
]);
$thistime
=
round
(
$thistime
,
3
);
echo
"本程序执行耗时:"
.
$thistime
.
" 秒。"
;
}
private
function
create_sku_mongo
()
{
set_time_limit
(
0
);
$starttime
=
explode
(
' '
,
microtime
());
$mongo
=
new
\MongoClient
(
env
(
'MONGO_HOST'
,
''
));
$mongodb
=
$mongo
->
ichunt
->
sku
;
$count
=
100
;
for
(
$dbcode
=
0
;
$dbcode
<
10
;
$dbcode
++
){
$db
=
DB
::
connection
(
'sku_'
.
$dbcode
);
$i
=
0
;
for
(
$table
=
0
;
$table
<
10
;
$table
++
){
for
(
$p
=
1
;
$p
<
$count
+
1
;
$p
++
){
$data
=
[];
$list
=
$db
->
table
(
'lie_sku_'
.
$table
)
->
select
(
'goods_id'
,
'spu_id'
,
'moq'
,
'supplier_id'
)
->
paginate
(
10000
,[
'*'
],
''
,
$p
);
foreach
(
$list
as
$k
=>
$v
){
$data
[]
=
[
'goods_id'
=>
intval
(
$v
->
goods_id
),
'spu_id'
=>
intval
(
$v
->
spu_id
),
'supplier_id'
=>
intval
(
$v
->
supplier_id
),
'moq'
=>
intval
(
$v
->
moq
)
];
$i
++
;
}
$mongodb
->
batchInsert
(
$data
);
$count
=
$list
->
lastPage
();
echo
$i
.
'->'
;
}
}
}
//程序运行时间
$endtime
=
explode
(
' '
,
microtime
());
$thistime
=
$endtime
[
0
]
+
$endtime
[
1
]
-
(
$starttime
[
0
]
+
$starttime
[
1
]);
$thistime
=
round
(
$thistime
,
3
);
echo
"本程序执行耗时:"
.
$thistime
.
" 秒。"
;
}
private
function
create_spu_redis
(
$request
){
set_time_limit
(
0
);
$redis
=
RedisDB
::
connection
();
$db
=
DB
::
connection
(
'spu'
);
$table
=
$request
->
input
(
'table'
);
$data
=
[];
$list
=
$db
->
table
(
'lie_spu_'
.
$table
)
->
select
(
'spu_id'
,
'class_id1'
,
'class_id2'
,
'brand_id'
,
'class_id3'
,
'spu_name'
,
'status'
,
'images_l'
,
'images_s'
,
'encap'
,
'pdf'
,
'spu_brief'
,
'has_rohs'
,
'attrs'
,
'spu_detail'
,
'sale_time'
,
'create_time'
,
'update_time'
,
'remark'
,
'bussiness_area'
)
->
paginate
(
1000
);
foreach
(
$list
as
$k
=>
$v
){
$info
=
(
array
)
$v
;
$info
[
'class_id'
]
=
0
;
if
(
!
empty
(
$info
[
'class_id1'
])){
$info
[
'class_id'
]
=
$info
[
'class_id1'
];
}
if
(
!
empty
(
$info
[
'class_id2'
])){
$info
[
'class_id'
]
=
$info
[
'class_id2'
];
}
if
(
!
empty
(
$info
[
'class_id3'
])){
$info
[
'class_id'
]
=
$info
[
'class_id3'
];
}
$info
[
'class_name'
]
=
$redis
->
hget
(
'class'
,
$info
[
'class_id'
]);
$info
[
'brand_name'
]
=
$redis
->
hget
(
'brand'
,
$info
[
'brand_id'
]);
switch
(
$info
[
'status'
]){
case
0
:
$info
[
'status_name'
]
=
'审核中'
;
break
;
case
1
:
$info
[
'status_name'
]
=
'上架'
;
break
;
case
2
:
$info
[
'status_name'
]
=
'审核不通过'
;
break
;
case
3
:
$info
[
'status_name'
]
=
'下架'
;
break
;
default
:
$info
[
'status_name'
]
=
'未知'
;
}
$info
[
'create_time_s'
]
=
date
(
'Y-m-d H:i'
,
$info
[
'create_time'
]);
$data
[
$v
->
spu_id
]
=
json_encode
(
$info
);
}
$result
=
$redis
->
hmset
(
'spu'
,
$data
);
$objdata
[
'count'
]
=
$list
->
count
();
$objdata
[
'last_page'
]
=
$list
->
lastPage
();
if
(
$result
==
'OK'
){
$this
->
Export
(
0
,
''
,
$objdata
);
}
else
{
$this
->
Export
(
20001
,
'写入Redis出错'
);
}
}
private
function
sku_redis
(){
$redis
=
Redis
::
connection
();
$count
=
100
;
$i
=
0
;
for
(
$dbcode
=
0
;
$dbcode
<
10
;
$dbcode
++
)
{
$db
=
DB
::
connection
(
'sku_'
.
$dbcode
);
for
(
$table
=
0
;
$table
<
10
;
$table
++
)
{
for
(
$p
=
1
;
$p
<
$count
+
1
;
$p
++
)
{
$data
=
[];
$list
=
$db
->
table
(
'lie_sku_'
.
$table
)
->
select
(
'goods_id'
,
'spu_id'
,
'old_goods_id'
,
'goods_name'
,
'goods_type'
,
'supplier_id'
,
'goods_status'
,
'encoded'
,
'batch_sn'
,
'moq'
,
'mpq'
,
'stock'
,
'hk_delivery_time'
,
'cn_delivery_time'
,
'goods_details'
,
'ladder_price'
,
'single_price'
,
'former_price'
,
'sale_time'
,
'create_time'
,
'update_time'
,
'remark'
,
'goods_images'
)
->
paginate
(
1000
,
[
'*'
],
''
,
$p
);
foreach
(
$list
as
$k
=>
$v
)
{
$v
=
(
array
)
$v
;
$data
[
$v
[
'spu_id'
]]
=
json_encode
(
$v
);
$i
++
;
}
$result
=
$redis
->
hmset
(
'spu'
,
$data
);
$count
=
$list
->
lastPage
();
echo
$i
.
'->'
;
}
}
}
echo
'初始化完成'
;
}
//同名同父级则重复
private
function
isDuplicatedInSameLevel
(
$class_name
,
$parent_id
)
{
$find
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify'
)
->
where
(
'class_name'
,
$class_name
)
->
get
();
if
(
$find
)
{
foreach
(
$find
as
$classify
)
{
if
(
$classify
->
parent_id
==
$parent_id
){
return
true
;
}
}
}
return
false
;
}
//解绑供应商
private
function
Unbundling
(
$request
){
$id
=
$request
->
input
(
'supplier_id'
);
$code
=
$request
->
input
(
'code'
);
if
(
empty
(
$id
)){
$this
->
Export
(
15201
,
'网络连接错误'
);
}
$data
[
'code'
]
=
''
;
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_supplier'
)
->
where
(
'supplier_id'
,
$id
)
->
where
(
'code'
,
$code
)
->
update
(
$data
);
if
(
!
$db
){
$this
->
Export
(
15202
,
'解绑失败'
);
}
$this
->
Export
(
0
,
'解绑成功'
);
}
//修改SKU状态
private
function
operation_sku_status
(
$request
){
$map
=
$request
->
input
(
'goods_id'
);
if
(
empty
(
$map
)
||
!
is_array
(
$map
)){
$this
->
Export
(
14021
,
'请选择要操作的SKU'
,
'0'
);
}
$status
=
$request
->
input
(
'status'
);
$Redis
=
RedisDB
::
connection
();
switch
(
$status
){
case
'offshelf'
:
$updata
[
'goods_status'
]
=
3
;
$errinfo
=
'成功下架'
;
break
;
case
'passed'
:
$errinfo
=
'成功上架'
;
$updata
[
'goods_status'
]
=
1
;
break
;
case
'negative'
:
$updata
[
'goods_status'
]
=
2
;
$errinfo
=
'审核不通过'
;
break
;
}
$i
=
0
;
foreach
(
$map
as
$k
=>
$v
){
$dbinfo
=
resolve
(
$v
);
$list
=
DB
::
connection
(
$dbinfo
[
'db'
])
->
table
(
$dbinfo
[
'table'
])
->
where
(
'goods_id'
,
$v
)
->
update
(
$updata
);
if
(
$list
){
$info
=
json_decode
(
$Redis
->
hget
(
'sku'
,
$v
),
true
);
$info
[
'goods_status'
]
=
$updata
[
'goods_status'
];
Handle_sku
(
$info
);
$i
++
;
}
}
$this
->
Export
(
0
,
$errinfo
.
$i
.
'件SPU'
,
$i
);
}
//清空指定缓存
private
function
redisRemove
(
$key
)
{
$Redis
=
RedisDB
::
connection
();
return
$Redis
->
del
(
$key
);
}
//清空已存储的所有元素
private
function
redisFlush
()
{
$Redis
=
RedisDB
::
connection
();
return
$Redis
->
flushall
();
}
}
This diff is collapsed.
Click to expand it.
app/Http/Controllers/FootStoneController.php
deleted
100644 → 0
View file @
cfe21d14
<?php
namespace
App\Http\Controllers
;
use
Illuminate\Http\Request
;
use
App\Http\Requests
;
use
DB
;
use
RedisDB
;
function
CheckActive
(
$menus
,
&
$arr
,
$url
)
{
for
(
$i
=
0
;
$i
<
count
(
$menus
);
$i
++
)
{
$menu
=
$menus
[
$i
];
array_push
(
$arr
,
$i
);
if
(
isset
(
$menu
->
href
)
&&
(
$menu
->
href
==
$url
||
(
$menu
->
href
==
'/'
&&
$url
==
'//'
)))
return
true
;
if
(
isset
(
$menu
->
childs
)
&&
count
(
$menu
->
childs
)
>
0
)
{
$ret
=
CheckActive
(
$menu
->
childs
,
$arr
,
$url
);
if
(
$ret
)
return
$ret
;
}
array_pop
(
$arr
);
}
return
false
;
}
function
createMenuReal
(
$menus
,
$active
,
$level
)
{
$subclass
=
(
$level
==
0
)
?
'nav-second-level'
:
'nav-third-level'
;
$ret
=
''
;
for
(
$ii
=
0
;
$ii
<
(
$level
==
0
?
1
:
2
);
$ii
++
)
{
for
(
$i
=
0
;
$i
<
count
(
$menus
);
$i
++
)
{
$menu
=
$menus
[
$i
];
$act
=
(
count
(
$active
)
>
$level
&&
$active
[
$level
]
==
$i
)
?
true
:
false
;
$actclass
=
$act
?
' class="active"'
:
''
;
$actmenu
=
$act
?
' in'
:
''
;
if
(
isset
(
$menu
->
childs
)
&&
count
(
$menu
->
childs
)
>
0
)
{
if
(
$ii
!=
0
&&
$level
>
0
)
continue
;
$ret
.=
'<li'
.
$actclass
.
'><a><i class="'
.
$menu
->
class
.
'"></i><span class="nav-label">'
.
$menu
->
title
.
'</span><span class="fa arrow"></span></a>'
.
'<ul class="nav '
.
$subclass
.
' collapse'
.
$actmenu
.
'">'
.
createMenuReal
(
$menu
->
childs
,
$act
?
$active
:
[],
$level
+
1
)
.
'</ul></li>'
;
}
else
{
if
(
$ii
!=
1
&&
$level
>
0
)
continue
;
$ret
.=
'<li'
.
$actclass
.
'><a href="'
.
$menu
->
href
.
'"><i class="'
.
$menu
->
class
.
'"></i><span class="nav-label">'
.
$menu
->
title
.
'</span></a></li>'
;
}
}
}
return
$ret
;
}
function
createMenu
(
$menus
,
$url
)
{
$actives
=
[];
$ret
=
CheckActive
(
$menus
,
$actives
,
$url
);
if
(
!
$ret
)
$actives
=
[];
return
createMenuReal
(
$menus
,
$actives
,
0
);
}
function
Crumbs
(
$menus
,
$uri
)
{
$actives
=
[];
CheckActive
(
$menus
,
$actives
,
$uri
);
$ret
=
''
;
foreach
(
$actives
as
$k
=>
$v
)
{
if
(
$k
==
count
(
$actives
)
-
1
)
{
$ret
.=
'<li class="active"><a>'
.
$menus
[
$actives
[
0
]]
->
childs
[
$actives
[
1
]]
->
title
.
'</a></li>'
;
}
else
{
$ret
.=
'<li><a href="#">'
.
$menus
[
$actives
[
0
]]
->
title
.
'</a></li>'
;
}
}
return
$ret
;
}
class
FootStoneController
extends
Controller
{
private
function
templateData
(
Request
$request
,
$id
,
$viewid
)
{
$uri
=
'/'
.
$request
->
path
();
$paths
=
[[
"title"
=>
"基石管理系统"
,
"href"
=>
'/database/'
]];
$username
=
$request
->
user
->
email
;
$useremail
=
$request
->
user
->
email
;
$menuconfig
=
DB
::
table
(
'config'
)
->
where
(
'config_id'
,
3
)
->
first
();
$menus
=
[];
if
(
$menuconfig
&&
!
(
$menus
=
json_decode
(
$menuconfig
->
config_data
)))
$menus
=
[];
$referer
=
$this
->
get_referer
(
$request
);
$data
=
[
'id'
=>
$id
,
'title'
=>
'基石管理系统'
,
'header'
=>
$request
->
user
->
header
,
'uri'
=>
$uri
,
'paths'
=>
$paths
,
'username'
=>
$username
,
'useremail'
=>
$useremail
,
'menus'
=>
$menus
,
'options'
=>
'[]'
,
'referer'
=>
$referer
,
];
return
view
(
$viewid
,
$data
);
}
public
function
index
(
Request
$request
)
{
$uri
=
'/'
.
$request
->
path
();
$paths
=
[[
"title"
=>
"首页"
,
"href"
=>
'/database/'
]];
$username
=
$request
->
user
->
email
;
$useremail
=
$request
->
user
->
email
;
$menuconfig
=
DB
::
table
(
'config'
)
->
where
(
'config_id'
,
3
)
->
first
();
$menus
=
[];
if
(
$menuconfig
&&
!
(
$menus
=
json_decode
(
$menuconfig
->
config_data
)))
$menus
=
[];
$referer
=
$this
->
get_referer
(
$request
);
$data
=
[
'header'
=>
$request
->
user
->
header
,
'uri'
=>
$uri
,
'paths'
=>
$paths
,
'username'
=>
$username
,
'useremail'
=>
$useremail
,
'menus'
=>
$menus
,
'options'
=>
'[]'
,
'referer'
=>
$referer
,
];
return
view
(
'index'
,
$data
);
}
public
function
footstone
(
Request
$request
,
$id
=
0
)
{
return
$this
->
templateData
(
$request
,
$id
,
'footstone'
);
}
public
function
info
(
Request
$request
,
$id
=
0
)
{
return
$this
->
$id
(
$request
,
$id
,
'common'
);
}
public
function
get_referer
(
$request
)
{
// echo $request->headers->get('referer') . "\n";
$pos
=
strpos
(
$request
->
headers
->
get
(
'referer'
),
'info'
);
$referer
=
0
;
if
(
$pos
===
false
)
$referer
=
0
;
else
$referer
=
1
;
// echo "referer:" . $referer . "\n";
return
$referer
;
}
//----------------------------SKU---------------------------
private
function
skulist
(
Request
$request
,
$id
,
$viewid
){
$list
=
[];
$page
=
''
;
$data
[
'data'
][
'goods_id'
]
=
[];
$map
=
$request
->
input
();
if
(
!
empty
(
$map
[
'create_time_start/condition'
])
||
!
empty
(
$map
[
'create_time_end/condition'
])){
$create_time_start
=!
empty
(
$map
[
'create_time_start/condition'
])
?
strtotime
(
$map
[
'create_time_start/condition'
])
:
'1420041600'
;
$create_time_end
=!
empty
(
$map
[
'create_time_end/condition'
])
?
strtotime
(
$map
[
'create_time_end/condition'
])
:
time
();
$map
[
'create_time/range'
]
=
$create_time_start
.
','
.
$create_time_end
;
}
foreach
(
$map
as
$k
=>
$v
){
if
(
empty
(
$v
)
AND
$v
!=
'0'
){
unset
(
$map
[
$k
]);
}
}
$collert
=
$map
;
unset
(
$map
[
'class_name/condition'
]);
unset
(
$map
[
'brand_name/condition'
]);
unset
(
$map
[
'create_time_start/condition'
]);
unset
(
$map
[
'create_time_end/condition'
]);
$url
=
env
(
'ES_SKU_URL'
,
''
);
$return
=
curl
(
$url
,
$map
,
1
);
$data
=
json_decode
(
$return
,
true
);
if
(
$data
[
'error_code'
]
==
0
)
{
$redis
=
RedisDB
::
connection
();
foreach
(
$data
[
'data'
][
'goods_id'
]
as
$k
=>
$v
)
{
$info
=
json_decode
(
$redis
->
hget
(
'sku'
,
$v
));
if
(
!
$info
)
{
$dbinfo
=
resolve
(
$v
);
$info
=
DB
::
connection
(
$dbinfo
[
'db'
])
->
table
(
$dbinfo
[
'table'
])
->
where
(
'goods_id'
,
$v
)
->
first
();
if
(
$info
)
{
$info
=
Handle_sku
(
$info
);
}
else
{
break
;
}
}
$list
[
$k
]
=
(
array
)
$info
;
}
$page
=
generate_page
(
$request
,
$data
[
'data'
][
'total'
],
20
,
$collert
);
}
$supplier
=
$this
->
Obtain_supplier
();
if
(
!
isset
(
$map
[
'goods_status/condition'
])){
$_GET
[
'goods_status/condition'
]
=
''
;
}
if
(
!
isset
(
$map
[
'supplier_name/condition'
])){
$_GET
[
'supplier_name/condition'
]
=
''
;
}
$data
=
[
'title'
=>
'SKU列表'
,
'aa'
=>
'dd'
,
'id'
=>
$id
,
'list'
=>
$list
,
'page'
=>
$page
,
'supplier'
=>
$supplier
];
return
view
(
$viewid
,
$data
);
}
//新增/编辑SKU
private
function
addsku
(
Request
$request
,
$id
,
$viewid
)
{
Csrf
(
$request
);
$spu_name
=
''
;
// $jsondata = '[{"purchases":1,"price_cn":0,"price_us":9.24},{"purchases":10,"price_cn":0,"price_us":8.91},{"purchases":25,"price_cn":0,"price_us":7.92},{"purchases":50,"price_cn":0,"price_us":7.26},{"purchases":100,"price_cn":0,"price_us":6.6},{"purchases":250,"price_cn":0,"price_us":5.28},{"purchases":500,"price_cn":0,"price_us":5.115},{"purchases":1000,"price_cn":0,"price_us":4.785}]';
// $ladder_prices=json_decode($jsondata,true);
$ladder_prices
=
[];
//查出所有供应商
$suppliers
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_supplier'
)
->
get
();
$supplier_name
=
''
;
$collert
=
$request
->
input
(
'sku_id'
);
if
(
!
empty
(
$collert
)){
$data
=
resolve
(
$collert
);
$info
=
DB
::
connection
(
$data
[
'db'
])
->
table
(
$data
[
'table'
])
->
where
(
'goods_id'
,
$collert
)
->
first
();
$info
=
(
array
)
$info
;
//根据spu_id查询spu_name
$data_spu
=
resolve
(
$info
[
'spu_id'
]);
$info_spu
=
DB
::
connection
(
$data_spu
[
'db'
])
->
table
(
$data_spu
[
'table'
])
->
where
(
'spu_id'
,
$info
[
'spu_id'
])
->
first
();
$spu_name
=
$info_spu
->
spu_name
;
//根据supplier_id查询出 选定的供应商
foreach
(
$suppliers
as
$supplier
)
{
if
(
$supplier
->
supplier_id
==
$info
[
'supplier_id'
])
{
$supplier_name
=
$supplier
->
supplier_name
;
break
;
}
}
//阶梯价格
$ladder_prices
=
json_decode
(
$info
[
'ladder_price'
],
true
);
if
(
empty
(
$ladder_prices
)
||
!
is_array
(
$ladder_prices
))
{
$ladder_prices
=
[];
}
}
if
(
empty
(
$info
)){
$info
=
[
'goods_id'
=>
''
,
'spu_id'
=>
''
,
'old_goods_id'
=>
''
,
'goods_name'
=>
''
,
'goods_type'
=>
''
,
'supplier_id'
=>
''
,
'goods_status'
=>
''
,
'encoded'
=>
''
,
'batch_sn'
=>
''
,
'moq'
=>
''
,
'mpq'
=>
''
,
'stock'
=>
''
,
'hk_delivery_time'
=>
''
,
'cn_delivery_time'
=>
''
,
'goods_details'
=>
''
,
'ladder_price'
=>
[],
'single_price'
=>
''
,
'former_price'
=>
''
,
'sale_time'
=>
''
,
'create_time'
=>
''
,
'update_time'
=>
''
,
'remark'
=>
''
,
'goods_images'
=>
''
,
];
}
//枚举
$goods_types
=
[
'自营'
,
'联营'
,
'专卖'
];
$goods_statuses
=
[
'待审核'
,
'审核通过(上架)'
,
'下架'
,
// '删除'
];
$data
=
[
'title'
=>
'addsku'
,
'id'
=>
$id
,
'info'
=>
$info
,
'goods_types'
=>
$goods_types
,
'goods_statuses'
=>
$goods_statuses
,
'spu_name'
=>
$spu_name
,
'suppliers'
=>
$suppliers
,
'supplier_name'
=>
$supplier_name
,
'ladder_prices'
=>
$ladder_prices
,
];
// dump($data);die;
return
view
(
$viewid
,
$data
);
}
//----------------------------制造商---------------------------
//制造商列表
private
function
brandlist
(
Request
$request
,
$id
,
$viewid
)
{
$map
=
$request
->
input
(
'brand_name'
);
$list
=
$this
->
Obtain_brand
(
$map
);
$data
=
[
'title'
=>
'ss'
,
'id'
=>
$id
,
'lists'
=>
$list
];
return
view
(
$viewid
,
$data
);
}
//点击 查看映射制造商
private
function
maintainbrand
(
Request
$request
,
$id
,
$viewid
)
{
$map
=
$_GET
[
'brand_id'
];
$result
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand'
)
->
where
(
'brand_id'
,
'='
,
$map
)
->
first
();
$brand_name
=
$result
->
brand_name
;
$list
=
$this
->
Maintain_brand
(
$map
,
20
);
$page
=
str_replace
(
'href='
,
'data-page='
,
$list
->
links
());
$data
=
[
'title'
=>
'aa'
,
'id'
=>
$id
,
'lists'
=>
$list
,
'brand_name'
=>
$brand_name
];
return
view
(
$viewid
,
$data
);
}
// 添加/编辑制造商
private
function
addbrand
(
Request
$request
,
$id
,
$viewid
)
{
Csrf
(
$request
);
$collert
=
$request
->
input
(
'brand_id'
);
if
(
!
empty
(
$collert
)){
$info
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand'
)
->
where
(
'brand_id'
,
$collert
)
->
first
();
$info
=
(
array
)
$info
;
}
if
(
empty
(
$info
)){
$info
=
[
'brand_id'
=>
''
,
'status'
=>
''
,
'brand_name'
=>
''
,
'brand_logo'
=>
''
,
'main_product'
=>
''
,
'brand_brief'
=>
''
,
'brand_area'
=>
''
,
'brand_desc'
=>
''
,
];
}
$data
=
[
'title'
=>
'asd'
,
'id'
=>
$id
,
'info'
=>
$info
];
return
view
(
$viewid
,
$data
);
}
//制造商映射
private
function
brandmapping
(
Request
$request
,
$id
,
$viewid
){
$request
=
$this
->
Obtain_supplier
();
$data
=
[
'title'
=>
'S'
,
'aa'
=>
'dd'
,
'id'
=>
$id
,
'supplier'
=>
$request
];
return
view
(
$viewid
,
$data
);
}
//----------------------------分类---------------------------
//分类列表
private
function
classifylist
(
Request
$request
,
$id
,
$viewid
)
{
//取出所有分类数据 infos 用作逐条对比 区分级别
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify'
);
$infos
=
$db
->
select
(
'class_id'
,
'parent_id'
,
'class_name'
,
'status'
)
->
get
();
$class_id
=
''
;
$url
=
$request
->
fullUrl
();
if
(
strpos
(
$url
,
'class_id'
)
!=
false
)
{
$class_id
=
$_GET
[
'class_id'
];
}
$list
=
$this
->
Obtain_classify
(
$class_id
,
20
);
$page
=
str_replace
(
'href='
,
'data-page='
,
$list
->
links
());
$data
=
[
'title'
=>
'ss'
,
'id'
=>
$id
,
'lists'
=>
$list
,
'infos'
=>
$infos
,
'into'
=>
true
,
];
return
view
(
$viewid
,
$data
);
}
//分类映射
private
function
classifymapping
(
$request
,
$id
,
$viewid
){
$supplier
=
$this
->
Obtain_supplier
();
$data
=
[
'title'
=>
'分类映射'
,
'id'
=>
$id
,
'supplier'
=>
$supplier
,
];
return
view
(
$viewid
,
$data
);
}
//查看映射的分类
private
function
mappingclassifylist
(
$request
,
$id
,
$viewid
)
{
$request_data
=
$request
->
input
();
$class_id
=
$request_data
[
'class_id'
];
$dt
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify_mapping'
);
$allclasses
=
$dt
->
get
();
$mapclasses
=
$dt
->
select
(
'cm_id'
,
'cm_name'
,
'supplier_name'
,
'parent_id'
,
'liexin_class_id'
)
->
where
(
'liexin_class_id'
,
'='
,
$class_id
)
->
get
();
//根据当前class_id 对比 映射表中的 liexin_class_id
$arr1
=
[];
$arr2
=
[];
$arr3
=
[];
foreach
(
$mapclasses
as
$obj1
)
{
//找出上级不为0的,为0的话直接添加并结束循环(说明到顶级了)
if
(
$obj1
->
parent_id
!=
0
)
{
array_push
(
$arr1
,
$obj1
);
foreach
(
$allclasses
as
$obj2
)
{
//从所有里面找与obj1上级id相等的 1.父级不为0继续找上级 2.为0直接添加并结束循环(说明到了顶级)
if
(
$obj1
->
parent_id
==
$obj2
->
liexin_class_id
&&
$obj2
->
parent_id
!=
0
)
{
array_push
(
$arr2
,
$obj2
);
foreach
(
$allclasses
as
$obj3
)
{
//如果还能进来说明一定到了顶级(第三级) 相等则直接添加
if
(
$obj2
->
parent_id
==
$obj3
->
liexin_class_id
)
{
array_push
(
$arr3
,
$obj3
);
break
;
}
}
}
else
if
(
$obj1
->
parent_id
==
$obj2
->
liexin_class_id
&&
$obj2
->
parent_id
==
0
)
{
array_push
(
$arr2
,
$obj2
);
break
;
}
}
}
else
{
array_push
(
$arr1
,
$obj1
);
break
;
}
}
// foreach ($result as $class_map_obj)
// {
// if($class_id == $class_map_obj->liexin_class_id)
// {
// if($class_map_obj->parent_id == 0)
// {
// array_push($mapclasses,$class_map_obj);
//
// }else
// {
//
// }
// }
// }
$lists
=
array_merge
(
$arr3
,
$arr2
,
$arr1
);
// $page=str_replace('href=','data-page=',$mapclasses->links());
$data
=
[
'title'
=>
'映射分类'
,
'id'
=>
$id
,
'lists'
=>
$lists
,
// 'page'=>$page
];
return
view
(
$viewid
,
$data
);
}
//----------------------------spu---------------------------
//SPUl列表
private
function
spulist
(
Request
$request
,
$id
,
$viewid
){
$list
=
[];
$page
=
''
;
$map
=
$request
->
input
();
if
(
!
empty
(
$map
[
'create_time_start/condition'
])
||
!
empty
(
$map
[
'create_time_end/condition'
])){
$create_time_start
=!
empty
(
$map
[
'create_time_start/condition'
])
?
strtotime
(
$map
[
'create_time_start/condition'
])
:
'1420041600'
;
$create_time_end
=!
empty
(
$map
[
'create_time_end/condition'
])
?
strtotime
(
$map
[
'create_time_end/condition'
])
:
time
();
$map
[
'create_time/range'
]
=
$create_time_start
.
','
.
$create_time_end
;
}
foreach
(
$map
as
$k
=>
$v
){
if
(
empty
(
$v
)
AND
$v
!=
'0'
){
unset
(
$map
[
$k
]);
}
}
$collert
=
$map
;
unset
(
$map
[
'class_name/condition'
]);
unset
(
$map
[
'brand_name/condition'
]);
unset
(
$map
[
'create_time_start/condition'
]);
unset
(
$map
[
'create_time_end/condition'
]);
$url
=
env
(
'ES_SPU_URL'
,
''
);
$return
=
curl
(
$url
,
$map
,
1
);
$data
=
json_decode
(
$return
,
true
);
if
(
$data
[
'error_code'
]
==
0
)
{
$redis
=
RedisDB
::
connection
();
foreach
(
$data
[
'data'
][
'spu_id'
]
as
$k
=>
$v
)
{
$info
=
json_decode
(
$redis
->
hget
(
'spu'
,
$v
));
if
(
!
$info
)
{
$dbinfo
=
resolve
(
$v
);
$info
=
DB
::
connection
(
$dbinfo
[
'db'
])
->
table
(
$dbinfo
[
'table'
])
->
where
(
'spu_id'
,
$v
)
->
first
();
if
(
$info
)
{
$info
=
Handle_spu
(
$info
);
}
else
{
break
;
}
}
$list
[
$k
]
=
(
array
)
$info
;
}
$page
=
generate_page
(
$request
,
$data
[
'data'
][
'total'
],
10
,
$collert
);
}
if
(
!
isset
(
$map
[
'status/condition'
])){
$_GET
[
'status/condition'
]
=
''
;
}
$data
=
[
'title'
=>
'SPU列表'
,
'id'
=>
$id
,
'list'
=>
$list
,
'page'
=>
$page
];
return
view
(
$viewid
,
$data
);
}
//查找SPU插件
private
function
Find_spu
(
$request
,
$id
,
$viewid
){
$map
=
$request
->
input
();
$map
[
'offset'
]
=
27
;
$url
=
env
(
'ES_SPU_URL'
,
''
);
$return
=
curl
(
$url
,
$map
,
1
);
$data
=
json_decode
(
$return
,
true
);
if
(
$data
[
'error_code'
]
==
0
)
{
$redis
=
RedisDB
::
connection
();
foreach
(
$data
[
'data'
][
'spu_id'
]
as
$k
=>
$v
)
{
$info
=
json_decode
(
$redis
->
hget
(
'spu'
,
$v
));
if
(
!
$info
)
{
$dbinfo
=
resolve
(
$v
);
$info
=
DB
::
connection
(
$dbinfo
[
'db'
])
->
table
(
$dbinfo
[
'table'
])
->
where
(
'spu_id'
,
$v
)
->
first
();
if
(
$info
)
{
$info
=
Handle_spu
(
$info
);
}
else
{
break
;
}
}
$list
[
$k
]
=
(
array
)
$info
;
}
$page
=
generate_page
(
$request
,
$data
[
'data'
][
'total'
],
20
,
$map
);
}
$supplier
=
$this
->
Obtain_supplier
();
$data
=
[
'title'
=>
'查找SPU'
,
'id'
=>
$id
,
'list'
=>
$list
?
$list
:
[],
'supplier'
=>
$supplier
,
'page'
=>
$page
];
return
view
(
$viewid
,
$data
);
}
//新增/编辑SPU
private
function
addSpu
(
Request
$request
,
$id
,
$viewid
){
Csrf
(
$request
);
$brand_name
=
''
;
$class_name
=
''
;
$chosen_bussiness_areas
=
[];
//商品参数行数
$row_counts
=
0
;
$attrs
=
[];
//查看是否有带入的spu_id
$collert
=
$request
->
input
(
'spu_id'
);
//如果有,查出它在哪个库、哪个表、并取出该spu_id对应的对象
if
(
!
empty
(
$collert
)){
$data
=
resolve
(
$collert
);
$info
=
DB
::
connection
(
$data
[
'db'
])
->
table
(
$data
[
'table'
])
->
where
(
'spu_id'
,
$collert
)
->
first
();
$info
=
(
array
)
$info
;
//找到相应的brand_name并传入
$brands
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand'
)
->
get
();
foreach
(
$brands
as
$brand
)
{
if
(
$brand
->
brand_id
==
$info
[
'brand_id'
])
{
$brand_name
=
$brand
->
brand_name
;
}
}
//找到相应的class_name并传入
$classes
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify'
)
->
get
();
foreach
(
$classes
as
$class
)
{
if
(
$class
->
class_id
==
$info
[
'class_id3'
])
{
$class_name
=
$class
->
class_name
;
break
;
}
}
//提取选中的应用领域
$chosen_bussiness_areas_str
=
$info
[
'bussiness_area'
];
$chosen_bussiness_areas
=
explode
(
'|'
,
$chosen_bussiness_areas_str
);
//商品参数
$att
=
json_decode
(
$info
[
'attrs'
],
true
);
if
(
is_array
(
$att
)
&&
count
(
$att
)
>
0
)
{
foreach
(
$att
as
$attr
)
{
array_push
(
$attrs
,
$attr
[
'attr_name'
]
.
':'
.
$attr
[
'attr_value'
]);
}
$attr_counts
=
count
(
$attrs
);
if
(
$attr_counts
!=
0
)
{
if
(
$attr_counts
%
2
==
0
)
{
$row_counts
=
$attr_counts
/
2
;
}
else
{
$row_counts
=
(
$attr_counts
+
1
)
/
2
;
}
}
}
}
if
(
empty
(
$info
))
{
$info
=
[
'spu_id'
=>
''
,
'class_id1'
=>
''
,
'class_id2'
=>
''
,
'class_id3'
=>
''
,
'brand_id'
=>
''
,
'spu_name'
=>
''
,
'status'
=>
''
,
'images_l'
=>
''
,
'images_s'
=>
''
,
'encap'
=>
''
,
'pdf'
=>
''
,
'spu_brief'
=>
''
,
'has_rohs'
=>
''
,
'attrs'
=>
''
,
'spu_detail'
=>
''
,
'remark'
=>
''
,
'bussiness_area'
=>
''
,
];
}
//SPU 状态
$statuses
=
[
'待审核'
,
'审核通过(上架)'
,
'审核不通过'
,
'下架'
,
// '删除'
];
//应用领域
$bussiness_areas
=
[
'消费电子'
,
'照明电子'
,
'医疗电子'
,
'仪器仪表'
,
'通讯/网络'
,
'交通/汽车'
,
'安防/监控'
,
'工业/自动化'
,
'军事/国防'
,
'便携设备'
,
'能源/勘测'
,
'船舶/航天'
];
//是否含铅
$has_rohses
=
[
'含铅'
,
'不含铅'
,
'其他'
];
$data
=
[
'title'
=>
'新增SPU'
,
'id'
=>
$id
,
'info'
=>
$info
,
'bussiness_areas'
=>
$bussiness_areas
,
'has_rohses'
=>
$has_rohses
,
'brand_name'
=>
$brand_name
,
'class_name'
=>
$class_name
,
'statuses'
=>
$statuses
,
'chosen_bussiness_areas'
=>
$chosen_bussiness_areas
,
'attrs'
=>
$attrs
,
'row_counts'
=>
$row_counts
];
return
view
(
$viewid
,
$data
);
}
//初始化SPU
private
function
Initialization_spu
(
$request
,
$id
,
$viewid
){
$data
=
[
'title'
=>
'初始化SPU'
,
'id'
=>
$id
,
];
return
view
(
$viewid
,
$data
);
}
//选择品牌
private
function
Choice_brand
(
Request
$request
,
$id
,
$viewid
){
$map
=
$request
->
input
(
'brand_name'
);
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand'
)
->
where
(
'status'
,
'1'
);
if
(
$map
){
$db
=
$db
->
where
(
'brand_name'
,
'like'
,
'%'
.
$map
.
'%'
);
}
$list
=
$db
->
select
(
'brand_name'
,
'brand_id'
)
->
get
();
$data
=
[
'title'
=>
'品牌列表'
,
'id'
=>
$id
,
'list'
=>
$list
,
'into'
=>
'no'
];
return
view
(
$viewid
,
$data
);
}
//--------------------------------分类----------------------------------
//选择分类
private
function
Choice_class
(
Request
$request
,
$id
,
$viewid
){
$list
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify'
)
->
where
(
'status'
,
1
)
->
where
(
'parent_id'
,
0
)
->
get
();
$data
=
[
'title'
=>
'品牌列表'
,
'id'
=>
$id
,
'list'
=>
$list
,
'into'
=>
'no'
];
return
view
(
$viewid
,
$data
);
}
//添加/编辑分类
private
function
addclassify
(
Request
$request
,
$id
,
$viewid
)
{
Csrf
(
$request
);
//取出所有分类数据 infos
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify'
);
$infos
=
$db
->
select
(
'class_id'
,
'parent_id'
,
'class_name'
,
'status'
)
->
get
();
//判断是否有class_id,有则为编辑
$collert
=
$request
->
input
(
'class_id'
);
$info
=
[];
if
(
!
empty
(
$collert
)){
$info
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify'
)
->
where
(
'class_id'
,
$collert
)
->
first
();
}
$info
=
(
array
)
$info
;
if
(
empty
(
$info
)){
$info
=
[
'class_id'
=>
''
,
'status'
=>
''
,
'class_name'
=>
''
,
'class_icon'
=>
''
,
'parent_id'
=>
''
,
];
}
$data
=
[
'title'
=>
'ss'
,
'id'
=>
$id
,
'info'
=>
$info
,
'infos'
=>
$infos
];
return
view
(
$viewid
,
$data
);
}
//-----------------供应商--------------------------
//供应商列表
private
function
supplierlist
(
Request
$request
,
$id
,
$viewid
)
{
$db
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_supplier'
);
$list
=
$db
->
select
(
'supplier_id'
,
'type_id'
,
'supplier_name'
,
'code'
,
'status'
)
->
get
();
$data
=
[
'title'
=>
'ss'
,
'id'
=>
$id
,
'list'
=>
$list
,
];
return
view
(
$viewid
,
$data
);
}
//新增/编辑 供应商
// 添加/编辑制造商
private
function
addsupplier
(
Request
$request
,
$id
,
$viewid
)
{
$collert
=
$request
->
input
(
'supplier_id'
);
if
(
!
empty
(
$collert
)){
$info
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_supplier'
)
->
where
(
'supplier_id'
,
$collert
)
->
first
();
$info
=
(
array
)
$info
;
}
if
(
empty
(
$info
)){
$info
=
[
'supplier_id'
=>
''
,
'type_id'
=>
''
,
'supplier_name'
=>
''
,
'code'
=>
''
,
'status'
=>
''
,
];
}
$charger
=
[];
if
(
$info
[
'code'
]){
$code_name
=
DB
::
connection
()
->
table
(
'user_info'
)
->
where
(
'userId'
,
$info
[
'code'
])
->
select
(
'name'
,
'email'
,
'userId'
)
->
first
();
$info
[
'code_name'
]
=!
empty
(
$code_name
->
name
)
?
$code_name
->
name
:
$code_name
->
email
;
}
else
{
$code
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_supplier'
)
->
where
(
'code'
,
'>'
,
0
)
->
lists
(
'code'
);
$charger_id
=
DB
::
connection
()
->
table
(
'organization'
)
->
where
(
'departmentId'
,
env
(
'CHARGER_DEPARTMENT_ID'
,
''
))
->
whereNotIn
(
'userId'
,
$code
)
->
lists
(
'userId'
);
$charger
=
DB
::
connection
()
->
table
(
'user_info'
)
->
whereIn
(
'userId'
,
$charger_id
)
->
where
(
'status'
,
0
)
->
select
(
'name'
,
'userId'
)
->
get
();
}
$data
=
[
'title'
=>
'ss'
,
'id'
=>
$id
,
'info'
=>
$info
,
'charger'
=>
$charger
];
return
view
(
$viewid
,
$data
);
}
//---------------------internal methods-----------------------
private
function
Obtain_brand
(
$map
=
''
,
$limit
=
'20'
){
$result
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand'
);
if
(
$map
){
$result
=
$result
->
where
(
'brand_name'
,
'like'
,
'%'
.
$map
.
'%'
);
}
$result
=
$result
->
select
(
'brand_name'
,
'brand_id'
,
'brand_area'
,
'status'
)
->
paginate
(
$limit
);
return
$result
;
}
private
function
Obtain_classify
(
$class_id
,
$limit
=
'20'
){
$result
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_classify'
);
if
(
!
empty
(
$class_id
))
{
$result
=
$result
->
where
(
'parent_id'
,
'='
,
$class_id
)
->
paginate
(
$limit
);
}
else
{
$result
=
$result
->
select
(
'class_id'
,
'class_name'
,
'sort'
,
'status'
,
'parent_id'
)
->
paginate
(
$limit
);
}
return
$result
;
}
private
function
Obtain_supplier
(
$map
=
''
){
$result
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_supplier'
);
if
(
$map
){
$result
=
$result
->
where
(
'supplier_name'
,
'='
,
$map
);
}
$result
=
$result
->
select
(
'supplier_name'
,
'supplier_id'
)
->
get
();
return
$result
;
}
private
function
Maintain_brand
(
$map
=
''
,
$limit
=
'20'
)
{
$result
=
DB
::
connection
(
'spu'
)
->
table
(
'lie_brand_mapping'
);
if
(
$map
)
{
$result
=
$result
->
select
(
'supplier_name'
,
'supplier_brand_name'
)
->
where
(
'liexin_brand_id'
,
'='
,
$map
)
->
paginate
(
$limit
);
}
return
$result
;
}
}
This diff is collapsed.
Click to expand it.
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