Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
飞鱼0526
ShopXO
提交
70b5a4ba
ShopXO
项目概览
飞鱼0526
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
70b5a4ba
编写于
7月 18, 2020
作者:
D
devil
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
仓库订单拆分逻辑开发
上级
3af384ff
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
194 addition
and
96 deletion
+194
-96
application/index/controller/Buy.php
application/index/controller/Buy.php
+3
-3
application/service/BuyService.php
application/service/BuyService.php
+9
-1
application/service/OrderSplitService.php
application/service/OrderSplitService.php
+157
-0
application/service/WarehouseGoodsService.php
application/service/WarehouseGoodsService.php
+0
-1
application/service/WarehouseService.php
application/service/WarehouseService.php
+25
-4
application/tags.php
application/tags.php
+0
-87
未找到文件。
application/index/controller/Buy.php
浏览文件 @
70b5a4ba
...
...
@@ -50,9 +50,9 @@ class Buy extends Common
*/
public
function
Index
()
{
if
(
input
(
'post.'
)
)
if
(
$this
->
data_post
)
{
session
(
'buy_post_data'
,
$
_POST
);
session
(
'buy_post_data'
,
$
this
->
data_post
);
return
redirect
(
MyUrl
(
'index/buy/index'
));
}
else
{
// 站点类型,是否开启了展示型
...
...
@@ -82,7 +82,7 @@ class Buy extends Common
$buy_base
=
$buy_ret
[
'data'
][
'base'
];
$buy_goods
=
$buy_ret
[
'data'
][
'goods'
];
$buy_extension_data
=
$buy_ret
[
'data'
][
'extension_data'
];
print_r
(
$buy_goods
);
die
;
// 用户地址
$address
=
UserService
::
UserAddressList
([
'user'
=>
$this
->
user
]);
$this
->
assign
(
'user_address_list'
,
$address
[
'data'
]);
...
...
application/service/BuyService.php
浏览文件 @
70b5a4ba
...
...
@@ -17,6 +17,7 @@ use app\service\UserService;
use
app\service\ResourcesService
;
use
app\service\PaymentService
;
use
app\service\ConfigService
;
use
app\service\OrderSplitService
;
/**
* 购买服务层
...
...
@@ -710,6 +711,13 @@ class BuyService
}
}
// 订单拆分
$order_split
=
OrderSplitService
::
Run
([
'goods'
=>
$goods
]);
if
(
$order_split
[
'code'
]
!=
0
)
{
return
$order_split
;
}
// 商品/基础信息
$total_price
=
empty
(
$goods
)
?
0
:
array_sum
(
array_column
(
$goods
,
'total_price'
));
$base
=
[
...
...
@@ -767,7 +775,7 @@ class BuyService
// 返回数据
$result
=
[
'goods'
=>
$
goods
,
'goods'
=>
$
order_split
[
'data'
]
,
'base'
=>
$base
,
'extension_data'
=>
$extension_data
,
];
...
...
application/service/OrderSplitService.php
0 → 100644
浏览文件 @
70b5a4ba
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace
app\service
;
use
think\Db
;
use
think\facade\Hook
;
use
app\service\WarehouseService
;
/**
* 订单拆分服务层
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-07-18
* @desc description
*/
class
OrderSplitService
{
/**
* 订单拆分入口
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-07-18
* @desc description
* @param [array] $params [输入参数]
*/
public
static
function
Run
(
$params
=
[])
{
// 请求参数
$p
=
[
[
'checked_type'
=>
'empty'
,
'key_name'
=>
'goods'
,
'error_msg'
=>
'商品为空'
,
],
[
'checked_type'
=>
'is_array'
,
'key_name'
=>
'goods'
,
'error_msg'
=>
'商品有误'
,
],
];
$ret
=
ParamsChecked
(
$params
,
$p
);
if
(
$ret
!==
true
)
{
return
DataReturn
(
$ret
,
-
1
);
}
// 商品仓库集合
$warehouse_goods
=
self
::
GoodsWarehouseAggregate
(
$params
[
'goods'
]);
return
DataReturn
(
'操作成功'
,
0
,
$warehouse_goods
);
}
/**
* 商品仓库集合
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-07-18
* @desc description
* @param [array] $data [商品数据]
*/
public
static
function
GoodsWarehouseAggregate
(
$data
)
{
$result
=
[];
foreach
(
$data
as
$v
)
{
// 不存在规格则使用默认
if
(
empty
(
$v
[
'spec'
]))
{
$spec
=
[
[
'type'
=>
'默认规格'
,
'value'
=>
'default'
,
]
];
}
else
{
$spec
=
$v
[
'spec'
];
}
// 获取商品库存
$where
=
[
'wgs.goods_id'
=>
$v
[
'goods_id'
],
'wgs.md5_key'
=>
md5
(
implode
(
''
,
array_column
(
$spec
,
'value'
))),
'wg.is_enable'
=>
1
,
'w.is_enable'
=>
1
,
'w.is_delete_time'
=>
0
,
];
$field
=
'distinct w.id,w.name,w.alias,w.lng,w.lat,w.province,w.city,w.county,w.address,wgs.inventory,w.is_default,w.level'
;
$warehouse
=
Db
::
name
(
'WarehouseGoodsSpec'
)
->
alias
(
'wgs'
)
->
join
([
'__WAREHOUSE_GOODS__'
=>
'wg'
],
'wgs.warehouse_id=wg.warehouse_id'
)
->
join
([
'__WAREHOUSE__'
=>
'w'
],
'wg.warehouse_id=w.id'
)
->
where
(
$where
)
->
field
(
$field
)
->
order
(
'w.level desc,w.is_default desc,wgs.inventory desc'
)
->
select
();
// 默认仓库
$warehouse_default
=
[];
// 商品仓库分组
if
(
!
empty
(
$warehouse
))
{
$goods
=
[];
foreach
(
$warehouse
as
$w
)
{
// 是否还存在未分配的数量
if
(
$v
[
'stock'
]
>
0
)
{
// 追加商品并减除数量
$goods
[]
=
$v
;
$v
[
'stock'
]
-=
$w
[
'inventory'
];
// 是否第一次赋值
if
(
!
array_key_exists
(
$w
[
'id'
],
$result
))
{
$warehouse_handle
=
WarehouseService
::
DataHandle
([
$w
]);
$result
[
$w
[
'id'
]]
=
$warehouse_handle
[
0
];
$result
[
$w
[
'id'
]][
'goods_items'
]
=
[];
unset
(
$result
[
$w
[
'id'
]][
'is_default'
],
$result
[
$w
[
'id'
]][
'level'
],
$result
[
$w
[
'id'
]][
'inventory'
]);
}
// 商品归属到仓库下
if
(
!
empty
(
$goods
))
{
$result
[
$w
[
'id'
]][
'goods_items'
]
=
array_merge
(
$result
[
$w
[
'id'
]][
'goods_items'
],
$goods
);
}
}
else
{
break
;
}
}
}
else
{
// 未获取到仓库则使用默认仓库
if
(
empty
(
$warehouse_default
))
{
$warehouse_default
=
Db
::
name
(
'Warehouse'
)
->
where
([
'is_default'
=>
1
,
'is_enable'
=>
1
,
'is_delete_time'
=>
0
])
->
field
(
'id,name,alias,lng,lat,province,city,county,address'
)
->
find
();
}
if
(
!
empty
(
$warehouse_default
))
{
if
(
!
array_key_exists
(
$warehouse_default
[
'id'
],
$result
))
{
$warehouse_handle
=
WarehouseService
::
DataHandle
([
$warehouse_default
]);
$result
[
$warehouse_default
[
'id'
]]
=
$warehouse_handle
[
0
];
$result
[
$warehouse_default
[
'id'
]][
'goods_items'
]
=
[];
}
// 商品归属到仓库下
$result
[
$warehouse_default
[
'id'
]][
'goods_items'
][]
=
$v
;
}
}
}
return
array_values
(
$result
);
}
}
?>
\ No newline at end of file
application/service/WarehouseGoodsService.php
浏览文件 @
70b5a4ba
...
...
@@ -42,7 +42,6 @@ class WarehouseGoodsService
$n
=
isset
(
$params
[
'n'
])
?
intval
(
$params
[
'n'
])
:
10
;
$order_by
=
'id desc'
;
$data
=
Db
::
name
(
'WarehouseGoods'
)
->
field
(
$field
)
->
where
(
$where
)
->
order
(
$order_by
)
->
limit
(
$m
,
$n
)
->
select
();
return
DataReturn
(
'处理成功'
,
0
,
self
::
DataHandle
(
$data
));
}
...
...
application/service/WarehouseService.php
浏览文件 @
70b5a4ba
...
...
@@ -39,11 +39,32 @@ class WarehouseService
$field
=
empty
(
$params
[
'field'
])
?
'*'
:
$params
[
'field'
];
$order_by
=
empty
(
$params
[
'order_by'
])
?
'level desc, id desc'
:
trim
(
$params
[
'order_by'
]);
$data
=
Db
::
name
(
'Warehouse'
)
->
field
(
$field
)
->
where
(
$where
)
->
order
(
$order_by
)
->
select
();
return
DataReturn
(
'处理成功'
,
0
,
self
::
DataHandle
(
$data
));
}
/**
* 数据处理
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-07-18
* @desc description
* @param [array] $data [仓库数据]
*/
public
static
function
DataHandle
(
$data
)
{
if
(
!
empty
(
$data
))
{
// 地区数据
$ids
=
array_unique
(
array_merge
(
array_column
(
$data
,
'province'
),
array_column
(
$data
,
'city'
),
array_column
(
$data
,
'county'
)));
$region
=
Db
::
name
(
'Region'
)
->
where
([
'id'
=>
$ids
])
->
column
(
'name'
,
'id'
);
// 字段列表
$keys
=
ArrayKeys
(
$data
);
// 获取商品信息
if
(
in_array
(
'province'
,
$keys
)
&&
in_array
(
'city'
,
$keys
)
&&
in_array
(
'county'
,
$keys
))
{
// 地区数据
$ids
=
array_unique
(
array_merge
(
array_column
(
$data
,
'province'
),
array_column
(
$data
,
'city'
),
array_column
(
$data
,
'county'
)));
$region
=
Db
::
name
(
'Region'
)
->
where
([
'id'
=>
$ids
])
->
column
(
'name'
,
'id'
);
}
// 循环处理数据
foreach
(
$data
as
&
$v
)
...
...
@@ -73,7 +94,7 @@ class WarehouseService
}
}
}
return
DataReturn
(
'success'
,
0
,
$data
)
;
return
$data
;
}
/**
...
...
application/tags.php
浏览文件 @
70b5a4ba
...
...
@@ -32,92 +32,5 @@ return array (
'log_write'
=>
array
(
),
'plugins_css'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
1
=>
'app\\plugins\\freightfee\\Hook'
,
2
=>
'app\\plugins\\limitedtimediscount\\Hook'
,
),
'plugins_service_users_center_left_menu_handle'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_service_header_navigation_top_right_handle'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_service_order_status_change_history_success_handle'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_service_order_aftersale_audit_handle_end'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_service_site_extraction_address_list'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_service_buy_order_insert_end'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_service_goods_spec_extends_handle'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_view_admin_user_save'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_service_user_save_handle'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_view_goods_detail_base_buy_nav_min_inside'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_view_goods_detail_photo_within'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_view_goods_detail_base_bottom'
=>
array
(
0
=>
'app\\plugins\\distribution\\Hook'
,
),
'plugins_service_buy_handle'
=>
array
(
0
=>
'app\\plugins\\freightfee\\Hook'
,
),
'plugins_view_goods_detail_title'
=>
array
(
0
=>
'app\\plugins\\freightfee\\Hook'
,
),
'plugins_js'
=>
array
(
0
=>
'app\\plugins\\limitedtimediscount\\Hook'
,
),
'plugins_service_navigation_header_handle'
=>
array
(
0
=>
'app\\plugins\\limitedtimediscount\\Hook'
,
1
=>
'app\\plugins\\speedplaceorder\\Hook'
,
),
'plugins_service_goods_handle_end'
=>
array
(
0
=>
'app\\plugins\\limitedtimediscount\\Hook'
,
),
'plugins_service_goods_spec_base'
=>
array
(
0
=>
'app\\plugins\\limitedtimediscount\\Hook'
,
),
'plugins_view_goods_detail_base_top'
=>
array
(
0
=>
'app\\plugins\\limitedtimediscount\\Hook'
,
),
'plugins_view_home_floor_top'
=>
array
(
0
=>
'app\\plugins\\limitedtimediscount\\Hook'
,
),
);
?>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录