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
534ca87a
authored
Nov 11, 2022
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
订单添加
parent
f500d123
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
10 deletions
app/Http/Controllers/Api/CartApiController.php
app/Http/Middleware/CheckApiLogin.php
app/Http/Services/CartService.php
app/Http/Controllers/Api/CartApiController.php
View file @
534ca87a
...
@@ -37,13 +37,19 @@ class CartApiController extends Controller
...
@@ -37,13 +37,19 @@ class CartApiController extends Controller
'data'
,
'data'
,
]);
]);
$result
=
CartService
::
saveCart
(
$data
,
$request
->
user
->
id
);
$result
=
CartService
::
saveCart
(
$data
,
$request
->
user
->
id
,
$request
->
user
->
gid
);
return
!
$result
?
$this
->
setError
(
'Add cart failed , please contact administrator'
)
:
$this
->
setSuccess
(
'Add inquiry success'
);
return
!
$result
?
$this
->
setError
(
'Add cart failed , please contact administrator'
)
:
$this
->
setSuccess
(
'Add inquiry success'
);
}
}
//购物车列表
//购物车列表
public
function
cartLists
(
Request
$request
){
public
function
cartLists
(
Request
$request
){
$result
=
CartService
::
cartLists
(
$request
->
user
->
id
);
$result
=
CartService
::
cartLists
(
$request
->
user
->
id
,
$request
->
user
->
gid
);
return
$this
->
setSuccessData
(
$result
);
}
//查询当前购物车数量
public
function
cartMyCount
(
Request
$request
){
$result
=
CartService
::
cartLists
(
$request
->
user
->
id
,
$request
->
user
->
gid
);
return
$this
->
setSuccessData
(
$result
);
return
$this
->
setSuccessData
(
$result
);
}
}
...
...
app/Http/Middleware/CheckApiLogin.php
View file @
534ca87a
...
@@ -16,7 +16,7 @@ class CheckApiLogin
...
@@ -16,7 +16,7 @@ class CheckApiLogin
*/
*/
public
function
handle
(
$request
,
Closure
$next
)
public
function
handle
(
$request
,
Closure
$next
)
{
{
if
(
!
\Auth
::
check
()
)
{
if
(
!
\Auth
::
check
()
&&
!
$request
->
is
(
'api/cart/*'
))
{
//一些接口可以登录或者不登录都可以通行
$response
=
[
$response
=
[
'code'
=>
1
,
'code'
=>
1
,
'msg'
=>
'need login...'
,
'msg'
=>
'need login...'
,
...
@@ -24,6 +24,13 @@ class CheckApiLogin
...
@@ -24,6 +24,13 @@ class CheckApiLogin
return
response
()
->
json
(
$response
);
return
response
()
->
json
(
$response
);
}
else
{
}
else
{
$request
->
user
=
\Auth
::
user
();
$request
->
user
=
\Auth
::
user
();
if
(
!
$request
->
user
){
$request
->
user
->
id
=
0
;
}
$gid
=
$request
->
cookie
(
'sem_gid'
);
if
(
$gid
){
$request
->
user
->
gid
=
$gid
;
}
return
$next
(
$request
);
return
$next
(
$request
);
}
}
}
}
...
...
app/Http/Services/CartService.php
View file @
534ca87a
...
@@ -18,7 +18,7 @@ class CartService
...
@@ -18,7 +18,7 @@ class CartService
static
$week_filter
=
[
"周"
];
static
$week_filter
=
[
"周"
];
//添加或者更新购物车
//添加或者更新购物车
public
static
function
saveCart
(
$data
,
$user_id
)
public
static
function
saveCart
(
$data
,
$user_id
=
""
,
$gid
=
""
)
{
{
try
{
try
{
...
@@ -35,11 +35,16 @@ class CartService
...
@@ -35,11 +35,16 @@ class CartService
$goods_id
=
$v
[
'goods_id'
];
$goods_id
=
$v
[
'goods_id'
];
$temp
=
[
$temp
=
[
'user_id'
=>
$user_id
,
'goods_id'
=>
$v
[
'goods_id'
],
'goods_id'
=>
$v
[
'goods_id'
],
'update_time'
=>
time
(),
];
];
$skuInfo
=
$goodsInfoArr
[
$goods_id
];
//sku库存
if
(
$user_id
){
$temp
[
"user_id"
]
=
$user_id
;
}
else
{
$temp
[
"gid"
]
=
$gid
;
}
$skuInfo
=
$goodsInfoArr
[
$goods_id
];
//sku库存
$digikeyInfo
=
$redis
->
hget
(
"sku_raw_map"
,
$goods_id
);
//digikey 编码
$digikeyInfo
=
$redis
->
hget
(
"sku_raw_map"
,
$goods_id
);
//digikey 编码
if
(
$digikeyInfo
){
if
(
$digikeyInfo
){
$digikeyArr
=
json_decode
(
$digikeyInfo
,
true
);
$digikeyArr
=
json_decode
(
$digikeyInfo
,
true
);
...
@@ -94,8 +99,10 @@ class CartService
...
@@ -94,8 +99,10 @@ class CartService
}
}
}
}
//刷新购物车并且返回列表
/*
public
static
function
cartLists
(
$user_id
){
* 刷新购物车并且返回列表
*/
public
static
function
cartLists
(
$user_id
,
$gid
=
""
){
//当前用户所有可用的购物车数据
//当前用户所有可用的购物车数据
$query
=
CartModel
::
where
([
'user_id'
=>
$user_id
,
"status"
=>
1
])
$query
=
CartModel
::
where
([
'user_id'
=>
$user_id
,
"status"
=>
1
])
...
@@ -119,7 +126,13 @@ class CartService
...
@@ -119,7 +126,13 @@ class CartService
$temp
=
[
$temp
=
[
'user_id'
=>
$user_id
,
'user_id'
=>
$user_id
,
'goods_id'
=>
$v
[
'goods_id'
],
'goods_id'
=>
$v
[
'goods_id'
],
'update_time'
=>
time
()
];
];
if
(
$user_id
){
$temp
[
"user_id"
]
=
$user_id
;
}
else
{
$temp
[
"gid"
]
=
$gid
;
}
$skuInfo
=
$goodsInfoArr
[
$goods_id
];
//sku库存
$skuInfo
=
$goodsInfoArr
[
$goods_id
];
//sku库存
$digikeyInfo
=
$redis
->
hget
(
"sku_raw_map"
,
$goods_id
);
//digikey 编码
$digikeyInfo
=
$redis
->
hget
(
"sku_raw_map"
,
$goods_id
);
//digikey 编码
...
@@ -144,10 +157,9 @@ class CartService
...
@@ -144,10 +157,9 @@ class CartService
}
}
}
}
$temp
[
"status"
]
=
$temp
[
"buy_number"
]
>
0
?
CartModel
::
STATUS_YES
:
CartModel
::
STATUS_NO
;
$temp
[
"status"
]
=
$temp
[
"buy_number"
]
>
0
?
CartModel
::
status_yes
:
CartModel
::
status_no
;
$temp
[
"buy_price"
]
=
$buy_price
;
$temp
[
"buy_price"
]
=
$buy_price
;
$temp
[
"update_time"
]
=
time
();
$temp
[
"update_time"
]
=
time
();
$temp
[
"update_time"
]
=
time
();
$flag
=
CartModel
::
where
([
"cart_id"
=>
$v
[
"cart_id"
]])
->
update
(
$temp
);
$flag
=
CartModel
::
where
([
"cart_id"
=>
$v
[
"cart_id"
]])
->
update
(
$temp
);
if
(
!
$flag
){
if
(
!
$flag
){
continue
;
continue
;
...
@@ -267,6 +279,13 @@ class CartService
...
@@ -267,6 +279,13 @@ class CartService
return
$info
;
return
$info
;
}
}
/*
* 购物车当前数量
*/
public
static
function
cartMyCount
(
$user_id
,
$gid
=
""
){
$where
=
$user_id
?
[
"user_id"
=>
$user_id
]
:
[
"gid"
=>
$gid
];
return
CartModel
::
where
(
$where
)
->
count
();
}
}
}
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