Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Card often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Card, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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() |
|
| 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 | $cardInfo = []; |
|
| 104 | 1 | $cardInfo['base_info'] = $baseInfo; |
|
| 105 | |||
| 106 | 1 | $card['card'][$type] = []; |
|
| 107 | 1 | $card['card'][$type] = array_merge($cardInfo, $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 $cards |
||
| 120 | * |
||
| 121 | * @return array|bool |
||
| 122 | */ |
||
| 123 | 1 | public function qrCode($cards = []) |
|
| 124 | { |
||
| 125 | 1 | return $this->parseJSON('json', [self::API_QRCODE_CREATE, $cards]); |
|
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * ticket 换取二维码图片. |
||
| 130 | * |
||
| 131 | * @param string $ticket |
||
| 132 | * |
||
| 133 | * @return array |
||
| 134 | */ |
||
| 135 | 1 | public function showQrCode($ticket = null) |
|
| 154 | |||
| 155 | /** |
||
| 156 | * 通过ticket换取二维码 链接. |
||
| 157 | * |
||
| 158 | * @param string $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 bool $refresh 是否强制刷新 |
||
| 173 | * |
||
| 174 | * @return string $apiTicket |
||
| 175 | */ |
||
| 176 | 2 | View Code Duplication | public function cardApiTicket($refresh = 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 || $refresh) { |
|
| 183 | 1 | $result = $this->parseJSON('get', [self::API_GET_CARD_TICKET, ['type' => 'wx_card']]); |
|
| 184 | |||
| 185 | 1 | $this->getCache()->save($key, $result['ticket'], $result['expires_in'] - 500); |
|
| 186 | |||
| 187 | 1 | return $result['ticket']; |
|
| 188 | } |
||
| 189 | |||
| 190 | 1 | return $ticket; |
|
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * 微信卡券:JSAPI 卡券Package - 基础参数没有附带任何值 - 再生产环境中需要根据实际情况进行修改. |
||
| 195 | * |
||
| 196 | * @param array $cards |
||
| 197 | * @param int $timestamp |
||
| 198 | * @param string $apiTicket |
||
| 199 | * |
||
| 200 | * @return string |
||
| 201 | */ |
||
| 202 | 1 | public function wxCardPackage(array $cards, $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 | $result = []; |
|
| 213 | 1 | foreach ($cards as $index => $card) { |
|
| 214 | 1 | View Code Duplication | if (empty($card['code']) || !isset($card['code'])) { |
| 215 | 1 | $card['code'] = ''; |
|
| 216 | 1 | } |
|
| 217 | |||
| 218 | 1 | View Code Duplication | if (empty($card['openid']) || !isset($card['openid'])) { |
| 219 | 1 | $card['openid'] = ''; |
|
| 220 | 1 | } |
|
| 221 | |||
| 222 | 1 | $arrays = [$apiTicket, $timestamp, $card['card_id'], $card['code'], $card['openid']]; |
|
| 223 | 1 | sort($arrays, SORT_STRING); |
|
| 224 | 1 | $string = sha1(implode($arrays)); |
|
| 225 | |||
| 226 | 1 | $result['cardList'][$index]['cardId'] = $card['card_id']; |
|
| 227 | 1 | $result['cardList'][$index]['cardExt']['code'] = $card['code']; |
|
| 228 | 1 | $result['cardList'][$index]['cardExt']['openid'] = $card['openid']; |
|
| 229 | |||
| 230 | 1 | $result['cardList'][$index]['cardExt']['timestamp'] = $timestamp; |
|
| 231 | 1 | $result['cardList'][$index]['cardExt']['signature'] = $string; |
|
| 232 | |||
| 233 | 1 | if (!empty($card['outer_id'])) { |
|
| 234 | 1 | $result['cardList'][$index]['cardExt']['outer_id'] = $card['outer_id']; |
|
| 235 | 1 | } |
|
| 236 | |||
| 237 | 1 | $result['cardList'][$index]['cardExt'] = json_encode($result['cardList'][$index]['cardExt']); |
|
| 238 | 1 | } |
|
| 239 | |||
| 240 | 1 | return json_encode($result); |
|
| 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 公众号文章,SCENE_H5 h5页面,SCENE_IVR 自动回复,SCENE_CARD_CUSTOM_CELL 卡券自定义cell] |
||
| 250 | * @param array $cardList |
||
| 251 | * |
||
| 252 | * @return array |
||
| 253 | */ |
||
| 254 | 1 | public function landingPage($banner, $pageTitle, $canShare, $scene, $cardList) |
|
| 255 | { |
||
| 256 | $params = [ |
||
| 257 | 1 | 'banner' => $banner, |
|
| 258 | 1 | 'page_title' => $pageTitle, |
|
| 259 | 1 | 'can_share' => $canShare, |
|
| 260 | 1 | 'scene' => $scene, |
|
| 261 | 1 | 'card_list' => $cardList, |
|
| 262 | 1 | ]; |
|
| 263 | |||
| 264 | 1 | return $this->parseJSON('json', [self::API_LANDING_PAGE, $params]); |
|
| 265 | } |
||
| 266 | |||
| 267 | /** |
||
| 268 | * 导入code接口. |
||
| 269 | * |
||
| 270 | * @param string $cardId |
||
| 271 | * @param array $code |
||
| 272 | * |
||
| 273 | * @return array |
||
| 274 | */ |
||
| 275 | 1 | View Code Duplication | public function deposit($cardId, $code) |
| 276 | { |
||
| 277 | $params = [ |
||
| 278 | 1 | 'card_id' => $cardId, |
|
| 279 | 1 | 'code' => $code, |
|
| 280 | 1 | ]; |
|
| 281 | |||
| 282 | 1 | return $this->parseJSON('json', [self::API_DEPOSIT, $params]); |
|
| 283 | } |
||
| 284 | |||
| 285 | /** |
||
| 286 | * 查询导入code数目. |
||
| 287 | * |
||
| 288 | * @param string $cardId |
||
| 289 | * |
||
| 290 | * @return array |
||
| 291 | */ |
||
| 292 | 1 | View Code Duplication | public function getDepositCount($cardId) |
| 293 | { |
||
| 294 | $params = [ |
||
| 295 | 1 | 'card_id' => $cardId, |
|
| 296 | 1 | ]; |
|
| 297 | |||
| 298 | 1 | return $this->parseJSON('json', [self::API_GET_DEPOSIT_COUNT, $params]); |
|
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * 核查code接口. |
||
| 303 | * |
||
| 304 | * @param string $cardId |
||
| 305 | * @param array $code |
||
| 306 | * |
||
| 307 | * @return array |
||
| 308 | */ |
||
| 309 | 1 | View Code Duplication | public function checkCode($cardId, $code) |
| 310 | { |
||
| 311 | $params = [ |
||
| 312 | 1 | 'card_id' => $cardId, |
|
| 313 | 1 | 'code' => $code, |
|
| 314 | 1 | ]; |
|
| 315 | |||
| 316 | 1 | return $this->parseJSON('json', [self::API_CHECK_CODE, $params]); |
|
| 317 | } |
||
| 318 | |||
| 319 | /** |
||
| 320 | * 图文消息群发卡券. |
||
| 321 | * |
||
| 322 | * @param string $cardId |
||
| 323 | * |
||
| 324 | * @return array |
||
| 325 | */ |
||
| 326 | 1 | View Code Duplication | public function getHtml($cardId) |
| 327 | { |
||
| 328 | $params = [ |
||
| 329 | 1 | 'card_id' => $cardId, |
|
| 330 | 1 | ]; |
|
| 331 | |||
| 332 | 1 | return $this->parseJSON('json', [self::API_GET_HTML, $params]); |
|
| 333 | } |
||
| 334 | |||
| 335 | /** |
||
| 336 | * 设置测试白名单. |
||
| 337 | * |
||
| 338 | * @param array $openid |
||
| 339 | * @param array $username |
||
| 340 | * |
||
| 341 | * @return array |
||
| 342 | */ |
||
| 343 | 1 | public function testWhitelist($openid, $username) |
|
| 344 | { |
||
| 345 | $params = [ |
||
| 346 | 1 | 'openid' => $openid, |
|
| 347 | 1 | 'username' => $username, |
|
| 348 | 1 | ]; |
|
| 349 | |||
| 350 | 1 | return $this->parseJSON('json', [self::API_TEST_WHITE_LIST, $params]); |
|
| 351 | } |
||
| 352 | |||
| 353 | /** |
||
| 354 | * 查询Code接口. |
||
| 355 | * |
||
| 356 | * @param string $code |
||
| 357 | * @param bool $checkConsume |
||
| 358 | * @param string $cardId |
||
| 359 | * |
||
| 360 | * @return array |
||
| 361 | */ |
||
| 362 | 1 | View Code Duplication | public function getCode($code, $checkConsume, $cardId) |
| 363 | { |
||
| 364 | $params = [ |
||
| 365 | 1 | 'code' => $code, |
|
| 366 | 1 | 'check_consume' => $checkConsume, |
|
| 367 | 1 | 'card_id' => $cardId, |
|
| 368 | 1 | ]; |
|
| 369 | |||
| 370 | 1 | return $this->parseJSON('json', [self::API_CODE_GET, $params]); |
|
| 371 | } |
||
| 372 | |||
| 373 | /** |
||
| 374 | * 核销Code接口. |
||
| 375 | * |
||
| 376 | * @param string $cardId |
||
| 377 | * @param string $code |
||
| 378 | * |
||
| 379 | * @return array |
||
| 380 | */ |
||
| 381 | 1 | View Code Duplication | public function consume($cardId, $code) |
| 382 | { |
||
| 383 | $params = [ |
||
| 384 | 1 | 'card_id' => $cardId, |
|
| 385 | 1 | 'code' => $code, |
|
| 386 | 1 | ]; |
|
| 387 | |||
| 388 | 1 | return $this->parseJSON('json', [self::API_CONSUME, $params]); |
|
| 389 | } |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Code解码接口. |
||
| 393 | * |
||
| 394 | * @param string $encryptedCode |
||
| 395 | * |
||
| 396 | * @return array |
||
| 397 | */ |
||
| 398 | 1 | public function decrypt($encryptedCode) |
|
| 399 | { |
||
| 400 | $params = [ |
||
| 401 | 1 | 'encrypt_code' => $encryptedCode, |
|
| 402 | 1 | ]; |
|
| 403 | |||
| 404 | 1 | return $this->parseJSON('json', [self::API_DECRYPT, $params]); |
|
| 405 | } |
||
| 406 | |||
| 407 | /** |
||
| 408 | * 获取用户已领取卡券接口. |
||
| 409 | * |
||
| 410 | * @param string $openid |
||
| 411 | * @param string $cardId |
||
| 412 | * |
||
| 413 | * @return array |
||
| 414 | */ |
||
| 415 | 1 | View Code Duplication | public function getCardList($openid, $cardId = '') |
| 416 | { |
||
| 417 | $params = [ |
||
| 418 | 1 | 'openid' => $openid, |
|
| 419 | 1 | 'card_id' => $cardId, |
|
| 420 | 1 | ]; |
|
| 421 | |||
| 422 | 1 | return $this->parseJSON('json', [self::API_GET_CARD_LIST, $params]); |
|
| 423 | } |
||
| 424 | |||
| 425 | /** |
||
| 426 | * 查看卡券详情. |
||
| 427 | * |
||
| 428 | * @param string $cardId |
||
| 429 | * |
||
| 430 | * @return array |
||
| 431 | */ |
||
| 432 | 1 | View Code Duplication | public function getCard($cardId) |
| 433 | { |
||
| 434 | $params = [ |
||
| 435 | 1 | 'card_id' => $cardId, |
|
| 436 | 1 | ]; |
|
| 437 | |||
| 438 | 1 | return $this->parseJSON('json', [self::API_CARD_GET, $params]); |
|
| 439 | } |
||
| 440 | |||
| 441 | /** |
||
| 442 | * 批量查询卡列表. |
||
| 443 | * |
||
| 444 | * @param int int $offset |
||
| 445 | * @param int int $count |
||
| 446 | * @param string $statusList |
||
| 447 | * |
||
| 448 | * @return array |
||
| 449 | */ |
||
| 450 | 1 | View Code Duplication | public function getBatch($offset = 0, $count = 10, $statusList = 'CARD_STATUS_VERIFY_OK') |
| 451 | { |
||
| 452 | $params = [ |
||
| 453 | 1 | 'offset' => $offset, |
|
| 454 | 1 | 'count' => $count, |
|
| 455 | 1 | 'status_list' => $statusList, |
|
| 456 | 1 | ]; |
|
| 457 | |||
| 458 | 1 | return $this->parseJSON('json', [self::API_BATCH_GET, $params]); |
|
| 459 | } |
||
| 460 | |||
| 461 | /** |
||
| 462 | * 更改卡券信息接口 and 设置跟随推荐接口. |
||
| 463 | * |
||
| 464 | * @param string $cardId |
||
| 465 | * @param string $type |
||
| 466 | * @param array $baseInfo |
||
| 467 | * @param array $especial |
||
| 468 | * |
||
| 469 | * @return array |
||
| 470 | */ |
||
| 471 | 1 | public function update($cardId, $type, $baseInfo = [], $especial = []) |
|
| 472 | { |
||
| 473 | 1 | $card = []; |
|
| 474 | 1 | $card['card_id'] = $cardId; |
|
| 475 | 1 | $card[$type] = []; |
|
| 476 | |||
| 477 | 1 | $cardInfo = []; |
|
| 478 | 1 | $cardInfo['base_info'] = $baseInfo; |
|
| 479 | |||
| 480 | 1 | $card[$type] = array_merge($cardInfo, $especial); |
|
| 481 | |||
| 482 | 1 | return $this->parseJSON('json', [self::API_UPDATE, $card]); |
|
| 483 | } |
||
| 484 | |||
| 485 | /** |
||
| 486 | * 设置微信买单接口. |
||
| 487 | * 设置买单的card_id必须已经配置了门店,否则会报错. |
||
| 488 | * |
||
| 489 | * @param string $cardId |
||
| 490 | * @param bool $isOpen |
||
| 491 | * |
||
| 492 | * @return array |
||
| 493 | */ |
||
| 494 | 1 | View Code Duplication | public function payCellSet($cardId, $isOpen = true) |
| 495 | { |
||
| 496 | $params = [ |
||
| 497 | 1 | 'card_id' => $cardId, |
|
| 498 | 1 | 'is_open' => $isOpen, |
|
| 499 | 1 | ]; |
|
| 500 | |||
| 501 | 1 | return $this->parseJSON('json', [self::API_PAY_CELL_SET, $params]); |
|
| 502 | } |
||
| 503 | |||
| 504 | /** |
||
| 505 | * 修改库存接口. |
||
| 506 | * |
||
| 507 | * @param string $cardId |
||
| 508 | * @param string $stock |
||
| 509 | * @param int $value |
||
| 510 | * |
||
| 511 | * @return array |
||
| 512 | */ |
||
| 513 | 1 | public function modifyStock($cardId, $stock = 'increase', $value = 0) |
|
| 514 | { |
||
| 515 | $params = [ |
||
| 516 | 1 | 'card_id' => $cardId, |
|
| 517 | 1 | ]; |
|
| 518 | |||
| 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 string $code |
||
| 534 | * @param string $newCode |
||
| 535 | * @param array $cardId |
||
| 536 | * |
||
| 537 | * @return array |
||
| 538 | */ |
||
| 539 | 1 | View Code Duplication | public function updateCode($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 string $cardId |
||
| 554 | * |
||
| 555 | * @return array |
||
| 556 | */ |
||
| 557 | 1 | View Code Duplication | public function delete($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 string $code |
||
| 570 | * @param string $cardId |
||
| 571 | * |
||
| 572 | * @return array |
||
| 573 | */ |
||
| 574 | 1 | View Code Duplication | public function disable($code, $cardId = '') |
| 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 string $beginDate |
||
| 588 | * @param string $endDate |
||
| 589 | * @param int $condSource |
||
| 590 | * |
||
| 591 | * @return array |
||
| 592 | */ |
||
| 593 | 1 | public function getCardBizUinInfo($beginDate, $endDate, $condSource = 0) |
|
| 611 | |||
| 612 | /** |
||
| 613 | * 获取免费券数据接口. |
||
| 614 | * |
||
| 615 | * @param string $beginDate |
||
| 616 | * @param string $endDate |
||
| 617 | * @param int $condSource |
||
| 618 | * @param string $cardId |
||
| 619 | * |
||
| 620 | * @return array |
||
| 621 | */ |
||
| 622 | 1 | View Code Duplication | public function getFreeCardInfo($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 string $beginDate |
||
| 638 | * @param string $endDate |
||
| 639 | * @param int $condSource |
||
| 640 | * |
||
| 641 | * @return array |
||
| 642 | */ |
||
| 643 | 1 | View Code Duplication | public function getMemberCardInfo($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 = []) |
|
| 665 | |||
| 666 | /** |
||
| 667 | * 设置开卡字段接口. |
||
| 668 | * |
||
| 669 | * @param string $cardId |
||
| 670 | * @param array $requiredForm |
||
| 671 | * @param array $optionalForm |
||
| 672 | * |
||
| 673 | * @return array |
||
| 674 | */ |
||
| 675 | 1 | public function activateUserForm($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 string $cardId |
||
| 689 | * @param string $code |
||
| 690 | * |
||
| 691 | * @return array |
||
| 692 | */ |
||
| 693 | 1 | View Code Duplication | public function getMemberCardUser($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 updateMemberCardUser($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 string $brandName |
||
| 721 | * @param string $logoUrl |
||
| 722 | * @param string $protocol |
||
| 723 | * @param int $endTime |
||
| 724 | * @param int $primaryCategoryId |
||
| 725 | * @param int $secondaryCategoryId |
||
| 726 | * @param string $agreementMediaId |
||
| 727 | * @param string $operatorMediaId |
||
| 728 | * @param string $appId |
||
| 729 | * |
||
| 730 | * @return array |
||
| 731 | */ |
||
| 732 | 1 | public function subMerchant($brandName, $logoUrl, $protocol, $endTime, $primaryCategoryId, $secondaryCategoryId, $agreementMediaId, $operatorMediaId, $appId = '') |
|
| 750 | |||
| 751 | /** |
||
| 752 | * 卡券开放类目查询接口. |
||
| 753 | * |
||
| 754 | * @return array|bool |
||
| 755 | */ |
||
| 756 | 1 | public function getApplyProtocol() |
|
| 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) |
|
| 774 | |||
| 775 | /** |
||
| 776 | * Return cache manager. |
||
| 777 | * |
||
| 778 | * @return \Doctrine\Common\Cache\Cache |
||
| 779 | */ |
||
| 780 | 2 | public function getCache() |
|
| 784 | |||
| 785 | /** |
||
| 786 | * Set current url. |
||
| 787 | * |
||
| 788 | * @param string $url |
||
| 789 | * |
||
| 790 | * @return array |
||
| 791 | */ |
||
| 792 | 1 | public function setUrl($url) |
|
| 798 | } |
||
| 799 |