Exemple #1
0
def get_aftersale_detail(store_detail, backno):
    url = DOMAIN["api"]
    app_params = {
        "jType": "aftersale_detail",
        "jCusKey": store_detail["store_key"],
        "type": "json",
        "token": store_detail["access_token"],
        "boNo": backno
    }
    code = {
        "code": store_detail["app_secret"]
    }
    data = make_md5(app_params, code)

    resp = requests_util.post(url=url, data=data)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)
    error_msg = None
    if "error_response" in res:
        error_msg = res["error_response"]
    if "info" in res:
        if res["info"].isdigit():
            error_msg = JuanpiErrorCodes[res["info"]]
        else:
            error_msg = res["info"]
    order_detail = ""
    if "data" in res:
        order_detail = res["data"]
    return order_detail, error_msg
Exemple #2
0
def get_aftersale_response(
        store_detail,
        start_stamp,
        end_stamp,
        pageno,
        pagesize,
        aftersale_type=2):
    if start_stamp < end_stamp - common_params.DAY_1 * 7:
        start_stamp = end_stamp - common_params.DAY_1 * 7
    modefied_time = str(int(start_stamp)) + "|" + str(int(end_stamp))
    url = DOMAIN["api"]
    app_params = {
        "jType": "aftersale_list",
        "jCusKey": store_detail["store_key"],
        "jPagesize": pagesize,
        "jPage": pageno,
        "type": "json",
        "token": store_detail["access_token"],
        "aftersaleType": aftersale_type,        # 售后类型: 1 仅退款; 2 退货退款
        "modefied_time": modefied_time,
        # "show_detail": 1
    }
    code = {
        "code": store_detail["app_secret"]
    }
    data = make_md5(app_params, code)

    resp = requests_util.post(url=url, data=data)
    if not resp:
        return ""
    res = json.loads(resp.text)
    return res
Exemple #3
0
def get_order_response(
        store_detail,
        start_stamp,
        end_stamp,
        pageno,
        pagesize,
        order_status=2):
    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))
    create_time = str(int(start_stamp)) + "|" + str(int(end_stamp))
    url = DOMAIN["api"]
    app_params = {
        "jType": "order_list",
        "jCusKey": store_detail["store_key"],
        "jPagesize": pagesize,
        "jPage": pageno,
        "type": "json",
        "token": store_detail["access_token"],
        "jOrderStatus": order_status,
        "create_time": create_time,
        # "show_detail": 1
    }
    code = {
        "code": store_detail["app_secret"]
    }
    data = make_md5(app_params, code)

    resp = requests_util.post(url=url, data=data)
    if not resp:
        return ""
    res = json.loads(resp.text)
    return res
Exemple #4
0
def get_ware_reponse(
    store_detail,
    start_stamp,
    end_stamp,
    pageno,
    pagesize,
):
    onsale_time = str(int(start_stamp)) + "|" + str(int(end_stamp))
    url = DOMAIN["api"]
    app_params = {
        "jType": "sgoods_list",
        "jCusKey": store_detail["store_key"],
        "jPagesize": pagesize,
        "jPage": pageno,
        "type": "json",
        "token": store_detail["access_token"],
        "field": "sgoodsid,sgoodsid_v2,cgid,title,cname",
        "onsale_time": onsale_time
    }
    code = {
        "code": store_detail["app_secret"]
    }
    data = make_md5(app_params, code)

    resp = requests_util.post(url=url, data=data)
    if not resp:
        return ""
    res = json.loads(resp.text)
    return res
Exemple #5
0
def get_ware_reponse(store_detail, start_stamp, end_stamp, pageno, pagesize):
    update_start = time.strftime("%Y-%m-%d%H:%M:%S", time.localtime(end_stamp))
    update_end = time.strftime("%Y-%m-%d%H:%M:%S", time.localtime(start_stamp))
    sys_params = {
        "method": "vdian.item.list.get",
        "access_token": store_detail["access_token"],
        "format": "json",
        "version": "1.0",
    }
    # status = 1:或不传为在架商品,status = 2:为下架商品, 4:表示下架和在架商品
    app_params = {
        "page_num": pageno,
        "page_size": pagesize,
        "status": 1,
        "update_start": update_start,
        "update_end": update_end
    }
    api_url = DOMAIN["get_order"]
    url = api_url + "?param=" + \
        json.dumps(app_params) + "&public=" + json.dumps(sys_params)

    resp = requests_util.post(url)
    if not resp:
        return ""
    res = json.loads(resp.text)
    return res
Exemple #6
0
def order_delivery_split(
        store_detail,
        order_id,
        express_code,
        deliver_no,
        skus_param):
    if express_code is None:
        return False, "express_code is None"
    url = DOMAIN["api"]
    app_params = {
        "jType": "send_goods",
        "jCusKey": store_detail["store_key"],
        "jOrderNo": order_id,
        "jDeliverEname": express_code["companypinyin"],
        "jDeliverCname": express_code["companyname"],
        "jDeliverNo": deliver_no,
        "type": "json",
        "token": store_detail["access_token"],
        "jIsSplit": 1,
        "jOrderGiftIds": skus_param["jOrderGiftIds"],
        "jOrderGoodsIds": skus_param["jOrderGoodsIds"]
    }
    code = {
        "code": store_detail["app_secret"]
    }
    data = make_md5(app_params, code)

    resp = requests_util.post(url=url, data=data)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)
    success = False
    error_msg = None
    if "error_response" in res:
        error_msg = res["error_response"]
    if "info" in res:
        if res["info"].isdigit():
            error_msg = JuanpiErrorCodes[res["info"]]
        else:
            error_msg = res["info"]
    if "info" in res and res["info"] == "20000":
        success = True
    return success, error_msg
Exemple #7
0
def get_ware_detail(store_detail, ware_id):
    # url = "https://open.youzan.com/api/oauthentry/youzan.item/3.0.0/get"
    url = DOMAIN["api"]
    app_params = {
        "jType": "sgoods_info",
        "jCusKey": store_detail["store_key"],
        "jSgoodsId": ware_id,
        "type": "json",
        "token": store_detail["access_token"],
        "field": "skuid,zid,fid,zid_value,fid_value,price,cprice,inventory,sales,sgoodsno,add_time,last_modified"}
    code = {
        "code": store_detail["app_secret"]
    }
    data = make_md5(app_params, code)

    resp = requests_util.post(url=url, data=data)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)

    error_msg = None
    if "error_response" in res:
        if "msg" in res["error_response"]:
            error_msg = res["error_response"]
    if "info" in res:
        if res["info"].isdigit():
            error_msg = JuanpiErrorCodes[res["info"]]
        else:
            error_msg = res["info"]

    ware_detail = {}
    if "data" not in res:
        return "", error_msg
    if "sgoodsinfo" not in res["data"]:
        return "", error_msg
    ware_detail.update(res["data"]["sgoodsinfo"])
    if "list" not in res["data"]:
        return "", error_msg
    ware_detail_list = res["data"]["list"]
    if len(ware_detail_list) > 0:
        ware_detail["list"] = (ware_detail_list)
    return ware_detail, error_msg
Exemple #8
0
def refresh_token(store_detail, timeout=common_params.TIMEOUT):
    url = DOMAIN['oauth']
    params = {
        'content-type': 'application/x-www-form-urlencoded',
        'client_id': store_detail['app_key'],
        'client_secret': store_detail['app_secret'],
        'grant_type': 'silent',
        'kdt_id': store_detail['store_key']
    }
    resp = requests_util.post(url, data=params, timeout=timeout)
    res = json.loads(resp.text)
    access_token = None
    error_msg = None
    if "error_description" in res:
        error_msg = res["error_description"]
    if "access_token" in res:
        access_token = res['access_token']
        store_detail['expire_in'] = res['expires_in']
        store_detail['access_token'] = res['access_token']
    return access_token, error_msg
Exemple #9
0
def get_express_list():
    url = DOMAIN["get_express"]
    resp = requests_util.post(url=url)
    if not resp:
        return "", common_params.OBTAIN_DATA_FAILED
    res = json.loads(resp.text)
    error_msg = None
    if "error_response" in res:
        error_msg = res["error_response"]
    if "info" in res:
        if res["info"].isdigit():
            error_msg = JuanpiErrorCodes[res["info"]]
        else:
            error_msg = res["info"]
    express_list = {}
    if "info" in res and res["info"] == "20000":
        express_info = res["data"]
        for item in express_info:
            express = express_info[item]
            express_list[express["companyname"]] = express
    return express_list, error_msg
Exemple #10
0
def refresh_token(store_detail, timeout=common_params.TIMEOUT):
    url = DOMAIN.get("oauth", "")
    data = {
        "secret": store_detail["app_key"],
        "scope": "order_list,order_info,sgoods_list,sgoods_info,send_goods,aftersale_list,aftersale_detail"
    }
    resp = requests_util.post(url, data=data, timeout=timeout)
    res = json.loads(resp.text)
    access_token = None
    if "data" in res and "token" in res["data"]:
        access_token = res["data"]["token"]
        store_detail['expire_in'] = res["data"]['expire']
        store_detail['access_token'] = res["data"]['token']
    error_msg = None
    if "error_response" in res:
        error_msg = res["error_response"]
    if "info" in res:
        if res["info"].isdigit():
            error_msg = JuanpiErrorCodes[res["info"]]
        else:
            error_msg = res["info"]
    return access_token, error_msg
Exemple #11
0
 def request(self):
     request_url = self.make_sign()
     response = requests_util.post(request_url)
     return response