切换导航条
此项目
正在载入...
登录
景龙
/
feifangu
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
jinglong
5 years ago
提交
0105962799a978d617df3d4112c5ab9c8886e34d
1 个父辈
4c9da264
1 个管道 的构建
通过
耗费 1 秒
修改库存不足
变更
2
构建
1
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
29 行增加
和
13 行删除
application/api/controller/Cars.php
application/api/controller/Common.php
application/api/controller/Cars.php
查看文件 @
0105962
...
...
@@ -51,12 +51,12 @@ class Cars extends Api
//检测库存
$stock_res
=
Common
::
findSoftWhereData
(
'goods'
,[
'id'
=>
$data
[
'goods_id'
]],
'id,stock,style g_style'
);
if
(
$stock_res
){
//查看规格所属索引
$s_index
=
array_search
(
$data
[
'style'
],
Common
::
salePrice
(
trim
(
$stock_res
[
'g_style'
])));
$stock
=
Common
::
salePrice
(
$stock_res
[
'stock'
])[
$s_index
];
if
((
$stock
<=>
$data
[
'goods_number'
])
==
-
1
){
//检测库存
$check_stock
=
Common
::
checkStock
(
$data
[
'style'
],
$data
[
'goods_number'
],
$stock_res
[
'g_style'
],
$stock_res
[
'stock'
]);
if
(
!
$check_stock
){
$this
->
error
(
'库存不足'
);
}
}
//查询有无记录
$where
=
[
...
...
@@ -130,13 +130,13 @@ class Cars extends Api
foreach
(
$res
as
&
$value
){
$value
[
'image'
]
=
$this
->
auth
->
absolutionUrlOne
(
$value
[
'image'
]);
$total_price
+=
$value
[
'price'
]
*
$value
[
'goods_number'
];
//查看规格所属索引
$s_index
=
array_search
(
$value
[
'style'
],
Common
::
salePrice
(
$value
[
'g_style'
]));
$value
[
'stock'
]
=
Common
::
salePrice
(
$value
[
'stock'
])[
$s_index
];
if
((
$value
[
'stock'
]
<=>
$value
[
'goods_number'
])
==
-
1
){
//购物车数量大于库存
//检测库存
$check_stock
=
Common
::
checkStock
(
$value
[
'style'
],
$value
[
'goods_number'
],
$value
[
'g_style'
],
$value
[
'stock'
]);
if
(
!
$check_stock
){
$value
[
'goods_number'
]
=
$value
[
'stock'
];
}
}
// $total_price = array_sum(array_map(function ($product_row) {
// return $product_row['price'] * $product_row['goods_number'];
...
...
@@ -324,10 +324,8 @@ class Cars extends Api
$value
[
'price'
]
=
$g_value
[
'price'
];
//商品价格
//检测库存
//查看规格所属索引
$s_index
=
array_search
(
$g_value
[
'style'
],
Common
::
salePrice
(
$value
[
'g_style'
]));
$stock
=
Common
::
salePrice
(
$value
[
'stock'
])[
$s_index
];
if
((
$stock
<=>
$g_value
[
'goods_number'
])
==
-
1
){
$check_stock
=
Common
::
checkStock
(
$g_value
[
'style'
],
$g_value
[
'goods_number'
],
$value
[
'g_style'
],
$value
[
'stock'
]);
if
(
!
$check_stock
){
$this
->
error
(
'库存不足'
);
}
$value
[
'goods_number'
]
=
$g_value
[
'goods_number'
];
//商品数量
...
...
application/api/controller/Common.php
查看文件 @
0105962
...
...
@@ -402,6 +402,24 @@ class Common
}
/**
* @param $style 传递规格
* @param $goods_number 传递数量
* @param $g_style 数据库商品规格
* @param $g_stock 数据库商品库存
* @ApiInternal
* @return bool
*/
public
static
function
checkStock
(
$style
,
$goods_number
,
$g_style
,
$g_stock
){
$s_index
=
array_search
(
$style
,
self
::
salePrice
(
$g_style
));
$stock
=
self
::
salePrice
(
$g_stock
)[
$s_index
];
if
((
$stock
<=>
$goods_number
)
==
-
1
){
//库存不足
return
false
;
}
return
true
;
}
/**
* 合并数组
* @ApiInternal
*/
...
...
请
注册
或
登录
后发表评论