Search.php
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace app\api\controller;
use app\admin\model\Record;
use app\common\controller\Api;
use think\Validate;
/**
* 商品检索接口
*/
class Search extends Api
{
protected $noNeedLogin = ['searchGoodsList'];
protected $noNeedRight = ['*'];
protected $uid = '';
public function _initialize()
{
parent::_initialize();
$this->uid = $this->auth->getUserId();
}
/**
* @ApiTitle (商品检索列表)
* @ApiSummary (商品检索列表)
* @ApiMethod (GET)
* @ApiRoute (/api/search/searchGoodsList)
*
* @ApiParams (name="keyword", type="string", required=true, description="检索关键字")
* @ApiParams (name="page", type="inter", required=true, description="分页页码")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1574941706",
"data": {
"data": [
{
"id": 7,//商品id
"image": "http://jinglong.springchunjia.cn/uploads/20191128/8a677f5a0418059bf1b974c50026af13.png",//图片路径
"name": "MONENT 动感系列",//商品名称
"tag": [//商品标签
"日式简约",
"隐秘乡奢",
"家庭情侣"
],
"style": [//商品规格
"主餐匙,茶匙各1件",
"古堡灰"
],
"sale_price": 2299//销售价格
"expense_price": //运费(0:显示包运费标签)
"is_new_tag": 0//新人价格标签(0:不显示,1:显示)
},
{
"id": 4,
"image": "http://jinglong.springchunjia.cn/uploads/20191128/93971e55b83d1a09c1831f8197514305.png",
"name": "MONENT 动感系列",
"tag": [
"AB级",
"ABX级",
"ABN级"
],
"new_price": 2499,
"sale_price": 2599
},
],
"total_page": 1
}
})
*/
public function searchGoodsList(){
if($this->request->isGet()){
$keyword = $this->request->get('keyword');
$page = $this->request->get('page');
$rule = config('verify.search_goods');
$validate = new Validate($rule['rule'],$rule['msg']);
if (!$validate->check(['keyword'=>$keyword,'page'=>$page])) {
$this->error($validate->getError());
}
$where = ['type_name|name'=>['like','%'.$keyword.'%']];
//暂时
$arr = Common::searchGoodsList($keyword,$where,$page,$this->uid);
//写入检索记录
// $record = Common::findWhereData('record',['uid'=>$this->uid,'keyword'=>$keyword],'id,keyword');
// if(!$record){
// //创建记录
// $recordModel = new Record();
// $recordModel->create(['uid'=>$this->uid,'keyword'=>$keyword]);
// }
$this->success('成功',$arr);
}else{
$this->error('请求方式错误');
}
}
}