def get_finance_county_brand_dealer(county_id=None, car_brand_id=None, per_page=10, page=1): """ 根据县区ID和品牌ID返回经销商信息 先按VIP排序再按评分排序 参数 ---- county_id : int 县区ID car_brand_id : int 品牌ID per_page : int 当前页返回的数据数量 page : int 页码 返回值 ------ result_list : list 返回经销商数组 """ (offset, count) = common_utils.offset_count(per_page=per_page, page=page) county_id = common_utils.to_int(county_id) car_brand_id = common_utils.to_int(car_brand_id) dealer_id_list = dealer_utils.get_dealer_id_list(county_id=county_id, car_brand_id=car_brand_id) if not dealer_id_list: return None dealer_sql_template = ''' SELECT id, (pre_sales_score+after_sales_score)/2 as sales_score FROM t_base_dealer WHERE is_enable=1 AND is_frozen=0 AND id in ({{dealer_id_list}}) ORDER BY is_vip desc, sales_score desc LIMIT %(offset)s, %(count)s ''' param = { 'dealer_id_list': common_utils.int_list_to_str(dealer_id_list), 'offset': offset, 'count': count, } dealer_sql = Template(dealer_sql_template).render(param) cursor = connection().cursor() cursor.execute(dealer_sql, param) dealers = dictfetchall(cursor) result_list = [] for dealer in dealers: dealer = dealer_utils.get_dealer_by_id(dealer_id=dealer['id']) result_list.append(dealer) return result_list
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
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
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
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
def get_dealer_by_default(city_id=None, county_id=None, brand_id=None, series_id=None, per_page=10, page=1, newest_activity=None): """ PC端找好店首页 WAP端找好店首页-默认 先按VIP排序再按评分排序 参数 ---- city_id : int 城市ID county_id : int, 可选 县区ID brand_id : int, 可选 品牌ID series_id : int, 可选 车系ID per_page : int 当前页返回的数据数量 page : int 页码 newest_activity : int 是否返回最新促销活动数组 activity_list,1返回,0不返回。 会覆盖车系ID对应的促销活动数组 activity_list 返回值 ------ result_dict : dict 返回当前城市的经销商数量和过滤后的经销商数量和经销商数组 """ (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) brand_id = common_utils.to_int(brand_id) series_id = common_utils.to_int(series_id) newest_activity = common_utils.to_int(newest_activity) dealer_id_list = dealer_utils.get_dealer_id_list(city_id=city_id, county_id=county_id, car_brand_id=brand_id, car_series_id=series_id) if not dealer_id_list: return None dealer_sql_template = ''' SELECT id, (pre_sales_score+after_sales_score)/2 as sales_score FROM t_base_dealer WHERE is_enable=1 AND is_frozen=0 AND id in ({{dealer_id_list}}) ORDER BY is_vip desc, sales_score desc LIMIT %(offset)s, %(count)s ''' param = { 'dealer_id_list': common_utils.int_list_to_str(dealer_id_list), 'offset': offset, 'count': count, } dealer_sql = Template(dealer_sql_template).render(param) cursor = connection().cursor() cursor.execute(dealer_sql, param) dealers = dictfetchall(cursor) dealer_list = [] for dealer in dealers: dealer = dealer_utils.get_dealer_by_id(dealer_id=dealer['id']) if newest_activity: tmp_activity_list = activity_utils.get_activity_list_by_dealer( dealer_id=dealer['id'], activity_type=1, ) dealer['activity_list'] = tmp_activity_list elif series_id: activity_list = activity_utils.get_activity_list_by_dealer_series( dealer_id=dealer['id'], car_series_id=series_id) dealer['activity_list'] = activity_list dealer_list.append(dealer) filter_count = len(dealer_id_list) # city count city_count = dealer_utils.get_dealer_count(city_id=city_id) result_dict = { 'city_count': city_count, 'filter_count': filter_count, 'dealer_list': dealer_list, 'page_count': int((filter_count + count - 1) / count), } # filter car series if series_id: result_dict['car_series_list'] = [ car_series_utils.get_carseries_by_id(car_series_id=series_id) ] else: all_dealer_list = dealer_utils.get_dealer_list_by_id_list( dealer_id_list=dealer_id_list) tmp_dict = {} for tmp_dealer in all_dealer_list: if tmp_dealer['car_series_ids']: for tmp_car_series_id in tmp_dealer['car_series_ids']: tmp_dict[tmp_car_series_id] = 1 tmp_car_series_id_list = tmp_dict.keys() car_series_list = [] for tmp_car_series_id in tmp_car_series_id_list: car_series_info = car_series_utils.get_carseries_by_id( car_series_id=tmp_car_series_id) if car_series_info: if brand_id: if car_series_info['car_brand_id'] == brand_id: car_series_list.append(car_series_info) else: car_series_list.append(car_series_info) if car_series_list: car_series_list = sorted( car_series_list, key=lambda tmp_car_series: tmp_car_series['order_no']) result_dict['car_series_list'] = car_series_list return result_dict
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
def get_dealer_by_distance(city_id=None, county_id=None, brand_id=None, series_id=None, longitude=None, latitude=None, per_page=10, page=1, newest_activity=None): """ WAP端找好店首页-离我最近 按经纬度距离排序 参数 ---- city_id : int 城市ID county_id : int, 可选 县区ID brand_id : int, 可选 品牌ID series_id : int, 可选 车系ID longitude : float 经度 latitude : float 纬度 per_page : int 当前页返回的数据数量 page : int 页码 newest_activity : int 是否返回最新促销活动数组 activity_list,1返回,0不返回。 会覆盖车系ID对应的促销活动数组 activity_list 返回值 ------ result_dict : dict 返回当前城市的经销商数量和过滤后的经销商数量和经销商数组 """ (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) brand_id = common_utils.to_int(brand_id) series_id = common_utils.to_int(series_id) longitude = common_utils.to_float(longitude) latitude = common_utils.to_float(latitude) newest_activity = common_utils.to_int(newest_activity) dealer_id_list = dealer_utils.get_dealer_id_list(city_id=city_id, county_id=county_id, car_brand_id=brand_id, car_series_id=series_id) if not dealer_id_list: return None dealer_sql_template = ''' SELECT id, ( (longitude-%(longitude)s)*(longitude-%(longitude)s) +(latitude-%(latitude)s)*(latitude-%(latitude)s) ) AS dealer_distance FROM t_base_dealer WHERE is_enable=1 AND is_frozen=0 AND id in ({{dealer_id_list}}) ORDER BY dealer_distance LIMIT %(offset)s, %(count)s ''' param = { 'dealer_id_list': common_utils.int_list_to_str(dealer_id_list), 'longitude': longitude, 'latitude': latitude, 'offset': offset, 'count': count, } dealer_sql = Template(dealer_sql_template).render(param) cursor = connection().cursor() cursor.execute(dealer_sql, param) dealers = dictfetchall(cursor) dealer_list = [] for dealer in dealers: dealer = dealer_utils.get_dealer_by_id(dealer_id=dealer['id']) dealer['distance'] = common_utils.geo_distance(latitude, longitude, dealer['latitude'], dealer['longitude']) if newest_activity: tmp_activity_list = activity_utils.get_activity_list_by_dealer( dealer_id=dealer['id'], activity_type=1, ) dealer['activity_list'] = tmp_activity_list elif series_id: activity_list = activity_utils.get_activity_list_by_dealer_series( dealer_id=dealer['id'], car_series_id=series_id) if activity_list: dealer['activity_list'] = activity_list dealer_list.append(dealer) filter_count = len(dealer_id_list) # city count city_count = dealer_utils.get_dealer_count(city_id=city_id) result_dict = { 'city_count': city_count, 'filter_count': filter_count, 'dealer_list': dealer_list, 'page_count': int((filter_count + count - 1) / count), } return result_dict