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
f49da4de
authored
Nov 29, 2022
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
更新购物车
parent
26e5fa7a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
app/Http/Services/CartService.php
app/Http/Services/CartService.php
View file @
f49da4de
...
@@ -24,7 +24,6 @@ class CartService
...
@@ -24,7 +24,6 @@ class CartService
$con
=
DB
::
connection
();
$con
=
DB
::
connection
();
$con
->
beginTransaction
();
$con
->
beginTransaction
();
$redis
=
Redis
::
connection
();
$redis
=
Redis
::
connection
();
$goodsInfoArr
=
ThirdService
::
getGoodsInfo
([
$goods_id
]);
$goodsInfoArr
=
ThirdService
::
getGoodsInfo
([
$goods_id
]);
...
@@ -33,8 +32,10 @@ class CartService
...
@@ -33,8 +32,10 @@ class CartService
'update_time'
=>
time
(),
'update_time'
=>
time
(),
];
];
if
(
$user_id
){
if
(
$user_id
){
$checkHas
=
CartModel
::
where
([
"user_id"
=>
$user_id
,
"goods_id"
=>
$goods_id
,
"status"
=>
1
])
->
first
();
$temp
[
"user_id"
]
=
$user_id
;
$temp
[
"user_id"
]
=
$user_id
;
}
else
{
}
else
{
$checkHas
=
CartModel
::
where
([
"gid"
=>
$gid
,
"goods_id"
=>
$goods_id
,
"status"
=>
1
])
->
first
();
$temp
[
"gid"
]
=
$gid
;
$temp
[
"gid"
]
=
$gid
;
}
}
...
@@ -62,7 +63,7 @@ class CartService
...
@@ -62,7 +63,7 @@ class CartService
}
}
$temp
[
"buy_price"
]
=
$buy_price
;
$temp
[
"buy_price"
]
=
$buy_price
;
$checkHas
=
CartModel
::
where
([
"user_id"
=>
$user_id
,
"goods_id"
=>
$goods_id
,
"status"
=>
1
])
->
first
();
if
(
$buy_number
<
\Arr
::
get
(
$skuInfo
,
"moq"
)
||
$buy_number
>
$skuInfo
[
"stock"
]
){
if
(
$buy_number
<
\Arr
::
get
(
$skuInfo
,
"moq"
)
||
$buy_number
>
$skuInfo
[
"stock"
]
){
return
false
;
return
false
;
}
}
...
@@ -74,12 +75,13 @@ class CartService
...
@@ -74,12 +75,13 @@ class CartService
$temp
[
"update_time"
]
=
time
();
$temp
[
"update_time"
]
=
time
();
$temp
[
"status"
]
=
$buy_number
>
0
?
CartModel
::
status_yes
:
CartModel
::
status_no
;
$temp
[
"status"
]
=
$buy_number
>
0
?
CartModel
::
status_yes
:
CartModel
::
status_no
;
$flag
=
CartModel
::
where
([
"cart_id"
=>
$checkHas
[
"cart_id"
]])
->
update
(
$temp
);
$flag
=
CartModel
::
where
([
"cart_id"
=>
$checkHas
[
"cart_id"
]])
->
update
(
$temp
);
if
(
!
$flag
){
if
(
!
$flag
){
return
false
;
return
false
;
}
}
}
else
{
//不存在插入购物车
}
else
{
//不存在插入购物车
$temp
[
"user_id"
]
=
$user_id
;
$temp
[
"gid"
]
=
$gid
;
$temp
[
"status"
]
=
$buy_number
>
0
?
CartModel
::
status_yes
:
CartModel
::
status_no
;
$temp
[
"status"
]
=
$buy_number
>
0
?
CartModel
::
status_yes
:
CartModel
::
status_no
;
$temp
[
"create_time"
]
=
time
();
$temp
[
"create_time"
]
=
time
();
$temp
[
"update_time"
]
=
time
();
$temp
[
"update_time"
]
=
time
();
...
@@ -211,6 +213,7 @@ class CartService
...
@@ -211,6 +213,7 @@ class CartService
$where
[
"gid"
]
=
$gid
;
$where
[
"gid"
]
=
$gid
;
}
}
$query
=
CartModel
::
where
(
$where
)
->
wherein
(
"status"
,[
CartModel
::
status_no
,
CartModel
::
status_yes
])
->
orderBy
(
'status'
,
'desc'
);
$query
=
CartModel
::
where
(
$where
)
->
wherein
(
"status"
,[
CartModel
::
status_no
,
CartModel
::
status_yes
])
->
orderBy
(
'status'
,
'desc'
);
if
(
$cart_ids
){
if
(
$cart_ids
){
$query
=
$query
->
wherein
(
"cart_id"
,
explode
(
","
,
$cart_ids
));
$query
=
$query
->
wherein
(
"cart_id"
,
explode
(
","
,
$cart_ids
));
...
@@ -401,14 +404,14 @@ class CartService
...
@@ -401,14 +404,14 @@ class CartService
public
static
function
cartMyCount
(
$user_id
,
$gid
=
""
){
public
static
function
cartMyCount
(
$user_id
,
$gid
=
""
){
$where
=
$user_id
?
[
"user_id"
=>
$user_id
]
:
[
"gid"
=>
$gid
];
$where
=
$user_id
?
[
"user_id"
=>
$user_id
]
:
[
"gid"
=>
$gid
];
#登录后数据带入此购物车
#登录后数据带入此购物车
if
(
$user_id
>
0
){
if
(
$user_id
>
0
&&
$gid
){
$gidCart
=
CartModel
::
where
([
"gid"
=>
$gid
,
"status"
=>
1
])
->
get
()
->
toArray
();
$gidCart
=
CartModel
::
where
([
"gid"
=>
$gid
,
"status"
=>
1
])
->
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
,
"status"
=>
1
,
"goods_id"
=>
$v
[
"goods_id"
]])
->
first
();
if
(
$nowCart
){
if
(
$nowCart
){
CartModel
::
where
([
"cart_id"
=>
$nowCart
[
"cart_id"
]])
->
update
([
"buy_number"
=>
$v
[
"buy_number"
],
"update_time"
=>
time
()]);
CartModel
::
where
([
"cart_id"
=>
$nowCart
[
"cart_id"
]
,
"gid"
=>
""
])
->
update
([
"buy_number"
=>
$v
[
"buy_number"
],
"update_time"
=>
time
()]);
}
else
{
}
else
{
CartModel
::
where
([
"cart_id"
=>
$v
[
"cart_id"
]])
->
update
([
"user_id"
=>
$user_id
,
"update_time"
=>
time
()]);
CartModel
::
where
([
"cart_id"
=>
$v
[
"cart_id"
]
,
"gid"
=>
""
])
->
update
([
"user_id"
=>
$user_id
,
"update_time"
=>
time
()]);
}
}
}
}
}
}
...
...
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