|
@@ -36,7 +36,7 @@ class Buy extends Core
|
|
|
Dever::alert('错误的商品');
|
|
|
}
|
|
|
|
|
|
- $this->data['goods'] = Dever::load('goods/lib/info')->getInfo($id);
|
|
|
+ $this->data['goods'] = Dever::load('shop/lib/info')->getGoodsInfo($this->shop_id, $id);
|
|
|
|
|
|
//$this->data['shop'] = $this->shop;
|
|
|
|
|
@@ -73,14 +73,15 @@ class Buy extends Core
|
|
|
|
|
|
$info = Dever::db('shop/cart')->find($where);
|
|
|
|
|
|
-
|
|
|
$where['num'] = Dever::input('num');
|
|
|
if (!$info) {
|
|
|
+ # 验证库存
|
|
|
+ Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);
|
|
|
$state = Dever::db('shop/cart')->insert($where);
|
|
|
} else {
|
|
|
$where['num'] += $info['num'];
|
|
|
# 验证库存
|
|
|
- $this->total($where['num'], $info['goods_id'], $this->shop_id, $info['sku_id'], 2);
|
|
|
+ Dever::load('shop/lib/info')->checkTotal($where['num'], $where['goods_id'], $this->shop_id, $where['sku_id'], 2);
|
|
|
$where['where_id'] = $info['id'];
|
|
|
$state = Dever::db('shop/cart')->update($where);
|
|
|
}
|
|
@@ -116,9 +117,9 @@ class Buy extends Core
|
|
|
if ($num <= 0) {
|
|
|
$state = Dever::db('shop/cart')->delete($where);
|
|
|
} else {
|
|
|
- $where['num'] = $num;
|
|
|
+ $where['num'] = $info['num'] + $num;
|
|
|
# 验证库存
|
|
|
- $this->total($where['num'], $info['goods_id'], $this->shop_id, $info['sku_id'], 2);
|
|
|
+ Dever::load('shop/lib/info')->checkTotal($where['num'], $info['goods_id'], $this->shop_id, $info['sku_id'], 2);
|
|
|
$state = Dever::db('shop/cart')->update($where);
|
|
|
}
|
|
|
}
|
|
@@ -285,7 +286,7 @@ class Buy extends Core
|
|
|
$this->data['list'][$k]['ku_state'] = 1;
|
|
|
|
|
|
# 验证是否有货
|
|
|
- $total = $this->total($n, $v, $this->shop_id, $s);
|
|
|
+ $total = Dever::load('shop/lib/info')->checkTotal($n, $v, $this->shop_id, $s);
|
|
|
|
|
|
if ($total <= 0) {
|
|
|
$this->data['list'][$k]['ku_state'] = 2;
|
|
@@ -347,27 +348,4 @@ class Buy extends Core
|
|
|
|
|
|
return $pay;
|
|
|
}
|
|
|
-
|
|
|
- # 验证库存
|
|
|
- private function total(&$num, $goods_id, $shop_id, $sku_id, $state = 1)
|
|
|
- {
|
|
|
- $total = 0;
|
|
|
- $w['goods_id'] = $goods_id;
|
|
|
- $w['shop_id'] = $shop_id;
|
|
|
- $w['sku_id'] = $sku_id ? $sku_id : -1;
|
|
|
- $sku = Dever::db('shop/goods_sku')->getOne($w);
|
|
|
-
|
|
|
- if ($sku) {
|
|
|
- $total = $sku['num'];
|
|
|
- }
|
|
|
-
|
|
|
- if ($num > $total) {
|
|
|
- if ($state == 2) {
|
|
|
- Dever::alert('库存不足');
|
|
|
- }
|
|
|
- $num = $total;
|
|
|
- }
|
|
|
-
|
|
|
- return $total;
|
|
|
- }
|
|
|
}
|