Shop.php
9.4 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
/**
* Created by PhpStorm.
* User: 86132
* Date: 2020/11/17
* Time: 20:51
*/
namespace app\api\controller;
use think\Db;
use app\common\controller\Api;
/**
* 商城板块接口
*/
class Shop extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* 商城板块接口
* @ApiTitle (轮播图)
* @ApiSummary (轮播图)
* @ApiMethod (POST)
* @ApiRoute (/api/Shop/Banner)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": [
"/uploads/20201117/673680f3f8eff5f23230f77947b9b092.png",
"/uploads/20201117/afee095e2ce79ad688bb890d7fb555ad.png"
]
})
*/
public function Banner()
{
$BannerArray = Db::name('shop_banner')->order('weigh desc')->select();
$Banner = [];
if (!empty($BannerArray)) {
foreach ($BannerArray as $k => $v) {
$Banner[$k]['Id'] = $v['id'];
$Banner[$k]['Image'] = cdnurl($v['image']);
$Banner[$k]['Type'] = $v['type'];
$Banner[$k]['Web'] = $v['web'];
$Banner[$k]['Page'] = $v['page'];
$Banner[$k]['GoodsId'] = $v['Goods_id'];
}
}
$this->success('成功', $Banner);
}
/**
* 商城板块接口
* @ApiTitle (左侧分类)
* @ApiSummary (左侧分类)
* @ApiMethod (POST)
* @ApiRoute (/api/Shop/LeftList)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": [
{
"Id": 1,
"Title": "睡美人计划"
},
{
"Id": 2,
"Title": "日间补充"
},
{
"Id": 3,
"Title": "能量补充"
}
]
})
*/
public function LeftList()
{
$Array = Db::name('season_hot')->order('weigh desc')->select();
$List = [];
if (!empty($Array)) {
foreach ($Array as $k => $v) {
$List[$k]['Id'] = $v['id'];
$List[$k]['Title'] = $v['title'];
}
}
$this->success('成功', $List);
}
/**
* 商城板块接口
* @ApiTitle (商品筛选--有更改【返回一句话介绍+可赚金额】)
* @ApiSummary (商品筛选--有更改【返回一句话介绍+可赚金额】)
* @ApiMethod (POST)
* @ApiRoute (/api/Shop/ChooseGoods)
* @ApiParams (name="keywords", type="string", required=true, description="搜索关键字")
* @ApiParams (name="type", type="int", required=true, description="分类ID")
* @ApiParams (name="sell", type="int", required=true, description="销量1=升序,2=降序")
* @ApiParams (name="price", type="string", required=true, description="价格1=升序,2=降序")
* @ApiParams (name="pages", type="string", required=true, description="pages")
* @ApiParams (name="rows", type="string", required=true, description="rows")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"Count": 6,
"List": [
{
"Id": 6,
"Image": "/uploads/20201113/afee095e2ce79ad688bb890d7fb555ad.png",
"Title": "悉见复方身体按摩油",
"Speci": "15ml",
"Price": "128.00",
"Sales": 0,
"Type": 0 1=精选,0=否
},
{
"Id": 1,
"Image": "/uploads/20201113/afee095e2ce79ad688bb890d7fb555ad.jpg",
"Title": "晚安复方纯精油",
"Speci": "15ml",
"Price": "187.99",
"Sales": 0,
"Type": 0
},
{
"Id": 3,
"Image": "/uploads/20201113/afee095e2ce79ad688bb890d7fb555ad.png",
"Title": "于意复方纯精油",
"Speci": "15ml",
"Price": "208.00",
"Sales": 0,
"Type": 0
},
{
"Id": 13,
"Image": "/uploads/20201113/afee095e2ce79ad688bb890d7fb555ad.png",
"Title": "悉知复方纯精油",
"Speci": "15ml",
"Price": "218.00",
"Sales": 0,
"Type": 0
},
{
"Id": 11,
"Image": "/uploads/20201113/afee095e2ce79ad688bb890d7fb555ad.png",
"Title": "如是复方纯精油",
"Speci": "15ml",
"Price": "238.00",
"Sales": 0,
"Type": 0
},
{
"Id": 7,
"Image": "/uploads/20201113/afee095e2ce79ad688bb890d7fb555ad.png",
"Title": "安之复方纯精油",
"Speci": "15ml",
"Price": "268.00",
"Sales": 0,
"Type": 0
}
]
}
})
*/
public function ChooseGoods()
{
$params = $this->request->param();
//查询系列
$GoodsIds = Db::name('season_hot')->where('id', $params['type'])->find();
//精品
$Jing = Db::name('bili')->where('type', 1)->value('first');
//通品
$Tong = Db::name('bili')->where('type', 2)->value('first');
if (empty($GoodsIds)) {
$data = [
'Count' => 0,
'List' => []
];
} else {
if (strstr($GoodsIds['Goods_ids'], ',')) {
//商品ID $SeasonGoodsArray
$GoodsIdsArray = explode(',', $GoodsIds['Goods_ids']);
} else {
$GoodsIdsArray = explode(' ', $GoodsIds['Goods_ids']);
}
$GoodsArray = [];
foreach ($GoodsIdsArray as $k => $v) {
$IfEmptyGoodsArray = Db::name('goods')->where('id', $v)->find();
if (!empty($IfEmptyGoodsArray)) {
$GoodsArray[$k]['Id'] = $IfEmptyGoodsArray['id'];
$GoodsArray[$k]['Image'] = cdnurl($IfEmptyGoodsArray['image']);
$GoodsArray[$k]['Title'] = $IfEmptyGoodsArray['title'];
$GoodsArray[$k]['OneTalk'] = $IfEmptyGoodsArray['one_talk'];
$GoodsArray[$k]['Speci'] = $IfEmptyGoodsArray['speci'];
$GoodsArray[$k]['Price'] = $IfEmptyGoodsArray['price'];
$GoodsArray[$k]['Sales'] = $IfEmptyGoodsArray['sales'];
$GoodsArray[$k]['Type'] = $IfEmptyGoodsArray['type'];
if ($IfEmptyGoodsArray['type'] == 1) {
$GoodsArray[$k]['KeZhuan'] = round($IfEmptyGoodsArray['price'] * $Jing, 1);
} else {
$GoodsArray[$k]['KeZhuan'] = round($IfEmptyGoodsArray['price'] * $Tong, 1);
}
}
}
if (empty($GoodsArray)) {
$data = [
'Count' => 0,
'List' => []
];
} else {
//关键字筛选
if (!empty($params['keywords']) || $params['keywords'] != '' || $params['keywords'] != "" || $params['keywords'] != null) {
$GoodsArrayFirst = [];
foreach ($GoodsArray as $k => $v) {
if (strstr($v['Title'], $params['keywords'])) {
$GoodsArrayFirst[$k]['Id'] = $v['Id'];
$GoodsArrayFirst[$k]['Image'] = $v['Image'];
$GoodsArrayFirst[$k]['Title'] = $v['Title'];
$GoodsArrayFirst[$k]['OneTalk'] = $v['one_talk'];
$GoodsArrayFirst[$k]['Speci'] = $v['Speci'];
$GoodsArrayFirst[$k]['Price'] = $v['Price'];
$GoodsArrayFirst[$k]['Sales'] = $v['Sales'];
$GoodsArrayFirst[$k]['Type'] = $v['Type'];
if ($v['type'] == 1) {
$GoodsArrayFirst[$k]['KeZhuan'] = $v['price'] * $Jing;
} else {
$GoodsArrayFirst[$k]['KeZhuan'] = $v['price'] * $Tong;
}
}
}
} else {
$GoodsArrayFirst = $GoodsArray;
}
if (empty($GoodsArrayFirst)) {
$data = [
'Count' => 0,
'List' => []
];
} else {
//销量排序
if ($params['sell'] == 1) {
//升序
$GoodsArraySell = $this->SalesAsc($GoodsArrayFirst);
} else {
//降序
$GoodsArraySell = $this->SalesDesc($GoodsArrayFirst);
}
//价格排序
if ($params['price'] == 1) {
//升序
$GoodsArrayPrice = $this->PriceAsc($GoodsArraySell);
} else {
//降序
$GoodsArrayPrice = $this->PriceDesc($GoodsArraySell);
}
$NewList = $this->page_array($params['rows'], $params['pages'], $GoodsArrayPrice, 0);
$data = [
'Count' => count($GoodsArrayPrice),
'List' => $NewList
];
}
}
}
$this->success('成功', $data);
}
}