no message

parent e42b1a4e
......@@ -49,7 +49,7 @@ class CartApiController extends Controller
//查询当前购物车数量
public function cartMyCount(Request $request){
$result = CartService::cartLists($request->user->id,$request->user->gid);
$result = CartService::cartMyCount($request->user->id,$request->user->gid);
return $this->setSuccessData($result);
}
......
......@@ -7,6 +7,8 @@ use Closure;
class CheckApiLogin
{
public $no_login_url = ["api/cart/cartLists","api/cart/cartMyCount"];
/**
* Handle an incoming request.
*
......@@ -16,21 +18,20 @@ class CheckApiLogin
*/
public function handle($request, Closure $next)
{
if (!\Auth::check() && !$request->is('api/cart/*')) { //一些接口可以登录或者不登录都可以通行
$response = [
'code' => 1,
'msg' => 'need login...',
];
return response()->json($response);
if (!\Auth::check() ) {
if (in_array($request->path(),$this->no_login_url)){ //一些接口可以登录或者不登录都可以通行
request()->offsetSet("user",(object)["id"=>0,"gid"=>$request->cookie('sem_gid')]);
return $next($request);
}else{
$response = [
'code' => 1,
'msg' => 'need login...',
];
return response()->json($response);
}
} else {
$request->user = \Auth::user();
if (!$request->user){
$request->user->id = 0;
}
$gid = $request->cookie('sem_gid');
if ($gid){
$request->user->gid = $gid;
}
$request->user->gid = "";
return $next($request);
}
}
......
......@@ -102,14 +102,26 @@ class CartService
/*
* 刷新购物车并且返回列表
*/
public static function cartLists($user_id,$gid=""){
public static function cartLists($user_id,$gid="",$page_size=100,$page=1){
//当前用户所有可用的购物车数据
$query = CartModel::where(['user_id'=>$user_id,"status"=>1])
->orderBy('cart_id', 'desc');
$result = $query->get()->toArray();
$where["status"] = 1;
if (!$user_id && !$gid){
return [];
}
if ($user_id){
$where["user_id"] = $user_id;
}
if ($gid){
$where["gid"] = $gid;
}
$query = CartModel::where($where)->orderBy('cart_id', 'desc');
$res = $query->paginate($page_size, ['*'], 'page', $page)->toArray();
$result = $res["data"];
if (!$result){
return false;
return [];
}
try{
......@@ -178,11 +190,10 @@ class CartService
"brand_id"=>$skuInfo["brand_id"], //品牌id
"brand_name"=>$skuInfo["brand_name"], //品牌名称
"stock"=>$skuInfo["stock"], //库存
"stock_format"=>numberToHtml($skuInfo["stock"]), //库存加密
"max_buy_stock"=>$skuInfo["max_buy_stock"], //最大可购买数量
"moq"=>numberToHtml($skuInfo["moq"]), //最少起订量
"mpq"=>numberToHtml($skuInfo["mpq"]), //标准包装量
"mult"=>numberToHtml($skuInfo["multiple"]), //递增量
"moq"=>$skuInfo["moq"], //最少起订量
"mpq"=>$skuInfo["mpq"], //标准包装量
"mult"=>$skuInfo["multiple"], //递增量
"hk_delivery_time"=>$skuInfo["hk_delivery_time"], //香港交期
"ladder_price"=>$skuInfo["ladder_price"], //价格阶梯
"is_buy"=>$skuInfo["is_buy"], //是否能购买
......@@ -191,7 +202,12 @@ class CartService
$con->commit();
return $cartList;
return [
"total"=> $res["total"], //返回总条数
"page"=>$res["current_page"], //第几页
"page_size"=> $page_size, //每页多少条
"lists"=>$cartList //数据列表
] ;
}catch (\Exception $e){
$con->rollback();
throw new InvalidRequestException($e->getMessage().$e->getLine());
......@@ -251,10 +267,6 @@ class CartService
}
$original_price = $info["original_price"];
#梯度价转换
foreach ($original_price as $e=>&$f){
$f["purchases_format"] = numberToHtml($f["purchases"]);
}
usort($original_price, function ($current, $next) { //原始价格倒叙
return $current['purchases'] < $next['purchases'];
......
......@@ -47,6 +47,7 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route::POST('cart/saveCart', 'CartApiController@saveCart'); //添加或者更新购物车
Route::POST('cart/cartLists', 'CartApiController@cartLists'); //购物车列表
Route::POST('cart/cartMyCount', 'CartApiController@cartMyCount'); //购物车总数
});
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