Passed
Pull Request — master (#1601)
by
unknown
03:06
created

Client::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
ccs 3
cts 3
cp 1
crap 1
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
namespace EasyWeChat\OfficialAccount\Goods;
13
14
use EasyWeChat\Kernel\BaseClient;
15
16
/**
17
 * Class Client.
18
 *
19
 * @author her-cat <[email protected]>
20
 */
21
class Client extends BaseClient
22
{
23
    /**
24
     * Add the goods.
25
     *
26
     * @param array $data
27
     *
28
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
29
     *
30
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
31
     */
32 1
    public function add(array $data)
33
    {
34 1
        return $this->httpPostJson('scan/product/v2/add', [
35 1
            'product' => $data,
36
        ]);
37
    }
38
39
    /**
40
     * Update the goods.
41
     *
42
     * @param array $data
43
     *
44
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
45
     *
46
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
47
     */
48 1
    public function update(array $data)
49
    {
50 1
        return $this->httpPostJson('scan/product/v2/add', [
51 1
            'product' => $data,
52
        ]);
53
    }
54
55
    /**
56
     * Get add or update goods results.
57
     *
58
     * @param string $ticket
59
     *
60
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
61
     *
62
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
63
     */
64 1
    public function status(string $ticket)
65
    {
66 1
        return $this->httpPostJson('scan/product/v2/status', [
67 1
            'status_ticket' => $ticket,
68
        ]);
69
    }
70
71
    /**
72
     * Get goods information.
73
     *
74
     * @param string $pid
75
     *
76
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
77
     *
78
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
79
     */
80 1
    public function get(string $pid)
81
    {
82 1
        return $this->httpPostJson('scan/product/v2/getinfo', [
83
            'product' => [
84 1
                'pid' => $pid,
85
            ],
86
        ]);
87
    }
88
89
    /**
90
     * Get a list of goods.
91
     *
92
     * @param string $context
93
     * @param int $page
94
     * @param int $size
95
     *
96
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
97
     *
98
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
99
     */
100 1
    public function list(string $context = '', int $page = 1, int $size = 10)
101
    {
102 1
        return $this->httpPostJson('scan/product/v2/getinfobypage', [
103 1
            'page_context' => $context,
104 1
            'page_num' => $page,
105 1
            'page_size' => $size,
106
        ]);
107
    }
108
}
109