添加清除本地购物车方法

This commit is contained in:
wangxiaowei 2024-11-01 11:46:40 +08:00
parent 427c84b2fc
commit 5ab9f79914
2 changed files with 38 additions and 0 deletions

@ -145,4 +145,19 @@ class LocalStoreGoods extends Api
return JsonServer::error($e->getMessage());
}
}
public function clearCart()
{
$form = $this->request->post();
try {
$result = LocalStoreGoodsCartLogic::clearCart($form, $this->user_id);
if ($result) {
return JsonServer::success('操作成功', $result);
}
return JsonServer::error('操作失败');
} catch (\Exception $e) {
return JsonServer::error($e->getMessage());
}
}
}

@ -144,4 +144,27 @@ class LocalStoreGoodsCartLogic extends Logic
return false;
}
}
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()
]);
}
}
}