|
@@ -79,6 +79,8 @@ class Buy extends Core
|
|
|
$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);
|
|
|
$where['where_id'] = $info['id'];
|
|
|
$state = Dever::db('shop/cart')->update($where);
|
|
|
}
|
|
@@ -115,6 +117,8 @@ class Buy extends Core
|
|
|
$state = Dever::db('shop/cart')->delete($where);
|
|
|
} else {
|
|
|
$where['num'] = $num;
|
|
|
+
|
|
|
+ $this->total($where['num'], $info['goods_id'], $this->shop_id, $info['sku_id'], 2);
|
|
|
$state = Dever::db('shop/cart')->update($where);
|
|
|
}
|
|
|
}
|
|
@@ -272,33 +276,14 @@ class Buy extends Core
|
|
|
foreach ($goods_id as $k => $v) {
|
|
|
$s = isset($sku_id[$k]) ? $sku_id[$k] : 0;
|
|
|
$n = isset($num[$k]) ? $num[$k] : 1;
|
|
|
- $total = 0;
|
|
|
$this->data['list'][$k]['goods'] = Dever::load('goods/lib/info')->getPayInfo($v, $s, $n);
|
|
|
|
|
|
|
|
|
$this->data['list'][$k]['goods']['ku_state'] = 1;
|
|
|
+
|
|
|
|
|
|
- if ($s > 0) {
|
|
|
- $w['goods_id'] = $v;
|
|
|
- $w['shop_id'] = $this->shop_id;
|
|
|
- $w['sku_id'] = $s;
|
|
|
- $sku = Dever::db('shop/goods_sku')->getOne($w);
|
|
|
-
|
|
|
- if ($sku) {
|
|
|
- $total = $sku['num'];
|
|
|
- }
|
|
|
- } else {
|
|
|
- $w['goods_id'] = $v;
|
|
|
- $w['shop_id'] = $this->shop_id;
|
|
|
- $goods = Dever::db('shop/goods')->getOne($w);
|
|
|
- if ($goods) {
|
|
|
- $total = $goods['num'];
|
|
|
- }
|
|
|
- }
|
|
|
+ $total = $this->total($n, $v, $this->shop_id, $s);
|
|
|
|
|
|
- if ($n > $total) {
|
|
|
- $n = $total;
|
|
|
- }
|
|
|
if ($total <= 0) {
|
|
|
$this->data['list'][$k]['goods']['ku_state'] = 2;
|
|
|
}
|
|
@@ -354,4 +339,36 @@ class Buy extends Core
|
|
|
|
|
|
return $pay;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private function total(&$num, $goods_id, $shop_id, $sku_id, $state = 1)
|
|
|
+ {
|
|
|
+ $total = 0;
|
|
|
+ if ($sku_id > 0) {
|
|
|
+ $w['goods_id'] = $goods_id;
|
|
|
+ $w['shop_id'] = $shop_id;
|
|
|
+ $w['sku_id'] = $sku_id;
|
|
|
+ $sku = Dever::db('shop/goods_sku')->getOne($w);
|
|
|
+
|
|
|
+ if ($sku) {
|
|
|
+ $total = $sku['num'];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $w['goods_id'] = $goods_id;
|
|
|
+ $w['shop_id'] = $shop_id;
|
|
|
+ $goods = Dever::db('shop/goods')->getOne($w);
|
|
|
+ if ($goods) {
|
|
|
+ $total = $goods['num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($num > $total) {
|
|
|
+ if ($state == 2) {
|
|
|
+ Dever::alert('库存不足');
|
|
|
+ }
|
|
|
+ $num = $total;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $total;
|
|
|
+ }
|
|
|
}
|