Completed
Push — master ( a3c7a7...bd72ff )
by Carlos
02:47
created

Order   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 108
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getById() 0 6 1
A getByAttribute() 0 14 4
A setDelivery() 0 21 3
A close() 0 6 1
1
<?php
2
/**
3
 * Order.php
4
 *
5
 * Part of Overtrue\Wechat.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    a939638621 <[email protected]>
11
 * @copyright 2015 a939638621 <[email protected]>
12
 * @link      https://github.com/a939638621
13
 */
14
15
namespace Overtrue\Wechat\Shop;
16
17
18
use Overtrue\Wechat\Shop\Foundation\Base;
19
use Overtrue\Wechat\Shop\Foundation\Order as OrderInterface;
20
use Overtrue\Wechat\Shop\Foundation\ShopsException;
21
22
/**
23
 * 订单管理
24
 *
25
 * Class Order
26
 * @package Shop
27
 */
28
class Order extends Base implements OrderInterface
29
{
30
31
    /**
32
     * 快递
33
     */
34
    const EMS = 'Fsearch_code';
35
    const STO = '002shentong';
36
    const ZTO = '066zhongtong';
37
    const YTO = '056yuantong';
38
    const TTK = '042tiantian';
39
    const SF = '003shunfeng';
40
    const YUN_DA = '059Yunda';
41
    const ZJS = '064zhaijisong';
42
    const HUI_TONG = '020huitong';
43
    const YI_XUN = 'zj001yixun';
44
45
    const API_GET_BY_ID = 'https://api.weixin.qq.com/merchant/order/getbyid';
46
    const API_GET_BY_ATTRIBUTE = 'https://api.weixin.qq.com/merchant/order/getbyfilter';
47
    const API_SET_DELIVERY = 'https://api.weixin.qq.com/merchant/order/setdelivery';
48
    const API_CLOSE = 'https://api.weixin.qq.com/merchant/order/close';
49
50
51
    /**
52
     * 根据订单ID获取订单详情
53
     *
54
     * @param $orderId
55
     * @return array
56
     * @throws ShopsException
57
     */
58
    public function getById($orderId)
59
    {
60
        $this->response = $this->http->jsonPost(self::API_GET_BY_ID, array('order_id'=>$orderId));
61
62
        return $this->getResponse();
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getResponse(); of type boolean|array adds the type boolean to the return on line 62 which is incompatible with the return type declared by the interface Overtrue\Wechat\Shop\Foundation\Order::getById of type array.
Loading history...
63
    }
64
65
    /**
66
     * 根据订单状态/创建时间获取订单详情
67
     *
68
     * @param null $status
69
     * @param null $beginTime
70
     * @param null $endTime
71
     * @return mixed
72
     * @throws ShopsException
73
     */
74
    public function getByAttribute($status = null, $beginTime = null, $endTime = null)
75
    {
76
        $data = array();
77
78
        if (!empty($status)) $data['status'] = $status;
79
        if (!empty($beginTime)) $data['begintime'] = $beginTime;
80
        if (!empty($endTime)) $data['endtime'] = $endTime;
81
82
83
        $this->response = $this->http->jsonPost(self::API_GET_BY_ATTRIBUTE, $data);
84
85
        return $this->getResponse();
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getResponse(); of type boolean|array adds the type boolean to the return on line 85 which is incompatible with the return type declared by the interface Overtrue\Wechat\Shop\Fou...n\Order::getByAttribute of type array.
Loading history...
86
87
    }
88
89
    /**
90
     * 设置发货信息
91
     *
92
     * @param $orderId
93
     * @param string $deliveryCompany
94
     * @param string $deliveryTrackNo
95
     * @param int $isOthers
96
     * @return bool
97
     * @throws ShopsException
98
     */
99
    public function setDelivery($orderId,$deliveryCompany = null,$deliveryTrackNo = null,$isOthers = 0)
100
    {
101
102
        $data = array(
103
            'order_id' => $orderId,
104
        );
105
106
        $data['is_others'] = $isOthers;
107
108
        if (empty($deliveryCompany) && empty($deliveryTrackNo)) {
109
            $data['need_delivery'] = 0;
110
        } else {
111
            $data['need_delivery'] = 1;
112
            $data['delivery_company'] = $deliveryCompany;
113
            $data['delivery_track_no'] = $deliveryTrackNo;
114
        }
115
116
        $this->response = $this->http->jsonPost(self::API_SET_DELIVERY, $data);
117
118
        return $this->getResponse();
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getResponse(); of type boolean|array adds the type array to the return on line 118 which is incompatible with the return type declared by the interface Overtrue\Wechat\Shop\Foundation\Order::setDelivery of type boolean.
Loading history...
119
    }
120
121
    /**
122
     * 关闭订单
123
     *
124
     * @param $orderId
125
     * @return bool
126
     * @throws ShopsException
127
     */
128
    public function close($orderId)
129
    {
130
        $this->response = $this->http->jsonPost(self::API_CLOSE, array('order_id'=>$orderId));
131
132
        return $this->getResponse();
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->getResponse(); of type boolean|array adds the type array to the return on line 132 which is incompatible with the return type declared by the interface Overtrue\Wechat\Shop\Foundation\Order::close of type boolean.
Loading history...
133
    }
134
135
}