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
0540a7fb
authored
Jun 16, 2020
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
up
parent
5b331f1e
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
659 additions
and
43 deletions
app/Exceptions/BomException.php
app/Http/Controllers/BomApiController.php
app/Model/Bom/BomItemMatchModel.php
app/Model/Bom/BomItemModel.php
app/Services/Bom/BomService.php
config/website.php
public/js/web/BomView.js
resources/views/web/BomView.blade.php
app/Exceptions/BomException.php
0 → 100644
View file @
0540a7fb
<?php
namespace
App\Exceptions
;
class
BomException
extends
\Exception
{
}
\ No newline at end of file
app/Http/Controllers/BomApiController.php
View file @
0540a7fb
...
...
@@ -77,7 +77,14 @@ class BomApiController extends Controller{
//bom单详情 保存bom单
public
function
saveBomInfo
(
$request
,
$id
){
$this
->
bomService
->
saveBomInfo
(
$request
);
$res
=
$this
->
bomService
->
saveBomInfo
(
$request
);
return
$this
->
ajaxReturn
(
$res
[
'errcode'
],
$res
[
'errmsg'
]);
}
public
function
createBomOrder
(
$request
,
$id
){
$res
=
$this
->
bomService
->
createBomOrder
(
$request
);
return
$this
->
ajaxReturn
(
$res
[
'errcode'
],
$res
[
'errmsg'
]);
}
...
...
app/Model/Bom/BomItemMatchModel.php
View file @
0540a7fb
...
...
@@ -27,10 +27,22 @@ class BomItemMatchModel extends BomItemMatchBaseModel{
public
function
getBomItemsMatching
(
$bom_id
,
$bom_item_id
){
$suffix
=
substr
(
strrev
(
$bom_id
),
0
,
1
);
return
self
::
suffix
(
$suffix
)
->
where
(
'bom_id'
,
$bom_id
)
->
where
(
"bom_item_id"
,
$bom_item_id
)
->
first
();
return
self
::
suffix
(
$suffix
)
->
where
(
'bom_id'
,
$bom_id
)
->
where
(
"bom_item_id"
,
$bom_item_id
)
->
where
(
"status"
,
1
)
->
first
();
}
public
function
updateBomMatch
(
$bom_id
,
$where
,
$data
){
$suffix
=
substr
(
strrev
(
$bom_id
),
0
,
1
);
return
self
::
suffix
(
$suffix
)
->
where
(
$where
)
->
update
(
$data
);
}
public
function
addBomMatch
(
$bom_id
,
$data
){
$suffix
=
substr
(
strrev
(
$bom_id
),
0
,
1
);
return
self
::
suffix
(
$suffix
)
->
insert
(
$data
);
}
...
...
app/Model/Bom/BomItemModel.php
View file @
0540a7fb
...
...
@@ -25,9 +25,13 @@ class BomItemModel extends BomItemMatchBaseModel{
}
public
function
getBomItems
(
$bom_id
){
public
function
getBomItems
(
$request
,
$bom_id
){
$page
=
$request
->
input
(
"page"
,
1
);
$limit
=
$request
->
input
(
"limit"
,
10
);
$suffix
=
substr
(
strrev
(
$bom_id
),
0
,
1
);
return
self
::
suffix
(
$suffix
)
->
where
(
'bom_id'
,
$bom_id
)
->
get
();
$query
=
self
::
suffix
(
$suffix
)
->
select
(
"*"
)
->
where
(
'bom_id'
,
$bom_id
);
$query
=
$query
->
paginate
(
$limit
,[],
'page'
,
$page
);
return
$query
;
}
...
...
app/Services/Bom/BomService.php
View file @
0540a7fb
...
...
@@ -5,11 +5,22 @@ use App\Model\Bom\BomModel;
use
App\Model\Bom\BomItemMatchModel
;
use
App\Model\Bom\BomItemModel
;
use
App\Model\Bom\BomItemMatchExtendModel
;
use
App\Exceptions\BomException
;
use
DB
;
class
BomService
{
//1专卖2联营3自营4寄售5第三方仓库 0:自营 1:联营 2:专卖
public
static
$GOODSTYPE
=
[
1
=>
2
,
2
=>
1
,
3
=>
0
,
4
=>
0
,
5
=>
0
,
];
public
function
__construct
(){
$this
->
bomModel
=
new
BomModel
;
$this
->
bomItemMatchModel
=
new
BomItemMatchModel
;
}
protected
function
getRole
(
$request
){
...
...
@@ -67,10 +78,14 @@ class BomService {
$bomItemModel
=
new
BomItemModel
;
$bomItemModelMatch
=
new
BomItemMatchModel
;
$bomItemMatchExtendModel
=
new
BomItemMatchExtendModel
;
$bom_items
=
$bomItemModel
->
getBomItems
(
$bom
->
bom_id
);
$bom_items
=
$bomItemModel
->
getBomItems
(
$
request
,
$
bom
->
bom_id
);
foreach
(
$bom_items
as
$k
=>&
$item
){
$bom_item_matching
=
$bomItemModelMatch
->
getBomItemsMatching
(
$bom
->
bom_id
,
$item
->
bom_item_id
);
if
(
$bom_item_matching
){
$item
->
match_is_corder
=
$bom_item_matching
->
is_corder
;
$item
->
match_goods_type
=
$bom_item_matching
->
goods_type
;
$item
->
matching_id
=
$bom_item_matching
->
matching_id
;
$item
->
match_number
=
$bom_item_matching
->
number
;
$item
->
match_goods_id
=
$bom_item_matching
->
goods_id
;
$item
->
match_goods_name
=
$bom_item_matching
->
goods_name
;
$item
->
match_brand_name
=
$bom_item_matching
->
brand_name
;
...
...
@@ -81,38 +96,516 @@ class BomService {
$item
->
match_price
=
$bom_item_matching
->
price
;
$item
->
match_amount
=
$bom_item_matching
->
price
*
$bom_item_matching
->
number
;
$item
->
is_corder
=
$bom_item_matching
->
is_corder
;
}
$item
->
bom_match_extend
=
$bomItemMatchExtendModel
->
get_bom_match_extend
(
$bom
->
bom_id
,
$bom_item_matching
->
matching_id
);
}
return
[
count
(
$bom_items
),
collect
(
$bom_items
)
->
toArray
()];
}
$list
=
$bom_items
->
toArray
();
// dump($list);
return
[
$list
[
'total'
],
$list
[
"data"
]];
}
protected
function
getSku
(
$goods_id
){
$url
=
Config
(
'website.search-skuid'
);
$data
[
'id'
]
=
$goods_id
;
protected
function
getSku
(
$user_id
,
$item
,
$extend
){
try
{
$url
=
Config
(
'website.search-skuid-finalInfo'
);
$data
[
'id'
]
=
$item
[
"match_goods_id"
];
$data
[
'num'
]
=
isset
(
$item
[
"match_number"
])
?
intval
(
$item
[
"match_number"
])
:
0
;
$data
[
'currency'
]
=
$extend
[
"currency"
];
$data
[
'uid'
]
=
intval
(
$user_id
)
?
intval
(
$user_id
)
:
0
;
$data
[
'k1'
]
=
time
();
$data
[
'k2'
]
=
md5
(
md5
(
$data
[
'k1'
])
.
'fh6y5t4rr351d2c3bryi'
);
$response
=
json_decode
(
curlApi
(
$url
,
$data
,
'POST'
),
true
);
dump
(
$response
);
if
(
$response
[
'err_code'
]
!=
0
){
return
false
;
}
else
{
return
$response
[
'data'
];
}
}
catch
(
\Exception
$e
){
return
false
;
}
}
/**
* 新获取最终销售价
* @param [type] $goods [description]
* @return [type] [description]
*/
function
ladder_final_price
(
$goods
,
$extend
)
{
$currency
=
isset
(
$extend
[
'currency'
])
?
$extend
[
'currency'
]
:
1
;
$use_ac
=
isset
(
$goods
[
'ac_type'
])
?
$goods
[
'ac_type'
]
:
0
;
if
(
$currency
==
1
)
{
$field
=
$use_ac
?
'price_ac'
:
'price_cn'
;
}
else
{
$field
=
$use_ac
?
'price_us'
:
'price_us'
;
//美元不支持优惠
}
$arr
=
[
'price'
=>
$goods
[
$field
],
'price_total'
=>
isset
(
$goods
[
$field
.
'_total'
])
?
$goods
[
$field
.
'_total'
]
:
$goods
[
$field
]
*
$goods
[
'num'
],
'num'
=>
$goods
[
'num'
],
];
return
$arr
;
}
/*
* 获取商品的会员价
*/
protected
function
saveBomItemMatchingBySearchApi
(
$bom_item_matching
,
$goods
,
$extend
=
[]){
// dump("获取api商品信息 修改商品");
//价格计算
$goods_prices
=
$this
->
ladder_final_price
(
$goods
,
$extend
);
//获取优惠前 原始价格
// $initial_prices = $this->ladder_final_price($goods, $extend);
//修改bom单匹配信息
$goodsInfo
=
$goods
[
'goods_info'
];
// dump($goodsInfo);
$where
=
[
'bom_id'
=>
$bom_item_matching
[
'bom_id'
],
"matching_id"
=>
$bom_item_matching
[
'matching_id'
]];
$delivery
=
""
;
if
(
is_array
(
$goodsInfo
[
'delivery_time'
])){
if
(
isset
(
$goodsInfo
[
'delivery_time'
][
$extend
[
'delivery_type'
]])){
$delivery
=
$goodsInfo
[
'delivery_time'
][
$extend
[
'delivery_type'
]];
}
}
$num
=
$bom_item_matching
[
'match_number'
];
if
(
in_array
(
$goodsInfo
[
'goods_type'
],
array
(
1
,
2
))){
//联营
}
else
{
//自营
$mpl
=
!
empty
(
$goodsInfo
[
'mpl'
])
?
$goodsInfo
[
'mpl'
]
:
1
;
//旧数据
$modNum
=
$num
%
$mpl
;
$num
=
$num
-
intval
(
$modNum
);
}
$data
=
[
"goods_id"
=>
$goodsInfo
[
'goods_id'
],
"goods_name"
=>
$goodsInfo
[
'goods_name'
],
"brand_id"
=>
$goodsInfo
[
'brand_id'
],
"brand_name"
=>
$goodsInfo
[
'brand_name'
],
"goods_type"
=>
static
::
$GOODSTYPE
[
$goodsInfo
[
'goods_type'
]],
"supplier_id"
=>
$goodsInfo
[
'supplier_id'
],
"supplier_name"
=>
$goodsInfo
[
'supplier_name'
],
"delivery"
=>
$delivery
,
//货期
"delivery_type"
=>
$extend
[
'delivery_type'
],
//交货类型
"number"
=>
$num
,
"price"
=>
$goods_prices
[
'price'
],
"pdf"
=>
$goodsInfo
[
'pdf'
],
"stock"
=>
$goodsInfo
[
'goods_number'
],
"moq"
=>
$goodsInfo
[
'min_buy'
],
"mpq"
=>
$goodsInfo
[
'min_mpq'
],
"encap"
=>
$goodsInfo
[
'encap'
],
"status"
=>
1
,
"update_time"
=>
time
(),
"ladder_price"
=>
json_encode
(
$goodsInfo
[
'tiered'
]),
];
$bk
=
$this
->
bomItemMatchModel
->
updateBomMatch
(
$bom_item_matching
[
'bom_id'
],
$where
,
$data
);
if
(
$bk
===
false
){
return
false
;
}
else
{
return
true
;
}
}
protected
function
addBomItemMatchingBySearchApi
(
$bom_item_matching
,
$goods
,
$extend
=
[]){
//价格计算
$goods_prices
=
$this
->
ladder_final_price
(
$goods
,
$extend
);
//获取优惠前 原始价格
// $initial_prices = $this->ladder_final_price($goods, $extend);
//修改bom单匹配信息
$goodsInfo
=
$goods
[
'goods_info'
];
// $where = ['bom_id'=>$bom_item_matching['bom_id'],"matching_id"=>$bom_item_matching['matching_id']];
$num
=
$bom_item_matching
[
'match_number'
];
if
(
in_array
(
$goodsInfo
[
'goods_type'
],
array
(
1
,
2
))){
//联营
}
else
{
//自营
$mpl
=
!
empty
(
$goodsInfo
[
'mpl'
])
?
$goodsInfo
[
'mpl'
]
:
1
;
//旧数据
$modNum
=
$num
%
$mpl
;
$num
=
$num
-
intval
(
$modNum
);
}
$data
=
[
"bom_id"
=>
$bom_item_matching
[
'bom_id'
],
"bom_item_id"
=>
$bom_item_matching
[
'bom_item_id'
],
"goods_id"
=>
$goodsInfo
[
'goods_id'
],
"goods_name"
=>
$goodsInfo
[
'goods_name'
],
"brand_id"
=>
$goodsInfo
[
'brand_id'
],
"brand_name"
=>
$goodsInfo
[
'brand_name'
],
"goods_type"
=>
static
::
$GOODSTYPE
[
$goodsInfo
[
'goods_type'
]],
"supplier_id"
=>
$goodsInfo
[
'supplier_id'
],
"supplier_name"
=>
$goodsInfo
[
'supplier_name'
],
"delivery"
=>
$goodsInfo
[
'delivery_time'
],
"delivery_type"
=>
$extend
[
'delivery_type'
],
//交货类型
"number"
=>
$num
,
"price"
=>
$goods_prices
[
'price'
],
"pdf"
=>
$goodsInfo
[
'pdf'
],
"stock"
=>
$goodsInfo
[
'goods_number'
],
"moq"
=>
$goodsInfo
[
'min_buy'
],
"mpq"
=>
$goodsInfo
[
'min_mpq'
],
"encap"
=>
$goodsInfo
[
'encap'
],
"status"
=>
1
,
"update_time"
=>
time
(),
"ladder_price"
=>
json_encode
(
$goodsInfo
[
'tiered'
]),
];
// dump($data);
$bk
=
$this
->
bomItemMatchModel
->
addBomMatch
(
$bom_item_matching
[
'bom_id'
],
$data
);
if
(
$bk
===
false
){
return
false
;
}
else
{
return
true
;
}
}
public
function
saveBomItemMatching
(
$bom_item_matching
,
$extend
){
// dump("不需要匹配商品,直接修改bom单");
$goodsInfo
=
$bom_item_matching
;
// dump($goodsInfo);return;
if
(
isset
(
$bom_item_matching
[
'matching_id'
])
&&
$bom_item_matching
[
'matching_id'
]
>
0
){
//修改
$where
=
[
'bom_id'
=>
$bom_item_matching
[
'bom_id'
],
"matching_id"
=>
$bom_item_matching
[
'matching_id'
]];
$data
=
[
"goods_id"
=>
0
,
"goods_name"
=>
trim
(
$goodsInfo
[
'match_goods_name'
]),
"brand_id"
=>
0
,
"brand_name"
=>
trim
(
$goodsInfo
[
'match_brand_name'
]),
"goods_type"
=>
1
,
//默认联营
"delivery"
=>
trim
(
$goodsInfo
[
'match_delivery'
]),
//货期
"delivery_type"
=>
$extend
[
'delivery_type'
],
//交货类型
"number"
=>
intval
(
$goodsInfo
[
'match_number'
]),
"price"
=>
$goodsInfo
[
'match_price'
],
"pdf"
=>
""
,
"supplier_name"
=>
trim
(
$goodsInfo
[
'match_supplier_name'
]),
"supplier_id"
=>
"0"
,
"stock"
=>
0
,
"moq"
=>
0
,
"mpq"
=>
0
,
"encap"
=>
""
,
"status"
=>
1
,
"update_time"
=>
time
(),
"ladder_price"
=>
""
,
];
$bk
=
$this
->
bomItemMatchModel
->
updateBomMatch
(
$goodsInfo
[
'bom_id'
],
$where
,
$data
);
if
(
$bk
===
false
){
return
false
;
}
else
{
return
true
;
}
}
else
{
//新增
$data
=
[
"bom_id"
=>
$goodsInfo
[
'bom_id'
],
"bom_item_id"
=>
$goodsInfo
[
'bom_item_id'
],
"goods_id"
=>
0
,
"goods_name"
=>
isset
(
$goodsInfo
[
'match_goods_name'
])
?
trim
(
$goodsInfo
[
'match_goods_name'
])
:
''
,
"brand_id"
=>
0
,
"brand_name"
=>
isset
(
$goodsInfo
[
'match_brand_name'
])
?
trim
(
$goodsInfo
[
'match_brand_name'
])
:
''
,
"goods_type"
=>
1
,
//默认联营
"delivery"
=>
isset
(
$goodsInfo
[
'match_delivery'
])
?
trim
(
$goodsInfo
[
'match_delivery'
])
:
''
,
//货期
"delivery_type"
=>
isset
(
$extend
[
'delivery_type'
])
?
$extend
[
'delivery_type'
]
:
1
,
//交货类型
"number"
=>
isset
(
$goodsInfo
[
'match_number'
])
?
intval
(
$goodsInfo
[
'match_number'
])
:
0
,
"price"
=>
isset
(
$goodsInfo
[
'match_price'
])
?
$goodsInfo
[
'match_price'
]
:
0
,
"supplier_name"
=>
isset
(
$goodsInfo
[
'match_supplier_name'
])
?
trim
(
$goodsInfo
[
'match_supplier_name'
])
:
''
,
"supplier_id"
=>
"0"
,
"pdf"
=>
""
,
"stock"
=>
0
,
"moq"
=>
0
,
"mpq"
=>
0
,
"encap"
=>
""
,
"status"
=>
1
,
"add_time"
=>
time
(),
"update_time"
=>
time
(),
"ladder_price"
=>
""
,
];
$bk
=
$this
->
bomItemMatchModel
->
addBomMatch
(
$goodsInfo
[
'bom_id'
],
$data
);
if
(
$bk
===
false
){
return
false
;
}
else
{
return
true
;
}
}
}
public
function
saveBomInfo
(
$request
){
try
{
$err_msg
=
[];
$data
=
$request
->
input
(
"data"
,
''
);
// dump($data);exit;
$bom_id
=
$data
[
0
][
"bom_id"
];
$bom
=
BomModel
::
where
([
"bom_id"
=>
intval
(
$bom_id
)])
->
select
(
"user_id"
,
"where"
)
->
first
();
$user_id
=
$bom
->
user_id
;
$bom_where
=
$bom
->
where
;
$delivery_type
=
0
;
//交货地
if
(
!
$user_id
){
throw
new
BomException
(
"该bom单没有绑定用户id"
,
-
1
);
}
if
(
$bom_where
){
$bom_where_arr
=
json_decode
(
$bom_where
,
true
);
if
(
isset
(
$bom_where_arr
[
"delivery_type"
])){
$delivery_type
=
$bom_where_arr
[
"delivery_type"
];
}
}
if
(
!
in_array
(
$delivery_type
,[
1
,
2
])){
$delivery_type
=
1
;
}
$currency
=
$delivery_type
;
$extend
[
"delivery_type"
]
=
$delivery_type
;
$extend
[
"currency"
]
=
$currency
;
foreach
(
$data
as
$k
=>
$item
){
//已下单的不能修改
if
(
isset
(
$item
[
'match_is_corder'
])
&&
$item
[
'match_is_corder'
]
==
1
){
// array_push($err_msg,sprintf("第%s个型号已下单,无法更改;",$k));
continue
;
}
//设置匹配的默认数量
if
(
!
isset
(
$item
[
"match_number"
])
||
intval
(
$item
[
"match_number"
])
<=
0
){
if
(
isset
(
$item
[
'number'
])
&&
$item
[
'number'
]
>
0
){
$item
[
"match_number"
]
=
intval
(
$item
[
'number'
]);
}
else
{
$item
[
"match_number"
]
=
1
;
}
}
//如果客服修改了goods_id则 需要重新匹配的商品信息
if
(
isset
(
$item
[
'match_goods_id'
])
&&
$item
[
'match_goods_id'
]
&&
intval
(
$item
[
'match_goods_id'
])
>
0
){
// dump($item);continue;
//请求api 获取商品信息
$res
=
$this
->
getSku
(
$user_id
,
$item
,
$extend
);
// dump($res);
//如果获取到了商品数据
if
(
$res
!==
false
){
if
(
isset
(
$item
[
'matching_id'
])
&&
$item
[
'matching_id'
]
>
0
){
//修改 查询到了商品信息 修改本地bom单信息
if
(
$this
->
saveBomItemMatchingBySearchApi
(
$item
,
$res
,
$extend
)){
continue
;
}
}
else
{
//新增
if
(
$this
->
addBomItemMatchingBySearchApi
(
$item
,
$res
,
$extend
)){
continue
;
}
}
}
else
{
//没搜索到商品 直接将商品id设为0
$item
[
"match_goods_id"
]
=
0
;
}
}
//没有找到商品信息
//直接按照客服提交的信息修改内容 并且修改goods_id=0 goods_type类型为联营
$this
->
saveBomItemMatching
(
$item
,
$extend
);
}
return
[
'errcode'
=>
0
,
"errmsg"
=>
"保存成功"
];
}
catch
(
BomException
$e
){
return
[
'errcode'
=>
$e
->
getCode
(),
"errmsg"
=>
$e
->
getMessage
()];
}
catch
(
\Exception
$e
){
return
[
'errcode'
=>-
1
,
"errmsg"
=>
$e
->
getMessage
()];
}
}
/*
* bom下单
* 自营单
* 联营单
*/
public
function
createBomOrder
(
$request
){
try
{
$err_msg
=
[];
$data
=
$request
->
input
(
"data"
,
''
);
// dump($data);exit;
$bom_id
=
$data
[
0
][
"bom_id"
];
$bom
=
BomModel
::
where
([
"bom_id"
=>
intval
(
$bom_id
)])
->
select
(
"user_id"
,
"where"
)
->
first
();
$user_id
=
$bom
->
user_id
;
$bom_where
=
$bom
->
where
;
$delivery_type
=
0
;
//交货地
if
(
!
$user_id
){
throw
new
BomException
(
"该bom单没有绑定用户id"
,
-
1
);
}
if
(
$bom_where
){
$bom_where_arr
=
json_decode
(
$bom_where
,
true
);
if
(
isset
(
$bom_where_arr
[
"delivery_type"
])){
$delivery_type
=
$bom_where_arr
[
"delivery_type"
];
}
}
if
(
!
in_array
(
$delivery_type
,[
1
,
2
])){
$delivery_type
=
1
;
}
$currency
=
$delivery_type
;
$extend
[
"delivery_type"
]
=
$delivery_type
;
$extend
[
"currency"
]
=
$currency
;
$extend
[
"bom_id"
]
=
$bom_id
;
dump
(
$extend
);
// dump($data);
$address_id
=
$this
->
getAddress
(
$user_id
);
dump
(
$address_id
);
$ziying
=
[];
$lianying
=
[];
foreach
(
$data
as
$k
=>
$item
){
dump
(
$item
[
'match_goods_id'
]);
if
(
$item
[
'match_goods_id'
]
&&
intval
(
$item
[
'match_goods_id'
])
>
0
){
$this
->
getSku
(
$item
[
'match_goods_id'
]);
if
(
$item
[
"is_corder"
]
==
1
)
continue
;
if
(
in_array
(
$item
[
"match_goods_type"
],[
0
])){
//自营
$ziying
[
$k
][
"id"
]
=
$item
[
"match_goods_id"
];
$ziying
[
$k
][
"num"
]
=
$item
[
"match_number"
];
}
else
{
//联营
//
}
}
//加入购物车
$addZYShopCart
=
$this
->
createZYOrderToShopCart
(
$user_id
,
$ziying
,
$extend
);
if
(
!
empty
(
$addZYShopCart
)
&&
$addZYShopCart
[
'err_code'
]
==
0
){
//假如购物车成功
//获取自营购物车
$car_ids
=
$this
->
getShopCart
(
$user_id
,
3
);
array_push
(
$err_msg
,
$addZYShopCart
[
"err_msg"
]);
if
(
!
empty
(
$car_ids
)){
$extend
[
'address_id'
]
=
$address_id
;
//创建订单
$addzyOrder
=
$this
->
createOrder
(
$user_id
,
$car_ids
,
$extend
,
3
);
if
(
!
empty
(
$addzyOrder
)
&&
$addzyOrder
[
'err_code'
]
==
0
){
//创建订单成功
}
else
{
if
(
is_array
(
$addzyOrder
)
&&
!
empty
(
$addzyOrder
)){
array_push
(
$err_msg
,
$addzyOrder
[
"err_msg"
]);
}
}
}
}
else
{
//bom加入购物车失败
if
(
is_array
(
$addZYShopCart
)
&&
!
empty
(
$addZYShopCart
)){
array_push
(
$err_msg
,
$addZYShopCart
[
"err_msg"
]);
}
}
// $this->createZYOrder($lianying);
}
catch
(
BomException
$e
){
return
[
'errcode'
=>
$e
->
getCode
(),
"errmsg"
=>
$e
->
getMessage
()];
}
catch
(
\Exception
$e
){
return
[
'errcode'
=>-
1
,
"errmsg"
=>
$e
->
getMessage
()];
}
}
/*
* 创建订单
*
*/
protected
function
createOrder
(
$user_id
,
$car_ids
,
$extend
,
$type
=
3
){
$url
=
Config
(
'website.api_create_order'
);
$data
[
'bom_id'
]
=
$extend
[
"bom_id"
];
$data
[
'uid'
]
=
intval
(
$user_id
)
?
intval
(
$user_id
)
:
0
;
$data
[
"type"
]
=
2
;
//订单类型:1.联营, 2.自营线上, 3.自营线下, 4.自营其他业务订单
$data
[
"cart_id"
]
=
implode
(
","
,
$car_ids
);
$data
[
'address_id'
]
=
$extend
[
"address_id"
];
$data
[
'k1'
]
=
time
();
$data
[
'k2'
]
=
md5
(
md5
(
$data
[
'k1'
])
.
'fh6y5t4rr351d2c3bryi'
);
$response
=
json_decode
(
curlApi
(
$url
,
$data
,
'POST'
),
true
);
return
$response
;
}
/*
* 获取到后台加入的自营的购物车商品
*/
protected
function
getShopCart
(
$user_id
=
0
,
$type
=
3
){
$goodsType
=
[];
if
(
$type
==
3
){
//自营
$goodsType
=
[
3
];
}
else
{
//联营
$goodsType
=
[
1
,
2
];
}
$query
=
DB
::
connection
(
"order"
)
->
table
(
"lie_shopping_cart"
)
->
where
([
"user_id"
=>
$user_id
,
"status"
=>
1
])
->
where
(
"bom_id"
,
"!="
,
0
)
->
whereIn
(
"goods_type"
,
$goodsType
)
->
select
(
"cart_id"
)
->
pluck
(
"cart_id"
);
return
$query
;
}
/*
* 创建自营订单 到购物车
*/
protected
function
createZYOrderToShopCart
(
$user_id
,
$ziying
,
$extend
){
$url
=
Config
(
'website.addzyorder_url'
);
$data
[
'type'
]
=
2
;
$data
[
'bom_id'
]
=
$extend
[
"bom_id"
];
$data
[
'delivery_place'
]
=
$extend
[
'delivery_type'
];
$data
[
"data"
]
=
array_merge
(
$ziying
);
$data
[
'uid'
]
=
intval
(
$user_id
)
?
intval
(
$user_id
)
:
0
;
$data
[
'k1'
]
=
time
();
$data
[
'k2'
]
=
md5
(
md5
(
$data
[
'k1'
])
.
'fh6y5t4rr351d2c3bryi'
);
$response
=
json_decode
(
curlApi
(
$url
,
$data
,
'POST'
),
true
);
return
$response
;
}
protected
function
getAddress
(
$user_id
){
$address
=
DB
::
connection
(
"order"
)
->
table
(
"lie_user_address"
)
->
where
([
"user_id"
=>
$user_id
])
->
select
(
"address_id"
,
"is_default"
)
->
orderBy
(
"address_id"
,
"desc"
)
->
get
();
if
(
!
$address
){
throw
new
BomException
(
"没有找到该用户对应的收货地址"
,
-
1
);
}
$address_id
=
0
;
foreach
(
$address
as
$k
=>
$item
){
if
(
$item
->
is_default
==
1
){
$address_id
=
$item
->
address_id
;
break
;
}
}
if
(
$address_id
){
return
$address_id
;
}
return
$address
[
0
]
->
address_id
;
}
protected
function
getTax
(
$user_id
){
$tax
=
DB
::
connection
(
"order"
)
->
table
(
"lie_taxinfo"
)
->
where
([
"user_id"
=>
$user_id
])
->
select
(
"tax_id"
,
"tax_title"
,
"inv_type"
,
"is_default"
)
->
orderBy
(
"tax_id"
,
"desc"
)
->
get
();
if
(
!
tax_id
){
return
false
;
}
$tax_id
=
0
;
foreach
(
$tax
as
$k
=>
$item
){
if
(
$item
->
is_default
==
1
){
$tax_id
=
$item
->
tax_id
;
break
;
}
}
if
(
$tax_id
){
return
$tax_id
;
}
return
$tax
[
0
]
->
tax_id
;
}
...
...
config/website.php
View file @
0540a7fb
...
...
@@ -58,6 +58,17 @@ return [
// 'search-skuid' => 'http://www.liexin.com/v3/sku/list',
'search-skuid'
=>
'http://api.liexin.com/goods/detail'
,
'search-skuid-finalInfo'
=>
'http://api.liexin.com/cart/bomOrderGetFinalGoods'
,
//批量下自营订单
'addzyorder_url'
=>
'http://api.liexin.com/cart/addBatch'
,
//联营
'addlyorder_url'
=>
'http://api.liexin.com/cart/addBatchByOrderSystem'
,
//创建订单
'api_create_order'
=>
'http://api.liexin.com/order/create'
,
// 新增SKU入口
'add-sku-url'
=>
'http://footstone.liexin.net/manage/addsku'
,
...
...
public/js/web/BomView.js
View file @
0540a7fb
...
...
@@ -2,28 +2,56 @@ layui.use(['form', 'table', 'laydate'], function() {
var
form
=
layui
.
form
;
var
table
=
layui
.
table
;
var
laydate
=
layui
.
laydate
;
var
table
=
layui
.
table
;
//转换静态表格
table
.
init
(
'bomView'
,
{
url
:
'/ajax/bom/BomView?bom_id='
+
bom_id
//数据接口
limit
:
10
,
url
:
'/ajax/bom/BomView?bom_id='
+
bom_id
//数据接口
,
toolbar
:
'#toolbarDemo'
//开启头部工具栏,并为其绑定左侧模板
,
defaultToolbar
:[]
,
method
:
'post'
,
cellMinWidth
:
80
//全局定义常规单元格的最小宽度
,
page
:
fals
e
//开启分页
,
page
:
tru
e
//开启分页
});
//头工具栏事件
table
.
on
(
'toolbar(bomView)'
,
function
(
obj
){
switch
(
obj
.
event
){
case
'save_form'
:
var
listdata
=
layui
.
table
.
cache
;
console
.
log
(
listdata
[
1
])
var
datax
=
{}
datax
.
data
=
listdata
[
1
]
function
renderTable
(){
table
.
init
(
'bomView'
,
{
limit
:
10
,
url
:
'/ajax/bom/BomView?bom_id='
+
bom_id
//数据接口
,
toolbar
:
'#toolbarDemo'
//开启头部工具栏,并为其绑定左侧模板
,
defaultToolbar
:[]
,
method
:
'post'
,
cellMinWidth
:
80
//全局定义常规单元格的最小宽度
,
page
:
true
//开启分页
});
}
form
.
on
(
'checkbox(checkall)'
,
function
(
data
)
{
var
child
=
$
(
data
.
elem
).
parents
(
'.layui-tab-item'
).
find
(
'input[type="checkbox"]'
);
child
.
each
(
function
(
index
,
item
)
{
item
.
checked
=
data
.
elem
.
checked
;
});
form
.
render
(
'checkbox'
);
});
//监听单元格编辑
table
.
on
(
'edit(bomView)'
,
function
(
obj
){
var
value
=
obj
.
value
//得到修改后的值
,
data
=
obj
.
data
//得到所在行所有键值
,
field
=
obj
.
field
;
//得到字段
if
(
field
!=
"match_goods_id"
){
obj
.
data
.
match_goods_id
=
0
;
obj
.
update
(
data
)
//修改当前行数据
}
});
function
save_form_ajax
(
datax
){
layer
.
open
({
title
:
"保存bom单"
,
content
:
"你确定保存吗?"
,
...
...
@@ -35,32 +63,77 @@ layui.use(['form', 'table', 'laydate'], function() {
type
:
'post'
,
data
:
datax
,
success
:
function
(
resp
)
{
//if (resp.err_code == 0) {
// layer.msg(resp.err_msg);
// // renderTable(); // 重新加载table
// $('.search').trigger("click"); // 触发搜索按钮
// if(typeof resp.data.redictUrl != "undefined"){
// window.location.href=resp.data.redictUrl;
// }
// return false;
//}
//
//layer.alert(resp.err_msg);
if
(
resp
.
errcode
==
0
)
{
layer
.
msg
(
resp
.
errmsg
);
renderTable
();
// 重新加载table
}
else
{
layer
.
alert
(
resp
.
errmsg
);
}
},
error
:
function
(
err
)
{
console
.
log
(
err
)
}
})
return
false
;
},
cancel
:
function
(
index
)
{
layer
.
close
(
index
);
}
})
}
//layer.msg('保存中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
function
create_order_ajax
(
datax
){
layer
.
open
({
title
:
"创建bom订单"
,
content
:
"你确定下单吗?"
,
btn
:
[
'确认?'
,
'取消'
],
yes
:
function
(
index
)
{
layer
.
close
(
index
);
$
.
ajax
({
url
:
"/ajax/bom/createBomOrder"
,
type
:
'post'
,
data
:
datax
,
success
:
function
(
resp
)
{
if
(
resp
.
errcode
==
0
)
{
layer
.
msg
(
resp
.
errmsg
);
renderTable
();
// 重新加载table
}
else
{
layer
.
alert
(
resp
.
errmsg
);
}
},
error
:
function
(
err
)
{
console
.
log
(
err
)
}
})
return
false
;
},
cancel
:
function
(
index
)
{
layer
.
close
(
index
);
}
})
}
//头工具栏事件
table
.
on
(
'toolbar(bomView)'
,
function
(
obj
){
var
checkStatus
=
table
.
checkStatus
(
"layui_table_bomView"
);
var
data
=
checkStatus
.
data
;
if
(
checkStatus
.
data
.
length
<=
0
){
layer
.
msg
(
'请先选择需要保存的数据行'
,
{
icon
:
16
,
time
:
3000
,
shade
:
0.3
})
return
}
var
datax
=
{}
datax
.
data
=
data
switch
(
obj
.
event
){
case
'create_order'
:
create_order_ajax
(
datax
);
break
;
case
'save_form'
:
save_form_ajax
(
datax
)
break
;
};
});
...
...
resources/views/web/BomView.blade.php
View file @
0540a7fb
...
...
@@ -22,19 +22,22 @@
-webkit-border-radius
:
6px
;
}
</style>
<table
class=
"layui-table"
lay-filter=
"bomView"
>
<table
class=
"layui-table"
lay-filter=
"bomView"
id=
"layui_table_bomView"
>
<thead>
<tr>
<th
lay-data=
"{fixed: 'left',templet:'#checkbd'}"
><input
type=
"checkbox"
>
全选
</th>
<th
lay-data=
"{type:'numbers', width:80, sort: true,fixed: 'left'}"
>
序号
</th>
<th
lay-data=
"{field:'goods_name', width:150,fixed: 'left'}"
>
需求型号
</th>
<th
lay-data=
"{field:'brand_name',fixed: 'left',width:140,}"
>
品牌
</th>
<th
lay-data=
"{field:'goods_name', width:150}"
>
需求型号
</th>
<th
lay-data=
"{field:'brand_name',width:140,}"
>
品牌
</th>
<th
lay-data=
"{field:'number',width:120,}"
>
需求数量
</th>
<th
lay-data=
"{field:'attrs',width:120,}"
>
参数
</th>
<th
lay-data=
"{field: 'match_goods_id',width:150,edit:'text'}"
>
skuID(可修改)
</th>
<th
lay-data=
"{field: 'match_goods_name',width:200,edit:'text'}"
>
推荐型号(可修改)
</th>
<th
lay-data=
"{field: 'match_brand_name',width:200,edit:'text'}"
>
推荐品牌(可修改)
</th>
<th
lay-data=
"{field:'
number', width:130,edit: 'text',edit:'text'}"
>
数量(可修改)
</th>
<th
lay-data=
"{field:'
match_number', width:130,edit:'text'}"
><i
class=
"layui-icon-edit"
></i>
推荐
数量(可修改)
</th>
<th
lay-data=
"{field:'match_price',width:130,edit:'text'}"
>
单价(可修改)
</th>
<th
lay-data=
"{field:'match_delivery',width:160,edit:'text'}"
>
货期/天(可修改)
</th>
<th
lay-data=
"{field:'match_supplier_name'
}"
>
供应商
</th>
<th
lay-data=
"{field:'match_supplier_name'
,edit:'text',width:160}"
>
供应商(可修改)
</th>
<th
lay-data=
"{field:'match_mpq'}"
>
包装
</th>
<th
lay-data=
"{field:'match_moq'}"
>
起订量
</th>
<th
lay-data=
"{field:'match_amount',width:100}"
>
小计
</th>
...
...
@@ -48,6 +51,7 @@
<script
type=
"text/html"
id=
"toolbarDemo"
>
<
div
class
=
"layui-btn-container"
>
<
button
class
=
"layui-btn layui-btn-sm"
lay
-
event
=
"save_form"
>
保存
<
/button>
<
button
class
=
"layui-btn layui-btn-sm"
lay
-
event
=
"create_order"
>
下单
<
/button>
<
/div>
</script>
...
...
@@ -60,6 +64,11 @@
@{{
#
}
}}
</script>
<script
type=
"text/html"
id=
"checkbd"
>
@{{
#
if
(
d
.
is_corder
!=
1
)
{
}}
<
input
type
=
"checkbox"
name
=
"layTableCheckbox"
lay
-
skin
=
"primary"
>
@{{
#
}
}}
</script>
<script
type=
"text/html"
id=
"match_extend_order_amount"
>
...
...
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