def get_aftersale_orders( store_id, store_detail, start_stamp, end_stamp, callback=None): total, error_msg = get_aftersale_total( store_detail, start_stamp, end_stamp) if total <= 0: return total, error_msg pagesize = common_params.PAGE_SIZE print("订单总数为: ", total) pages = common_params.get_pages(total, pagesize) for i in range(pages): pageno = i + 1 order_list, error_msg = get_aftersale_list( store_detail, start_stamp, end_stamp, pageno, pagesize) for order in order_list: aftersale_order_detail, error_msg = get_aftersale_detail( store_detail, order["backno"]) if callback: callback( store_id, store_detail, transfer_aftersale_order( aftersale_order_detail, common_params.get_short_name(__file__)))
def get_orders( user_param, store_detail, start_stamp, end_stamp, callback=None): total, error_msg = get_order_total(store_detail, start_stamp, end_stamp) if total <= 0: return total, error_msg pagesize = common_params.PAGE_SIZE # print("订单总数为: ", total) pages = common_params.get_pages(total, pagesize) index = 0 status = {} for i in range(pages): pageno = i + 1 order_list, error_msg = get_order_list( store_detail, start_stamp, end_stamp, pageno, pagesize) if isinstance(error_msg, str) and len(error_msg): return total, error_msg for order in order_list: order_detail, error_msg = get_order_detail( store_detail, order["orderno"]) if isinstance(error_msg, str) and len(error_msg): return total, error_msg oms_order = transfer_order(order_detail, common_params.get_short_name(__file__)) if callback: if index == 0: status["callback_status"] = "start" status["start_stamp"] = time.time() index += 1 callback(user_param, store_detail, oms_order, index, status) if callback: status["callback_status"] = "end" status["end_stamp"] = time.time() callback(user_param, store_detail, None, index, status) return total, error_msg
def get_wares(user_param, store_detail, start_stamp, end_stamp, callback=None): total, error_msg = get_ware_total(store_detail, start_stamp, end_stamp) if total <= 0: return total, error_msg # print("商品总数为: ", total) pagesize = common_params.PAGE_SIZE pages = common_params.get_pages(total, pagesize) index = 0 status = {} for i in range(pages): pageno = i + 1 ware_list, error_msg = get_ware_list( store_detail, start_stamp, end_stamp, pageno, pagesize) if isinstance(error_msg, str) and len(error_msg): return total, error_msg for ware in ware_list: ware_detail, error_msg = get_ware_detail(store_detail, ware["item_id"]) if isinstance(error_msg, str) and len(error_msg): return total, error_msg sku_list = to_oms_sku( store_detail["user_id"], ware_detail) if isinstance(sku_list, list): for sku in sku_list: if callback: if index == 0: status["callback_status"] = "start" status["start_stamp"] = time.time() index += 1 callback(user_param, store_detail, sku, total, index, status) if callback: status["callback_status"] = "end" status["end_stamp"] = time.time() callback(user_param, store_detail, None, total, index, status) return total, error_msg
def update(cls, request): result = {'success': False, 'error_code': '10003'} token = request.META.get('HTTP_TOKEN') if token: token_json = jwt_token_certify(token) if token_json and isinstance(token_json, dict): user_id = token_json['u'] request_data = request.data if 'store_id' in request_data: store_id = request_data['store_id'] store = None try: store = Store.objects.get(id=store_id) except BaseException: raise CustomException('10003', '店铺不存在') store_account = { 'app_key': store.app_key, 'app_secret': store.app_secret, 'store_key': store.store_key, 'access_token': store.access_token } goods_num = interface.get_product_total( store.platform_name, store_account) pages = common_params.get_pages(goods_num) index = 1 for i in range(pages): pageno = i + 1 product_page = interface.get_product_list( store.platform_name, store_account, pageno) for product in product_page: oms_goods = interface.to_oms_sku( store.platform_name, user_id, product) sku = Sku(**oms_goods) sku.save() print("index = %s, 商品标识 = %s, 商品编号 = %s" % (index, oms_goods["item_code"], oms_goods["sku_name"])) index += 1 # 返回的结果 result_data = { 'user_id': user_id, 'store_id': store_id, 'goods_num': goods_num } # thread_goods = GoodsThread(platform, goods_num, store_account) # thread_goods.start() return result_data else: raise CustomException('10003', '店铺不存在') elif token_json is None: raise CustomException('10012', 'token不存在') elif token_json is False: raise CustomException('10011', 'token 认证失败') else: raise CustomException('10010', 'token不存在') return result
def get_orders(user_param, store_detail, start_stamp, end_stamp, callback=None): total, error_msg = get_order_total(store_detail, start_stamp, end_stamp) # if total <= 0: # return total, error_msg pagesize = common_params.PAGE_SIZE # print("订单总数为: ", total) pages = common_params.get_pages(total, pagesize) index = 0 status = {} status["start_stamp"] = time.time() for i in range(pages): pageno = i + 1 order_list, error_msg = get_order_list(store_detail, start_stamp, end_stamp, pageno, pagesize) if isinstance(error_msg, str) and len(error_msg): return total, error_msg for item in order_list: order_detail = None if "trade_fullinfo_get_response" in item and "trade" in item[ "trade_fullinfo_get_response"]: order_detail = item["trade_fullinfo_get_response"]["trade"] if order_detail is None: continue oms_order = transfer_order(order_detail, common_params.get_short_name(__file__)) if callback: if index == 0: status["callback_status"] = "start" else: status["callback_status"] = "running" index += 1 callback(user_param, store_detail, oms_order, index, status) if callback: status["callback_status"] = "end" status["end_stamp"] = time.time() callback(user_param, store_detail, None, index, status) return total, error_msg
def get_orders(store_id, store_detail, start_stamp, end_stamp, callback=None): total, error_msg = get_order_total(store_detail, start_stamp, end_stamp) if total <= 0: return pagesize = common_params.PAGE_SIZE print("订单总数为: ", total) pages = common_params.get_pages(total, pagesize) start_timestamp = time.time() for i in range(pages): pageno = i + 1 order_list, error_msg = get_order_list( store_detail, start_stamp, end_stamp, pageno, pagesize) for order in order_list: order_detail, error_msg = get_order_detail( store_detail, order["tid"]) oms_order = transfer_order( order_detail, common_params.get_short_name(__file__)) if callback: callback(store_id, store_detail, oms_order) end_timestamp = time.time() span = end_timestamp - start_timestamp print("耗时%s秒" % span)