Completed
Pull Request — master (#464)
by
unknown
03:36
created

Card::getCardList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 9
loc 9
ccs 5
cts 5
cp 1
crap 1
rs 9.6666
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 Psr\Http\Message\ResponseInterface;
27
28
class Card extends AbstractAPI
29
{
30
    /**
31
     * Cache.
32
     *
33
     * @var Cache
34
     */
35
    protected $cache;
36
37
    /**
38
     * Ticket cache prefix.
39
     */
40
    const TICKET_CACHE_PREFIX = 'overtrue.wechat.card_api_ticket.';
41
42
    const API_GET_COLORS = 'https://api.weixin.qq.com/card/getcolors';
43
    const API_CREATE = 'https://api.weixin.qq.com/card/create';
44
    const API_QRCODE_CREATE = 'https://api.weixin.qq.com/card/qrcode/create';
45
    const API_QRCODE_SHOW = 'https://mp.weixin.qq.com/cgi-bin/showqrcode';
46
    const API_GET_CARD_TICKET = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket';
47
    const API_LANDING_PAGE = 'https://api.weixin.qq.com/card/landingpage/create';
48
    const API_DEPOSIT = 'https://api.weixin.qq.com/card/code/deposit';
49
    const API_GET_DEPOSIT_COUNT = 'https://api.weixin.qq.com/card/code/getdepositcount';
50
    const API_CHECK_CODE = 'https://api.weixin.qq.com/card/code/checkcode';
51
    const API_GET_HTML = 'https://api.weixin.qq.com/card/mpnews/gethtml';
52
    const API_TEST_WHITE_LIST = 'https://api.weixin.qq.com/card/testwhitelist/set';
53
    const API_CODE_GET = 'https://api.weixin.qq.com/card/code/get';
54
    const API_CONSUME = 'https://api.weixin.qq.com/card/code/consume';
55
    const API_DECRYPT = 'https://api.weixin.qq.com/card/code/decrypt';
56
    const API_GET_CARD_LIST = 'https://api.weixin.qq.com/card/user/getcardlist';
57
    const API_CARD_GET = 'https://api.weixin.qq.com/card/get';
58
    const API_BATCH_GET = 'https://api.weixin.qq.com/card/batchget';
59
    const API_UPDATE = 'https://api.weixin.qq.com/card/update';
60
    const API_PAY_CELL_SET = 'https://api.weixin.qq.com/card/paycell/set';
61
    const API_MODIFY_STOCK = 'https://api.weixin.qq.com/card/modifystock';
62
    const API_CODE_UPDATE = 'https://api.weixin.qq.com/card/code/update';
63
    const API_CARD_DELETE = 'https://api.weixin.qq.com/card/delete';
64
    const API_UNAVAILABLE = 'https://api.weixin.qq.com/card/code/unavailable';
65
    const API_CARD_BIZ_UIN_INFO = 'https://api.weixin.qq.com/datacube/getcardbizuininfo';
66
    const API_CARD_CARD_INFO = 'https://api.weixin.qq.com/datacube/getcardcardinfo';
67
    const API_CARD_MEMBER_CARD_INFO = 'https://api.weixin.qq.com/datacube/getcardmembercardinfo';
68
    const API_CARD_ACTIVATE = 'https://api.weixin.qq.com/card/membercard/activate';
69
    const API_ACTIVATE_USER_FORM = 'https://api.weixin.qq.com/card/membercard/activateuserform/set';
70
    const API_MEMBER_USER_INFO = 'https://api.weixin.qq.com/card/membercard/userinfo/get';
71
    const API_UPDATE_USER = 'https://api.weixin.qq.com/card/membercard/updateuser';
72
    const API_SUB_MERCHANT = 'https://api.weixin.qq.com/card/submerchant/submit';
73
    const API_GET_APPLY_PROTOCOL = 'https://api.weixin.qq.com/card/getapplyprotocol';
74
75
    /**
76
     * 获取卡券颜色.
77
     *
78
     * @return array
79
     */
80 1
    public function getColors()
81
    {
82 1
        return $this->parseJSON('get', [self::API_GET_COLORS]);
83
    }
84
85
    /**
86
     * 创建卡券.
87
     *
88
     * @param string $cardType
89
     * @param array  $baseInfo
90
     * @param array  $especial
91
     * @param array  $advancedInfo
92
     *
93
     * @return bool|array
94
     */
95 1
    public function create($cardType = 'member_card', $baseInfo = [], $especial = [], $advancedInfo = [])
96
    {
97 1
        $card = [];
98 1
        $card['card'] = [];
99 1
        $card['card']['card_type'] = strtoupper($cardType);
100
101 1
        $type = strtolower($cardType);
102
103 1
        $card_info = [];
104 1
        $card_info['base_info'] = $baseInfo;
105
106 1
        $card['card'][$type] = [];
107 1
        $card['card'][$type] = array_merge($card_info, $especial, $advancedInfo);
108
109 1
        if (is_string($cardType) && is_array($baseInfo) && is_array($especial)) {
110 1
            return $this->parseJSON('json', [self::API_CREATE, $card]);
111
        }
112
113
        return false;
114
    }
115
116
    /**
117
     * 创建二维码.
118
     *
119
     * @param array $cardList
120
     *
121
     * @return array|bool
122
     */
123 1
    public function qrCode($cardList = [])
124
    {
125 1
        return $this->parseJSON('json', [self::API_QRCODE_CREATE, $cardList]);
126
    }
127
128
    /**
129
     * ticket 换取二维码图片.
130
     *
131
     * @param null $ticket
132
     *
133
     * @return array
134
     */
135 1
    public function showQrCode($ticket = null)
136
    {
137
        $params = [
138 1
            'ticket' => $ticket,
139 1
        ];
140
141 1
        $http = $this->getHttp();
142
143
        /** @var ResponseInterface $response */
144 1
        $response = $http->get(self::API_QRCODE_SHOW, $params);
145
146
        return [
147 1
            'status' => $response->getStatusCode(),
148 1
            'reason' => $response->getReasonPhrase(),
149 1
            'headers' => $response->getHeaders(),
150 1
            'body' => strval($response->getBody()),
151 1
            'url' => self::API_QRCODE_SHOW . '?' . http_build_query($params),
152 1
        ];
153
    }
154
155
    /**
156
     * 通过ticket换取二维码 链接.
157
     *
158
     * @param $ticket
159
     *
160
     * @return string
161
     */
162 1
    public function showQrCodeUrl($ticket)
163
    {
164 1
        $params = '?ticket=' . $ticket;
165
166 1
        return self::API_QRCODE_SHOW . $params;
167
    }
168
169
    /**
170
     * 获取 卡券 Api_ticket.
171
     *
172
     * @param  boolean $isRefresh 是否强制刷新
173
     *
174
     * @return string  $apiTicket
175
     */
176 2
    public function cardApiTicket($isRefresh = false)
177
    {
178 2
        $key = self::TICKET_CACHE_PREFIX . $this->getAccessToken()->getAppId();
179
180 2
        $ticket = $this->getCache()->fetch($key);
181
182 2
        if (!$ticket || $isRefresh) {
183 1
            $result = $this->parseJSON('get', [self::API_GET_CARD_TICKET, ['type' => 'wx_card']]);
184
185 1
            $res = $this->getCache()->save($key, $result['ticket'], $result['expires_in'] - 500);
0 ignored issues
show
Unused Code introduced by
$res is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
186
187 1
            return $result['ticket'];
188
        }
189
190 1
        return $ticket;
191
    }
192
193
    /**
194
     * 微信卡券:JSAPI 卡券Package - 基础参数没有附带任何值 - 再生产环境中需要根据实际情况进行修改.
195
     *
196
     * @param array $cardList
197
     * @param null  $timestamp
198
     * @param null  $apiTicket
199
     *
200
     * @return string
201
     */
202 1
    public function wxCardPackage(array $cardList, $timestamp = null, $apiTicket = null)
203
    {
204 1
        if (empty($timestamp) || $timestamp == '') {
205 1
            $timestamp = time();
206 1
        }
207
208 1
        if (empty($apiTicket) || $apiTicket == '') {
209 1
            $apiTicket = $this->cardApiTicket();
210 1
        }
211
212 1
        $resultArray = [];
213 1
        foreach ($cardList as $key => $value) {
214 1 View Code Duplication
            if (empty($value['code']) || !isset($value['code'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
215 1
                $value['code'] = '';
216 1
            }
217
218 1 View Code Duplication
            if (empty($value['openid']) || !isset($value['openid'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
219 1
                $value['openid'] = '';
220 1
            }
221
222 1
            $arrays = [$apiTicket, $timestamp, $value['card_id'], $value['code'], $value['openid']];
223 1
            sort($arrays, SORT_STRING);
224 1
            $string = sha1(implode($arrays));
225
226 1
            $resultArray['cardList'][$key]['cardId'] = $value['card_id'];
227 1
            $resultArray['cardList'][$key]['cardExt']['code'] = $value['code'];
228 1
            $resultArray['cardList'][$key]['cardExt']['openid'] = $value['openid'];
229
230 1
            $resultArray['cardList'][$key]['cardExt']['timestamp'] = $timestamp;
231 1
            $resultArray['cardList'][$key]['cardExt']['signature'] = $string;
232
233 1
            if (!empty($value['outer_id'])) {
234 1
                $resultArray['cardList'][$key]['cardExt']['outer_id'] = $value['outer_id'];
235 1
            }
236
237 1
            $resultArray['cardList'][$key]['cardExt'] = json_encode($resultArray['cardList'][$key]['cardExt']);
238 1
        }
239
240 1
        $resultJson = json_encode($resultArray);
241
242 1
        return $resultJson;
243
    }
244
245
    /**
246
     * 创建货架接口.
247
     *
248
     * @param $banner
249
     * @param $pageTitle
250
     * @param $canShare
251
     * @param $scene
252
     * @param $cardList
253
     *
254
     * @return array
255
     */
256 1
    public function landingPage($banner, $pageTitle, $canShare, $scene, $cardList)
257
    {
258
        $params = [
259 1
            'banner' => $banner,
260 1
            'page_title' => $pageTitle,
261 1
            'can_share' => $canShare,
262 1
            'scene' => $scene,
263 1
            'card_list' => $cardList,
264 1
        ];
265
266 1
        return $this->parseJSON('json', [self::API_LANDING_PAGE, $params]);
267
    }
268
269
    /**
270
     * 导入code接口.
271
     *
272
     * @param $cardId
273
     * @param $code
274
     *
275
     * @return array
276
     */
277 1 View Code Duplication
    public function deposit($cardId, $code)
278
    {
279
        $params = [
280 1
            'card_id' => $cardId,
281 1
            'code' => $code,
282 1
        ];
283
284 1
        return $this->parseJSON('json', [self::API_DEPOSIT, $params]);
285
    }
286
287
    /**
288
     * 查询导入code数目.
289
     *
290
     * @param $cardId
291
     *
292
     * @return array
293
     */
294 1 View Code Duplication
    public function getDepositCount($cardId)
295
    {
296
        $params = [
297 1
            'card_id' => $cardId,
298 1
        ];
299
300 1
        return $this->parseJSON('json', [self::API_GET_DEPOSIT_COUNT, $params]);
301
    }
302
303
    /**
304
     * 核查code接口.
305
     *
306
     * @param $cardId
307
     * @param $code
308
     *
309
     * @return array
310
     */
311 1 View Code Duplication
    public function checkCode($cardId, $code)
312
    {
313
        $params = [
314 1
            'card_id' => $cardId,
315 1
            'code' => $code,
316 1
        ];
317
318 1
        return $this->parseJSON('json', [self::API_CHECK_CODE, $params]);
319
    }
320
321
    /**
322
     * 图文消息群发卡券.
323
     *
324
     * @param $cardId
325
     *
326
     * @return array
327
     */
328 1 View Code Duplication
    public function getHtml($cardId)
329
    {
330
        $params = [
331 1
            'card_id' => $cardId,
332 1
        ];
333
334 1
        return $this->parseJSON('json', [self::API_GET_HTML, $params]);
335
    }
336
337
    /**
338
     * 设置测试白名单.
339
     *
340
     * @param $openid
341
     * @param $username
342
     *
343
     * @return array
344
     */
345 1
    public function testWhiteList($openid, $username)
346
    {
347
        $params = [
348 1
            'openid' => $openid,
349 1
            'username' => $username,
350 1
        ];
351
352 1
        return $this->parseJSON('json', [self::API_TEST_WHITE_LIST, $params]);
353
    }
354
355
    /**
356
     * 查询Code接口.
357
     *
358
     * @param $code
359
     * @param $checkConsume
360
     * @param $cardId
361
     *
362
     * @return array
363
     */
364 1 View Code Duplication
    public function codeGet($code, $checkConsume, $cardId)
365
    {
366
        $params = [
367 1
            'code' => $code,
368 1
            'check_consume' => $checkConsume,
369 1
            'card_id' => $cardId,
370 1
        ];
371
372 1
        return $this->parseJSON('json', [self::API_CODE_GET, $params]);
373
    }
374
375
    /**
376
     * 核销Code接口.
377
     *
378
     * @param $cardId
379
     * @param $code
380
     *
381
     * @return array
382
     */
383 1 View Code Duplication
    public function consume($cardId, $code)
384
    {
385
        $params = [
386 1
            'card_id' => $cardId,
387 1
            'code' => $code,
388 1
        ];
389
390 1
        return $this->parseJSON('json', [self::API_CONSUME, $params]);
391
    }
392
393
    /**
394
     * Code解码接口.
395
     *
396
     * @param $encryptCode
397
     *
398
     * @return array
399
     */
400 1
    public function decrypt($encryptCode)
401
    {
402
        $params = [
403 1
            'encrypt_code' => $encryptCode,
404 1
        ];
405
406 1
        return $this->parseJSON('json', [self::API_DECRYPT, $params]);
407
    }
408
409
    /**
410
     * 获取用户已领取卡券接口.
411
     *
412
     * @param        $openid
413
     * @param string $cardId
414
     *
415
     * @return array
416
     */
417 1 View Code Duplication
    public function getCardList($openid, $cardId = '')
418
    {
419
        $params = [
420 1
            'openid' => $openid,
421 1
            'card_id' => $cardId,
422 1
        ];
423
424 1
        return $this->parseJSON('json', [self::API_GET_CARD_LIST, $params]);
425
    }
426
427
    /**
428
     * 查看卡券详情.
429
     *
430
     * @param $cardId
431
     *
432
     * @return array
433
     */
434 1 View Code Duplication
    public function cardGet($cardId)
435
    {
436
        $params = [
437 1
            'card_id' => $cardId,
438 1
        ];
439
440 1
        return $this->parseJSON('json', [self::API_CARD_GET, $params]);
441
    }
442
443
    /**
444
     * 批量查询卡列表.
445
     *
446
     * @param int    $offset
447
     * @param int    $count
448
     * @param string $statusList
449
     *
450
     * @return array
451
     */
452 1 View Code Duplication
    public function batchGet($offset = 0, $count = 10, $statusList = 'CARD_STATUS_VERIFY_OK')
453
    {
454
        $params = [
455 1
            'offset' => $offset,
456 1
            'count' => $count,
457 1
            'status_list' => $statusList,
458 1
        ];
459
460 1
        return $this->parseJSON('json', [self::API_BATCH_GET, $params]);
461
    }
462
463
    /**
464
     * 更改卡券信息接口 and 设置跟随推荐接口.
465
     *
466
     * @param       $cardId
467
     * @param       $type
468
     * @param array $baseInfo
469
     * @param array $especial
470
     *
471
     * @return array
472
     */
473 1
    public function update($cardId, $type, $baseInfo = [], $especial = [])
474
    {
475 1
        $card = [];
476 1
        $card['card_id'] = $cardId;
477 1
        $card[$type] = [];
478
479 1
        $cardInfo = [];
480 1
        $cardInfo['base_info'] = $baseInfo;
481
482 1
        $card[$type] = array_merge($cardInfo, $especial);
483
484 1
        return $this->parseJSON('json', [self::API_UPDATE, $card]);
485
    }
486
487
    /**
488
     * 设置微信买单接口.
489
     * 设置买单的card_id必须已经配置了门店,否则会报错.
490
     *
491
     * @param      $cardId
492
     * @param bool $isOpen
493
     *
494
     * @return array
495
     */
496 1 View Code Duplication
    public function payCellSet($cardId, $isOpen = true)
497
    {
498
        $params = [
499 1
            'card_id' => $cardId,
500 1
            'is_open' => $isOpen,
501 1
        ];
502
503 1
        return $this->parseJSON('json', [self::API_PAY_CELL_SET, $params]);
504
    }
505
506
    /**
507
     * 修改库存接口.
508
     *
509
     * @param        $cardId
510
     * @param string $stock
511
     * @param int    $value
512
     *
513
     * @return array
514
     */
515 1
    public function modifyStock($cardId, $stock = 'increase', $value = 0)
516
    {
517 1
        $params = [];
518 1
        $params['card_id'] = $cardId;
519 1
        if ($stock == 'increase') {
520 1
            $params['increase_stock_value'] = intval($value);
521 1
        } elseif ($stock == 'reduce') {
522
            $params['reduce_stock_value'] = intval($value);
523
        } else {
524
            return false;
525
        }
526
527 1
        return $this->parseJSON('json', [self::API_MODIFY_STOCK, $params]);
528
    }
529
530
    /**
531
     * 更改Code接口.
532
     *
533
     * @param       $code
534
     * @param       $newCode
535
     * @param array $cardId
536
     *
537
     * @return array
538
     */
539 1 View Code Duplication
    public function codeUpdate($code, $newCode, $cardId = [])
540
    {
541
        $params = [
542 1
            'code' => $code,
543 1
            'new_code' => $newCode,
544 1
            'card_id' => $cardId,
545 1
        ];
546
547 1
        return $this->parseJSON('json', [self::API_CODE_UPDATE, $params]);
548
    }
549
550
    /**
551
     * 删除卡券接口.
552
     *
553
     * @param $cardId
554
     *
555
     * @return array
556
     */
557 1 View Code Duplication
    public function cardDelete($cardId)
558
    {
559
        $params = [
560 1
            'card_id' => $cardId,
561 1
        ];
562
563 1
        return $this->parseJSON('json', [self::API_CARD_DELETE, $params]);
564
    }
565
566
    /**
567
     * 设置卡券失效.
568
     *
569
     * @param      $code
570
     * @param null $cardId
571
     *
572
     * @return array
573
     */
574 1 View Code Duplication
    public function unavailable($code, $cardId = null)
575
    {
576
        $params = [
577 1
            'code' => $code,
578 1
            'card_id' => $cardId,
579 1
        ];
580
581 1
        return $this->parseJSON('json', [self::API_UNAVAILABLE, $params]);
582
    }
583
584
    /**
585
     * 拉取卡券概况数据接口.
586
     *
587
     * @param     $beginDate
588
     * @param     $endDate
589
     * @param int $condSource
590
     *
591
     * @return array
592
     */
593 1
    public function getCardBizUinInfo($beginDate, $endDate, $condSource = 0)
594
    {
595 1
        if (is_numeric($beginDate)) {
596
            $beginDate = date('Y-m-d', $beginDate);
597
        }
598
599 1
        if (is_numeric($endDate)) {
600
            $endDate = date('Y-m-d', $endDate);
601
        }
602
603
        $params = [
604 1
            'begin_date' => $beginDate,
605 1
            'end_date' => $endDate,
606 1
            'cond_source' => intval($condSource),
607 1
        ];
608
609 1
        return $this->parseJSON('json', [self::API_CARD_BIZ_UIN_INFO, $params]);
610
    }
611
612
    /**
613
     * 获取免费券数据接口.
614
     *
615
     * @param        $beginDate
616
     * @param        $endDate
617
     * @param int    $condSource
618
     * @param string $cardId
619
     *
620
     * @return array
621
     */
622 1 View Code Duplication
    public function getCardCardInfo($beginDate, $endDate, $condSource = 0, $cardId = '')
623
    {
624
        $params = [
625 1
            'begin_date' => $beginDate,
626 1
            'end_date' => $endDate,
627 1
            'cond_source' => intval($condSource),
628 1
            'card_id' => $cardId,
629 1
        ];
630
631 1
        return $this->parseJSON('json', [self::API_CARD_CARD_INFO, $params]);
632
    }
633
634
    /**
635
     * 拉取会员卡数据接口.
636
     *
637
     * @param     $beginDate
638
     * @param     $endDate
639
     * @param int $condSource
640
     *
641
     * @return array
642
     */
643 1 View Code Duplication
    public function getCardMemberCardInfo($beginDate, $endDate, $condSource = 0)
644
    {
645
        $params = [
646 1
            'begin_date' => $beginDate,
647 1
            'end_date' => $endDate,
648 1
            'cond_source' => intval($condSource),
649 1
        ];
650
651 1
        return $this->parseJSON('json', [self::API_CARD_MEMBER_CARD_INFO, $params]);
652
    }
653
654
    /**
655
     * 会员卡接口激活.
656
     *
657
     * @param array $activate
658
     *
659
     * @return array
660
     */
661 1
    public function activate($activate = [])
662
    {
663 1
        return $this->parseJSON('json', [self::API_CARD_ACTIVATE, $activate]);
664
    }
665
666
    /**
667
     * 设置开卡字段接口.
668
     *
669
     * @param       $cardId
670
     * @param array $requiredForm
671
     * @param array $optionalForm
672
     *
673
     * @return array
674
     */
675 1
    public function activateUserFrom($cardId, $requiredForm = [], $optionalForm = [])
676
    {
677 1
        $card = [];
678 1
        $card['card_id'] = $cardId;
679
680 1
        $params = array_merge($card, $requiredForm, $optionalForm);
681
682 1
        return $this->parseJSON('json', [self::API_ACTIVATE_USER_FORM, $params]);
683
    }
684
685
    /**
686
     * 拉取会员信息接口.
687
     *
688
     * @param $cardId
689
     * @param $code
690
     *
691
     * @return array
692
     */
693 1 View Code Duplication
    public function memberCardUserInfo($cardId, $code)
694
    {
695
        $params = [
696 1
            'card_id' => $cardId,
697 1
            'code' => $code,
698 1
        ];
699
700 1
        return $this->parseJSON('json', [self::API_MEMBER_USER_INFO, $params]);
701
    }
702
703
    /**
704
     * 更新会员信息.
705
     *
706
     * @param array $updateUser
707
     *
708
     * @return array
709
     */
710 1
    public function memberCardUpdateUser($updateUser = [])
711
    {
712 1
        $params = $updateUser;
713
714 1
        return $this->parseJSON('json', [self::API_UPDATE_USER, $params]);
715
    }
716
717
    /**
718
     * 添加子商户.
719
     *
720
     * @param        $brandName
721
     * @param        $logoUrl
722
     * @param        $protocol
723
     * @param        $endTime
724
     * @param        $primaryCategoryId
725
     * @param        $secondaryCategoryId
726
     * @param        $agreementMediaId
727
     * @param        $operatorMediaId
728
     * @param string $appId
729
     *
730
     * @return array
731
     */
732 1
    public function subMerchant($brandName, $logoUrl, $protocol, $endTime, $primaryCategoryId, $secondaryCategoryId, $agreementMediaId, $operatorMediaId, $appId = '')
733
    {
734
        $params = [
735
            'info' => [
736 1
                'brand_name' => $brandName,
737 1
                'logo_url' => $logoUrl,
738 1
                'protocol' => $protocol,
739 1
                'end_time' => $endTime,
740 1
                'primary_category_id' => $primaryCategoryId,
741 1
                'secondary_category_id' => $secondaryCategoryId,
742 1
                'agreement_media_id' => $agreementMediaId,
743 1
                'operator_media_id' => $operatorMediaId,
744 1
                'app_id' => $appId,
745 1
            ],
746 1
        ];
747
748 1
        return $this->parseJSON('json', [self::API_SUB_MERCHANT, $params]);
749
    }
750
751
    /**
752
     * 卡券开放类目查询接口.
753
     *
754
     * @return array|bool
755
     */
756 1
    public function getApplyProtocol()
757
    {
758 1
        return $this->parseJSON('get', [self::API_GET_APPLY_PROTOCOL]);
759
    }
760
761
    /**
762
     * Set cache manager.
763
     *
764
     * @param \Doctrine\Common\Cache\Cache $cache
765
     *
766
     * @return $this
767
     */
768 2
    public function setCache(Cache $cache)
769
    {
770 2
        $this->cache = $cache;
771
772 2
        return $this;
773
    }
774
775
    /**
776
     * Return cache manager.
777
     *
778
     * @return \Doctrine\Common\Cache\Cache
779
     */
780 2
    public function getCache()
781
    {
782 2
        return $this->cache ?: $this->cache = new FilesystemCache(sys_get_temp_dir());
783
    }
784
785
    /**
786
     * Set current url.
787
     *
788
     * @param string $url
789
     *
790
     * @return array
791
     */
792 1
    public function setUrl($url)
793
    {
794 1
        $this->url = $url;
0 ignored issues
show
Bug introduced by
The property url does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
795
796 1
        return $this;
797
    }
798
}
799