Esempio n. 1
0
def exchange_goldbean(merchant_id, serial_num, name, identify_id, ratio):
    customer = db.customer_get_by_serial_num(serial_num)
    if not customer:
        raise exception.SerialNumIsNotExist()
    if name != customer['name'] or identify_id != customer['identify_id']:
        raise exception.CustomerInfoNotMatch()
    if customer['gb'] < int(ratio) * 5000:
        raise exception.CustomerGoldbeanNotEnough()
    if customer['qualification_gb'] < 500:
        raise exception.CustomerHasNoQualification()
    merchant = db.merchant_get_by_id(merchant_id)
    exchange_ratio = get_merchant_rule(merchant_id)
    values = {
        'gb_exchange_count': merchant['gb_exchange_count'] + 1,
        'gb_to_money': merchant['gb_to_money'] + exchange_ratio['level%s' % ratio]
    }
    db.merchant_update_by_id(merchant_id, values)
    values = {
        'gb': customer['gb'] - int(ratio) * 5000,
        'gb_exchange_count': customer['gb_exchange_count'] + 1,
        'gain_money': customer['gain_money'] + exchange_ratio['level%s' % ratio],
        'qualification_gb': 0
    }
    db.customer_update_by_id(customer['id'], values)
    values = {
        'merchant_id': merchant_id,
        'customer_name': customer['name'],
        'customer_id': customer['id'],
        'exchange_money': exchange_ratio['level%s' % ratio],
        'exchange_goldbean': int(ratio) * 5000
    }
    return db.exchange_create(values)
Esempio n. 2
0
def get_search_customer_list(page, type, content):
    count = search_customer_count(type, content)
    if type == '0':
        temp = db.customer_all_list_by_serial_num(content)
    elif type == '1':
        temp = db.customer_all_list_by_name(content)
    elif type == '2':
        temp = db.customer_all_list_by_phone(content)
    elif type == '3':
        min_gb = int(content) * 5000
        max_gb = int(content) * 5000 + 5000 if content != '8' else 1000000000
        temp = db.customer_all_list_by_gb_range(min_gb, max_gb)
    elif type == '4':
        merchant = db.merchant_get_by_name(content)
        temp = db.customer_all_list_by_merchant_id(merchant['id'])
    page_num = count / 10 + 1 if count % 10 else count / 10
    if page < 1 or page > page_num:
        return []
    count = 1
    c_list = []
    for customer in temp:
        values = dict(customer)
        values['num'] = count
        merchant_id = customer['merchant_id']
        merchant = db.merchant_get_by_id(merchant_id)
        if merchant:
            values['merchant'] = merchant['name']
            c_list.append(values)
            count += 1
    return c_list[10 * (page - 1):10 * page]
Esempio n. 3
0
def recent_customer_list():
    temp = db.customer_recent_list()
    customer_list = []
    for customer in temp:
        customer_dict = dict(customer)
        merchant = db.merchant_get_by_id(customer_dict['merchant_id'])
        customer_dict['merchant_name'] = merchant['name']
        customer_list.append(customer_dict)
    return customer_list
Esempio n. 4
0
def customer_list(page):
    count = db.customer_count()
    page_num = count / 10 + 1 if count % 10 else count / 10
    if page < 1 or page > page_num:
        return []
    temp = db.customer_list()
    c_list = []
    count = 1
    for customer in temp:
        c_dict = dict(customer)
        c_dict['num'] = count
        merchant_id = customer['merchant_id']
        merchant = db.merchant_get_by_id(merchant_id)
        if merchant:
            c_dict['merchant'] = merchant['name']
            c_list.append(c_dict)
            count += 1
    return c_list[10 * (page - 1):10 * page]
Esempio n. 5
0
def bind_customer(merchant_id, serial_num, password, name, identify_id, phone, email, we_chat):
    if not db.user_username_if_exist_in_db(serial_num):
        raise exception.SerialNumIsNotExist()
    user = db.user_get_by_username(serial_num)
    if password != user['password']:
        raise exception.PasswordIsWrongException()
    customer = db.customer_get_by_serial_num(serial_num)
    if customer['merchant_id']:
        raise exception.SerialNumIsAlreadyBinded()
    merchant = db.merchant_get_by_id(merchant_id)
    values = {
        'member_num': merchant['member_num'] + 1
    }
    db.merchant_update_by_id(merchant_id, values)
    values = {
        'merchant_id': merchant_id,
        'name': name,
        'identify_id': identify_id,
        'phone': phone,
        'email': email,
        'we_chat': we_chat
    }
    return db.customer_bind_by_serial_num(serial_num, values)
Esempio n. 6
0
def get_merchant_by_id(merchant_id):
    return dict(db.merchant_get_by_id(merchant_id))
Esempio n. 7
0
def merchant_get_by_id(merchant_id):
    merchant_dict = dict(db.merchant_get_by_id(merchant_id))
    merchant_dict['deadline'] = datetime_toString(merchant_dict['deadline'])
    return merchant_dict