def run(params): t_report_orders1days_obj = t_report_orders1days(params['dbcnxn']) t_report_orders1days_obj.deletedata_befor60day( params['ProductID']) # 删除 (普通仓) 60天以前数据 t_order_obj = t_order(params['ShopName'], params['dbcnxn']) warehouse_list = ['STANDARD', 'US', 'GB', 'DE', 'FBW'] for warehouse in warehouse_list: objs = t_order_obj.get_order_data_by_productid(params['ProductID'], warehouse) for obj in objs: if obj: insertintodict = {} insertintodict['WarehouseName'] = warehouse if warehouse == 'FBW': # FBW insertintodict['WarehouseName'] = "{}-{}".format( warehouse, obj[4]) insertintodict['ProductID'] = obj[0] # productid insertintodict['YYYYMMDD'] = obj[1] insertintodict['OrdersLast1Days'] = 0 if obj[2] is not None: insertintodict['OrdersLast1Days'] = int(obj[2]) insertintodict['UpdateTime'] = obj[3].strftime('%Y-%m-%d') insertintodict['ShopName'] = params['ShopName'] insertintodict['PlatformName'] = params['ShopName'].split('-')[ 0] # Wish- if warehouse == 'STANDARD': # 普通仓7天订单数 insertintodict[ 'OrdersLast7Days'] = t_report_orders1days_obj.getOrders7Days( params['ProductID'], obj[1]) t_report_orders1days_obj.insertinto(insertintodict) else: # 海外仓7天订单数 fbw insertintodict[ 'OrdersLast7Days'] = t_report_orders1days_obj.getOrders7Days_WarehouseName( params['ProductID'], obj[1], warehousename=warehouse) # print insertintodict t_report_orders1days_obj.insertinto_WarehouseName( insertintodict)
def refresh_fbw_flag(product_id, shopsku, shopname, connection): warehousecode = [ {'code': 'FBW-LAX', 'name': u'FBW-US-LAX (美国)', 'des': 'FBW-US', 'ware_code': 'LAX'}, {'code': 'FBW-SF', 'name': u'SF Express (爱沙尼亚)', 'des': 'FBW-EU', 'ware_code': 'SF'}, # {'code': 'FBW-CVG', 'name': u'FBW-US-CVG (美国)', 'des': 'FBW-US', 'ware_code': 'CVG'}, ] t_stocking_demand_fbw_obj = t_stocking_demand_fbw(connection=connection) t_order_obj = t_order(shopname, connection) t_online_info_wish_fbw_obj = t_online_info_wish_fbw(connection) flag = 'False' for warecode in warehousecode: warehousename = warecode['code'] # 目前默认是美西仓 FBW-LAX of_sales = t_order_obj.fbw_shopsku_sales(product_id, shopsku, warecode['ware_code']) # 下面获取销量 是销售数量 不是订单量 if of_sales['errorcode'] == 1: flag = 'True' sales_num = int(of_sales['ofsales']) if of_sales['errorcode'] == 1 and of_sales['ofsales'] else 0 demand_obj = t_stocking_demand_fbw_obj.getdemand_stock_num( product_id=product_id,shopsku=shopsku, shopname=shopname,warehouse=warecode['des'] ) if demand_obj['errorcode'] == -1: raise Exception(demand_obj['errortext']) elif demand_obj['errorcode'] == 0: stock_num = 0 - sales_num else: stock_num = int(demand_obj['deliver_stock']) - sales_num # 发货量-售出量=在线库存 flag = 'True' if flag == 'True': insert_param = { 'product_id': product_id, 'shopsku': shopsku, 'online_stock': stock_num, 'demand_stock': demand_obj.get('demand_stock', 0), 'warehouse_code': warehousename, 'of_sales': sales_num, 'deliver_stock': demand_obj.get('deliver_stock', 0), 'goodsshipping': of_sales.get('Shipping') } t_online_info_wish_fbw_obj.insert(insert_param) return flag
def getStartAndEnd(self, data): t_order_obj = t_order(self.t_api_scheduleImp.auth_info['ShopName'], self.t_api_scheduleImp.cnxn) Max_OrderLastUpdated = t_order_obj.getMax_OrderLastUpdated2() get_wish_product_order_updatetime_obj = get_wish_product_order_updatetime( self.t_api_scheduleImp.cnxn, self.t_api_scheduleImp.auth_info['ShopName']) end = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S') if Max_OrderLastUpdated == '1970-01-01': #没找到那就是 start = None else: #[最大时间+1s,现在) start = strtimeaddseconds(Max_OrderLastUpdated, -600) end = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S') data['since'] = start #data['start'] = start #data['end'] = end self.OneCmdRecoreDict['cmdtext'] = '[ %s , %s )' % (start, end) get_wish_product_order_updatetime_obj.update_time_or_insert( start, end, 'Order')
def GetListOrders(self): if self.OneCmdRecoreDict[ 'TransactionID'] is None or self.OneCmdRecoreDict[ 'TransactionID'].strip() == '': Params_dict = eval(self.OneCmdRecoreDict['Params'].replace( "`", "'")) #import requests #url_create = "https://merchant.wish.com/api/v2/product/create-download-job" data = { 'access_token': self.t_api_scheduleImp.auth_info['access_token'], 'format': 'json', } self.getStartAndEnd(data) ## if Params_dict.has_key('start') and Params_dict.has_key('end'): ## data['start'] = Params_dict['start'] ## data['end'] = Params_dict['end'] print 'data===================================%s' % data dict_ret = requests.post(Params_dict['url_create'], params=data, timeout=30) print dict_ret.__dict__ print '---------------\n' #dict_ret =eval(ret) print 'dict_ret=%s' % dict_ret print '---------------\n' _content = eval(dict_ret._content) #刷新一下token 1015 :问令牌过期 4000:权存取 if _content['code'] == 1015 or _content[ 'code'] == 1016: #or _content['code']== 4000 or _content['code']== 1016 or _content['code']== 1017 or _content['code']== 1018 or _content['code']== 9000 : # self.RefreshToken() self.OneCmdRecoreDict['ActualEndTime'] = datetime.datetime.now( ) self.OneCmdRecoreDict['TransactionID'] = '' self.OneCmdRecoreDict['ProcessingStatus'] = _content['code'] #self.t_api_scheduleImp.refreshScheduleTimeAndTimedelta(self.OneCmdRecoreDict) #self.t_api_scheduleImp.updateOneCmd(self.OneCmdRecoreDict) return if dict_ret.status_code == 200 and _content['code'] == 0: self.OneCmdRecoreDict['Status'] = '1' self.OneCmdRecoreDict['ProcessingStatus'] = 'SUBMIT' self.OneCmdRecoreDict[ 'ActualBeginTime'] = datetime.datetime.now() self.OneCmdRecoreDict['ActualEndTime'] = datetime.datetime.now( ) self.OneCmdRecoreDict['TransactionID'] = '{`job_id`:`%s`}' % ( _content['data']['job_id']) #self.t_api_scheduleImp.refreshScheduleTimeAndTimedelta(self.OneCmdRecoreDict) #self.t_api_scheduleImp.updateOneCmd(self.OneCmdRecoreDict) else: #报错 self.OneCmdRecoreDict['Status'] = dict_ret.status_code self.OneCmdRecoreDict['ProcessingStatus'] = _content['code'] self.OneCmdRecoreDict['ActualEndTime'] = datetime.datetime.now( ) #self.t_api_scheduleImp.refreshScheduleTimeAndTimedelta(self.OneCmdRecoreDict) #self.t_api_scheduleImp.updateOneCmd(self.OneCmdRecoreDict) self.t_api_scheduleImp.moveOneCmd(self.OneCmdRecoreDict) else: TransactionID_dict = eval( self.OneCmdRecoreDict['TransactionID'].replace("`", "'")) print 'TransactionID_dict=%s' % TransactionID_dict Params_dict = eval(self.OneCmdRecoreDict['Params'].replace( "`", "'")) print self.OneCmdRecoreDict['Params'] data = { 'access_token': self.t_api_scheduleImp.auth_info['access_token'], 'format': 'json', 'job_id': TransactionID_dict['job_id'], } dict_ret = requests.post(Params_dict['url_status'], params=data, timeout=30) #dict_ret =eval(ret) #print json.dumps(dict_ret, indent=1) print '--------------- dict_ret=%s' % dict_ret print '---------------dict_ret.__dict__ =%s' % dict_ret.__dict__ print '---------------dict_ret._content=%s' % dict_ret._content _content = eval(dict_ret._content) #刷新一下token 1015 :问令牌过期 4000:权存取 if _content['code'] == 1015 or _content[ 'code'] == 1016: #or _content['code']== 4000 or _content['code']== 1016 or _content['code']== 1017 or _content['code']== 1018 or _content['code']== 9000 : # self.RefreshToken() self.OneCmdRecoreDict['ActualEndTime'] = datetime.datetime.now( ) self.OneCmdRecoreDict['TransactionID'] = '' self.OneCmdRecoreDict['ProcessingStatus'] = _content['code'] #self.t_api_scheduleImp.refreshScheduleTimeAndTimedelta(self.OneCmdRecoreDict) #self.t_api_scheduleImp.updateOneCmd(self.OneCmdRecoreDict) return if dict_ret.status_code == 200 and _content['code'] == 0: if _content['data']['status'] == 'FINISHED': if _content['data']['total_count'] > 0 and _content[ 'data'].has_key('download_link'): #下载数据 download_link = _content['data'][ 'download_link'].replace('\\', '') print 'download_link=%s' % download_link req = urllib2.Request(download_link) csv_bytes = urllib2.urlopen(req, timeout=600).read().decode( 'ascii', 'ignore') csv_reader = csv.reader(StringIO(csv_bytes)) #for row in csv_reader: #print row t_order_obj = t_order( self.t_api_scheduleImp.auth_info['ShopName'], self.t_api_scheduleImp.cnxn) t_order_obj.insertWish(csv_reader) self.OneCmdRecoreDict['Status'] = '2' self.OneCmdRecoreDict['ProcessingStatus'] = _content[ 'data']['status'] self.OneCmdRecoreDict[ 'ActualEndTime'] = datetime.datetime.now() self.t_api_scheduleImp.moveOneCmd(self.OneCmdRecoreDict) elif _content['data']['status'] == 'PENDING' or _content[ 'data']['status'] == 'RUNNING': self.OneCmdRecoreDict['Status'] = '1' self.OneCmdRecoreDict['ProcessingStatus'] = _content[ 'data']['status'] self.OneCmdRecoreDict[ 'ActualEndTime'] = datetime.datetime.now() #self.t_api_scheduleImp.refreshScheduleTimeAndTimedelta(self.OneCmdRecoreDict) #self.t_api_scheduleImp.updateOneCmd(self.OneCmdRecoreDict) else: self.OneCmdRecoreDict['Status'] = '-2' self.OneCmdRecoreDict['ProcessingStatus'] = _content[ 'data']['status'] self.OneCmdRecoreDict[ 'ActualEndTime'] = datetime.datetime.now() self.t_api_scheduleImp.moveOneCmd(self.OneCmdRecoreDict) else: #报错 print '--------------------dict_ret.status_code=%s' % ( dict_ret.status_code) self.OneCmdRecoreDict['Status'] = '-3' self.OneCmdRecoreDict[ 'ProcessingStatus'] = dict_ret.status_code self.OneCmdRecoreDict['ActualEndTime'] = datetime.datetime.now( )
break if paging_bytes is not None: paging_bytes_dict = eval(paging_bytes) prolist = prolist + paging_bytes_dict['data'] if paging_bytes_dict.has_key( 'paging') and paging_bytes_dict['paging'].has_key( 'next'): if len(paging_bytes_dict['paging']['next']) <= 10: break else: pageurl = paging_bytes_dict['paging'][ 'next'].replace('\\', '') else: break else: break if prolist: t_order_obj = t_order(self.t_api_scheduleImp.auth_info['ShopName'], self.t_api_scheduleImp.cnxn) refreshdict = t_order_obj.insertWishV2(prolist) self.t_api_scheduleImp.cnxn.commit() self.OneCmdRecoreDict['Status'] = '2' self.OneCmdRecoreDict['ActualEndTime'] = datetime.datetime.now() self.t_api_scheduleImp.moveOneCmd(self.OneCmdRecoreDict) refreshdict['record'] = record return refreshdict