更新本地生活购物车总价
This commit is contained in:
parent
401b0033c4
commit
1bf2f7e308
@ -99,13 +99,10 @@ class LocalStoreGoodsCartLogic extends Logic
|
||||
if ($post['cart_id']) {
|
||||
$cart = LocalStoreGoodsCart::getSelfCart($user_id, $post['cart_id']);
|
||||
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();
|
||||
if ($post['goods_num'] > 999) {
|
||||
throw new \Exception('商品数量超出限制');
|
||||
}
|
||||
} else {
|
||||
throw new \Exception('商品数量超出限制');
|
||||
} else if ($cart['item_id'] > 0) {
|
||||
// 多规格商品
|
||||
$item = LocalStoreGoodsItem::where('id', $cart['item_id'])->field('price, stock')->find();
|
||||
if ($post['goods_num'] > $item['stock']) {
|
||||
@ -117,21 +114,20 @@ class LocalStoreGoodsCartLogic extends Logic
|
||||
'goods_num' => $post['goods_num']
|
||||
]);
|
||||
|
||||
$cart = LocalStoreGoodsCart::alias('c')
|
||||
$result = LocalStoreGoodsCart::alias('c')
|
||||
->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')
|
||||
->append(['pic', 'item'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$price = 0;
|
||||
foreach ($cart as &$v) {
|
||||
foreach ($result as &$v) {
|
||||
$price += ($v['goods_num'] * $v['price']);
|
||||
}
|
||||
|
||||
$price = number_format($price, 2, '.', '');
|
||||
|
||||
$price = number_format($price, 2, '.', '');
|
||||
} else {
|
||||
throw new \Exception('商品信息不存在');
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user