def get_premium_rate(request): if request.method == 'POST': product_code = request.POST.get('product_code', None) application_age = request.POST.get('application_age', None) gender = request.POST.get('gender', None) smoker = request.POST.get('smoker', None) premium_period = request.POST.get('premium_period', None) benefit_age_max = request.POST.get('benefit_age_max', 100) sum_insured = request.POST.get('sum_insured', 0) if product_code == None or application_age == None or gender == None or smoker == None or premium_period == None: errmsg = 'params error' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response try: premium_rate_obj = premium_rate.objects.filter(product_code=int(product_code), application_age=int(application_age), gender__in=[int(gender), 2], smoker__in=[int(smoker), 2], premium_period=int(premium_period), benefit_age_max=int(benefit_age_max)) premium_rslt = -1 if len(premium_rate_obj) > 0: premium_rslt = premium_rate_obj[0].annual_premium_10k * float(sum_insured) rslt = {} rslt['premium'] = premium_rslt rslt['feature'] = product.objects.filter(product_code=int(product_code))[0].feature_desc rslt_json = json.dumps(generate_response.gen('premium_info', rslt, return_code.NORMAL_RESPONSE, None)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response except Excetion, e: errmsg = 'invalid request' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.INVALID_REQUEST, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def filter_university(request): if request.method == 'POST': try: region = request.POST.get('region', None) expert = request.POST.get('expert', 'qs_ranking') yearly_cost = int(request.POST.get('yearly_cost', 99999999)) page = int(request.POST.get('page', 0)) expert_condition = {} expert_condition[expert+'__gte'] = 1 print expert_condition university_list = [] this_year = str(datetime.datetime.now().year) + '-1-1' print len(university_ranking.objects.filter(year__gte=this_year).order_by(expert)) for ur_obj in university_ranking.objects.filter(year__gte=this_year).filter(**expert_condition).order_by(expert): uf_obj = university_fee.objects.filter(university_code=ur_obj.university_code, year__gte=this_year)[0] u_obj = university.objects.filter(university_code=ur_obj.university_code)[0] u_obj_json = {} if uf_obj.cost <= yearly_cost and ( region == None or region == ''): u_obj_json['university_code'] = ur_obj.university_code u_obj_json['university_ranking'] = ur_obj.qs_ranking u_obj_json['university_name'] = u_obj.name_cn university_list.append(u_obj_json) elif uf_obj.cost <= yearly_cost and u_obj.region == region: u_obj_json['university_code'] = ur_obj.university_code u_obj_json['university_ranking'] = ur_obj.qs_ranking u_obj_json['university_name'] = u_obj.name_cn university_list.append(u_obj_json) else: print 'ha? university_code:', ur_obj.university_code sub_university_list_json = {} if page != 0: page = page - 1 sub_university_list_json['sub_list'] = university_list[page*5:page*5+5] sub_university_list_json['total_count'] = len(university_list) rslt_json = json.dumps(generate_response.gen('sub_university_list', sub_university_list_json, return_code.NORMAL_RESPONSE, None)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response except Excetion, e: errmsg = 'invalid request' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.INVALID_REQUEST, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def get_university_info(request): if request.method == 'POST': university_code = request.POST.get('university_code', None) ip_addr = request.POST.get('ip_addr', None) session_id = request.POST.get('session_id', None) client_tag = str(ip_addr) + '_' + str(session_id) if university_code == None: errmsg = 'params error' rslt_json = json.dumps( generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response u_obj = university.objects.filter(university_code=university_code)[0] this_year = str(datetime.datetime.now().year) + '-1-1' ur_obj = university_ranking.objects.filter( university_code=university_code, year__gte=this_year)[0] uf_obj = university_fee.objects.filter(university_code=university_code, year__gte=this_year)[0] university_info_json = {} university_info_json['name_cn'] = u_obj.name_cn university_info_json['name_en'] = u_obj.name_en university_info_json['qs_ranking'] = ur_obj.qs_ranking university_info_json['cost'] = uf_obj.cost university_info_json['country'] = u_obj.country university_info_json['website'] = u_obj.website university_info_json['introduction'] = u_obj.introduction university_info_json['logo'] = u_obj.logo university_info_json['pic1'] = u_obj.pic1 university_info_json['pic2'] = u_obj.pic2 university_info_json['pic3'] = u_obj.pic3 rslt_json = json.dumps( generate_response.gen('university_info', university_info_json, return_code.NORMAL_RESPONSE, None)) client_action_obj = client_action.objects.create( client_tag=client_tag, action_name='get_university_info', action_post=json.dumps(request.POST), action_return=json.dumps(university_info_json)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def filter_university(request): if request.method == 'POST': region = request.POST.get('region', None) expert = request.POST.get('expert', 'qs_ranking') yearly_cost = int(request.POST.get('yearly_cost', 99999999)) page = int(request.POST.get('page', 0)) ip_addr = request.POST.get('ip_addr', None) session_id = request.POST.get('session_id', None) client_tag = str(ip_addr) + '_' + str(session_id) expert_condition = {} expert_condition[expert + '__gte'] = 1 print expert_condition university_list = [] this_year = str(datetime.datetime.now().year) + '-1-1' print len( university_ranking.objects.filter( year__gte=this_year).order_by(expert)) for ur_obj in university_ranking.objects.filter( year__gte=this_year).filter( **expert_condition).order_by(expert): uf_obj = university_fee.objects.filter( university_code=ur_obj.university_code, year__gte=this_year)[0] u_obj = university.objects.filter( university_code=ur_obj.university_code)[0] u_obj_json = {} if uf_obj.cost <= yearly_cost and (region == None or region == ''): u_obj_json['university_code'] = ur_obj.university_code u_obj_json['university_ranking'] = ur_obj.qs_ranking u_obj_json['university_name'] = u_obj.name_cn university_list.append(u_obj_json) elif uf_obj.cost <= yearly_cost and u_obj.region == region: u_obj_json['university_code'] = ur_obj.university_code u_obj_json['university_ranking'] = ur_obj.qs_ranking u_obj_json['university_name'] = u_obj.name_cn university_list.append(u_obj_json) else: print 'ha? university_code:', ur_obj.university_code sub_university_list_json = {} if page != 0: page = page - 1 sub_university_list_json['sub_list'] = university_list[page * 5:page * 5 + 5] sub_university_list_json['total_count'] = len(university_list) rslt_json = json.dumps( generate_response.gen('sub_university_list', sub_university_list_json, return_code.NORMAL_RESPONSE, None)) client_action_obj = client_action.objects.create( client_tag=client_tag, action_name='filter_university', action_post=json.dumps(request.POST), action_return=json.dumps(sub_university_list_json)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def get_premium_rate_range(request): if request.method == 'POST': product_code = request.POST.get('product_code', None) application_age = request.POST.get('application_age', None) if product_code == None: errmsg = 'params error' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response try: premium_rate_range_json = {} application_age_min = 100 application_age_max = 0 premium_period_range = [] benefit_age_range = [] premium_rate_obj_arr = [] if application_age == None: premium_rate_obj_arr = premium_rate.objects.filter(product_code=int(product_code)) else: premium_rate_obj_arr = premium_rate.objects.filter(product_code=int(product_code), application_age=int(application_age)) for premium_rate_obj in premium_rate_obj_arr: if premium_rate_obj.application_age < application_age_min: application_age_min = premium_rate_obj.application_age if premium_rate_obj.application_age > application_age_max: application_age_max = premium_rate_obj.application_age premium_period_range.append(premium_rate_obj.premium_period) benefit_age_range.append(premium_rate_obj.benefit_age_max) premium_rate_range_json['premium_period_range'] = list(set(premium_period_range)) premium_rate_range_json['benefit_age_range'] = list(set(benefit_age_range)) premium_rate_range_json['application_age_min'] = application_age_min premium_rate_range_json['application_age_max'] = application_age_max rslt_json = json.dumps(generate_response.gen('premium_rate_range', premium_rate_range_json, return_code.NORMAL_RESPONSE, None)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response except Excetion, e: errmsg = 'invalid request' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.INVALID_REQUEST, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def get_insurance_list(request): if request.method == 'POST': product_type = request.POST.get('product_type', None) region = request.POST.get('region', None) ip_addr = request.POST.get('ip_addr', None) session_id = request.POST.get('session_id', None) client_tag = str(ip_addr) + '_' + str(session_id) if product_type == None or region == None: errmsg = 'params error' rslt_json = json.dumps( generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response product_list = [] for insurer_obj in insurer.objects.filter(region=region): for product_obj in product.objects.filter( product_type=int(product_type), insurer_code=insurer_obj.insurer_code): product_list_obj = {} product_list_obj['product_code'] = product_obj.product_code product_list_obj['product_name'] = product_obj.product_name product_list.append(product_list_obj) product_list_json = {} product_list_json['product_list'] = product_list rslt_json = json.dumps( generate_response.gen('product_list', product_list_json, return_code.NORMAL_RESPONSE, None)) client_action_obj = client_action.objects.create( client_tag=client_tag, action_name='get_insurance_list', action_post=json.dumps(request.POST), action_return=json.dumps(product_list_json)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def get_university_info(request): if request.method == 'POST': university_code = request.POST.get('university_code', None) if university_code == None: errmsg = 'params error' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response try: u_obj = university.objects.filter(university_code=university_code)[0] this_year = str(datetime.datetime.now().year) + '-1-1' ur_obj = university_ranking.objects.filter(university_code=university_code, year__gte=this_year)[0] uf_obj = university_fee.objects.filter(university_code=university_code, year__gte=this_year)[0] university_info_json = {} university_info_json['name_cn'] = u_obj.name_cn university_info_json['name_en'] = u_obj.name_en university_info_json['qs_ranking'] = ur_obj.qs_ranking university_info_json['cost'] = uf_obj.cost university_info_json['country'] = u_obj.country university_info_json['website'] = u_obj.website university_info_json['introduction'] = u_obj.introduction university_info_json['logo'] = u_obj.logo university_info_json['pic1'] = u_obj.pic1 university_info_json['pic2'] = u_obj.pic2 university_info_json['pic3'] = u_obj.pic3 rslt_json = json.dumps(generate_response.gen('university_info', university_info_json, return_code.NORMAL_RESPONSE, None)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response except Excetion, e: errmsg = 'invalid request' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.INVALID_REQUEST, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def reserve(request): if request.method == 'POST': name = request.POST.get('name', None) phone = request.POST.get('phone', None) question = request.POST.get('question', None) available_time = request.POST.get('available_time', None) ip_addr = request.POST.get('ip_addr', None) session_id = request.POST.get('session_id', None) client_tag = str(ip_addr) + '_' + str(session_id) if name == None or phone == None or available_time == None: errmsg = 'params error' rslt_json = json.dumps( generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response client_reservation_obj = client_reservation.objects.create( client_tag=client_tag, name=name, phone=phone, question=question, available_time=available_time) rslt_json = json.dumps( generate_response.gen('response', 'OK', return_code.NORMAL_RESPONSE, None)) client_action_obj = client_action.objects.create( client_tag=client_tag, action_name='reserve', action_post=json.dumps(request.POST), action_return='OK') response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def get_education_fee(request): if request.method == 'POST': university_code = request.POST.get('university_code', None) kid_age = request.POST.get('kid_age', None) scholar_type = int(request.POST.get('scholar_type', None)) expected_inflation = request.POST.get('expected_inflation', None) expected_return_rate = request.POST.get('expected_return_rate', None) ip_addr = request.POST.get('ip_addr', None) session_id = request.POST.get('session_id', None) client_tag = str(ip_addr) + '_' + str(session_id) if university_code == None or kid_age == None or scholar_type == None or expected_inflation == None or expected_return_rate == None: errmsg = 'params error' rslt_json = json.dumps( generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response expected_inflation = float(expected_inflation) / 100.0 expected_return_rate = float(expected_return_rate) / 100.0 school_year = 0 school_age = 0 if scholar_type == 1: school_year = 4 school_age = 18 elif scholar_type == 2: school_year = 2 school_age = 22 elif scholar_type == 3: school_year = 6 school_age = 18 else: errmsg = 'sholar type error' rslt_json = json.dumps( generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response education_fee_info_json = {} this_year = str(datetime.datetime.now().year) + '-1-1' u_obj = university.objects.filter(university_code=university_code)[0] uf_obj = university_fee.objects.filter(university_code=university_code, year__gte=this_year)[0] education_fee_info_json['name_cn'] = u_obj.name_cn education_fee_info_json['yearly_cost'] = uf_obj.cost education_fee_info_json['total_cost'] = uf_obj.cost * school_year education_fee_info_json['year_to_come'] = school_age - int(kid_age) education_fee_info_json['target_saving'] = total_cost_with_inflation( education_fee_info_json['total_cost'], education_fee_info_json['year_to_come'], expected_inflation) education_fee_info_json['monthly_saving'] = monthly_saving( education_fee_info_json['target_saving'], education_fee_info_json['year_to_come'], expected_return_rate) rslt_json = json.dumps( generate_response.gen('education_fee_info', education_fee_info_json, return_code.NORMAL_RESPONSE, None)) client_action_obj = client_action.objects.create( client_tag=client_tag, action_name='get_education_fee', action_post=json.dumps(request.POST), action_return=json.dumps(education_fee_info_json)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def get_education_fee(request): if request.method == 'POST': university_code = request.POST.get('university_code', None) kid_age = request.POST.get('kid_age', None) scholar_type = int(request.POST.get('scholar_type', None)) expected_inflation = request.POST.get('expected_inflation', None) expected_return_rate = request.POST.get('expected_return_rate', None) if university_code == None or kid_age == None or scholar_type == None or expected_inflation == None or expected_return_rate == None: errmsg = 'params error' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response try: expected_inflation = float(expected_inflation) / 100.0 expected_return_rate = float(expected_return_rate) / 100.0 school_year = 0 school_age = 0 if scholar_type == 1: school_year = 4 school_age = 18 elif scholar_type == 2: school_year = 2 school_age = 22 elif scholar_type == 3: school_year = 6 school_age = 18 else: errmsg = 'sholar type error' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response education_fee_info_json = {} this_year = str(datetime.datetime.now().year) + '-1-1' u_obj = university.objects.filter(university_code=university_code)[0] uf_obj = university_fee.objects.filter(university_code=university_code, year__gte=this_year)[0] education_fee_info_json['name_cn'] = u_obj.name_cn education_fee_info_json['yearly_cost'] = uf_obj.cost education_fee_info_json['total_cost'] = uf_obj.cost * school_year education_fee_info_json['year_to_come'] = school_age - int(kid_age) education_fee_info_json['target_saving'] = total_cost_with_inflation(education_fee_info_json['total_cost'], education_fee_info_json['year_to_come'], expected_inflation) education_fee_info_json['monthly_saving'] = monthly_saving(education_fee_info_json['target_saving'], education_fee_info_json['year_to_come'], expected_return_rate) # product recommendation of PU NENG recommend_product_list = [] recommend_product_code_list = [134,31,34] for product_obj in product.objects.filter(product_code__in=recommend_product_code_list): product_info_tmp = {} product_info_tmp['product_code'] = product_obj.product_code insurer_code_tmp = product_obj.insurer_code product_info_tmp['insurer_code'] = insurer_code_tmp product_info_tmp['insurer_logo'] = insurer.objects.filter(insurer_code=insurer_code_tmp)[0].logo product_info_tmp['product_name'] = product_obj.product_name product_info_tmp['application_age_min'] = product_obj.application_age_min product_info_tmp['application_age_max'] = product_obj.application_age_max product_info_tmp['benefit_age_max'] = product_obj.benefit_age_max if product_obj.benefit_age_max < 100 else '终身' product_type_tmp = product_obj.product_type if product_type_tmp == 2: product_info_tmp['product_type'] = '重疾险' if product_type_tmp == 4: product_info_tmp['product_type'] = '人寿险' insurer_code_tmp = product_obj.insurer_code insurer_obj_tmp = insurer.objects.get(insurer_code=insurer_code_tmp) product_info_tmp['insurer_name'] = insurer_obj_tmp.insurer_name recommend_product_list.append(product_info_tmp) education_fee_info_json['recommend_product_list'] = recommend_product_list # end of product recommendation of PU NENG rslt_json = json.dumps(generate_response.gen('education_fee_info', education_fee_info_json, return_code.NORMAL_RESPONSE, None)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response except Excetion, e: errmsg = 'invalid request' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.INVALID_REQUEST, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def get_insurance_need(request): if request.method == 'POST': ans1 = request.POST.get('ans1', None) ans2 = request.POST.get('ans2', None) ans3 = request.POST.get('ans3', None) ans4 = request.POST.get('ans4', None) ans5 = request.POST.get('ans5', None) ans6 = request.POST.get('ans6', None) ans7 = request.POST.get('ans7', None) ans8 = request.POST.get('ans8', None) ip_addr = request.POST.get('ip_addr', None) session_id = request.POST.get('session_id', None) client_tag = str(ip_addr) + '_' + str(session_id) if ans1 == None or ans2 == None or ans3 == None or ans4 == None or ans5 == None or ans6 == None or ans7 == None or ans8 == None: errmsg = 'params error' rslt_json = json.dumps( generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response # Life insurance family_liability = int(ans3) + int(ans4) * 5 non_social_security_L = 0 gov_medical_care_L = 0 smoker_L = 0 hereditary_disease_L = 0 traveller_L = 0 # critical_illness insurance non_social_security_CI = 0 gov_medical_care_CI = 0 smoker_CI = 0 hereditary_disease_CI = 0 traveller_CI = 0 # hospital insurance non_social_security_HE = 0 gov_medical_care_HE = 0 smoker_HE = 0 hereditary_disease_HE = 0 traveller_HE = 0 # accidental protection insurance non_social_security_AP = 0 gov_medical_care_AP = 0 smoker_AP = 0 hereditary_disease_AP = 0 traveller_AP = 0 # accidental medical insurance non_social_security_AME = 0 gov_medical_care_AME = 0 smoker_AME = 0 hereditary_disease_AME = 0 traveller_AME = 0 # set values according to the answers rule_obj_arr = rule.objects.all() social_security = int(ans1) inheritance = int(ans6) trip_frequency = int(ans7) smoking = int(ans5) if social_security == 3: print 'non social' non_social_security_L = rule_obj_arr[0].non_social_security non_social_security_CI = rule_obj_arr[1].non_social_security non_social_security_HE = rule_obj_arr[2].non_social_security non_social_security_AP = rule_obj_arr[3].non_social_security non_social_security_AME = rule_obj_arr[4].non_social_security if social_security == 2: print 'gov social' gov_medical_care_L = rule_obj_arr[0].gov_medical_care gov_medical_care_CI = rule_obj_arr[1].gov_medical_care gov_medical_care_HE = rule_obj_arr[2].gov_medical_care gov_medical_care_AP = rule_obj_arr[3].gov_medical_care gov_medical_care_AME = rule_obj_arr[4].gov_medical_care if smoking == 1: print 'smoke' smoker_L = rule_obj_arr[0].smoker smoker_CI = rule_obj_arr[1].smoker smoker_HE = rule_obj_arr[2].smoker smoker_AP = rule_obj_arr[3].smoker smoker_AME = rule_obj_arr[4].smoker if inheritance == 1: print 'inheritance' hereditary_disease_L = rule_obj_arr[0].hereditary_disease hereditary_disease_CI = rule_obj_arr[1].hereditary_disease hereditary_disease_HE = rule_obj_arr[2].hereditary_disease hereditary_disease_AP = rule_obj_arr[3].hereditary_disease hereditary_disease_AME = rule_obj_arr[4].hereditary_disease if trip_frequency == 1: print 'traveller' traveller_L = rule_obj_arr[0].traveller traveller_CI = rule_obj_arr[1].traveller traveller_HE = rule_obj_arr[2].traveller traveller_AP = rule_obj_arr[3].traveller traveller_AME = rule_obj_arr[4].traveller # fill out need life_need = rule_obj_arr[0].benchmark + float(ans2) * float( family_liability ) + non_social_security_L + gov_medical_care_L + smoker_L + hereditary_disease_L + traveller_L critical_illness_need = rule_obj_arr[ 1].benchmark + non_social_security_CI + gov_medical_care_CI + smoker_CI + hereditary_disease_CI + traveller_CI hospital_expense_need = rule_obj_arr[ 2].benchmark + non_social_security_HE + gov_medical_care_HE + smoker_HE + hereditary_disease_HE + traveller_HE accidental_protection_need = rule_obj_arr[ 3].benchmark + non_social_security_AP + gov_medical_care_AP + smoker_AP + hereditary_disease_AP + traveller_AP accidental_medical_expense_need = rule_obj_arr[ 4].benchmark + non_social_security_AME + gov_medical_care_AME + smoker_AME + hereditary_disease_AME + traveller_AME insurance_need_json = {} insurance_need_json['life_need'] = life_need insurance_need_json['critical_illness_need'] = critical_illness_need insurance_need_json['hospital_expense_need'] = hospital_expense_need insurance_need_json[ 'accidental_protection_need'] = accidental_protection_need insurance_need_json[ 'accidental_medical_expense_need'] = accidental_medical_expense_need rslt_json = json.dumps( generate_response.gen('insurance_need', insurance_need_json, return_code.NORMAL_RESPONSE, None)) client_action_obj = client_action.objects.create( client_tag=client_tag, action_name='get_insurance_need', action_post=json.dumps(request.POST), action_return=json.dumps(insurance_need_json)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def get_premium(request): if request.method == 'POST': # print request.POST product_type = request.POST.get('product_type', None) sum_insured = request.POST.get('sum_insured', None) gender = request.POST.get('gender', None) application_age = request.POST.get('application_age', None) premium_period = request.POST.get('premium_period', None) ip_addr = request.POST.get('ip_addr', None) session_id = request.POST.get('session_id', None) client_tag = str(ip_addr) + '_' + str(session_id) benefit_age_max = 100 if product_type == None or sum_insured == None or gender == None or application_age == None or premium_period == None: errmsg = 'params error' rslt_json = json.dumps( generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response # get CN premium product_code_arr = [] for insurer_obj in insurer.objects.filter(region='CN'): for product_obj in product.objects.filter( product_type=int(product_type), insurer_code=insurer_obj.insurer_code, saving=1): product_code_arr.append(product_obj.product_code) premium_arr = [] for p_code in product_code_arr: premium_rate_obj_arr = premium_rate.objects.filter( product_code=p_code, application_age=application_age, gender=gender, premium_period=premium_period, benefit_age_max=benefit_age_max) if len(premium_rate_obj_arr) != 0: premium_arr.append( float(premium_rate_obj_arr[0].annual_premium_10k)) print premium_rate_obj_arr[ 0].product_code, premium_rate_obj_arr[0].annual_premium_10k cn_premium = median(premium_arr) * float(sum_insured) / 10000.0 print '=' * 10 # get HK premium product_code_arr = [] for insurer_obj in insurer.objects.filter(region='HK'): for product_obj in product.objects.filter( product_type=int(product_type), insurer_code=insurer_obj.insurer_code, saving=1): product_code_arr.append(product_obj.product_code) print 'HK:', product_code_arr premium_arr = [] for p_code in product_code_arr: print p_code premium_rate_obj_arr = premium_rate.objects.filter( product_code=p_code, application_age=application_age, gender=gender, premium_period=premium_period, benefit_age_max=benefit_age_max) if len(premium_rate_obj_arr) != 0: premium_arr.append( float(premium_rate_obj_arr[0].annual_premium_10k)) print premium_rate_obj_arr[ 0].product_code, premium_rate_obj_arr[0].annual_premium_10k hk_premium = median(premium_arr) * float(sum_insured) / 10000.0 # discount discount = float(hk_premium / cn_premium) premium_info_json = {} premium_info_json['cn_premium'] = cn_premium premium_info_json['hk_premium'] = hk_premium premium_info_json['discount'] = discount rslt_json = json.dumps( generate_response.gen('premium_info', premium_info_json, return_code.NORMAL_RESPONSE, None)) client_action_obj = client_action.objects.create( client_tag=client_tag, action_name='get_premium', action_post=json.dumps(request.POST), action_return=json.dumps(premium_info_json)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def product_compare(request): if request.method == 'POST': product_code_a = request.POST.get('product_a', None) product_code_b = request.POST.get('product_b', None) ip_addr = request.POST.get('ip_addr', None) session_id = request.POST.get('session_id', None) client_tag = str(ip_addr) + '_' + str(session_id) if product_code_a == None or product_code_b == None: errmsg = 'params error' rslt_json = json.dumps( generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response # product a info product_a_json = {} product_a = product.objects.filter(product_code=int(product_code_a))[0] insurer_a = insurer.objects.filter( insurer_code=product_a.insurer_code)[0] product_a_json['product_code'] = product_a.product_code product_a_json['product_name'] = product_a.product_name product_a_json['insurer_name'] = insurer_a.insurer_name product_a_json['insurer_logo'] = insurer_a.logo product_a_json['application_age'] = [ product_a.application_age_min, product_a.application_age_max ] product_a_json['benefit_age_max'] = product_a.benefit_age_max product_a_json['terms'] = product_a.terms product_a_json['brochure'] = product_a.brochure life_info = product_a.life product_a_life_json = {} if life_info == 1: death_illness = '' death_accident = '' life_product_obj_arr = life.objects.filter( product_code=int(product_code_a)) death_illness = '保额X' if life_product_obj_arr[ 0].claim_base == 1 else '保费X' death_accident = '保额X' if life_product_obj_arr[ 0].claim_base == 1 else '保费X' death_illness += str( int(life_product_obj_arr[0].death_illness * 100)) + '%' death_accident += str( int(life_product_obj_arr[0].death_accident * 100)) + '%' saving_product_obj_arr = saving.objects.filter( product_code=int(product_code_a)) if len(saving_product_obj_arr) > 0: if saving_product_obj_arr[0].par != 0: death_illness += ' + 分红' death_accident += ' + 分红' product_a_life_json['death_illness'] = death_illness product_a_life_json['death_accident'] = death_accident claim_18 = life_product_obj_arr[0].claim_18 if claim_18 == 0: claim_18_str = '无限制' elif claim_18 == 1: claim_18_str = '不超过10万' else: claim_18_str = '退还保费' product_a_life_json['claim_18'] = claim_18_str advance_payment_with_ci = life_product_obj_arr[ 0].advance_payment_with_ci if advance_payment_with_ci == 0: advance_payment_with_ci_str = '不共用保额' else: advance_payment_with_ci_str = '共用保额' product_a_life_json[ 'advance_payment_with_ci'] = advance_payment_with_ci_str product_a_life_json['waiting_period'] = life_product_obj_arr[ 0].waiting_period product_a_json['life'] = product_a_life_json ci_info = product_a.ci product_a_ci_json = {} if ci_info == 1: ci_product_obj_arr = ci.objects.filter( product_code=int(product_code_a)) product_a_ci_json['ci'] = ci_product_obj_arr[0].ci product_a_ci_json['early_stage_ci'] = ci_product_obj_arr[ 0].early_stage_ci product_a_ci_json['non_ci'] = ci_product_obj_arr[0].non_ci product_a_ci_json['juvenile_minor_illness'] = ci_product_obj_arr[ 0].juvenile_minor_illness product_a_ci_json['ci_max_claim'] = ci_product_obj_arr[ 0].ci_max_claim product_a_ci_json['face_amount_growth_rate'] = ci_product_obj_arr[ 0].face_amount_growth_rate * 100 product_a_ci_json['waiting_period'] = ci_product_obj_arr[ 0].waiting_period product_a_json['ci'] = product_a_ci_json saving_info = product_a.saving product_a_saving_json = {} if saving_info == 1: saving_product_obj_arr = saving.objects.filter( product_code=int(product_code_a)) # product_a_saving_json['expected_irr_avg'] = saving_product_obj_arr[0].expected_irr_avg * 100 # product_a_saving_json['guaranteed_irr'] = saving_product_obj_arr[0].guaranteed_irr * 100 # product_a_saving_json['par_distribution'] = saving_product_obj_arr[0].par_distribution * 100 currency_type = str(product_a.currency) y20_irr = saving_product_obj_arr[0].y20_expected_irr y30_irr = saving_product_obj_arr[0].y30_expected_irr y40_irr = saving_product_obj_arr[0].y40_expected_irr # product_a_saving_json['total_mortage'] = '200000' + ' ' + currency_type # product_a_saving_json['total_saving_20'] = str(expected_saving(y20_irr, 10000, 20, 20)) + ' ' + currency_type # product_a_saving_json['total_saving_30'] = str(expected_saving(y30_irr, 10000, 20, 30)) + ' ' + currency_type # product_a_saving_json['total_saving_40'] = str(expected_saving(y40_irr, 10000, 20, 40)) + ' ' + currency_type product_a_json['saving'] = product_a_saving_json # product b info product_b_json = {} product_b = product.objects.filter(product_code=int(product_code_b))[0] insurer_b = insurer.objects.filter( insurer_code=product_b.insurer_code)[0] product_b_json['product_code'] = product_b.product_code product_b_json['product_name'] = product_b.product_name product_b_json['insurer_name'] = insurer_b.insurer_name product_b_json['insurer_logo'] = insurer_b.logo product_b_json['application_age'] = [ product_b.application_age_min, product_b.application_age_max ] product_b_json['benefit_age_max'] = product_b.benefit_age_max product_b_json['terms'] = product_b.terms product_b_json['brochure'] = product_b.brochure life_info = product_b.life product_b_life_json = {} if life_info == 1: death_illness = '' death_accident = '' life_product_obj_arr = life.objects.filter( product_code=int(product_code_b)) death_illness = '保额X' if life_product_obj_arr[ 0].claim_base == 1 else '保费X' death_accident = '保额X' if life_product_obj_arr[ 0].claim_base == 1 else '保费X' death_illness += str( int(life_product_obj_arr[0].death_illness * 100)) + '%' death_accident += str( int(life_product_obj_arr[0].death_accident * 100)) + '%' saving_product_obj_arr = saving.objects.filter( product_code=int(product_code_b)) if len(saving_product_obj_arr) > 0: if saving_product_obj_arr[0].par != 0: death_illness += ' + 分红' death_accident += ' + 分红' product_b_life_json['death_illness'] = death_illness product_b_life_json['death_accident'] = death_accident claim_18 = life_product_obj_arr[0].claim_18 if claim_18 == 0: claim_18_str = '无限制' elif claim_18 == 1: claim_18_str = '不超过10万' else: claim_18_str = '退还保费' product_b_life_json['claim_18'] = claim_18_str advance_payment_with_ci = life_product_obj_arr[ 0].advance_payment_with_ci if advance_payment_with_ci == 0: advance_payment_with_ci_str = '不共用保额' else: advance_payment_with_ci_str = '共用保额' product_b_life_json[ 'advance_payment_with_ci'] = advance_payment_with_ci_str product_b_life_json['waiting_period'] = life_product_obj_arr[ 0].waiting_period product_b_json['life'] = product_b_life_json ci_info = product_b.ci product_b_ci_json = {} if ci_info == 1: ci_product_obj_arr = ci.objects.filter( product_code=int(product_code_b)) product_b_ci_json['ci'] = ci_product_obj_arr[0].ci product_b_ci_json['early_stage_ci'] = ci_product_obj_arr[ 0].early_stage_ci product_b_ci_json['non_ci'] = ci_product_obj_arr[0].non_ci product_b_ci_json['juvenile_minor_illness'] = ci_product_obj_arr[ 0].juvenile_minor_illness product_b_ci_json['ci_max_claim'] = ci_product_obj_arr[ 0].ci_max_claim product_b_ci_json['face_amount_growth_rate'] = ci_product_obj_arr[ 0].face_amount_growth_rate product_b_ci_json['waiting_period'] = ci_product_obj_arr[ 0].waiting_period product_b_json['ci'] = product_b_ci_json saving_info = product_b.saving product_b_saving_json = {} if saving_info == 1: saving_product_obj_arr = saving.objects.filter( product_code=int(product_code_b)) # product_b_saving_json['expected_irr_avg'] = saving_product_obj_arr[0].expected_irr_avg * 100 # product_b_saving_json['guaranteed_irr'] = saving_product_obj_arr[0].guaranteed_irr * 100 # product_b_saving_json['par_distribution'] = saving_product_obj_arr[0].par_distribution * 100 currency_type = str(product_b.currency) y20_irr = saving_product_obj_arr[0].y20_expected_irr y30_irr = saving_product_obj_arr[0].y30_expected_irr y40_irr = saving_product_obj_arr[0].y40_expected_irr # product_b_saving_json['total_mortage'] = '200000' + ' ' + currency_type # product_b_saving_json['total_saving_20'] = str(expected_saving(y20_irr, 10000, 20, 20)) + ' ' + currency_type # product_b_saving_json['total_saving_30'] = str(expected_saving(y30_irr, 10000, 20, 30)) + ' ' + currency_type # product_b_saving_json['total_saving_40'] = str(expected_saving(y40_irr, 10000, 20, 40)) + ' ' + currency_type product_b_json['saving'] = product_b_saving_json product_cmp_json = {} product_cmp_json['product_a'] = product_a_json product_cmp_json['product_b'] = product_b_json rslt_json = json.dumps( generate_response.gen('product_cmp', product_cmp_json, return_code.NORMAL_RESPONSE, None)) client_action_obj = client_action.objects.create( client_tag=client_tag, action_name='product_compare', action_post=json.dumps(request.POST), action_return=json.dumps(product_cmp_json)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def retire_fee(request): if request.method == 'POST': # birthday = request.GET.get('birthday', None) gender = request.POST.get('gender', None) salary_base = request.POST.get('salary_base', None) try: city_name = request.POST.get('city', None) print '1', city_name city_name = city_name.encode('utf-8') print '2', city_name except Exception as e: print e expected_retire_age = request.POST.get('expected_retire_age', None) expected_monthly_expense = request.POST.get('expected_monthly_expense', None) expected_yearly_tourfee = request.POST.get('expected_yearly_tourfee', None) expected_yearly_healthcare = request.POST.get( 'expected_yearly_healthcare', None) expected_legacy = request.POST.get('expected_yearly_legacy', None) #gender: 0 for female, 1 for male if gender == '1': retire_age_std = 65 social_security_std = 35 global_age_avg = 78 else: retire_age_std = 60 social_security_std = 30 global_age_avg = 82 expected_social_security = float(social_security_std - retire_age_std + int(expected_retire_age)) if expected_social_security < 15: # ss for social security ss_time_ratio = 0 else: ss_time_ratio = expected_social_security / float( social_security_std) city_salary_info = city_salary.objects.filter( city=city_name).order_by('-update_date')[:1] if len(city_salary_info) == 0: print 'no city found' ss_fee_ratio = float( salary_base) / city_salary_info[0].employee_avg_salary if ss_fee_ratio < 0.6: ss_fee_ratio = 0.6 if ss_fee_ratio > 3: ss_fee_ratio = 3 expected_monthly_retire_fee = city_salary_info[ 0].retiree_avg_salary * ss_fee_ratio * ss_time_ratio monthly_total_expense = float(expected_monthly_expense) + float( expected_yearly_tourfee) / 12 + float( expected_yearly_healthcare) / 12 # print expected_retire_age, expected_legacy expected_total_expense = monthly_total_expense * 12 * ( global_age_avg - float(expected_retire_age)) + float(expected_legacy) retire_gap = expected_total_expense - expected_monthly_retire_fee * 12 * ( global_age_avg - float(retire_age_std)) # product recommendation of PU NENG recommend_product_list = [] recommend_product_code_list = [134, 31, 34] for product_obj in product.objects.filter( product_code__in=recommend_product_code_list): product_info_tmp = {} product_info_tmp['product_name'] = product_obj.product_name product_info_tmp[ 'application_age_min'] = product_obj.application_age_min product_info_tmp[ 'application_age_max'] = product_obj.application_age_max product_info_tmp[ 'benefit_age_max'] = product_obj.benefit_age_max if product_obj.benefit_age_max < 100 else '终身' product_type_tmp = product_obj.product_type if product_type_tmp == 2: product_info_tmp['product_type'] = '重疾险' if product_type_tmp == 4: product_info_tmp['product_type'] = '人寿险' insurer_code_tmp = product_obj.insurer_code insurer_obj_tmp = insurer.objects.get( insurer_code=insurer_code_tmp) product_info_tmp['insurer_name'] = insurer_obj_tmp.insurer_name recommend_product_list.append(product_info_tmp) # end of product recommendation of PU NENG retirement_fee_json = { 'expected_monthly_retire_fee': expected_monthly_retire_fee, 'retire_gap': retire_gap, 'monthly_total_expense': monthly_total_expense, 'recommend_product_list': recommend_product_list } rslt_json = json.dumps( generate_response.gen('retirement_fee', retirement_fee_json, return_code.NORMAL_RESPONSE, None)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response
def get_reservation(request): if request.method == 'POST': account = request.POST.get('account', None) passwd = request.POST.get('password', None) if account == None or passwd == None: errmsg = 'bad request' rslt_json = json.dumps( generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response if account != 'iplan' or passwd != 'Bcl12345': errmsg = 'bad request' rslt_json = json.dumps( generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response today = str(datetime.date.today()).replace('-', '_') save_file = './client_reservation_files/client_reservation_' + today + '.xls' client_reservation_xls = Workbook() client_reservation_sheet = client_reservation_xls.add_sheet( 'client_reservation_sheet') row = 0 col = 0 count = 0 print len(client_reservation.objects.all()) for client_reservation_obj in client_reservation.objects.all(): client_tag = client_reservation_obj.client_tag client_reservation_sheet.write(row, col, u'姓名') client_reservation_sheet.write(row, col + 2, client_reservation_obj.name) client_reservation_sheet.write(row + 1, col, u'电话') client_reservation_sheet.write(row + 1, col + 2, client_reservation_obj.phone) client_reservation_sheet.write(row + 2, col, u'咨询') client_reservation_sheet.write(row + 2, col + 2, client_reservation_obj.question) client_reservation_sheet.write(row + 3, col, u'可联系时间段') client_reservation_sheet.write( row + 3, col + 2, client_reservation_obj.available_time) client_reservation_sheet.write(row + 4, col, u'日期') client_reservation_sheet.write( row + 4, col + 2, str(client_reservation_obj.update_date)) row += 5 for client_action_obj in client_action.objects.filter( client_tag=client_tag): if client_action_obj.action_name == 'get_premium': action_post = json.loads(client_action_obj.action_post) action_return = json.loads(client_action_obj.action_return) client_reservation_sheet.write(row, col, u'保险类型') product_type = action_post['product_type'] product_type_cn = '' if product_type == 1: product_type_cn = u'意外险' elif product_type == 2: product_type_cn = u'重疾险' elif product_type == 3: product_type_cn = u'综合险' elif product_type == 4: product_type_cn = u'人寿险' elif product_type == 5: product_type_cn = u'医疗险' elif product_type == 6: product_type_cn = u'防癌险' elif product_type == 7: product_type_cn = u'储蓄险' else: product_type_cn = u'无' client_reservation_sheet.write(row + 1, col, product_type_cn) client_reservation_sheet.write(row, col + 1, u'配置保额') client_reservation_sheet.write(row + 1, col + 1, action_post['sum_insured']) client_reservation_sheet.write(row, col + 2, u'供款年期') client_reservation_sheet.write( row + 1, col + 2, action_post['premium_period']) client_reservation_sheet.write(row, col + 3, u'性别') client_reservation_sheet.write(row + 1, col + 3, action_post['gender']) client_reservation_sheet.write(row, col + 4, u'年龄') client_reservation_sheet.write( row + 1, col + 4, action_post['application_age']) client_reservation_sheet.write(row, col + 5, u'国内') client_reservation_sheet.write(row + 1, col + 5, action_return['cn_premium']) client_reservation_sheet.write(row, col + 6, u'香港') client_reservation_sheet.write(row + 1, col + 6, action_return['hk_premium']) client_reservation_sheet.write(row, col + 7, u'折扣') client_reservation_sheet.write(row + 1, col + 7, action_return['discount']) col += 8 elif client_action_obj.action_name == 'product_compare': action_post = json.loads(client_action_obj.action_post) action_return = json.loads(client_action_obj.action_return) print action_post client_reservation_sheet.write(row, col, u'保险比较A') product_a = product.objects.filter( product_code=action_post['product_a'])[0] client_reservation_sheet.write(row + 1, col, product_a.product_name) client_reservation_sheet.write(row, col + 1, u'保险比较B') product_b = product.objects.filter( product_code=action_post['product_b'])[0] client_reservation_sheet.write(row + 1, col + 1, product_b.product_name) col += 2 elif client_action_obj.action_name == 'get_insurance_need': action_post = json.loads(client_action_obj.action_post) action_return = json.loads(client_action_obj.action_return) client_reservation_sheet.write(row, col, u'社保类型') client_reservation_sheet.write(row + 1, col, action_post['ans1']) client_reservation_sheet.write(row, col + 1, u'收入比重') client_reservation_sheet.write(row + 1, col + 1, action_post['ans2']) client_reservation_sheet.write(row, col + 2, u'剩余按揭') client_reservation_sheet.write(row + 1, col + 2, action_post['ans3']) client_reservation_sheet.write(row, col + 3, u'家庭费用') client_reservation_sheet.write(row + 1, col + 3, action_post['ans4']) client_reservation_sheet.write(row, col + 4, u'是否吸烟') client_reservation_sheet.write(row + 1, col + 4, action_post['ans5']) client_reservation_sheet.write(row, col + 5, u'是否有遗传病') client_reservation_sheet.write(row + 1, col + 5, action_post['ans6']) client_reservation_sheet.write(row, col + 6, u'是否经常出差') client_reservation_sheet.write(row + 1, col + 6, action_post['ans7']) client_reservation_sheet.write(row, col + 7, u'预算') client_reservation_sheet.write(row + 1, col + 7, action_post['ans8']) client_reservation_sheet.write(row, col + 8, u'人寿需求') client_reservation_sheet.write(row + 1, col + 8, action_return['life_need']) client_reservation_sheet.write(row, col + 9, u'重疾需求') client_reservation_sheet.write( row + 1, col + 9, action_return['critical_illness_need']) client_reservation_sheet.write(row, col + 10, u'医疗费用需求') client_reservation_sheet.write( row + 1, col + 10, action_return['hospital_expense_need']) client_reservation_sheet.write(row, col + 11, u'意外保护需求') client_reservation_sheet.write( row + 1, col + 11, action_return['accidental_protection_need']) client_reservation_sheet.write(row, col + 12, u'意外医疗费用需求') client_reservation_sheet.write( row + 1, col + 12, action_return['accidental_medical_expense_need']) col += 13 elif client_action_obj.action_name == 'get_education_fee': action_post = json.loads(client_action_obj.action_post) action_return = json.loads(client_action_obj.action_return) client_reservation_sheet.write(row, col, u'学校代码') client_reservation_sheet.write( row + 1, col, action_post['university_code']) client_reservation_sheet.write(row, col + 1, u'学校名称') client_reservation_sheet.write(row + 1, col + 1, action_return['name_cn']) client_reservation_sheet.write(row, col + 2, u'子女年龄') client_reservation_sheet.write(row + 1, col + 2, action_post['kid_age']) client_reservation_sheet.write(row, col + 3, u'学习类型') client_reservation_sheet.write(row + 1, col + 3, action_post['scholar_type']) client_reservation_sheet.write(row, col + 4, u'预计通胀率') client_reservation_sheet.write( row + 1, col + 4, action_post['expected_inflation']) client_reservation_sheet.write(row, col + 5, u'预计回报率') client_reservation_sheet.write( row + 1, col + 5, action_post['expected_return_rate']) client_reservation_sheet.write(row, col + 6, u'每年费用') client_reservation_sheet.write( row + 1, col + 6, action_return['yearly_cost']) client_reservation_sheet.write(row, col + 7, u'总费用') client_reservation_sheet.write(row + 1, col + 7, action_return['total_cost']) client_reservation_sheet.write(row, col + 8, u'距今多少年') client_reservation_sheet.write( row + 1, col + 8, action_return['year_to_come']) client_reservation_sheet.write(row, col + 9, u'目标金额') client_reservation_sheet.write( row + 1, col + 9, action_return['target_saving']) client_reservation_sheet.write(row, col + 10, u'每月储蓄') client_reservation_sheet.write( row + 1, col + 10, action_return['monthly_saving']) col += 11 row += 3 col = 0 count += 1 client_reservation_xls.save(save_file) wrapper = FileWrapper(file(save_file)) response = HttpResponse(wrapper, content_type='application/octet-stream') response['Content-Length'] = os.path.getsize(save_file) response['Content-Disposition'] = 'attachment; filename=%s' % ( 'client_reservation_' + today + '.xls') return response
def get_insurance_need(request): if request.method == 'POST': ans1 = request.POST.get('ans1', None) ans2 = request.POST.get('ans2', None) ans3 = request.POST.get('ans3', None) ans4 = request.POST.get('ans4', None) ans5 = request.POST.get('ans5', None) ans6 = request.POST.get('ans6', None) ans7 = request.POST.get('ans7', None) ans8 = request.POST.get('ans8', None) ip_addr = request.POST.get('ip_addr', None) session_id = request.POST.get('session_id', None) client_tag = str(ip_addr) + '_' + str(session_id) if ans1 == None or ans2 == None or ans3 == None or ans4 == None or ans5 == None or ans6 == None or ans7 == None or ans8 == None: errmsg = 'params error' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.PARAM_ERROR, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response try: # Life insurance family_liability = int(ans3)*10000 + int(ans4) * 5 * 10000 non_social_security_L = 0 gov_medical_care_L = 0 smoker_L = 0 hereditary_disease_L = 0 traveller_L = 0 # critical_illness insurance non_social_security_CI = 0 gov_medical_care_CI = 0 smoker_CI = 0 hereditary_disease_CI = 0 traveller_CI = 0 # hospital insurance non_social_security_HE = 0 gov_medical_care_HE = 0 smoker_HE = 0 hereditary_disease_HE = 0 traveller_HE = 0 # accidental protection insurance non_social_security_AP = 0 gov_medical_care_AP = 0 smoker_AP = 0 hereditary_disease_AP = 0 traveller_AP = 0 # accidental medical insurance non_social_security_AME = 0 gov_medical_care_AME = 0 smoker_AME = 0 hereditary_disease_AME = 0 traveller_AME = 0 # set values according to the answers rule_obj_arr = rule.objects.all() social_security = int(ans1) inheritance = int(ans6) trip_frequency = int(ans7) smoking = int(ans5) if social_security == 3: print 'non social' non_social_security_L = rule_obj_arr[0].non_social_security non_social_security_CI = rule_obj_arr[1].non_social_security non_social_security_HE = rule_obj_arr[2].non_social_security non_social_security_AP = rule_obj_arr[3].non_social_security non_social_security_AME = rule_obj_arr[4].non_social_security if social_security == 2: print 'gov social' gov_medical_care_L = rule_obj_arr[0].gov_medical_care gov_medical_care_CI = rule_obj_arr[1].gov_medical_care gov_medical_care_HE = rule_obj_arr[2].gov_medical_care gov_medical_care_AP = rule_obj_arr[3].gov_medical_care gov_medical_care_AME = rule_obj_arr[4].gov_medical_care if smoking == 1: print 'smoke' smoker_L = rule_obj_arr[0].smoker smoker_CI = rule_obj_arr[1].smoker smoker_HE = rule_obj_arr[2].smoker smoker_AP = rule_obj_arr[3].smoker smoker_AME = rule_obj_arr[4].smoker if inheritance == 1: print 'inheritance' hereditary_disease_L = rule_obj_arr[0].hereditary_disease hereditary_disease_CI = rule_obj_arr[1].hereditary_disease hereditary_disease_HE = rule_obj_arr[2].hereditary_disease hereditary_disease_AP = rule_obj_arr[3].hereditary_disease hereditary_disease_AME = rule_obj_arr[4].hereditary_disease if trip_frequency == 1: print 'traveller' traveller_L = rule_obj_arr[0].traveller traveller_CI = rule_obj_arr[1].traveller traveller_HE = rule_obj_arr[2].traveller traveller_AP = rule_obj_arr[3].traveller traveller_AME = rule_obj_arr[4].traveller # fill out need life_need = rule_obj_arr[0].benchmark + float(ans2) * float(family_liability) + non_social_security_L + gov_medical_care_L + smoker_L + hereditary_disease_L + traveller_L critical_illness_need1 = rule_obj_arr[1].benchmark + non_social_security_CI + gov_medical_care_CI + smoker_CI + hereditary_disease_CI + traveller_CI critical_illness_need2 = int(ans8) * 10000 * 5 if int(ans8)<30 else int(ans8) * 10000 * 3 critical_illness_need = max(critical_illness_need1, critical_illness_need2) hospital_expense_need = rule_obj_arr[2].benchmark + non_social_security_HE + gov_medical_care_HE + smoker_HE + hereditary_disease_HE + traveller_HE accidental_protection_need = rule_obj_arr[3].benchmark + non_social_security_AP + gov_medical_care_AP + smoker_AP + hereditary_disease_AP + traveller_AP accidental_medical_expense_need = rule_obj_arr[4].benchmark + non_social_security_AME + gov_medical_care_AME + smoker_AME + hereditary_disease_AME + traveller_AME insurance_need_json = {} insurance_need_json['life_need'] = life_need / 10000 insurance_need_json['critical_illness_need'] = critical_illness_need / 10000 insurance_need_json['hospital_expense_need'] = hospital_expense_need / 10000 insurance_need_json['accidental_protection_need'] = accidental_protection_need / 10000 insurance_need_json['accidental_medical_expense_need'] = accidental_medical_expense_need / 10000 # product recommendation of PU NENG recommend_product_list = [] recommend_product_code_list = [61,24,21] if life_need - critical_illness_need > 30: recommend_product_code_list = [61,24,21,133,27] for product_obj in product.objects.filter(product_code__in=recommend_product_code_list): product_info_tmp = {} product_info_tmp['product_code'] = product_obj.product_code insurer_code_tmp = product_obj.insurer_code product_info_tmp['insurer_code'] = insurer_code_tmp product_info_tmp['insurer_logo'] = insurer.objects.filter(insurer_code=insurer_code_tmp)[0].logo product_info_tmp['product_name'] = product_obj.product_name product_info_tmp['application_age_min'] = product_obj.application_age_min product_info_tmp['application_age_max'] = product_obj.application_age_max product_info_tmp['benefit_age_max'] = product_obj.benefit_age_max if product_obj.benefit_age_max < 100 else '终身' product_type_tmp = product_obj.product_type if product_type_tmp == 2: product_info_tmp['product_type'] = '重疾险' if product_type_tmp == 4: product_info_tmp['product_type'] = '人寿险' insurer_code_tmp = product_obj.insurer_code insurer_obj_tmp = insurer.objects.get(insurer_code=insurer_code_tmp) product_info_tmp['insurer_name'] = insurer_obj_tmp.insurer_name recommend_product_list.append(product_info_tmp) insurance_need_json['recommend_product_list'] = recommend_product_list # end of product recommendation of PU NENG rslt_json = json.dumps(generate_response.gen('insurance_need', insurance_need_json, return_code.NORMAL_RESPONSE, None)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response except Excetion, e: errmsg = 'invalid request' rslt_json = json.dumps(generate_response.gen('response', {}, return_code.INVALID_REQUEST, errmsg)) response = HttpResponse(rslt_json, content_type='application/json') response['Content-Length'] = len(rslt_json) return response