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
309264ef
authored
Nov 21, 2022
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
购物车
parent
cba11ccd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
4 deletions
app/Http/Controllers/Api/CartApiController.php
app/Http/Services/CartService.php
app/Models/CartModel.php
routes/api.php
app/Http/Controllers/Api/CartApiController.php
View file @
309264ef
...
...
@@ -53,5 +53,11 @@ class CartApiController extends Controller
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"
);
}
}
app/Http/Services/CartService.php
View file @
309264ef
...
...
@@ -115,7 +115,7 @@ class CartService
$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
();
$result
=
$res
[
"data"
];
...
...
@@ -303,5 +303,14 @@ class CartService
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
()]);
}
}
app/Models/CartModel.php
View file @
309264ef
...
...
@@ -10,10 +10,12 @@ class CartModel extends Model
protected
$table
=
'cart'
;
public
$timestamps
=
false
;
const
status_no
=
-
1
;
//状态禁用
const
status_delete
=
-
2
;
//商品已删除
const
status_no
=
-
1
;
//商品失效
const
status_yes
=
1
;
//状态启动
static
$status
=
[
self
::
status_no
=>
"禁用"
,
self
::
status_delete
=>
"已删除"
,
self
::
status_no
=>
"该商品已失效!"
,
self
::
status_yes
=>
"启动"
,
];
...
...
routes/api.php
View file @
309264ef
...
...
@@ -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/delete'
,
'UserAddressApiController@delete'
)
->
name
(
'user_address.delete'
);
Route
::
POST
(
'cart/saveCart'
,
'CartApiController@saveCart'
);
//添加或者更新购物车
Route
::
POST
(
'cart/cartDelete'
,
'CartApiController@cartDelete'
);
//批量删除购物车
Route
::
POST
(
'cart/cartLists'
,
'CartApiController@cartLists'
);
//购物车列表
Route
::
POST
(
'cart/cartMyCount'
,
'CartApiController@cartMyCount'
);
//购物车总数
...
...
@@ -56,5 +56,6 @@ Route::middleware(['api', 'api.check'])->namespace('Api')->group(function () {
Route
::
POST
(
'order/cancelOrder'
,
'OrderApiController@cancelOrder'
);
//取消订单
Route
::
POST
(
'order/orderDetail'
,
'OrderApiController@orderDetail'
);
//订单详情
});
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