切换导航条
此项目
正在载入...
登录
李忠强
/
temporaryfood
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
李忠强
3 years ago
提交
4809bb4a7b9f5be2025a4e8dec94d046861c0211
1 个父辈
a98b666c
更新
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
112 行增加
和
0 行删除
application/api/controller/Cart.php
application/api/model/Cart.php
application/api/controller/Cart.php
0 → 100644
查看文件 @
4809bb4
<?php
namespace
app\api\controller
;
use
app\common\controller\Api
;
/**
* 购物车
*/
class
Cart
extends
Api
{
protected
$noNeedLogin
=
[
'*'
];
protected
$noNeedRight
=
[
'*'
];
/**
* @ApiTitle (加入购物车)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="sku_id", type="integer", required=true, description="规格id")
* @ApiParams (name="goods_id", type="integer", required=true, description="商品id")
* @ApiParams (name="number", type="integer", required=true, description="购买数量")
* @ApiReturn ({
'code':'1',
'msg':'SUCCESS'
})
*/
public
function
addCart
()
{
$sku_id
=
$this
->
request
->
post
(
'sku_id'
);
$goods_id
=
$this
->
request
->
post
(
'goods_id'
);
$number
=
$this
->
request
->
post
(
'number'
);
if
(
!
is_numeric
(
$sku_id
)
||
!
is_numeric
(
$goods_id
)
||
!
is_numeric
(
$number
))
$this
->
error
(
'参数不合法'
);
$data
=
[
'user_id'
=>
$this
->
auth
->
id
,
'sku_id'
=>
$sku_id
,
'goods_id'
=>
$goods_id
,
'number'
=>
$number
,
];
$model
=
new
\app\api\model\Cart
();
$model
->
save
(
$data
);
$this
->
success
(
'SUCCESS'
);
}
/**
* @ApiTitle (增加购物车数量)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="integer", required=true, description="购物车id")
* @ApiParams (name="number", type="integer", required=true, description="增加数量")
* @ApiReturn ({
'code':'1',
'msg':'SUCCESS'
})
*/
public
function
addCartNumber
()
{
$id
=
$this
->
request
->
post
(
'id'
);
$number
=
$this
->
request
->
post
(
'number'
);
if
(
!
is_numeric
(
$id
)
||
!
is_numeric
(
$number
))
$this
->
error
(
'参数不合法'
);
$model
=
new
\app\api\model\Cart
();
$model
->
where
(
'id'
,
$id
)
->
setInc
(
'number'
,
$number
);
$this
->
success
(
'SUCCESS'
);
}
/**
* @ApiTitle (购物车列表)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiReturn ({
'code':'1',
'msg':'SUCCESS'
})
*/
public
function
cartList
()
{
$model
=
new
\app\api\model\Cart
();
$list
=
$model
->
with
([
'goods'
,
'sku'
])
->
where
(
'user_id'
,
$this
->
auth
->
id
)
->
select
();
$this
->
success
(
'SUCCESS'
,
$list
);
}
}
\ No newline at end of file
...
...
application/api/model/Cart.php
0 → 100644
查看文件 @
4809bb4
<?php
namespace
app\api\model
;
use
think\Model
;
class
Cart
extends
Model
{
protected
$createTime
=
'createtime'
;
protected
$updateTime
=
''
;
public
function
goods
()
{
return
$this
->
belongsTo
(
'Goods'
,
'goods_id'
,
'id'
);
}
public
function
sku
()
{
return
$this
->
belongsTo
(
'GoodsSpec'
,
'sku_id'
,
'id'
);
}
}
\ No newline at end of file
...
...
请
注册
或
登录
后发表评论