更新购物车

parent bbb5511e
Showing with 5 additions and 4 deletions
...@@ -405,13 +405,14 @@ class CartService ...@@ -405,13 +405,14 @@ class CartService
$where = $user_id ? ["user_id"=>$user_id]:["gid"=>$gid]; $where = $user_id ? ["user_id"=>$user_id]:["gid"=>$gid];
#登录后数据带入此购物车 #登录后数据带入此购物车
if ($user_id > 0 && $gid){ if ($user_id > 0 && $gid){
$gidCart = CartModel::where(["gid"=>$gid,"status"=>1])->get()->toArray(); $gidCart = CartModel::where(["gid"=>$gid])->wherein("status",[CartModel::status_no,CartModel::status_yes])->get()->toArray();
foreach ($gidCart as $k=>$v){ foreach ($gidCart as $k=>$v){
$nowCart = CartModel::where(["user_id"=>$user_id,"status"=>1,"goods_id"=>$v["goods_id"]])->first(); $nowCart = CartModel::where(["user_id"=>$user_id,"goods_id"=>$v["goods_id"]])->first();
if ($nowCart){ if ($nowCart){
CartModel::where(["cart_id"=>$nowCart["cart_id"],"gid"=>""])->update(["buy_number"=>$v["buy_number"],"update_time"=>time()]); CartModel::where(["cart_id"=>$nowCart["cart_id"]])->update(["buy_number"=>$v["buy_number"],"status"=>CartModel::status_yes,"gid"=>"","update_time"=>time()]);
CartModel::where(["cart_id"=>$v["cart_id"]])->delete();
}else{ }else{
CartModel::where(["cart_id"=>$v["cart_id"],"gid"=>""])->update(["user_id"=>$user_id,"update_time"=>time()]); CartModel::where(["cart_id"=>$v["cart_id"]])->update(["user_id"=>$user_id,"status"=>CartModel::status_yes,"gid"=>"","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