...
|
...
|
@@ -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'];//商品数量
|
...
|
...
|
|