예제 #1
0
파일: weidian.py 프로젝트: cash2one/OMS-1
def get_express_list(store_detail):
    sys_params = {
        "method": "vdian.order.expresslist",
        "access_token": store_detail["access_token"],
        "format": "json",
        "version": "1.0"
    }
    api_url = DOMAIN["get_order"]
    app_params = {}
    url = api_url + "?param=" + \
        json.dumps(app_params) + "&public=" + json.dumps(sys_params)
    resp = requests_util.get(url)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)

    express_list = {}
    error_msg = None
    if "status" in res:
        if "status_code" in res["status"] and "status_reason" in res["status"]:
            if res["status"]["status_code"]:
                error_msg = res["status"]["status_reason"]
    if "result" in res and "common_express" in res["result"]:
        express_info = res["result"]["common_express"]
        for item in express_info:
            express_list[item["express_company"]] = item

    return express_list, error_msg
예제 #2
0
def get_ware_detail(store_detail, ware_id):
    url = DOMAIN["api"]
    now = time.time()
    current_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
    param_json = {
        "numiid": ware_id,
        "nick": store_detail["store_key"],
    }
    app_params = {
        "method": "getItem",
        "access_key": store_detail["app_key"],
        "access_token": store_detail["access_token"],
        "timestamp": current_date,
        "format": "json",
        "v": "1.0",
        "param_json": param_json,
    }

    params = urllib.parse.urlencode(app_params)
    resp = requests_util.get(url=url, params=params)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)

    error_msg = None
    ware_detail = {}
    if "json" in res and "item_get_response" in res["json"]:
        response = res["json"]["item_get_response"]
        if "item" in response:
            ware_detail = response["item"]
    return ware_detail, error_msg
예제 #3
0
파일: weidian.py 프로젝트: cash2one/OMS-1
def accept_order_refund(store_detail, refund_no, refund_param):
    sys_params = {
        "method": "vdian.order.refund.accept",
        "access_token": store_detail["access_token"],
        "format": "json",
        "version": "1.1"
    }
    api_url = DOMAIN["get_order"]
    app_params = {"refund_no": refund_no}
    app_params.update(refund_param)
    url = api_url + "?param=" + \
        json.dumps(app_params) + "&public=" + json.dumps(sys_params)
    resp = requests_util.get(url)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)
    success = False
    error_msg = None
    if "status" in res:
        if "status_code" in res["status"] and "status_reason" in res["status"]:
            if res["status"]["status_code"]:
                error_msg = res["status"]["status_reason"]
        if "status_code" in res["status"] and res["status"]["status_code"] == 0:
            success = True
    return success, error_msg
예제 #4
0
파일: weidian.py 프로젝트: cash2one/OMS-1
def get_order_response(store_detail,
                       start_stamp,
                       end_stamp,
                       pageno,
                       pagesize,
                       order_type="all"):
    update_end = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(end_stamp))
    update_start = time.strftime("%Y-%m-%d %H:%M:%S",
                                 time.localtime(start_stamp))
    sys_params = {
        "method": "vdian.order.list.get",
        "access_token": store_detail["access_token"],
        "format": "json",
        "version": "1.2"
    }
    api_url = DOMAIN["get_order"]
    # order_type 订单类型,all:待发货;unpay:待付款;shiped:已发货;
    # refunding:退款中;finish:已完成;close:已关闭;all:全部类型
    app_params = {
        # "is_wei_order": 0,
        "page_num": pageno,
        "page_size": pagesize,
        "order_type": order_type,
        "update_start": update_start,
        "update_end": update_end,
    }
    url = api_url + "?param=" + \
        json.dumps(app_params) + "&public=" + json.dumps(sys_params)
    resp = requests_util.get(url)
    if not resp:
        return ""
    res = json.loads(resp.text)
    return res
예제 #5
0
def get_order_response(store_detail, start_stamp, end_stamp, pageno, pagesize):
    update_end = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(end_stamp))
    update_start = time.strftime("%Y-%m-%d %H:%M:%S",
                                 time.localtime(start_stamp))
    now = time.time()
    current_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
    url = DOMAIN["api"]
    param_json = {
        # "tid": "",
        "nick": store_detail["store_key"],
        "fromModified": update_start,
        "toModified": update_end,
        "status": -1,
        "page": pageno - 1,
        "limit": pagesize,
    }
    app_params = {
        "method": "getTrade",
        "access_key": store_detail["app_key"],
        "access_token": store_detail["access_token"],
        "timestamp": current_date,
        "v": "1.0",
        "format": "json",
        "param_json": param_json,
    }
    params = urllib.parse.urlencode(app_params)
    resp = requests_util.get(url=url, params=params)
    if not resp:
        return ""
    res = json.loads(resp.text)
    # res = kuda_data.orders
    return res
예제 #6
0
def order_delivery(store_detail, order_id,
                   express_code, deliver_no, item_details=None):
    express = transfer_express.get(express_code)
    if express is None:
        return False, "express_code is not found"

    url = "https://open.youzan.com/api/oauthentry/youzan.logistics.online/3.0.0/confirm"
    skus = None
    if item_details:
        for item in item_details:
            if skus:
                skus += "," + str(item)
            else:
                skus = str(item)
    app_params = {
        "access_token": store_detail["access_token"],
        "tid": order_id,
        "oids": skus,
        "out_stype": express["id"],
        "out_sid": deliver_no,
    }
    resp = requests_util.get(url=url, params=app_params)
    if not resp:
        return False, common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)
    success = False
    error_msg = None
    if "error_response" in res and "msg" in res["error_response"]:
        error_msg = res["error_response"]["msg"]
    if "response" in res and "is_success" in res["response"]:
        success = res["response"]["is_success"]
    return success, error_msg
예제 #7
0
def order_decrypt(store_detail, data):
    now = time.time()
    current_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
    url = DOMAIN["api"]
    param_json = {
        "jsons": data,
        "nick": store_detail["store_key"],
    }
    app_params = {
        "method": "decrypt",
        "access_key": store_detail["app_key"],
        "access_token": store_detail["access_token"],
        "timestamp": current_date,
        "format": "json",
        "v": "1.0",
        "param_json": param_json,
    }
    params = urllib.parse.urlencode(app_params)
    resp = requests_util.get(url=url, params=params)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)
    result = None
    error_msg = None
    if "success" in res:
        error_msg = res["msg"]
    if "jsons" in res:
        result = res["jsons"]
    return result, error_msg
예제 #8
0
파일: weidian.py 프로젝트: cash2one/OMS-1
def get_order_detail(store_detail, order_id):
    sys_params = {
        "method": "vdian.order.get",
        "access_token": store_detail["access_token"],
        "format": "json",
        "version": "1.0"
    }
    api_url = DOMAIN["get_order"]
    app_params = {"order_id": order_id}
    url = api_url + "?param=" + \
        json.dumps(app_params) + "&public=" + json.dumps(sys_params)
    resp = requests_util.get(url)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)

    detail = ""
    error_msg = None
    if "status" in res and "status_code" in res["status"]:
        if res["status"]["status_code"]:
            error_msg = res["status"]["status_reason"]
    if "result" in res:
        detail = res["result"]

    return detail, error_msg
예제 #9
0
def get_order_list(store_detail, start_stamp, end_stamp, pageno, pagesize):
    if end_stamp - start_stamp > common_params.MONTH_3:
        start_stamp = end_stamp - common_params.MONTH_3
    url = DOMAIN["get_order"]
    update_end = time.strftime(
        "%Y-%m-%d %H:%M:%S",
        time.localtime(end_stamp))
    update_start = time.strftime(
        "%Y-%m-%d %H:%M:%S",
        time.localtime(start_stamp))
    params = {
        "access_token": store_detail["access_token"],
        "start_update": update_start,
        "end_update": update_end,
        "page_no": pageno,
        "page_size": pagesize,
        "type": "all",
    }
    resp = requests_util.get(url=url, params=params)
    res = json.loads(resp.text)
    order_list = ""
    error_msg = None
    if "error_response" in res and "msg" in res["error_response"]:
        error_msg = res["error_response"]["msg"]
    if "response" in res:
        if "trades" in res["response"]:
            order_list = res["response"]["trades"]
    return order_list, error_msg
예제 #10
0
파일: weidian.py 프로젝트: cash2one/OMS-1
def order_delivery(store_detail,
                   order_id,
                   express_code,
                   deliver_no,
                   item_details=None):
    express = transfer_express.get(express_code)
    if express is None:
        return False, "express_code is not found"
    if item_details:
        method = "vdian.order.deliver.split"
    else:
        method = "vdian.order.deliver"
    sys_params = {
        "method": method,
        "access_token": store_detail["access_token"],
        "format": "json",
        "version": "1.0"
    }
    api_url = DOMAIN["get_order"]
    app_params = {
        "express_no": deliver_no,
        "order_id": order_id,
        "express_type": express["id"],
        "express_custom": ""
    }
    skus = []
    if item_details:
        for item in item_details:
            if "item_id" in item and "item_sku_id" in item:
                if len(item["item_id"]) and len(item["item_sku_id"]):
                    sku = {}
                    sku["item_sku_id"] = item["item_sku_id"]
                    sku["item_id"] = item["item_id"]
                    skus.append(sku)
    if len(skus):
        app_params["items"] = skus
    url = api_url + "?param=" + \
        json.dumps(app_params) + "&public=" + json.dumps(sys_params)
    resp = requests_util.get(url)
    if not resp:
        return False, common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)
    success = False
    error_msg = None
    if "status" in res:
        if "status_code" in res["status"] and "status_reason" in res["status"]:
            if res["status"]["status_code"]:
                error_msg = res["status"]["status_reason"]
            else:
                success = True
    return success, error_msg
예제 #11
0
def get_order_detail(store_detail, order_id):
    url = DOMAIN["get_order_detail"]
    params = {
        "access_token": store_detail["access_token"],
        "tid": order_id
    }
    resp = requests_util.get(url=url, params=params)
    res = json.loads(resp.text)
    detail = ""
    error_msg = None
    if "error_response" in res and "msg" in res["error_response"]:
        error_msg = res["error_response"]["msg"]
    if "response" in res and "trade" in res["response"]:
        detail = res["response"]["trade"]
    return detail, error_msg
예제 #12
0
def get_express_list(store_detail):
    url = "https://open.youzan.com/api/oauthentry/youzan.logistics.express/3.0.0/get"
    params = {
        "access_token": store_detail["access_token"],
    }
    resp = requests_util.get(url=url, params=params)
    if not resp:
        return ""
    res = json.loads(resp.text)
    express_list = {}
    error_msg = None
    if "error_response" in res and "msg" in res["error_response"]:
        error_msg = res["error_response"]["msg"]
    if "response" in res and "allExpress" in res["response"]:
        express_list = res["response"]["allExpress"]
    return express_list, error_msg
예제 #13
0
def get_ware_reponse(
        store_detail,
        start_stamp,
        end_stamp,
        pageno,
        pagesize):
    url = "https://open.youzan.com/api/oauthentry/youzan.items.onsale/3.0.0/get"
    params = {
        "access_token": store_detail["access_token"],
        "page_no": pageno,
        "page_size": pagesize,
    }
    resp = requests_util.get(url=url, params=params)
    if not resp:
        return ""
    res = json.loads(resp.text)
    return res
예제 #14
0
def get_ware_detail(store_detail, ware_id):
    url = "https://open.youzan.com/api/oauthentry/youzan.item/3.0.0/get"
    params = {
        "access_token": store_detail["access_token"],
        "item_id": ware_id,
    }
    resp = requests_util.get(url=url, params=params)
    if not resp:
        return ""
    res = json.loads(resp.text)
    error_msg = None
    ware_detail = None
    if "error_response" in res and "msg" in res["error_response"]:
        error_msg = res["error_response"]["msg"]
    if "response" in res and "item" in res["response"]:
        ware_detail = res["response"]["item"]
    return ware_detail, error_msg
예제 #15
0
파일: weidian.py 프로젝트: cash2one/OMS-1
def refresh_token(store_detail, timeout=common_params.TIMEOUT):
    oauth = DOMAIN['oauth']
    url = oauth + '&appkey=' + store_detail[
        'app_key'] + '&secret=' + store_detail['app_secret']
    resp = requests_util.get(url, timeout=timeout)
    res = json.loads(resp.text)
    status = res['status']
    access_token = None
    error_msg = None
    if status['status_code'] == 0:
        result = res['result']
        access_token = result['access_token']
        store_detail['access_token'] = access_token
        store_detail['expire_in'] = result['expire_in']
        store_detail['access_token'] = result['access_token']
    else:
        error_msg = res['status']['status_reason']
    return access_token, error_msg
예제 #16
0
def get_order_detail(store_detail, order_id):
    # update_end = time.strftime("%Y-%m-%d%H:%M:%S", time.localtime(end_stamp))
    # update_start = time.strftime(
    #     "%Y-%m-%d%H:%M:%S",
    #     time.localtime(start_stamp))
    now = time.time()
    current_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
    url = DOMAIN["api"]
    param_json = {
        "tid": order_id,
        "nick": store_detail["store_key"],
        # "fromModified": update_start,
        # "toModified": update_end,
        "status": -1,
    }
    app_params = {
        "method": "getTrade",
        "access_key": store_detail["app_key"],
        "access_token": store_detail["access_token"],
        "timestamp": current_date,
        "format": "json",
        "v": "1.0",
        "param_json": param_json,
    }
    params = urllib.parse.urlencode(app_params)
    resp = requests_util.get(url=url, params=params)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)
    error_msg = None
    if "msg" in res:
        if len(res["msg"]) != 0:
            error_msg = res["msg"]
    if "error_response" in res:
        error_msg = res["error_response"]
    if "info" in res:
        if res["info"].isdigit():
            error_msg = res["info"]
        else:
            error_msg = res["info"]
    order_detail = ""
    if "data" in res:
        order_detail = res["data"]
    return order_detail, error_msg
예제 #17
0
def order_delivery(store_detail,
                   order_id,
                   express_code,
                   deliver_no,
                   item_details=None):
    express = transfer_express.get(express_code)
    now = time.time()
    current_date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
    url = DOMAIN["api"]
    param_json = {
        "tid": order_id,
        "nick": store_detail["store_key"],
        # 0:线下发货 1:线上发货 2:虚拟发货
        "sendway": 1,
        "companycode": express["code"],
        "outsid": deliver_no,
    }
    app_params = {
        "method": "taobaoSend",
        "access_key": store_detail["app_key"],
        "access_token": store_detail["access_token"],
        "timestamp": current_date,
        "format": "json",
        "v": "1.0",
        "param_json": param_json,
    }
    params = urllib.parse.urlencode(app_params)
    resp = requests_util.get(url=url, params=params)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)
    # res = kuda_data.delivery
    result = None
    error_msg = None
    if "shipping" in res:
        error_msg = res["msg"]
    if "success" in res:
        result = res["success"]
    return result, error_msg