Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
semour
/
semour_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f4140683
authored
Nov 14, 2022
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
no message
parent
e42b1a4e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
28 deletions
.idea/workspace.xml
app/Http/Controllers/Api/CartApiController.php
app/Http/Middleware/CheckApiLogin.php
app/Http/Services/CartService.php
routes/api.php
.idea/workspace.xml
deleted
100644 → 0
View file @
e42b1a4e
This diff is collapsed.
Click to expand it.
app/Http/Controllers/Api/CartApiController.php
View file @
f4140683
...
...
@@ -49,7 +49,7 @@ class CartApiController extends Controller
//查询当前购物车数量
public
function
cartMyCount
(
Request
$request
){
$result
=
CartService
::
cart
Lists
(
$request
->
user
->
id
,
$request
->
user
->
gid
);
$result
=
CartService
::
cart
MyCount
(
$request
->
user
->
id
,
$request
->
user
->
gid
);
return
$this
->
setSuccessData
(
$result
);
}
...
...
app/Http/Middleware/CheckApiLogin.php
View file @
f4140683
...
...
@@ -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
);
}
}
...
...
app/Http/Services/CartService.php
View file @
f4140683
...
...
@@ -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'
];
...
...
routes/api.php
View file @
f4140683
...
...
@@ -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'
);
//购物车总数
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment