Example #1
0
 def select_order_item_ids(self, order_id):
     session = orders.DBSession()
     item_ids = session.query(orders.AprOrderItem, orders.AprOrderItem.OrderItemId) \
                       .filter_by(AmazonOrderId=order_id).all()
     item_ids = [item_id[1] for item_id in item_ids]
     session.close()
     return item_ids
Example #2
0
 def select_last_order_time(self):
     session = orders.DBSession()
     field_name = orders.AprOrder.LastUpdateDate
     last_order_time = session.query(orders.AprOrder, field_name).order_by(
         desc(field_name)).limit(1).one()
     session.close()
     return last_order_time[1]
Example #3
0
 def select_order_ids(self, order_date):
     order_date_from = order_date - datetime.timedelta(
         days=30)  # 获取前30天订单,判断是否更新
     session = orders.DBSession()
     order_ids = session.query(orders.AprOrder, orders.AprOrder.AmazonOrderId)\
                        .filter(orders.AprOrder.LastUpdateDate>order_date_from).all()
     order_ids = [order_id[1] for order_id in order_ids]
     session.close()
     return order_ids
Example #4
0
 def add_order_to_sql(self, json_order):
     session = orders.DBSession()
     try:
         session.add(orders.AprOrder(json_order))
         session.commit()
     except Exception as e:
         log.error('AddOrderError: %s', e)
     finally:
         session.close()
Example #5
0
 def update_order_item(self, item_id, json_order_item):
     session = orders.DBSession()
     try:
         session.query(orders.AprOrderItem).filter_by(OrderItemId=item_id) \
                                           .update(orders.update_order_item(json_order_item))
         session.commit()
     except Exception as e:
         log.error('UpdateOrderItemError: %s', e)
     finally:
         session.close()
Example #6
0
 def update_order_to_sql(self, order_id, json_order):
     session = orders.DBSession()
     try:
         session.query(orders.AprOrder).filter_by(AmazonOrderId=order_id) \
                                       .update(orders.update_order(json_order))
         session.commit()
     except Exception as e:
         log.error('UpdateOrderError: %s', e)
     finally:
         session.close()
Example #7
0
 def add_order_item(self, order_id, order_time, json_order_item):
     session = orders.DBSession()
     try:
         session.add(
             orders.AprOrderItem(order_id, order_time, json_order_item)),
         session.commit()
     except Exception as e:
         log.error('AddOrderItemError: %s', e)
     finally:
         session.close()
Example #8
0
 def select_order_for_id(self, order_id):
     session = orders.DBSession()
     try:
         od_info = session.query(orders.AprOrder, orders.AprOrder.BuyerName,
                                 orders.AprOrder.BuyerEmail, orders.AprOrder.PurchaseDate) \
                          .filter(orders.AprOrder.AmazonOrderId == order_id).one()
         return od_info
     except Exception as e:
         log.error('SelectOrderError: %s, OrderId: %s' % (e, order_id))
     finally:
         session.close()
Example #9
0
 def select_order_time(self, order_id):
     session = orders.DBSession()
     order_time = session.query(orders.AprOrder, orders.AprOrder.PurchaseDate) \
                         .filter_by(AmazonOrderId=order_id).one()
     session.close()
     return order_time[1]