Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
328b93ad92
@ -99,13 +99,10 @@ class LocalStoreGoodsCartLogic extends Logic
|
|||||||
if ($post['cart_id']) {
|
if ($post['cart_id']) {
|
||||||
$cart = LocalStoreGoodsCart::getSelfCart($user_id, $post['cart_id']);
|
$cart = LocalStoreGoodsCart::getSelfCart($user_id, $post['cart_id']);
|
||||||
if (!empty($cart)) {
|
if (!empty($cart)) {
|
||||||
if ($cart['item_id'] == 0) {
|
if ($cart['item_id'] == 0 && $post['goods_num'] > 999) {
|
||||||
// 单规格商品
|
// 单规格商品
|
||||||
$item = LocalStoreGoods::where('id', $cart['lsg_id'])->field('price')->find();
|
throw new \Exception('商品数量超出限制');
|
||||||
if ($post['goods_num'] > 999) {
|
} else if ($cart['item_id'] > 0) {
|
||||||
throw new \Exception('商品数量超出限制');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 多规格商品
|
// 多规格商品
|
||||||
$item = LocalStoreGoodsItem::where('id', $cart['item_id'])->field('price, stock')->find();
|
$item = LocalStoreGoodsItem::where('id', $cart['item_id'])->field('price, stock')->find();
|
||||||
if ($post['goods_num'] > $item['stock']) {
|
if ($post['goods_num'] > $item['stock']) {
|
||||||
@ -117,21 +114,20 @@ class LocalStoreGoodsCartLogic extends Logic
|
|||||||
'goods_num' => $post['goods_num']
|
'goods_num' => $post['goods_num']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$cart = LocalStoreGoodsCart::alias('c')
|
$result = LocalStoreGoodsCart::alias('c')
|
||||||
->join('local_store_goods g', 'c.lsg_id = g.id')
|
->join('local_store_goods g', 'c.lsg_id = g.id')
|
||||||
->where(['c.user_id' => $user_id, 'c.lstore_id' => $post['lstore_id'], 'c.is_delete' => 0, 'g.state' => 1, 'g.audit_status' => 1, 'g.delete_time' => 0])
|
->where(['c.user_id' => $user_id, 'c.lstore_id' => $cart['lstore_id'], 'c.is_delete' => 0, 'g.state' => 1, 'g.audit_status' => 1, 'g.delete_time' => 0])
|
||||||
->field('c.id, c.item_id, c.goods_num, g.id as lsg_id, g.title, g.price')
|
->field('c.id, c.item_id, c.goods_num, g.id as lsg_id, g.title, g.price')
|
||||||
->append(['pic', 'item'])
|
->append(['pic', 'item'])
|
||||||
->select()
|
->select()
|
||||||
->toArray();
|
->toArray();
|
||||||
|
|
||||||
$price = 0;
|
$price = 0;
|
||||||
foreach ($cart as &$v) {
|
foreach ($result as &$v) {
|
||||||
$price += ($v['goods_num'] * $v['price']);
|
$price += ($v['goods_num'] * $v['price']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$price = number_format($price, 2, '.', '');
|
$price = number_format($price, 2, '.', '');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new \Exception('商品信息不存在');
|
throw new \Exception('商品信息不存在');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user