切换导航条
此项目
正在载入...
登录
李忠强
/
temporaryfood
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
李忠强
3 years ago
提交
1f52f1fa076997e88ef7da5b122ff8fc437caa4d
1 个父辈
24255b66
更新
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
102 行增加
和
16 行删除
application/api/controller/Index.php
application/api/controller/Index.php
查看文件 @
1f52f1f
...
...
@@ -144,23 +144,109 @@ class Index extends Api
{
$page
=
$this
->
request
->
post
(
'page'
,
1
);
$model
=
new
Goods
();
$list
=
$model
->
where
(
'is_index'
,
'1'
)
->
where
(
'is_delete'
,
'0'
)
->
where
(
'goods_status'
,
'10'
)
->
field
(
'goods_id,goods_name,image'
)
->
paginate
(
10
,
false
,[
'page'
=>
$page
])
->
each
(
function
(
$item
,
$key
){
$item
[
'cart_number'
]
=
Db
::
name
(
'cart'
)
->
where
(
'user_id'
,
$this
->
auth
->
id
)
->
where
(
'goods_id'
,
$item
[
'goods_id'
])
->
sum
(
'number'
);
$goods_spec
=
Db
::
name
(
'litestore_goods_spec'
)
->
where
(
'goods_id'
,
$item
[
'goods_id'
])
->
find
();
$item
[
'price'
]
=
$goods_spec
[
'goods_price'
];
$item
[
'line_price'
]
=
$goods_spec
[
'line_price'
];
});
if
(
$this
->
auth
->
isLogin
()){
$list
=
$model
->
where
(
'is_index'
,
'1'
)
->
where
(
'is_delete'
,
'0'
)
->
where
(
'goods_status'
,
'10'
)
->
field
(
'goods_id,goods_name,image'
)
->
paginate
(
10
,
false
,[
'page'
=>
$page
])
->
each
(
function
(
$item
,
$key
){
$item
[
'cart_number'
]
=
Db
::
name
(
'cart'
)
->
where
(
'user_id'
,
$this
->
auth
->
id
)
->
where
(
'goods_id'
,
$item
[
'goods_id'
])
->
sum
(
'number'
);
$goods_spec
=
Db
::
name
(
'litestore_goods_spec'
)
->
where
(
'goods_id'
,
$item
[
'goods_id'
])
->
find
();
$item
[
'price'
]
=
$goods_spec
[
'goods_price'
];
$item
[
'line_price'
]
=
$goods_spec
[
'line_price'
];
});
}
else
{
$list
=
$model
->
where
(
'is_index'
,
'1'
)
->
where
(
'is_delete'
,
'0'
)
->
where
(
'goods_status'
,
'10'
)
->
field
(
'goods_id,goods_name,image'
)
->
paginate
(
10
,
false
,[
'page'
=>
$page
])
->
each
(
function
(
$item
,
$key
){
$item
[
'cart_number'
]
=
0
;
$goods_spec
=
Db
::
name
(
'litestore_goods_spec'
)
->
where
(
'goods_id'
,
$item
[
'goods_id'
])
->
find
();
$item
[
'price'
]
=
$goods_spec
[
'goods_price'
];
$item
[
'line_price'
]
=
$goods_spec
[
'line_price'
];
});
}
$this
->
success
(
'猜你喜欢'
,
$list
);
}
/**
* @ApiTitle (搜索)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name=text, type=string, required=true, description="搜索文字")
* @ApiParams (name=page, type=integer, required=false, description="页数 默认1")
* @ApiReturn ({
'code':'1',
'msg':'返回成功'
'data':{
"total": 4,
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [
{
"goods_id": 21,
"goods_name": "小米Mix3",
"image": null,
"cart_number": 10, 购物车数量
"price": "100.00", 价格
"line_price": "1000.00", 划线价
"image_text": "图片地址"
}
]
})
*/
public
function
search
()
{
$text
=
$this
->
request
->
post
(
'text'
);
$page
=
$this
->
request
->
post
(
'page'
,
1
);
if
(
!
$text
)
$this
->
error
(
'请填写搜索内容'
);
$model
=
new
Goods
();
if
(
$this
->
auth
->
isLogin
()){
$list
=
$model
->
where
(
'keywords'
,
'like'
,
'%'
.
$text
.
'%'
)
->
where
(
'is_delete'
,
'0'
)
->
where
(
'goods_status'
,
'10'
)
->
field
(
'goods_id,goods_name,image'
)
->
paginate
(
10
,
false
,[
'page'
=>
$page
])
->
each
(
function
(
$item
,
$key
){
$item
[
'cart_number'
]
=
Db
::
name
(
'cart'
)
->
where
(
'user_id'
,
$this
->
auth
->
id
)
->
where
(
'goods_id'
,
$item
[
'goods_id'
])
->
sum
(
'number'
);
$goods_spec
=
Db
::
name
(
'litestore_goods_spec'
)
->
where
(
'goods_id'
,
$item
[
'goods_id'
])
->
find
();
$item
[
'price'
]
=
$goods_spec
[
'goods_price'
];
$item
[
'line_price'
]
=
$goods_spec
[
'line_price'
];
});
}
else
{
$list
=
$model
->
where
(
'keywords'
,
'like'
,
'%'
.
$text
.
'%'
)
->
where
(
'is_delete'
,
'0'
)
->
where
(
'goods_status'
,
'10'
)
->
field
(
'goods_id,goods_name,image'
)
->
paginate
(
10
,
false
,[
'page'
=>
$page
])
->
each
(
function
(
$item
,
$key
){
$item
[
'cart_number'
]
=
0
;
$goods_spec
=
Db
::
name
(
'litestore_goods_spec'
)
->
where
(
'goods_id'
,
$item
[
'goods_id'
])
->
find
();
$item
[
'price'
]
=
$goods_spec
[
'goods_price'
];
$item
[
'line_price'
]
=
$goods_spec
[
'line_price'
];
});
}
$this
->
success
(
'搜索'
,
$list
);
}
}
...
...
请
注册
或
登录
后发表评论