更新购物车

parent 26e5fa7a
Showing with 9 additions and 6 deletions
......@@ -24,7 +24,6 @@ class CartService
$con = DB::connection();
$con->beginTransaction();
$redis = Redis::connection();
$goodsInfoArr = ThirdService::getGoodsInfo([$goods_id]);
......@@ -33,8 +32,10 @@ class CartService
'update_time' => time(),
];
if ($user_id){
$checkHas = CartModel::where(["user_id"=>$user_id,"goods_id"=>$goods_id,"status"=>1])->first();
$temp["user_id"] = $user_id;
}else{
$checkHas = CartModel::where(["gid"=>$gid,"goods_id"=>$goods_id,"status"=>1])->first();
$temp["gid"] = $gid;
}
......@@ -62,7 +63,7 @@ class CartService
}
$temp["buy_price"] = $buy_price;
$checkHas = CartModel::where(["user_id"=>$user_id,"goods_id"=>$goods_id,"status"=>1])->first();
if ($buy_number < \Arr::get($skuInfo,"moq") || $buy_number > $skuInfo["stock"] ){
return false;
}
......@@ -74,12 +75,13 @@ class CartService
$temp["update_time"] = time();
$temp["status"] = $buy_number > 0 ? CartModel::status_yes:CartModel::status_no;
$flag = CartModel::where(["cart_id"=>$checkHas["cart_id"]])->update($temp);
if (!$flag){
return false;
}
}else{ //不存在插入购物车
$temp["user_id"] = $user_id;
$temp["gid"] = $gid;
$temp["status"] = $buy_number > 0 ? CartModel::status_yes:CartModel::status_no;
$temp["create_time"] = time();
$temp["update_time"] = time();
......@@ -211,6 +213,7 @@ class CartService
$where["gid"] = $gid;
}
$query = CartModel::where($where)->wherein("status",[CartModel::status_no,CartModel::status_yes])->orderBy('status', 'desc');
if($cart_ids){
$query = $query->wherein("cart_id",explode(",",$cart_ids));
......@@ -401,14 +404,14 @@ class CartService
public static function cartMyCount($user_id,$gid=""){
$where = $user_id ? ["user_id"=>$user_id]:["gid"=>$gid];
#登录后数据带入此购物车
if ($user_id > 0 ){
if ($user_id > 0 && $gid){
$gidCart = CartModel::where(["gid"=>$gid,"status"=>1])->get()->toArray();
foreach ($gidCart as $k=>$v){
$nowCart = CartModel::where(["user_id"=>$user_id,"status"=>1,"goods_id"=>$v["goods_id"]])->first();
if ($nowCart){
CartModel::where(["cart_id"=>$nowCart["cart_id"]])->update(["buy_number"=>$v["buy_number"],"update_time"=>time()]);
CartModel::where(["cart_id"=>$nowCart["cart_id"],"gid"=>""])->update(["buy_number"=>$v["buy_number"],"update_time"=>time()]);
}else{
CartModel::where(["cart_id"=>$v["cart_id"]])->update(["user_id"=>$user_id,"update_time"=>time()]);
CartModel::where(["cart_id"=>$v["cart_id"],"gid"=>""])->update(["user_id"=>$user_id,"update_time"=>time()]);
}
}
}
......
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