def refresh(cls, lookup_type, account_info=None): if not account_info: from application.models.hwaccount import HwjdAccount # 如果没有传hwjd账号,则默认使用高德店的账号来获取基本配置信息 account_info = HwjdAccount.find_by_store_id(11) from application.integration.hwjd import get_hwjd_scrb_info results = get_hwjd_scrb_info(account_info, lookup_type) if len(results) > 0: cls.query.filter(cls.type == lookup_type).delete() for item in results: lookup = HwjdLookup() lookup.type = lookup_type lookup.code = item['CODE'] lookup.name = item['NAME'] lookup.extra = item['GGXH'] if lookup.type == u'品牌类型': names = lookup.name.split('-') if len(names) >= 2: lookup.make = names[0] lookup.model = names[1] db.session.add(lookup) return results
def update_hwjd_oa(hwjd_customer): account_info = HwjdAccount.find_by_store_id(hwjd_customer.store_id) if account_info: params = dict() params['Companycode'] = account_info.org_code params['Usercode'] = account_info.user_code params['Password'] = account_info.password params['Version'] = API_VERSION params['P_xml'] = hwjd_customer.to_xml() try: r = requests.post(Config.HWJD_OA_SERVER + HWJD_OA_SYNC_CUSTOMER_API, data=params) if r and r.status_code == 200 and 'OK' in r.content: return SUCCESS except: return FAIL return FAIL
def convert_from_reception(cls, reception): hc = cls.find_by_reception_id(reception.id) if not hc: hc = cls() hc.reception_id = reception.id hc.customer_id = reception.customer_id hc.store_id = reception.store_id hc.uuid = str(uuid.uuid4()) customer = reception.customer from application.models.hwaccount import HwjdAccount hwjd_account = HwjdAccount.find_by_store_id(hc.store_id) hc.company_code = hwjd_account.org_code if hwjd_account else '' hc.created_date = reception.rx_date hc.intent_car_code, hc.intent_car_model, hc.intent_car_name = convert_car_code( hc.store_id, customer.intent_car_ids) hc.visit_type = convert_visit_type(reception.rx_type) hc.rx_start = reception.created_on.strftime(TIME_FORMAT_WO_SEC) hc.rx_end = (reception.created_on + timedelta( seconds=reception.rx_duration)).strftime(TIME_FORMAT_WO_SEC) hc.rx_duration = reception.rx_duration hc.rx_type = convert_rx_type(reception.rx_type) hc.channel = u'其他' hc.sales = reception.sales.username hc.intent_car_color = customer.intent_car_colors.split( ',')[0] if customer.intent_car_colors and len( customer.intent_car_colors) > 0 else '' hc.intent_order_date = None hc.budget = customer.budget hc.payment = customer.payment hc.purchase_type = convert_purchase_type(customer) hc.intent_level = LookupValue.get_vendor_code_by_code( customer.intent_level, hc.store_id, 'intent-level') hc.on_file = convert_boolean(customer.mobile and len(customer.mobile) >= 11) hc.has_trail = convert_boolean( customer.test_drive_car_ids and customer.test_drive_car_ids != 'none' and len(customer.test_drive_car_ids) > 0) hc.name = customer.respect_name hc.age_group = LookupValue.get_vendor_code_by_code( customer.channel, hc.store_id, 'age-group') hc.gender = customer.gender_str hc.mobile = customer.mobile if customer.mobile and customer.mobile != '000' else '' hc.has_order = convert_boolean( Order.has_valid_orders_by_customer(hc.customer_id)) hc.discount = '' hc.price = '' hc.gadgets_gift = u'否' hc.gadgets_purchase = u'否' hc.competing_car_brand = u'未定' hc.competing_car_name = u'未定' hc.used_car_model = u'无' hc.remark = customer.remark from application.models.customer import CustomerAddlInfo addl_info = CustomerAddlInfo.find_by_customer_id(reception.customer_id) if addl_info: hc.purpose = addl_info.purpose hc.industry = addl_info.industry hc.district = addl_info.district hc.dealership = addl_info.dealership hc.used_car_value = addl_info.used_car_value hc.has_used_car_assess = addl_info.has_used_car_assessed return hc