1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the overtrue/wechat. |
5
|
|
|
* |
6
|
|
|
* (c) overtrue <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Card.php. |
14
|
|
|
* |
15
|
|
|
* @author overtrue <[email protected]> |
16
|
|
|
* @copyright 2016 overtrue <[email protected]> |
17
|
|
|
* |
18
|
|
|
* @link https://github.com/overtrue |
19
|
|
|
* @link http://overtrue.me |
20
|
|
|
*/ |
21
|
|
|
namespace EasyWeChat\Card; |
22
|
|
|
|
23
|
|
|
use Doctrine\Common\Cache\Cache; |
24
|
|
|
use Doctrine\Common\Cache\FilesystemCache; |
25
|
|
|
use EasyWeChat\Core\AbstractAPI; |
26
|
|
|
use EasyWeChat\Support\Arr; |
27
|
|
|
use Psr\Http\Message\ResponseInterface; |
28
|
|
|
|
29
|
|
|
class Card extends AbstractAPI |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Cache. |
33
|
|
|
* |
34
|
|
|
* @var Cache |
35
|
|
|
*/ |
36
|
|
|
protected $cache; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Ticket cache prefix. |
40
|
|
|
*/ |
41
|
|
|
const TICKET_CACHE_PREFIX = 'overtrue.wechat.card_api_ticket.'; |
42
|
|
|
|
43
|
|
|
const API_GET_COLORS = 'https://api.weixin.qq.com/card/getcolors'; |
44
|
|
|
const API_CREATE_CARD = 'https://api.weixin.qq.com/card/create'; |
45
|
|
|
const API_CREATE_QRCODE = 'https://api.weixin.qq.com/card/qrcode/create'; |
46
|
|
|
const API_SHOW_QRCODE = 'https://mp.weixin.qq.com/cgi-bin/showqrcode'; |
47
|
|
|
const API_GET_CARD_TICKET = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket'; |
48
|
|
|
const API_CREATE_LANDING_PAGE = 'https://api.weixin.qq.com/card/landingpage/create'; |
49
|
|
|
const API_DEPOSIT_CODE = 'https://api.weixin.qq.com/card/code/deposit'; |
50
|
|
|
const API_GET_DEPOSIT_COUNT = 'https://api.weixin.qq.com/card/code/getdepositcount'; |
51
|
|
|
const API_CHECK_CODE = 'https://api.weixin.qq.com/card/code/checkcode'; |
52
|
|
|
const API_GET_HTML = 'https://api.weixin.qq.com/card/mpnews/gethtml'; |
53
|
|
|
const API_SET_TEST_WHITE_LIST = 'https://api.weixin.qq.com/card/testwhitelist/set'; |
54
|
|
|
const API_GET_CODE = 'https://api.weixin.qq.com/card/code/get'; |
55
|
|
|
const API_CONSUME_CARD = 'https://api.weixin.qq.com/card/code/consume'; |
56
|
|
|
const API_DECRYPT_CODE = 'https://api.weixin.qq.com/card/code/decrypt'; |
57
|
|
|
const API_GET_CARD_LIST = 'https://api.weixin.qq.com/card/user/getcardlist'; |
58
|
|
|
const API_GET_CARD = 'https://api.weixin.qq.com/card/get'; |
59
|
|
|
const API_LIST_CARD = 'https://api.weixin.qq.com/card/batchget'; |
60
|
|
|
const API_UPDATE_CARD = 'https://api.weixin.qq.com/card/update'; |
61
|
|
|
const API_SET_PAY_CELL = 'https://api.weixin.qq.com/card/paycell/set'; |
62
|
|
|
const API_MODIFY_STOCK = 'https://api.weixin.qq.com/card/modifystock'; |
63
|
|
|
const API_UPDATE_CODE = 'https://api.weixin.qq.com/card/code/update'; |
64
|
|
|
const API_DELETE_CARD = 'https://api.weixin.qq.com/card/delete'; |
65
|
|
|
const API_DISABLE_CARD = 'https://api.weixin.qq.com/card/code/unavailable'; |
66
|
|
|
const API_ACTIVATE_CARD = 'https://api.weixin.qq.com/card/membercard/activate'; |
67
|
|
|
const API_ACTIVATE_USER_FORM = 'https://api.weixin.qq.com/card/membercard/activateuserform/set'; |
68
|
|
|
const API_GET_MEMBER_USER_INFO = 'https://api.weixin.qq.com/card/membercard/userinfo/get'; |
69
|
|
|
const API_UPDATE_MEMBER_CARD_USER = 'https://api.weixin.qq.com/card/membercard/updateuser'; |
70
|
|
|
const API_CREATE_SUB_MERCHANT = 'https://api.weixin.qq.com/card/submerchant/submit'; |
71
|
|
|
const API_UPDATE_SUB_MERCHANT = 'https://api.weixin.qq.com/card/submerchant/update'; |
72
|
|
|
const API_GET_SUB_MERCHANT = 'https://api.weixin.qq.com/card/submerchant/get'; |
73
|
|
|
const API_LIST_SUB_MERCHANT = 'https://api.weixin.qq.com/card/submerchant/batchget'; |
74
|
|
|
const API_GET_CATEGORIES = 'https://api.weixin.qq.com/card/getapplyprotocol'; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* 获取卡券颜色. |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
1 |
|
public function getColors() |
82
|
|
|
{ |
83
|
1 |
|
return $this->parseJSON('get', [self::API_GET_COLORS]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* 创建卡券. |
88
|
|
|
* |
89
|
|
|
* @param string $cardType |
90
|
|
|
* @param array $baseInfo |
91
|
|
|
* @param array $especial |
92
|
|
|
* @param array $advancedInfo |
93
|
|
|
* |
94
|
|
|
* @return bool|array |
95
|
|
|
*/ |
96
|
1 |
|
public function create($cardType = 'member_card', array $baseInfo = [], array $especial = [], array $advancedInfo = []) |
97
|
|
|
{ |
98
|
|
|
$params = [ |
99
|
|
|
'card' => [ |
100
|
1 |
|
'card_type' => strtoupper($cardType), |
101
|
1 |
|
strtolower($cardType) => array_merge(['base_info' => $baseInfo], $especial, $advancedInfo), |
102
|
1 |
|
], |
103
|
1 |
|
]; |
104
|
|
|
|
105
|
1 |
|
return $this->parseJSON('json', [self::API_CREATE_CARD, $params]); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* 创建二维码. |
110
|
|
|
* |
111
|
|
|
* @param array $cards |
112
|
|
|
* |
113
|
|
|
* @return array|bool |
114
|
|
|
*/ |
115
|
1 |
|
public function QRCode(array $cards = []) |
116
|
|
|
{ |
117
|
1 |
|
return $this->parseJSON('json', [self::API_CREATE_QRCODE, $cards]); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* ticket 换取二维码图片. |
122
|
|
|
* |
123
|
|
|
* @param string $ticket |
124
|
|
|
* |
125
|
|
|
* @return array |
126
|
|
|
*/ |
127
|
1 |
|
public function showQRCode($ticket = null) |
128
|
|
|
{ |
129
|
|
|
$params = [ |
130
|
1 |
|
'ticket' => $ticket, |
131
|
1 |
|
]; |
132
|
|
|
|
133
|
1 |
|
$http = $this->getHttp(); |
134
|
|
|
|
135
|
|
|
/** @var ResponseInterface $response */ |
136
|
1 |
|
$response = $http->get(self::API_SHOW_QRCODE, $params); |
137
|
|
|
|
138
|
|
|
return [ |
139
|
1 |
|
'status' => $response->getStatusCode(), |
140
|
1 |
|
'reason' => $response->getReasonPhrase(), |
141
|
1 |
|
'headers' => $response->getHeaders(), |
142
|
1 |
|
'body' => strval($response->getBody()), |
143
|
1 |
|
'url' => self::API_SHOW_QRCODE.'?'.http_build_query($params), |
144
|
1 |
|
]; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* 通过ticket换取二维码 链接. |
149
|
|
|
* |
150
|
|
|
* @param string $ticket |
151
|
|
|
* |
152
|
|
|
* @return string |
153
|
|
|
*/ |
154
|
1 |
|
public function getQRCodeUrl($ticket) |
155
|
|
|
{ |
156
|
1 |
|
return self::API_SHOW_QRCODE.'?ticket='.$ticket; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* 获取 卡券 Api_ticket. |
161
|
|
|
* |
162
|
|
|
* @param bool $refresh 是否强制刷新 |
163
|
|
|
* |
164
|
|
|
* @return string $apiTicket |
165
|
|
|
*/ |
166
|
2 |
View Code Duplication |
public function getAPITicket($refresh = false) |
167
|
|
|
{ |
168
|
2 |
|
$key = self::TICKET_CACHE_PREFIX.$this->getAccessToken()->getAppId(); |
169
|
|
|
|
170
|
2 |
|
$ticket = $this->getCache()->fetch($key); |
171
|
|
|
|
172
|
2 |
|
if (!$ticket || $refresh) { |
173
|
1 |
|
$result = $this->parseJSON('get', [self::API_GET_CARD_TICKET, ['type' => 'wx_card']]); |
174
|
|
|
|
175
|
1 |
|
$this->getCache()->save($key, $result['ticket'], $result['expires_in'] - 500); |
176
|
|
|
|
177
|
1 |
|
return $result['ticket']; |
178
|
|
|
} |
179
|
|
|
|
180
|
1 |
|
return $ticket; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* 微信卡券:JSAPI 卡券发放. |
185
|
|
|
* |
186
|
|
|
* @param array $cards |
187
|
|
|
* |
188
|
|
|
* @return string |
189
|
|
|
*/ |
190
|
|
|
public function jsConfigForAssign(array $cards) |
191
|
|
|
{ |
192
|
1 |
|
return json_encode(array_map(function ($card) { |
193
|
1 |
|
return $this->attachExtension($card['card_id'], $card); |
194
|
1 |
|
}, $cards)); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* 生成 js添加到卡包 需要的 card_list 项. |
199
|
|
|
* |
200
|
|
|
* @param string $cardId |
201
|
|
|
* @param array $extension |
202
|
|
|
* |
203
|
|
|
* @return string |
204
|
|
|
*/ |
205
|
1 |
|
public function attachExtension($cardId, array $extension = []) |
206
|
|
|
{ |
207
|
1 |
|
$timestamp = time(); |
208
|
|
|
$ext = [ |
209
|
1 |
|
'code' => Arr::get($extension, 'code'), |
210
|
1 |
|
'openid' => Arr::get($extension, 'openid', Arr::get($extension, 'open_id')), |
211
|
1 |
|
'timestamp' => $timestamp, |
212
|
1 |
|
'outer_id' => Arr::get($extension, 'outer_id'), |
213
|
1 |
|
'balance' => Arr::get($extension, 'balance'), |
214
|
1 |
|
]; |
215
|
1 |
|
$ext['signature'] = $this->getSignature( |
216
|
1 |
|
$this->getAPITicket(), |
217
|
1 |
|
$timestamp, |
218
|
1 |
|
$cardId, |
219
|
1 |
|
$ext['code'], |
220
|
1 |
|
$ext['openid'], |
221
|
1 |
|
$ext['balance'] |
222
|
1 |
|
); |
223
|
|
|
|
224
|
|
|
return [ |
225
|
1 |
|
'cardId' => $cardId, |
226
|
1 |
|
'cardExt' => json_encode($ext), |
227
|
1 |
|
]; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* 生成签名. |
232
|
|
|
* |
233
|
|
|
* @return string |
234
|
|
|
*/ |
235
|
1 |
|
public function getSignature() |
236
|
|
|
{ |
237
|
1 |
|
$params = func_get_args(); |
238
|
1 |
|
sort($params, SORT_STRING); |
239
|
|
|
|
240
|
1 |
|
return sha1(implode($params)); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* 创建货架接口. |
245
|
|
|
* |
246
|
|
|
* @param string $banner |
247
|
|
|
* @param string $pageTitle |
248
|
|
|
* @param bool $canShare |
249
|
|
|
* @param string $scene [SCENE_NEAR_BY 附近,SCENE_MENU 自定义菜单,SCENE_QRCODE 二维码,SCENE_ARTICLE 公众号文章, |
250
|
|
|
* SCENE_H5 h5页面,SCENE_IVR 自动回复,SCENE_CARD_CUSTOM_CELL 卡券自定义cell] |
251
|
|
|
* @param array $cardList |
252
|
|
|
* |
253
|
|
|
* @return array |
254
|
|
|
*/ |
255
|
1 |
|
public function createLandingPage($banner, $pageTitle, $canShare, $scene, $cardList) |
256
|
|
|
{ |
257
|
|
|
$params = [ |
258
|
1 |
|
'banner' => $banner, |
259
|
1 |
|
'page_title' => $pageTitle, |
260
|
1 |
|
'can_share' => $canShare, |
261
|
1 |
|
'scene' => $scene, |
262
|
1 |
|
'card_list' => $cardList, |
263
|
1 |
|
]; |
264
|
|
|
|
265
|
1 |
|
return $this->parseJSON('json', [self::API_CREATE_LANDING_PAGE, $params]); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* 导入code接口. |
270
|
|
|
* |
271
|
|
|
* @param string $cardId |
272
|
|
|
* @param array $code |
273
|
|
|
* |
274
|
|
|
* @return array |
275
|
|
|
*/ |
276
|
1 |
View Code Duplication |
public function deposit($cardId, $code) |
277
|
|
|
{ |
278
|
|
|
$params = [ |
279
|
1 |
|
'card_id' => $cardId, |
280
|
1 |
|
'code' => $code, |
281
|
1 |
|
]; |
282
|
|
|
|
283
|
1 |
|
return $this->parseJSON('json', [self::API_DEPOSIT_CODE, $params]); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* 查询导入code数目. |
288
|
|
|
* |
289
|
|
|
* @param string $cardId |
290
|
|
|
* |
291
|
|
|
* @return array |
292
|
|
|
*/ |
293
|
1 |
View Code Duplication |
public function getDepositedCount($cardId) |
294
|
|
|
{ |
295
|
|
|
$params = [ |
296
|
1 |
|
'card_id' => $cardId, |
297
|
1 |
|
]; |
298
|
|
|
|
299
|
1 |
|
return $this->parseJSON('json', [self::API_GET_DEPOSIT_COUNT, $params]); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
/** |
303
|
|
|
* 核查code接口. |
304
|
|
|
* |
305
|
|
|
* @param string $cardId |
306
|
|
|
* @param array $code |
307
|
|
|
* |
308
|
|
|
* @return array |
309
|
|
|
*/ |
310
|
1 |
View Code Duplication |
public function checkCode($cardId, $code) |
311
|
|
|
{ |
312
|
|
|
$params = [ |
313
|
1 |
|
'card_id' => $cardId, |
314
|
1 |
|
'code' => $code, |
315
|
1 |
|
]; |
316
|
|
|
|
317
|
1 |
|
return $this->parseJSON('json', [self::API_CHECK_CODE, $params]); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* 查询Code接口. |
322
|
|
|
* |
323
|
|
|
* @param string $code |
324
|
|
|
* @param bool $checkConsume |
325
|
|
|
* @param string $cardId |
326
|
|
|
* |
327
|
|
|
* @return array |
328
|
|
|
*/ |
329
|
1 |
View Code Duplication |
public function getCode($code, $checkConsume, $cardId) |
330
|
|
|
{ |
331
|
|
|
$params = [ |
332
|
1 |
|
'code' => $code, |
333
|
1 |
|
'check_consume' => $checkConsume, |
334
|
1 |
|
'card_id' => $cardId, |
335
|
1 |
|
]; |
336
|
|
|
|
337
|
1 |
|
return $this->parseJSON('json', [self::API_GET_CODE, $params]); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* 核销Code接口. |
342
|
|
|
* |
343
|
|
|
* @param string $cardId |
344
|
|
|
* @param string $code |
345
|
|
|
* |
346
|
|
|
* @return array |
347
|
|
|
*/ |
348
|
1 |
View Code Duplication |
public function consume($cardId, $code) |
349
|
|
|
{ |
350
|
|
|
$params = [ |
351
|
1 |
|
'card_id' => $cardId, |
352
|
1 |
|
'code' => $code, |
353
|
1 |
|
]; |
354
|
|
|
|
355
|
1 |
|
return $this->parseJSON('json', [self::API_CONSUME_CARD, $params]); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* Code解码接口. |
360
|
|
|
* |
361
|
|
|
* @param string $encryptedCode |
362
|
|
|
* |
363
|
|
|
* @return array |
364
|
|
|
*/ |
365
|
1 |
|
public function decryptCode($encryptedCode) |
366
|
|
|
{ |
367
|
|
|
$params = [ |
368
|
1 |
|
'encrypt_code' => $encryptedCode, |
369
|
1 |
|
]; |
370
|
|
|
|
371
|
1 |
|
return $this->parseJSON('json', [self::API_DECRYPT_CODE, $params]); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* 图文消息群发卡券. |
376
|
|
|
* |
377
|
|
|
* @param string $cardId |
378
|
|
|
* |
379
|
|
|
* @return array |
380
|
|
|
*/ |
381
|
1 |
View Code Duplication |
public function getHtml($cardId) |
382
|
|
|
{ |
383
|
|
|
$params = [ |
384
|
1 |
|
'card_id' => $cardId, |
385
|
1 |
|
]; |
386
|
|
|
|
387
|
1 |
|
return $this->parseJSON('json', [self::API_GET_HTML, $params]); |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* 设置测试白名单. |
392
|
|
|
* |
393
|
|
|
* @param array $openid |
|
|
|
|
394
|
|
|
* @param array $username |
|
|
|
|
395
|
|
|
* |
396
|
|
|
* @return array |
397
|
|
|
*/ |
398
|
1 |
|
public function setTestWhitelist($openids) |
399
|
|
|
{ |
400
|
|
|
$params = [ |
401
|
1 |
|
'openid' => $openids, |
402
|
1 |
|
]; |
403
|
|
|
|
404
|
1 |
|
return $this->parseJSON('json', [self::API_SET_TEST_WHITE_LIST, $params]); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* 设置测试白名单(by username). |
409
|
|
|
* |
410
|
|
|
* @param array $usernames |
411
|
|
|
* |
412
|
|
|
* @return array |
413
|
|
|
*/ |
414
|
1 |
|
public function setTestWhitelistByUsername($usernames) |
415
|
|
|
{ |
416
|
|
|
$params = [ |
417
|
1 |
|
'username' => $usernames, |
418
|
1 |
|
]; |
419
|
|
|
|
420
|
1 |
|
return $this->parseJSON('json', [self::API_SET_TEST_WHITE_LIST, $params]); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* 获取用户已领取卡券接口. |
425
|
|
|
* |
426
|
|
|
* @param string $openid |
427
|
|
|
* @param string $cardId |
428
|
|
|
* |
429
|
|
|
* @return array |
430
|
|
|
*/ |
431
|
1 |
View Code Duplication |
public function getUserCards($openid, $cardId = '') |
432
|
|
|
{ |
433
|
|
|
$params = [ |
434
|
1 |
|
'openid' => $openid, |
435
|
1 |
|
'card_id' => $cardId, |
436
|
1 |
|
]; |
437
|
|
|
|
438
|
1 |
|
return $this->parseJSON('json', [self::API_GET_CARD_LIST, $params]); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* 查看卡券详情. |
443
|
|
|
* |
444
|
|
|
* @param string $cardId |
445
|
|
|
* |
446
|
|
|
* @return array |
447
|
|
|
*/ |
448
|
1 |
View Code Duplication |
public function getCard($cardId) |
449
|
|
|
{ |
450
|
|
|
$params = [ |
451
|
1 |
|
'card_id' => $cardId, |
452
|
1 |
|
]; |
453
|
|
|
|
454
|
1 |
|
return $this->parseJSON('json', [self::API_GET_CARD, $params]); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* 批量查询卡列表. |
459
|
|
|
* |
460
|
|
|
* @param int $offset |
461
|
|
|
* @param int $count |
462
|
|
|
* @param string $statusList |
463
|
|
|
* |
464
|
|
|
* @return array |
465
|
|
|
*/ |
466
|
1 |
View Code Duplication |
public function lists($offset = 0, $count = 10, $statusList = 'CARD_STATUS_VERIFY_OK') |
467
|
|
|
{ |
468
|
|
|
$params = [ |
469
|
1 |
|
'offset' => $offset, |
470
|
1 |
|
'count' => $count, |
471
|
1 |
|
'status_list' => $statusList, |
472
|
1 |
|
]; |
473
|
|
|
|
474
|
1 |
|
return $this->parseJSON('json', [self::API_LIST_CARD, $params]); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* 更改卡券信息接口 and 设置跟随推荐接口. |
479
|
|
|
* |
480
|
|
|
* @param string $cardId |
481
|
|
|
* @param string $type |
482
|
|
|
* @param array $baseInfo |
483
|
|
|
* @param array $especial |
484
|
|
|
* |
485
|
|
|
* @return array |
486
|
|
|
*/ |
487
|
1 |
|
public function update($cardId, $type, $baseInfo = [], $especial = []) |
488
|
|
|
{ |
489
|
1 |
|
$card = []; |
490
|
1 |
|
$card['card_id'] = $cardId; |
491
|
1 |
|
$card[$type] = []; |
492
|
|
|
|
493
|
1 |
|
$cardInfo = []; |
494
|
1 |
|
$cardInfo['base_info'] = $baseInfo; |
495
|
|
|
|
496
|
1 |
|
$card[$type] = array_merge($cardInfo, $especial); |
497
|
|
|
|
498
|
1 |
|
return $this->parseJSON('json', [self::API_UPDATE_CARD, $card]); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
/** |
502
|
|
|
* 设置微信买单接口. |
503
|
|
|
* 设置买单的 card_id 必须已经配置了门店,否则会报错. |
504
|
|
|
* |
505
|
|
|
* @param string $cardId |
506
|
|
|
* @param bool $isOpen |
507
|
|
|
* |
508
|
|
|
* @return array |
509
|
|
|
*/ |
510
|
1 |
View Code Duplication |
public function setPayCell($cardId, $isOpen = true) |
511
|
|
|
{ |
512
|
|
|
$params = [ |
513
|
1 |
|
'card_id' => $cardId, |
514
|
1 |
|
'is_open' => $isOpen, |
515
|
1 |
|
]; |
516
|
|
|
|
517
|
1 |
|
return $this->parseJSON('json', [self::API_SET_PAY_CELL, $params]); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
/** |
521
|
|
|
* 增加库存. |
522
|
|
|
* |
523
|
|
|
* @param string $cardId |
524
|
|
|
* @param int $amount |
525
|
|
|
* |
526
|
|
|
* @return bool |
527
|
|
|
*/ |
528
|
1 |
|
public function increaseStock($cardId, $amount) |
529
|
|
|
{ |
530
|
1 |
|
return $this->updateStock($cardId, $amount, 'increase'); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* 减少库存. |
535
|
|
|
* |
536
|
|
|
* @param string $cardId |
537
|
|
|
* @param int $amount |
538
|
|
|
* |
539
|
|
|
* @return bool |
540
|
|
|
*/ |
541
|
1 |
|
public function reduceStock($cardId, $amount) |
542
|
|
|
{ |
543
|
1 |
|
return $this->updateStock($cardId, $amount, 'reduce'); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
/** |
547
|
|
|
* 修改库存接口. |
548
|
|
|
* |
549
|
|
|
* @param string $cardId |
550
|
|
|
* @param int $amount |
551
|
|
|
* @param string $action |
552
|
|
|
* |
553
|
|
|
* @return array |
554
|
|
|
*/ |
555
|
1 |
|
protected function updateStock($cardId, $amount, $action = 'increase') |
556
|
|
|
{ |
557
|
1 |
|
$key = $action === 'increase' ? 'increase_stock_value' : 'reduce_stock_value'; |
558
|
|
|
$params = [ |
559
|
1 |
|
'card_id' => $cardId, |
560
|
1 |
|
$key => abs($amount), |
561
|
1 |
|
]; |
562
|
|
|
|
563
|
1 |
|
return $this->parseJSON('json', [self::API_MODIFY_STOCK, $params]); |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
/** |
567
|
|
|
* 更改Code接口. |
568
|
|
|
* |
569
|
|
|
* @param string $code |
570
|
|
|
* @param string $newCode |
571
|
|
|
* @param array $cardId |
572
|
|
|
* |
573
|
|
|
* @return array |
574
|
|
|
*/ |
575
|
1 |
View Code Duplication |
public function updateCode($code, $newCode, $cardId = []) |
576
|
|
|
{ |
577
|
|
|
$params = [ |
578
|
1 |
|
'code' => $code, |
579
|
1 |
|
'new_code' => $newCode, |
580
|
1 |
|
'card_id' => $cardId, |
581
|
1 |
|
]; |
582
|
|
|
|
583
|
1 |
|
return $this->parseJSON('json', [self::API_UPDATE_CODE, $params]); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* 删除卡券接口. |
588
|
|
|
* |
589
|
|
|
* @param string $cardId |
590
|
|
|
* |
591
|
|
|
* @return array |
592
|
|
|
*/ |
593
|
1 |
View Code Duplication |
public function delete($cardId) |
594
|
|
|
{ |
595
|
|
|
$params = [ |
596
|
1 |
|
'card_id' => $cardId, |
597
|
1 |
|
]; |
598
|
|
|
|
599
|
1 |
|
return $this->parseJSON('json', [self::API_DELETE_CARD, $params]); |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
/** |
603
|
|
|
* 设置卡券失效. |
604
|
|
|
* |
605
|
|
|
* @param string $code |
606
|
|
|
* @param string $cardId |
607
|
|
|
* |
608
|
|
|
* @return array |
609
|
|
|
*/ |
610
|
1 |
View Code Duplication |
public function disable($code, $cardId = '') |
611
|
|
|
{ |
612
|
|
|
$params = [ |
613
|
1 |
|
'code' => $code, |
614
|
1 |
|
'card_id' => $cardId, |
615
|
1 |
|
]; |
616
|
|
|
|
617
|
1 |
|
return $this->parseJSON('json', [self::API_DISABLE_CARD, $params]); |
618
|
|
|
} |
619
|
|
|
|
620
|
|
|
/** |
621
|
|
|
* 会员卡接口激活. |
622
|
|
|
* |
623
|
|
|
* @param array $info |
624
|
|
|
* |
625
|
|
|
* @return array |
626
|
|
|
*/ |
627
|
1 |
|
public function activate($info = []) |
628
|
|
|
{ |
629
|
1 |
|
return $this->parseJSON('json', [self::API_ACTIVATE_CARD, $info]); |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
/** |
633
|
|
|
* 设置开卡字段接口. |
634
|
|
|
* |
635
|
|
|
* @param string $cardId |
636
|
|
|
* @param array $requiredForm |
637
|
|
|
* @param array $optionalForm |
638
|
|
|
* |
639
|
|
|
* @return array |
640
|
|
|
*/ |
641
|
1 |
|
public function activateUserForm($cardId, array $requiredForm = [], array $optionalForm = []) |
642
|
|
|
{ |
643
|
1 |
|
$params = array_merge(['card_id' => $cardId], $requiredForm, $optionalForm); |
644
|
|
|
|
645
|
1 |
|
return $this->parseJSON('json', [self::API_ACTIVATE_USER_FORM, $params]); |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* 拉取会员信息接口. |
650
|
|
|
* |
651
|
|
|
* @param string $cardId |
652
|
|
|
* @param string $code |
653
|
|
|
* |
654
|
|
|
* @return array |
655
|
|
|
*/ |
656
|
1 |
View Code Duplication |
public function getMemberCardUser($cardId, $code) |
657
|
|
|
{ |
658
|
|
|
$params = [ |
659
|
1 |
|
'card_id' => $cardId, |
660
|
1 |
|
'code' => $code, |
661
|
1 |
|
]; |
662
|
|
|
|
663
|
1 |
|
return $this->parseJSON('json', [self::API_GET_MEMBER_USER_INFO, $params]); |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
/** |
667
|
|
|
* 更新会员信息. |
668
|
|
|
* |
669
|
|
|
* @param array $params |
670
|
|
|
* |
671
|
|
|
* @return array |
672
|
|
|
*/ |
673
|
1 |
|
public function updateMemberCardUser(array $params = []) |
674
|
|
|
{ |
675
|
1 |
|
return $this->parseJSON('json', [self::API_UPDATE_MEMBER_CARD_USER, $params]); |
676
|
|
|
} |
677
|
|
|
|
678
|
|
|
/** |
679
|
|
|
* 添加子商户. |
680
|
|
|
* |
681
|
|
|
* @param array $info |
682
|
|
|
* |
683
|
|
|
* @return array |
684
|
|
|
*/ |
685
|
1 |
View Code Duplication |
public function createSubMerchant(array $info = []) |
686
|
|
|
{ |
687
|
|
|
$params = [ |
688
|
1 |
|
'info' => Arr::only($info, [ |
689
|
1 |
|
'brand_name', |
690
|
1 |
|
'logo_url', |
691
|
1 |
|
'protocol', |
692
|
1 |
|
'end_time', |
693
|
1 |
|
'primary_category_id', |
694
|
1 |
|
'secondary_category_id', |
695
|
1 |
|
'agreement_media_id', |
696
|
1 |
|
'operator_media_id', |
697
|
1 |
|
'app_id', |
698
|
1 |
|
]), |
699
|
1 |
|
]; |
700
|
|
|
|
701
|
1 |
|
return $this->parseJSON('json', [self::API_CREATE_SUB_MERCHANT, $params]); |
702
|
|
|
} |
703
|
|
|
|
704
|
|
|
/** |
705
|
|
|
* 更新子商户. |
706
|
|
|
* |
707
|
|
|
* @param int $merchantId |
708
|
|
|
* @param array $info |
709
|
|
|
* |
710
|
|
|
* @return array |
711
|
|
|
*/ |
712
|
1 |
View Code Duplication |
public function updateSubMerchant($merchantId, array $info = []) |
713
|
|
|
{ |
714
|
|
|
$params = [ |
715
|
1 |
|
'info' => array_merge(['merchant_id' => $merchantId], |
716
|
1 |
|
Arr::only($info, [ |
717
|
1 |
|
'brand_name', |
718
|
1 |
|
'logo_url', |
719
|
1 |
|
'protocol', |
720
|
1 |
|
'end_time', |
721
|
1 |
|
'primary_category_id', |
722
|
1 |
|
'secondary_category_id', |
723
|
1 |
|
'agreement_media_id', |
724
|
1 |
|
'operator_media_id', |
725
|
1 |
|
'app_id', |
726
|
1 |
|
])), |
727
|
1 |
|
]; |
728
|
|
|
|
729
|
1 |
|
return $this->parseJSON('json', [self::API_UPDATE_SUB_MERCHANT, $params]); |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
/** |
733
|
|
|
* 获取子商户信息. |
734
|
|
|
* |
735
|
|
|
* @param int $merchantId |
736
|
|
|
* |
737
|
|
|
* @return array |
738
|
|
|
*/ |
739
|
|
|
public function getSubMerchant($merchantId) |
740
|
|
|
{ |
741
|
|
|
return $this->parseJSON('json', [self::API_GET_SUB_MERCHANT, ['merchant_id' => $merchantId]]); |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
/** |
745
|
|
|
* 批量获取子商户信息. |
746
|
|
|
* |
747
|
|
|
* @param int $beginId |
748
|
|
|
* @param int $limit |
749
|
|
|
* @param string $status |
750
|
|
|
* |
751
|
|
|
* @return array |
752
|
|
|
*/ |
753
|
|
|
public function listSubMerchants($beginId = 0, $limit = 50, $status = 'CHECKING') |
754
|
|
|
{ |
755
|
|
|
$params = [ |
756
|
|
|
'begin_id' => $beginId, |
757
|
|
|
'limit' => $limit, |
758
|
|
|
'status' => $status, |
759
|
|
|
]; |
760
|
|
|
|
761
|
|
|
return $this->parseJSON('json', [self::API_LIST_SUB_MERCHANT, $params]); |
762
|
|
|
} |
763
|
|
|
|
764
|
|
|
/** |
765
|
|
|
* 卡券开放类目查询接口. |
766
|
|
|
* |
767
|
|
|
* @return array|bool |
768
|
|
|
*/ |
769
|
1 |
|
public function getCategories() |
770
|
|
|
{ |
771
|
1 |
|
return $this->parseJSON('get', [self::API_GET_CATEGORIES]); |
772
|
|
|
} |
773
|
|
|
|
774
|
|
|
/** |
775
|
|
|
* Set cache manager. |
776
|
|
|
* |
777
|
|
|
* @param \Doctrine\Common\Cache\Cache $cache |
778
|
|
|
* |
779
|
|
|
* @return $this |
780
|
|
|
*/ |
781
|
2 |
|
public function setCache(Cache $cache) |
782
|
|
|
{ |
783
|
2 |
|
$this->cache = $cache; |
784
|
|
|
|
785
|
2 |
|
return $this; |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
/** |
789
|
|
|
* Return cache manager. |
790
|
|
|
* |
791
|
|
|
* @return \Doctrine\Common\Cache\Cache |
792
|
|
|
*/ |
793
|
2 |
|
public function getCache() |
794
|
|
|
{ |
795
|
2 |
|
return $this->cache ?: $this->cache = new FilesystemCache(sys_get_temp_dir()); |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
/** |
799
|
|
|
* Set current url. |
800
|
|
|
* |
801
|
|
|
* @param string $url |
802
|
|
|
* |
803
|
|
|
* @return array |
804
|
|
|
*/ |
805
|
1 |
|
public function setUrl($url) |
806
|
|
|
{ |
807
|
1 |
|
$this->url = $url; |
|
|
|
|
808
|
|
|
|
809
|
1 |
|
return $this; |
810
|
|
|
} |
811
|
|
|
} |
812
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.