添加清除本地购物车方法
This commit is contained in:
parent
5ab9f79914
commit
493e8712be
@ -147,24 +147,54 @@ class LocalStoreGoodsCartLogic extends Logic
|
||||
|
||||
public static function clearCart($post, $user_id)
|
||||
{
|
||||
if ($post['cart_id'] > 0) {
|
||||
// 清空购物车单独的商品
|
||||
LocalStoreGoodsCart::where([
|
||||
'id' => $post['cart_id'],
|
||||
'user_id' => $user_id,
|
||||
'lstore_id' => $post['lstore_id'],
|
||||
])->update([
|
||||
'is_delete' => 1,
|
||||
'delete_time' => time()
|
||||
]);
|
||||
} else {
|
||||
LocalStoreGoodsCart::where([
|
||||
'user_id' => $user_id,
|
||||
'lstore_id' => $post['lstore_id'],
|
||||
])->update([
|
||||
'is_delete' => 1,
|
||||
'delete_time' => time()
|
||||
]);
|
||||
Db::startTrans();
|
||||
try {
|
||||
if (isset($post['cart_id']) > 0) {
|
||||
// 清空购物车单独的商品
|
||||
LocalStoreGoodsCart::where([
|
||||
'id' => $post['cart_id'],
|
||||
'user_id' => $user_id,
|
||||
'lstore_id' => $post['lstore_id'],
|
||||
])->update([
|
||||
'is_delete' => 1,
|
||||
'delete_time' => time()
|
||||
]);
|
||||
} else {
|
||||
// 清空购物车
|
||||
LocalStoreGoodsCart::where([
|
||||
'user_id' => $user_id,
|
||||
'lstore_id' => $post['lstore_id'],
|
||||
])->update([
|
||||
'is_delete' => 1,
|
||||
'delete_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
$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])
|
||||
->field('c.id, c.item_id, c.goods_num, g.id as lsg_id, g.title, g.price')
|
||||
->append(['pic', 'item'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$price = $goods_num = 0;
|
||||
foreach ($result as &$v) {
|
||||
$price += ($v['goods_num'] * $v['price']);
|
||||
$goods_num += $v['goods_num'];
|
||||
}
|
||||
$price = number_format($price, 2, '.', '');
|
||||
Db::commit();
|
||||
|
||||
return [
|
||||
'total_amount' => $price,
|
||||
'goods_num' => $goods_num
|
||||
];
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
dump($e->getMessage());die;
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user