Completed
Push — master ( e6b198...e30f90 )
by Messense
11:09 queued 10:06
created

MerchantOrder.get()   A

Complexity

Conditions 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3.1852
Metric Value
cc 2
dl 0
loc 9
ccs 1
cts 3
cp 0.3333
crap 3.1852
rs 9.6666
1
# -*- coding: utf-8 -*-
2 10
from __future__ import absolute_import, unicode_literals
3 10
from optionaldict import optionaldict
4 10
from wechatpy.client.api.base import BaseWeChatAPI
5
6
7 10
class MerchantOrder(BaseWeChatAPI):
8
9 10
    def get(self, order_id):
10
        res = self._post(
11
            'merchant/order/getbyid',
12
            data={
13
                'order_id': order_id
14
            },
15
            result_processor=lambda x: x['order']
16
        )
17
        return res
18
19 10
    def get_by_filter(self, status=None, begin_time=None, end_time=None):
20
        filter_dict = optionaldict(
21
            status=status,
22
            begintime=begin_time,
23
            endtime=end_time
24
        )
25
26
        res = self._post(
27
            'merchant/order/getbyfilter',
28
            data=dict(filter_dict),
29
            result_processor=lambda x: x['order_list']
30
        )
31
        return res
32
33 10
    def set_delivery(self, order_id, company, track_no,
34
                     need_delivery=1, is_others=0):
35
        return self._post(
36
            'merchant/order/setdelivery',
37
            data={
38
                'order_id': order_id,
39
                'delivery_company': company,
40
                'delivery_track_no': track_no,
41
                'need_delivery': need_delivery,
42
                'is_others': is_others
43
            }
44
        )
45
46 10
    def close(self, order_id):
47
        return self._post(
48
            'merchant/order/close',
49
            data={
50
                'order_id': order_id
51
            }
52
        )
53