no message

parent e567922c
......@@ -21,7 +21,7 @@ class CartApiController extends Controller
{
//添加购物车, items: {"goods_id":1166788996788323407,"goods_number":2}
public function addCart(Request $request)
public function saveCart(Request $request)
{
$validator = Validator::make($request->all(), [
'items' => 'required|string',
......@@ -37,13 +37,13 @@ class CartApiController extends Controller
'data',
]);
$result = CartService::addCart($data, $request->user->id);
$result = CartService::saveCart($data, $request->user->id);
return !$result ? $this->setError('Add cart failed , please contact administrator'):$this->setSuccess('Add inquiry success');
}
//购物车列表
public function cartLists(){
public function cartLists(Request $request){
$result = CartService::cartLists($request->user->id);
}
......
......@@ -14,8 +14,8 @@ use App\Models\CartModel;
//购物车服务器层
class CartService
{
//添加购物车
public static function addCart($data, $user_id)
//添加或者更新购物车
public static function saveCart($data, $user_id)
{
try{
......@@ -47,14 +47,14 @@ class CartService
$checkHas = CartModel::where(["user_id"=>$user_id,"goods_id"=>$goods_id,"status"=>1])->first();
if ($checkHas){ //存在累计库存
$temp["goods_number"] = $skuInfo["stock"] > ($item['buy_number']+$checkHas["buy_number"]) ? $item['buy_number']+$checkHas["buy_number"] : $skuInfo["stock"];
$temp["buy_number"] = $skuInfo["stock"] > ($item['buy_number']+$checkHas["buy_number"]) ? $item['buy_number']+$checkHas["buy_number"] : $skuInfo["stock"];
$temp["update_time"] = time();
$flag = CartModel::where(["cart_id"=>$checkHas["cart_id"]])->update($temp);
if (!$flag){
return false;
}
}else{ //不存在插入购物车
$temp["goods_number"] = $skuInfo["stock"] > $item['buy_number'] ? $item['buy_number'] : $skuInfo["stock"];
$temp["buy_number"] = $skuInfo["stock"] > $item['buy_number'] ? $item['buy_number'] : $skuInfo["stock"];
$temp["create_time"] = time();
$temp["update_time"] = time();
......@@ -75,7 +75,7 @@ class CartService
}
//刷新购物车并且返回列表
public static function cartUpdateGetLists($user_id){
public static function cartLists($user_id){
//当前用户所有可用的购物车数据
$query = CartModel::where(['user_id'=>$user_id,"status"=>1])
......@@ -92,6 +92,7 @@ class CartService
$redis = Redis::connection();
$goodsInfoArr = ThirdService::getGoodsInfo(array_column($result,"goods_id"));
$cartList = [];
foreach ($result as $item) {
$goods_id = $item['goods_id'];
......
......@@ -43,7 +43,8 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route::get('country/list', 'CountryApiController@list');
Route::POST('cart/addCart', 'CartApiController@addCart'); //添加购物车
Route::POST('cart/saveCart', 'CartApiController@saveCart'); //添加或者更新购物车
Route::POST('cart/cartLists', 'CartApiController@cartLists'); //购物车列表
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment