...
|
...
|
@@ -49,10 +49,17 @@ class Cars extends Api |
|
|
}
|
|
|
|
|
|
//检测库存
|
|
|
$stock = Common::findSoftWhereData('goods',['id'=>$data['goods_id']],'id,stock');
|
|
|
if($stock){
|
|
|
if(($stock['stock'] <=> $data['goods_number']) == -1){
|
|
|
$this->error('库存不足');
|
|
|
$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($stock_res['g_style']));
|
|
|
if($s_index){
|
|
|
$stock = Common::salePrice($stock_res['stock'])[$s_index];
|
|
|
if(($stock <=> $data['goods_number']) == -1){
|
|
|
$this->error('库存不足');
|
|
|
}
|
|
|
}else{
|
|
|
$this->error('出错了');
|
|
|
}
|
|
|
}
|
|
|
//查询有无记录
|
...
|
...
|
@@ -129,10 +136,12 @@ class Cars extends Api |
|
|
$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){
|
|
|
//购物车数量大于库存
|
|
|
$value['goods_number'] = $value['stock'];
|
|
|
if($s_index){
|
|
|
$value['stock'] = Common::salePrice($value['stock'])[$s_index];
|
|
|
if(($value['stock'] <=> $value['goods_number']) == -1){
|
|
|
//购物车数量大于库存
|
|
|
$value['goods_number'] = $value['stock'];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// $total_price = array_sum(array_map(function ($product_row) {
|
...
|
...
|
|