购物车

parent cba11ccd
...@@ -53,5 +53,11 @@ class CartApiController extends Controller ...@@ -53,5 +53,11 @@ class CartApiController extends Controller
return $this->setSuccessData($result); return $this->setSuccessData($result);
} }
//删除购物车
public function cartDelete(Request $request){
$result = CartService::cartDelete($request->user->id,$request->input("cart_id",0));
return $this->setSuccess("Delete cart success");
}
} }
...@@ -115,7 +115,7 @@ class CartService ...@@ -115,7 +115,7 @@ class CartService
$where["gid"] = $gid; $where["gid"] = $gid;
} }
$query = CartModel::where($where)->orderBy('status', 'desc'); $query = CartModel::where($where)->wherein("status",[CartModel::status_no,CartModel::status_yes])->orderBy('status', 'desc');
$res = $query->paginate($page_size, ['*'], 'page', $page)->toArray(); $res = $query->paginate($page_size, ['*'], 'page', $page)->toArray();
$result = $res["data"]; $result = $res["data"];
...@@ -303,5 +303,14 @@ class CartService ...@@ -303,5 +303,14 @@ class CartService
return CartModel::where($where)->count(); return CartModel::where($where)->count();
} }
/*
* 删除购物车
*/
public static function cartDelete($user_id,$cart_id){
return CartModel::where(["user_id"=>$user_id])
->wherein("cart_id",explode(",",$cart_id))
->update(["status"=>CartModel::status_delete,"update_time"=>time()]);
}
} }
...@@ -10,10 +10,12 @@ class CartModel extends Model ...@@ -10,10 +10,12 @@ class CartModel extends Model
protected $table = 'cart'; protected $table = 'cart';
public $timestamps = false; public $timestamps = false;
const status_no = -1; //状态禁用 const status_delete = -2; //商品已删除
const status_no = -1; //商品失效
const status_yes = 1; //状态启动 const status_yes = 1; //状态启动
static $status =[ static $status =[
self::status_no => "禁用", self::status_delete => "已删除",
self::status_no => "该商品已失效!",
self::status_yes => "启动", self::status_yes => "启动",
]; ];
......
...@@ -45,8 +45,8 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () { ...@@ -45,8 +45,8 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route::POST('user_address/update', 'UserAddressApiController@update')->name('user_address.update'); Route::POST('user_address/update', 'UserAddressApiController@update')->name('user_address.update');
Route::POST('user_address/delete', 'UserAddressApiController@delete')->name('user_address.delete'); Route::POST('user_address/delete', 'UserAddressApiController@delete')->name('user_address.delete');
Route::POST('cart/saveCart', 'CartApiController@saveCart'); //添加或者更新购物车 Route::POST('cart/saveCart', 'CartApiController@saveCart'); //添加或者更新购物车
Route::POST('cart/cartDelete', 'CartApiController@cartDelete'); //批量删除购物车
Route::POST('cart/cartLists', 'CartApiController@cartLists'); //购物车列表 Route::POST('cart/cartLists', 'CartApiController@cartLists'); //购物车列表
Route::POST('cart/cartMyCount', 'CartApiController@cartMyCount'); //购物车总数 Route::POST('cart/cartMyCount', 'CartApiController@cartMyCount'); //购物车总数
...@@ -56,5 +56,6 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () { ...@@ -56,5 +56,6 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route::POST('order/cancelOrder', 'OrderApiController@cancelOrder'); //取消订单 Route::POST('order/cancelOrder', 'OrderApiController@cancelOrder'); //取消订单
Route::POST('order/orderDetail', 'OrderApiController@orderDetail'); //订单详情 Route::POST('order/orderDetail', 'OrderApiController@orderDetail'); //订单详情
}); });
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