示例#1
0
def get_car_type_price_property(city_id=None, car_type_id=None):
    """
        根据城市ID和车型ID获取基本数据、报价和全部参数

        参数
        ----
        city_id : int
            城市ID
        car_type_id : int
            车型ID

        返回值
        ------
        result_list : list
            返回车型基本数据、报价和全部参数
    """
    city_id = common_utils.to_int(city_id)
    car_type_id = common_utils.to_int(car_type_id)
    car_type = car_type_utils.get_cartype_by_id(car_type_id=car_type_id)
    if not car_type:
        return None

    offer_price = offer_price_utils.get_offerprice(city_id=city_id,
                                                   car_type_id=car_type_id)
    car_type['offer_price'] = offer_price
    car_type['property'] = get_car_type_all_property(car_type_id)
    return car_type
示例#2
0
def get_dealer_activity_series_car_types(dealer_id=None, car_series_id=None):
    """
        WAP端经销商活动页面
        根据经销商ID和车系ID获取所有车型和报价,还有车系的经销商最低价最高价

        参数
        ----
        dealer_id : int
            经销商ID
        car_series_id : int
            车系ID

        返回值
        ------
        result_dict : dict
            返回所有车型和报价,还有车系的经销商最低价最高价
    """
    dealer_id = common_utils.to_int(dealer_id)
    car_series_id = common_utils.to_int(car_series_id)
    car_types = list_objs(model=ModelName.T_BASE_CAR_TYPE,
                          orderby=['guide_price'],
                          is_enable=1,
                          is_show=1,
                          car_series_id=car_series_id)
    if not car_types:
        return None
    car_type_list = []
    car_type_price_min = 99999999
    car_type_price_max = 0
    for car_type in car_types:
        tmp_car_type = car_type_utils.get_cartype_by_id(
            car_type_id=car_type.id)
        if not tmp_car_type:
            continue
        tmp_offer_price = offer_price_utils.get_offerprice(
            dealer_id=dealer_id, car_type_id=car_type.id)
        tmp_car_type['offer_price'] = tmp_offer_price
        car_type_list.append(tmp_car_type)
        # car type price
        if tmp_car_type['offer_price']['price'] < car_type_price_min:
            car_type_price_min = tmp_car_type['offer_price']['price']
        if tmp_car_type['offer_price']['price'] > car_type_price_max:
            car_type_price_max = tmp_car_type['offer_price']['price']
    result_dict = {
        'series':
        car_series_utils.get_carseries_by_id(car_series_id=car_series_id),
        'car_type_list': car_type_list
    }
    activity_list = activity_utils.get_activity_list_by_dealer_series(
        dealer_id=dealer_id, car_series_id=car_series_id)
    result_dict['series']['activity_list'] = activity_list
    result_dict['series']['car_type_price_min'] = car_type_price_min
    result_dict['series']['car_type_price_max'] = car_type_price_max
    return result_dict
示例#3
0
def get_car_series_data(city_id=None, car_series_id=None):
    """
        车系页面,PC和WAP通用。
        根据城市ID,车系ID获取车系对应的基本数据,活动,报价

        参数
        ----
        city_id : int
            城市ID
        car_series_id : int
            车系ID

        返回值
        ------
        result_dict : dict
            报价是当前城市的最低经销商报价,
            如果当前城市ID和车系ID没有经销商报价,
            price用车系的厂家最低价start_guideprice代替
    """
    city_id = common_utils.to_int(city_id)
    car_series_id = common_utils.to_int(car_series_id)
    car_series = car_series_utils.get_carseries_by_id(
        car_series_id=car_series_id)
    if not car_series:
        return None
    car_brand = car_brand_utils.get_carbrand_by_id(car_series['car_brand_id'])
    if not car_brand:
        return None
    activity_list = activity_utils.get_activity_list_by_city_series(
        city_id=city_id, car_series_id=car_series_id)
    for activity in activity_list:
        activity['dealer'] = dealer_utils.get_dealer_by_id(
            dealer_id=activity['dealer_id'])
    result_dict = {
        'brand': car_brand,
        'series': car_series,
        'activity_list': activity_list,
    }

    offer_price = offer_price_utils.get_offerprice(
        city_id=city_id,
        car_series_id=car_series_id,
    )
    result_dict['series']['offer_price'] = offer_price

    return result_dict
示例#4
0
def get_finance_dealer_car_types_price(dealer_id=None, car_type_id=None):
    """
        根据经销商ID和车型ID返回报价

        参数
        ----
        dealer_id : int
            经销商ID
        car_type_id : int
            车型ID

        返回值
        ------
        result_dict : dict
            返回报价
    """
    dealer_id = common_utils.to_int(dealer_id)
    car_type_id = common_utils.to_int(car_type_id)
    offer_price = offer_price_utils.get_offerprice(dealer_id=dealer_id,
                                                   car_type_id=car_type_id)
    return offer_price
示例#5
0
def get_car_type_data(city_id=None, car_type_id=None):
    """
        车型页面,PC和WAP通用,
        根据城市ID和车型ID获取车型数据,最低报价

        参数
        ----
        city_id : int
            城市ID
        car_type_id : int
            车型ID

        返回值
        ------
        result_dict : dict
            返回车型数据,最低报价,如果没有经销商报价就用官方指导价
    """
    city_id = common_utils.to_int(city_id)
    car_type_id = common_utils.to_int(car_type_id)
    car_type = car_type_utils.get_cartype_by_id(car_type_id=car_type_id)
    if not car_type:
        return None
    car_series = car_series_utils.get_carseries_by_id(
        car_series_id=car_type['car_series_id'])
    if not car_series:
        return None
    car_brand = car_brand_utils.get_carbrand_by_id(
        car_brand_id=car_series['car_brand_id'])
    if not car_brand:
        return None
    result_dict = {
        'brand': car_brand,
        'series': car_series,
        'type': car_type,
    }

    offer_price = offer_price_utils.get_offerprice(city_id=city_id,
                                                   car_type_id=car_type_id)
    result_dict['type']['offer_price'] = offer_price
    return result_dict
示例#6
0
def get_lowest_monthly_payment(city_id=None,
                               car_series_id=None,
                               car_type_id=None,
                               dealer_id=None,
                               finacial_product_id=None,
                               price=None):
    '''
        根据城市、车系,获取最低月供的金融方案
    '''
    offer_price = {
        "public_offer_price": price,
        "car_series_id": car_series_id,
        "car_type_id": car_type_id,
        "dealer_id": dealer_id
    }
    if not price:
        kw = {}
        if car_series_id: kw['car_series_id'] = car_series_id
        if car_type_id: kw['car_type_id'] = car_type_id
        if dealer_id: kw['dealer_id'] = dealer_id
        _offer_price = offer_price_utils.get_offerprice(**kw)
        offer_price['public_offer_price'] = _offer_price['public_offer_price']

    sql = """
        select * from (
            select
            p.id as product_id,
            p.is_final_payment,
            p.final_payment_scale,
            p.repayment_type,
            fpp.id as first_percent_id,
            fpp.FIRST_PAY_PERCENT as first_pay_percent,
            sku.id as sku_id,
            sku.SKU_ITEM as sku_item,
            sku.sku_rate as sku_rate,
            first_pay_percent * sku_item as less_monthly_flag
            FROM
            t_base_financial_product p,
            t_base_financial_first_pay_percent_rel fpp,
            t_base_financial_pro_sku sku,
            t_base_financial_series_rel fs
            where
            p.id = fpp.FINACIAL_PRODUCT_ID and
            p.id = sku.FINACIAL_PRODUCT_ID and
            p.id = fs.FINANCIAL_PRODUCT_ID and
            p.EFFECT_START_DATE <= now() and
            p.EFFECT_END_DATE >= now() and
            p.is_enable = 1 and
            fs.CAR_SERIES_ID = %(car_series_id)s
            {% if finacial_product_id -%}
            and p.id = %(finacial_product_id)s
            {%- endif %}
        ) xxx
        order by xxx.less_monthly_flag desc
        limit 1;
    """

    kw = {
        'car_series_id': car_series_id,
        'finacial_product_id': finacial_product_id
    }
    finance_data = db.fetchone(sql, kw)
    if not finance_data:
        return {}

    finance_data.update(offer_price)

    rtn_data = calc_financial(**finance_data)
    finance_data.update(rtn_data)

    return finance_data
示例#7
0
def list_financials(car_series_id=None,
                    car_type_id=None,
                    dealer_id=None,
                    first_pay_percent=0,
                    sku_item=0,
                    city_id=None,
                    order_by='monthly_payment',
                    corp_ids=None):
    '''
    '''
    order_dict = {
        'monthly_payment': 'xxx.less_monthly_flag',
        '-monthly_payment': 'xxx.less_monthly_flag desc',
        'hot': 'xxx.pass_percent',
        '-hot': 'xxx.pass_percent desc',
    }
    sql = """
        select distinct * from (
            select
            c.id as corp_id,
            c.corp_name,
            c.corp_logo,
            p.id as product_id,
            p.financial_product_name,
            p.pass_percent,
            p.repayment_type,
            p.is_final_payment,
            p.final_payment_scale,
            fpp.id as first_percent_id,
            fpp.FIRST_PAY_PERCENT as first_pay_percent,
            sku.id as sku_id,
            sku.SKU_ITEM as sku_item,
            sku.sku_rate as sku_rate,
            first_pay_percent * sku_item as less_monthly_flag
            FROM
            t_base_financial_product p,
            t_base_financial_corp c,
            t_base_financial_first_pay_percent_rel fpp,
            t_base_financial_pro_sku sku,
            t_base_financial_series_rel fs
            where
            p.id = fpp.FINACIAL_PRODUCT_ID and
            p.FINANCIAL_CORP_ID=c.ID and
            p.id = sku.FINACIAL_PRODUCT_ID and
            p.id = fs.FINANCIAL_PRODUCT_ID and
            p.EFFECT_START_DATE <= now() and
            p.EFFECT_END_DATE >= now() and
            p.is_enable = 1 and
            fs.CAR_SERIES_ID = %(car_series_id)s and
            fpp.FIRST_PAY_PERCENT = %(first_pay_percent)s and
            sku.sku_item = %(sku_item)s
            {% if corp_ids %}
            and c.id in ({{corp_ids}})
            {% endif %}
        ) xxx
        {% if order_by -%}
        order by {{order_by}}
        {% endif %}
    """

    kw = {}
    kw['car_series_id'] = car_series_id
    kw['first_pay_percent'] = first_pay_percent
    kw['sku_item'] = sku_item
    kw['corp_ids'] = corp_ids
    kw['order_by'] = order_dict.get(order_by, None)
    finance_datas = db.fetch(sql, kw)

    kw = {}
    if car_series_id: kw['car_series_id'] = car_series_id
    if car_type_id: kw['car_type_id'] = car_type_id
    if dealer_id: kw['dealer_id'] = dealer_id
    offer_price = offer_price_utils.get_offerprice(**kw)

    for finance_data in finance_datas:
        finance_data['public_offer_price'] = offer_price['public_offer_price']
        rtn_data = calc_financial(**finance_data)
        finance_data.update(rtn_data)

    for item in finance_datas:
        sql = "SELECT condition_name FROM t_base_financial_condition_rel WHERE is_enable=1 and FINACIAL_PRODUCT_ID = " + str(
            item['product_id']) + " GROUP BY CONDITION_NAME"
        item['conditions'] = db.fetch_col_array(sql, {}, 'condition_name')
        sql = "SELECT material_name FROM t_base_financial_material_rel WHERE is_enable=1 and FINACIAL_PRODUCT_ID = " + str(
            item['product_id']) + " GROUP BY MATERIAL_NAME"
        item['materials'] = db.fetch_col_array(sql, {}, 'material_name')
        sql = """
            select
            b.dict_key,b.dict_value,b.dict_ext_values,
            a.id,a.FEATURE_ID
            from t_base_financial_feature_rel a, t_base_data_dict b
            where
            b.id = a.feature_id and
            a.IS_ENABLE = 1 and
            b.is_enable = 1 and
            FINACIAL_PRODUCT_ID=%(product_id)s
        """
        features = db.fetch(sql, {'product_id': item['product_id']})
        for feature in features:
            feature['dict_ext_values'] = eval(feature['dict_ext_values'])
        item['features'] = features

    # order by monthly pay amount
    if 'monthly_payment' in order_by:
        reverse_flag = True if '-' in order_by else False
        finance_datas = sorted(finance_datas,
                               reverse=reverse_flag,
                               key=lambda t: t['monthly_pay_amount'])

    return finance_datas
示例#8
0
def get_financial_pack_data(city_id=None,
                            car_series_id=None,
                            car_type_id=None,
                            dealer_id=None,
                            finacial_product_id=None,
                            sku_item=None,
                            first_pay_percent=None):
    '''
        根据参数,获取金融相关包装数据
    '''
    finance_data = get_object(model=ModelName.T_BASE_FINANCIAL_PRODUCT,
                              id=finacial_product_id,
                              is_enable=1)
    finance_data = convert_obj(finance_data)

    # fetch finance corp
    finance_corp = get_object(model=ModelName.T_BASE_FINANCIAL_CORP,
                              id=finance_data['financial_corp_id'],
                              is_enable=1)
    finance_data['corp_id'] = finance_corp.id
    finance_data['corp_name'] = finance_corp.corp_name

    # fetch price
    kw = {}
    if car_series_id: kw['car_series_id'] = car_series_id
    if car_type_id: kw['car_type_id'] = car_type_id
    if dealer_id: kw['dealer_id'] = dealer_id
    _offer_price = offer_price_utils.get_offerprice(**kw)
    offer_price = {
        "public_offer_price": _offer_price['public_offer_price'],
        "car_series_id": car_series_id,
        "car_type_id": car_type_id,
        "dealer_id": dealer_id
    }
    finance_data.update(offer_price)

    # fetch first pay percent
    first_pay_percent_obj = get_object(
        model=ModelName.T_BASE_FINANCIAL_FIRST_PAY_PERCENT_REL,
        finacial_product_id=finacial_product_id,
        first_pay_percent=first_pay_percent,
        is_enable=1)
    if not first_pay_percent_obj:
        return {}
    first_pay_percent_obj = convert_obj(first_pay_percent_obj)
    finance_data['first_pay_percent_id'] = first_pay_percent_obj['id']
    finance_data['first_pay_percent'] = first_pay_percent_obj[
        'first_pay_percent']

    # fetch sku
    financial_pro_sku_obj = get_object(
        model=ModelName.T_BASE_FINANCIAL_PRO_SKU,
        is_enable=1,
        finacial_product_id=finacial_product_id,
        sku_item=sku_item)
    if not financial_pro_sku_obj:
        return {}

    financial_pro_sku_obj = convert_obj(financial_pro_sku_obj)
    finance_data['sku_id'] = financial_pro_sku_obj['id']
    finance_data['sku_name'] = financial_pro_sku_obj['sku_name']
    finance_data['sku_item'] = financial_pro_sku_obj['sku_item']
    finance_data['sku_rate'] = financial_pro_sku_obj['sku_rate']

    rtn_data = calc_financial(**finance_data)
    finance_data.update(rtn_data)

    return finance_data
示例#9
0
def get_finance_car_type_dealer(city_id=None,
                                county_id=None,
                                car_type_id=None,
                                per_page=10,
                                page=1):
    """
        任性贷车型页面,PC和WAP通用
        根据城市ID、县区ID和车型ID返回车型的经销商和报价
        排序按 堡垒店-》价格
        如果当前城市没有经销商,就返回最近的售全省的经销商的报价

        参数
        ----
        city_id : int
            城市ID
        county_id : int, 可选
            县区ID
        car_type_id : int
            车型ID
        per_page : int
            当前页返回的数据数量
        page : int
            页码

        返回值
        ------
        result_list : list
            返回车型的经销商和报价
    """
    (offset, count) = common_utils.offset_count(per_page=per_page, page=page)
    city_id = common_utils.to_int(city_id)
    county_id = common_utils.to_int(county_id)
    car_type_id = common_utils.to_int(car_type_id)

    car_type = car_type_utils.get_cartype_by_id(car_type_id=car_type_id)
    if not car_type:
        return None

    dealer_id_list = dealer_utils.get_dealer_id_list(
        city_id=city_id,
        county_id=county_id,
        car_series_id=car_type['car_series_id'])
    if not dealer_id_list:
        return None
    result_list = []
    for dealer_id in dealer_id_list:
        tmp_dealer = dealer_utils.get_dealer_by_id(dealer_id=dealer_id)
        if not tmp_dealer:
            continue
        tmp_offer_price = offer_price_utils.get_offerprice(
            car_type_id=car_type_id, dealer_id=dealer_id)
        car_type_dict = {
            'dealer': tmp_dealer,
            'offer_price': tmp_offer_price,
        }
        result_list.append(car_type_dict)
    if result_list:
        result_list = sorted(result_list,
                             key=lambda tmp_car_type:
                             (-tmp_car_type['dealer']['is_vip'], tmp_car_type[
                                 'offer_price']['public_offer_price']))
        result_list = result_list[offset:(offset + count)]
    return result_list
示例#10
0
def get_finance_group_series_car_types(car_series_id=None,
                                       property_key='pailiang'):
    """
        根据车系ID获取所有车型,然后根据property_key属性进行分组排序,
        并返回经销商报价

        参数
        ----
        car_series_id : int
            车系ID
        property_key : str
            车系下的车型按什么属性分组,例如'pailiang'按排量分组

        返回值
        ------
        result_list : list
            返回车系下所有排序好的车型
    """
    car_series_id = common_utils.to_int(car_series_id)
    car_types = list_objs(model=ModelName.T_BASE_CAR_TYPE,
                          is_enable=1,
                          is_show=1,
                          car_series_id=car_series_id)
    if not car_types:
        return None
    car_ids = list(car_types.values_list('id', flat=True))
    car_type_prop = get_object(
        model=ModelName.T_BASE_CAR_TYPE_PROPERTY_TEMPLATE,
        is_enable=1,
        property_key=property_key)
    if not car_type_prop:
        return None
    car_props = list_objs(model=ModelName.T_BASE_CAR_TYPE_PROPERTY,
                          orderby=['property_value'],
                          is_enable=1,
                          property_id=car_type_prop.id,
                          car_type_id__in=car_ids)
    if not car_props:
        return None
    car_type_dict = {}
    for car_type in car_types:
        tmp_car_type = car_type_utils.get_cartype_by_id(
            car_type_id=car_type.id)
        if not tmp_car_type:
            continue
        tmp_offer_price = offer_price_utils.get_offerprice(
            car_type_id=car_type.id)
        tmp_car_type['offer_price'] = tmp_offer_price
        car_type_dict[car_type.id] = tmp_car_type
    car_dict = {}
    for car_prop in car_props:
        key = car_prop.property_value
        if key in car_dict:
            if car_prop.car_type_id in car_type_dict:
                car_dict[key].append(car_type_dict[car_prop.car_type_id])
        else:
            car_dict[key] = []
            if car_prop.car_type_id in car_type_dict:
                car_dict[key].append(car_type_dict[car_prop.car_type_id])
    dict_keys = car_dict.keys()
    sorted_dict_keys = sorted(dict_keys)
    data_list = []
    for key in sorted_dict_keys:
        data_dict = {'value': key, 'car_type_list': car_dict[key]}
        data_list.append(data_dict)
    return data_list
示例#11
0
def get_car_series_dealer(city_id=None,
                          county_id=None,
                          car_series_id=None,
                          per_page=10,
                          page=1,
                          orderby='price',
                          descending=False):
    """
        WAP端车系页面
        返回对应城市、县区和车系的经销商

        参数
        ----
        city_id : int
            城市ID
        county_id : int, 可选
            县区ID
        car_series_id : int
            车系ID
        per_page : int
            当前页返回的数据数量
        page : int
            页码
        orderby : {'price', 'discount'}
            price按报价排序,discount按优惠排序
        descending : {0, 1}
            0按升序,1按降序

        返回值
        ------
        result_list : list
            返回经销商数组,包括对应车系的促销活动
    """
    (offset, count) = common_utils.offset_count(per_page=per_page, page=page)
    city_id = common_utils.to_int(city_id)
    county_id = common_utils.to_int(county_id)
    car_series_id = common_utils.to_int(car_series_id)
    orderby_price = True
    if orderby == 'discount':
        orderby_price = False
    else:
        orderby_price = True
    if descending:
        if isinstance(descending, str) and (descending.upper() != 'TRUE'):
            descending = False

    dealer_id_list = dealer_utils.get_dealer_id_list(
        city_id=city_id, county_id=county_id, car_series_id=car_series_id)
    if not dealer_id_list:
        return None
    result_list = []
    for dealer_id in dealer_id_list:
        tmp_dealer = dealer_utils.get_dealer_by_id(dealer_id=dealer_id)
        if not tmp_dealer:
            continue
        tmp_dealer['offer_price'] = offer_price_utils.get_offerprice(
            city_id=city_id,
            dealer_id=tmp_dealer['id'],
            car_series_id=car_series_id)
        activity_list = activity_utils.get_activity_list_by_dealer_series(
            dealer_id=tmp_dealer['id'], car_series_id=car_series_id)
        tmp_dealer['activity_list'] = activity_list
        result_list.append(tmp_dealer)
    if result_list:
        result_list = offer_price_utils.sorted_offer_price_list(
            offer_price_list=result_list,
            orderby_price=orderby_price,
            descending=descending)
        result_list = result_list[offset:(offset + count)]
    return result_list
示例#12
0
def get_on_sale_car_types(city_id=None,
                          car_series_id=None,
                          per_page=10,
                          page=1,
                          orderby='price',
                          descending=False):
    """
        车系页面,PC和WAP通用,
        根据城市ID和车系ID获取在售车型,按报价或者优惠排序
        返回值里的financial目前是在PC端用到

        参数
        ----
        city_id : int
            城市ID
        car_series_id : int
            车系ID
        per_page : int
            当前页返回的数据数量
        page : int
            页码
        orderby : {'price', 'discount'}
            price按报价排序,discount按优惠排序
        descending : {0, 1}
            0按升序,1按降序

        返回值
        ------
        result_dict : dict
            返回车系基本数据和车型数组
    """
    city_id = common_utils.to_int(city_id)
    car_series_id = common_utils.to_int(car_series_id)
    (offset, count) = common_utils.offset_count(per_page=per_page, page=page)
    orderby_price = True
    if orderby == 'discount':
        orderby_price = False
    else:
        orderby_price = True
    if descending:
        if isinstance(descending, str) and (descending.upper() != 'TRUE'):
            descending = False

    car_series = car_series_utils.get_carseries_by_id(
        car_series_id=car_series_id)
    if not car_series:
        return None

    car_type_id_list = car_type_utils.get_cartype_id_list_by_series(
        car_series_id=car_series_id)
    if not car_type_id_list:
        return None

    car_type_list = []
    for car_type_id in car_type_id_list:
        tmp_car_type = car_type_utils.get_cartype_by_id(
            car_type_id=car_type_id)
        if not tmp_car_type:
            continue
        tmp_offer_price = offer_price_utils.get_offerprice(
            city_id=city_id, car_type_id=car_type_id)
        tmp_car_type['offer_price'] = tmp_offer_price
        if 'dealer_id' in tmp_offer_price:
            tmp_dealer = dealer_utils.get_dealer_by_id(
                tmp_offer_price['dealer_id'])
            tmp_car_type['dealer'] = tmp_dealer
        else:
            tmp_car_type['dealer'] = None

        financial = get_lowest_monthly_payment(
            city_id=city_id,
            car_series_id=car_series_id,
            car_type_id=car_type_id,
            price=tmp_car_type['offer_price']['price'])
        tmp_car_type['financial'] = financial

        car_type_list.append(tmp_car_type)
    if car_type_list:
        car_type_list = offer_price_utils.sorted_offer_price_list(
            offer_price_list=car_type_list,
            orderby_price=orderby_price,
            descending=descending)
        car_type_list = car_type_list[offset:(offset + count)]
    result_dict = {'series': car_series, 'car_type_list': car_type_list}
    return result_dict
示例#13
0
def get_car_catalog_brand_data(city_id=None,
                               car_brand_id=None,
                               per_page=10,
                               page=1):
    """
        PC端惠挑车首页.
        根据品牌ID返回车系信息

        参数
        ----
        city_id : int
            城市ID
        car_brand_id : int
            品牌ID
        per_page : int
            当前页要获取的数据数量
        page : int
            页码

        返回值
        ------
        result_list : list
            根据t_base_car_series的order_no升序排序.
    """
    (offset, count) = common_utils.offset_count(per_page=per_page, page=page)
    city_id = common_utils.to_int(city_id)
    car_brand_id = common_utils.to_int(car_brand_id)
    car_series = None
    if car_brand_id == 0:
        car_series = list_objs(model=ModelName.T_BASE_CAR_SERIES,
                               orderby=['order_no'],
                               offset=offset,
                               count=count,
                               is_enable=1,
                               is_show=1)
    else:
        car_series = list_objs(model=ModelName.T_BASE_CAR_SERIES,
                               orderby=['order_no'],
                               offset=offset,
                               count=count,
                               is_enable=1,
                               is_show=1,
                               car_brand_id=car_brand_id)
    if not car_series:
        return None
    result_list = []
    for series in car_series:
        car_brand = car_brand_utils.get_carbrand_by_id(
            car_brand_id=series.car_brand_id)
        if not car_brand:
            continue
        series_data = {
            'brand':
            car_brand,
            'series':
            car_series_utils.get_carseries_by_id(car_series_id=series.id),
        }
        series_data['series']['offer_price'] = {}
        series_data['series']['activity_list'] = []

        offer_price = offer_price_utils.get_offerprice(
            city_id=city_id,
            car_series_id=series.id,
        )
        if 'dealer_id' in offer_price:
            series_data['series']['offer_price'] = offer_price
            activity_list = activity_utils.get_activity_list_by_dealer_series(
                dealer_id=offer_price['dealer_id'], car_series_id=series.id)
            series_data['series']['activity_list'] = activity_list
        else:
            series_data['series']['offer_price'] = {
                'public_offer_price':
                common_utils.to_int(series.start_guideprice),
                'price': common_utils.to_int(series.start_guideprice),
                'discount': 0,
                'guide_price': common_utils.to_int(series.start_guideprice),
            }
        financial = {}
        financial = get_lowest_monthly_payment(
            city_id=city_id,
            car_series_id=series.id,
            price=series_data['series']['offer_price']['price'])
        series_data['series']['financial'] = financial
        result_list.append(series_data)
    return result_list
示例#14
0
def get_dealer_on_sale_car_types(dealer_id=None,
                                 car_type=0,
                                 per_page=10,
                                 page=1):
    """
        找好店 PC端店铺页|WAP端商家详情页,
        根据经销商ID和官网车型级别查询在售车型

        参数
        ----
        dealer_id : int
            经销商ID
        car_type : {0, 1, 2, 3, 4}
            官网车型级别参数,0为全部,1是三厢,2是两厢,3是SUV,4是进口
        per_page : int
            当前页返回的数据数量
        page : int
            页码

        返回值
        ------
        result_list : list
            返回当前经销商的在售车系和对应的所有车型,根据车型报价排序
    """
    (offset, count) = common_utils.offset_count(per_page=per_page, page=page)
    dealer_id = common_utils.to_int(dealer_id)
    official_car_type = common_utils.to_int(car_type)

    dealer = dealer_utils.get_dealer_by_id(dealer_id)
    if not dealer:
        return None
    sale_series_id_list = dealer['car_series_ids']
    car_series_list = None
    if official_car_type == 0:
        car_series_list = list_objs(model=ModelName.T_BASE_CAR_SERIES,
                                    orderby=['order_no'],
                                    offset=offset,
                                    count=count,
                                    is_enable=1,
                                    is_show=1,
                                    id__in=sale_series_id_list)
    else:
        car_series_list = list_objs(model=ModelName.T_BASE_CAR_SERIES,
                                    orderby=['order_no'],
                                    offset=offset,
                                    count=count,
                                    is_enable=1,
                                    is_show=1,
                                    id__in=sale_series_id_list,
                                    official_car_level=official_car_type)
    result_list = []
    for tmp_car_series in car_series_list:
        car_type_id_list = car_type_utils.get_cartype_id_list_by_series(
            car_series_id=tmp_car_series.id)
        if not car_type_id_list:
            continue
        car_type_list = []
        for car_type_id in car_type_id_list:
            car_type = car_type_utils.get_cartype_by_id(
                car_type_id=car_type_id)
            if not car_type:
                continue
            car_type['offer_price'] = offer_price_utils.get_offerprice(
                dealer_id=dealer_id, car_type_id=car_type_id)
            car_type_list.append(car_type)
        if car_type_list:
            car_type_list = sorted(car_type_list,
                                   key=lambda tmp_car_type:
                                   (tmp_car_type['offer_price']['price']))
        activity_list = activity_utils.get_activity_list_by_dealer_series(
            dealer_id=dealer_id, car_series_id=tmp_car_series.id)
        info_dict = {
            'series':
            car_series_utils.get_carseries_by_id(
                car_series_id=tmp_car_series.id),
            'type_list':
            car_type_list,
            'activity_list':
            activity_list,
        }
        result_list.append(info_dict)
    result_list = sorted(result_list,
                         key=lambda price:
                         (price['type_list'][0]['offer_price']['price']
                          if price['type_list'] else 0))
    return result_list