def get_userAllProductCard(phone=13676561839, status=None): id = get_user_id(phone) tb_name = dbc.new_himo_micro_preferential check_db_connect(tb_name) status_list = [ 'unused', 'used', 'abolished', 'expired', 'activated', "inactivated" ] if status is None: num = len( DBM.query_all( tb_name, "select id from product_cards where user_id = {} ".format(id))) if num == 0: return None return num elif status in status_list: num = len( DBM.query_all( tb_name, f"select id from product_cards where user_id = {id} and status = '{status}'" )) if num == 0: return None return num else: return None
def get_city_list(): tb_name = dbc.himo_micro_store check_db_connect(tb_name) return len( DBM.query_all( tb_name, "SELECT DISTINCT areas.id FROM areas,stores " "WHERE areas.id = stores.area_id and stores.deleted_at is NULL "))
def get_store_id(city_id): tb_name = dbc.himo_micro_store check_db_connect(tb_name) return DBM.query_all( tb_name, "SELECT stores.id from areas,stores " "where areas.id = stores.area_id and areas.id = {} and " "(stores.store_type = 'gold' or stores.store_type = 'blue') and " "stores.deleted_at is NULL".format(city_id))
def get_user_invoice_history(phone=18888888888): id = get_user_id(phone) tb_name = dbc.new_himo_micro_order check_db_connect(tb_name) return len( DBM.query_all( tb_name, f'select * from orders where user_id={id} and ' f'deleted_at is null and invoice_id is not null'))
def get_user_order(id): tb_name = dbc.new_himo_micro_order check_db_connect(tb_name) return len( DBM.query_all( tb_name, "select * from orders where user_id='{}' and deleted_at is NULL". format(id)))
def real_money(): money_list = [] for li in order_list: money_list.append( DBM.query_all( tb_name, f'select * from sub_orders where order_id={li["id"]}')) return money_list
def get_userProductCard_unused(phone=13676561839): id = get_user_id(phone) tb_name = dbc.new_himo_micro_preferential check_db_connect(tb_name) return len( DBM.query_all( tb_name, 'select id from product_cards where status = "unused" ' 'and user_id = {} and stop_usage > now()' 'and deleted_at is null and order_num is null'.format(id)))
def get_all_store_by_city() -> int: # def get_all_store_by_city(cityIds:list) -> int: tb_name = dbc.himo_micro_store check_db_connect(tb_name) return len( DBM.query_all( tb_name, "select distinct stores.id from areas,stores where areas.id = stores.area_id and " "(stores.store_type = 'blue' or stores.store_type = 'gold') and stores.deleted_at is null" ))
def get_userVaildCoupons(phone=13676561839): id = get_user_id(phone) tb_name = dbc.new_himo_micro_preferential check_db_connect(tb_name) return len( DBM.query_all( tb_name, f'SELECT * from coupons where user_id = {id} ' f'and stop_usage > now() ' f'and deleted_at is null and order_num is null' f' and apply_in="himo"'))
def get_city_id(): tb_name = dbc.himo_micro_store check_db_connect(tb_name) id = DBM.query_all( tb_name, "select distinct areas.id from areas,stores where areas.id = stores.area_id" " and stores.deleted_at is null ") list_id = [] for i in range(len(id)): list_id.append(id[i]['id']) return list_id
def get_area_classification_id(store_id): db_name = dbc.himo_micro_store check_db_connect(db_name) area_dict = {"area_id": [], "num": []} area = (DBM.query_all( db_name, f"select * from area_classification_store " f"where store_id={store_id}")) for a in area: area_dict["area_id"].append(a['area_classification_id']) tb_name = dbc.new_himo_micro_product_v3 check_db_connect(tb_name) for i in area_dict['area_id']: area = DBM.query_all( tb_name, f"select * from discount_rules where store_classification_id={i} " f"and deleted_at is null") for a in area: if a: area_dict['num'].append(a) return area_dict
def get_product_category_by_store_id_and_cat_id(cat_id, store_id=1001): db_name = dbc.new_himo_micro_product check_db_connect(db_name) category = DBM.query_all( db_name, f"select * from products where category_id={cat_id} and c_hidden=0 and is_entity=0" ) # return category for i in category: if DBM.query_one( db_name, f"select * from product_store where product_id={i['id']} and store_id={store_id}" ) is None: return None return category
def get_userCouponsInfo(phone=13676561839, status=None): id = get_user_id(phone) tb_name = dbc.new_himo_micro_preferential check_db_connect(tb_name) status_list = ['unused', 'used', 'abolished', 'expired', 'activated'] if status is None: num = len( DBM.query_all( tb_name, f"select * from coupons where user_id = {id} " f"and apply_in='himo' and deleted_at is null")) if num == 0: return None return num elif status in status_list: num = len( DBM.query_all( tb_name, f"select * from coupons where user_id = {id} and status = '{status}' " f"and apply_in='himo' and deleted_at is null")) if num == 0: return None return num else: return None
def get_user_invoice_list(phone=18888888888): id = get_user_id(phone) tb_name = dbc.new_himo_micro_order check_db_connect(tb_name) order_list = DBM.query_all( tb_name, f'select * from orders where user_id={id} and ' f'deleted_at is null and invoice_id is null and status="finished"') # return order_list def real_money(): money_list = [] for li in order_list: money_list.append( DBM.query_all( tb_name, f'select * from sub_orders where order_id={li["id"]}')) return money_list money_list = real_money() def money_is_not_zero(): invoice_list = [] for i in range(len(money_list)): for li in money_list[i]: if li['real_money'] > 0.00: invoice_list.append(li) ''' if li['gift_card_paymen_no']is None: invoice_list.append(li) else: gcp = li['gift_card_paymen_no'] db_name = dbc.new_himo_micro_preferential check_db_connect(db_name) id = DBM.query_one(db_name, f"select * from gift_card_payments where payment_no={gcp}")["id"] card_id = DBM.query_one(db_name, f"select * from gift_card_payment_items where payment_id={id}") undetermined = DBM.query_one(db_name, f"select * from user_gift_cards where id={card_id['card_id']}") if undetermined['refund_id'] != None: ''' return invoice_list invoice_list = money_is_not_zero() if len(invoice_list) < 1: return None return invoice_list