def cash_join(request): c = {} c.update(csrf(request)) f = {} isSuccess = False isvalid = True cash_event = CashEventInfo() c['introducer'] = request.GET.get('u', '') openid = request.session.get("openid", "") if openid == "": return redirect("/oauth/?refer=/event/cash_join/?u=" + c['introducer']) openid_member_num = UserProfile.objects.filter(wx_openid=openid).count() if openid_member_num > 0: user_profile = UserProfile.objects.filter(wx_openid=openid).first() f['username'] = user_profile.user.first_name f['mobile'] = user_profile.mobile f['address'] = user_profile.address f['email'] = user_profile.user.email f['company'] = user_profile.company f['job_title'] = user_profile.job_title f['fund_customer_number'] = user_profile.fund_customer_number if request.method == 'POST': username = request.POST['username'] mobile = request.POST['mobile'] # address = request.POST['address'] # email = request.POST['email'] # company = request.POST['company'] # job_title = request.POST['job_title'] # hobby = request.POST['hobby'] # household_spending = int(request.POST['household_spending']) # investment_apply = int(request.POST['investment_apply']) # investement_focus = int(request.POST['investement_focus']) # fund_customer_number = request.POST['fund_customer_number'] if username.strip() == "": isvalid = False messages.warning(request, "请输入您的姓名!") if mobile.strip() == "": isvalid = False messages.warning(request, "请输入您的手机!") # if address.strip() == "": # isvalid = False # messages.warning(request, "请输入您的地址!") # # if email.strip() == "": # isvalid = False # messages.warning(request, "请输入您的Email地址!") # # if company.strip() == "": # isvalid = False # messages.warning(request, "请输入您的公司名称!") # # if job_title.strip() == "": # isvalid = False # messages.warning(request, "请输入您的职位!") # # # if household_spending == 0: # isvalid = False # messages.warning(request, "请选择您家庭的最大支出部分") # # if investment_apply == 0: # isvalid = False # messages.warning(request, "请选择您近期资金配资的安排") # # if investement_focus == 0: # isvalid = False # messages.warning(request, "请选择您在选择理财产品关注点") f['username'] = username f['mobile'] = mobile # f['address']=address # f['email']=email # f['company']=company # f['job_title']=job_title # f['hobby']=hobby # f['household_spending']=household_spending # f['investment_apply']=investment_apply # f['investement_focus']=investement_focus #f['fund_customer_number']=fund_customer_number if isvalid: user_num = UserProfile.objects.filter(user__first_name=username, mobile=mobile).count() if user_num > 0: _user_profile = UserProfile.objects.filter( user__first_name=username, mobile=mobile).first() # if hobby.strip() !="": # _user_profile.hobby = hobby # _user_profile.address=address # # _user_profile.company=company # _user_profile.job_title=job_title _user_profile.wx_openid = openid _user_profile.save() cash_event.user = _user_profile.user else: _user = User() max_id = User.objects.order_by('-id').first().id _user.username = "******" + str(max_id + 1) _user.first_name = username _user.password = make_password(_user.username) #_user.email=email _user.save() _new_user = User.objects.filter( username=_user.username).order_by('-id').first() _profile = UserProfile() _profile.user = _new_user _profile.mobile = mobile # _profile.address=address # _profile.company=company # _profile.job_title=job_title # _profile.hobby=hobby _profile.wx_openid = openid _profile.source = 4 _profile.save() cash_event.user = _new_user # cash_event.household_spending=household_spending # cash_event.investment_apply=investment_apply # cash_event.investement_focus=investement_focus cash_event.introducer = c['introducer'] try: _cash_record_num = CashEventInfo.objects.filter( user=cash_event.user).count() if _cash_record_num > 0: messages.success(request, "您已经报名参加过小金库活动!") else: cash_event.status = 1 cash_event.event_add_time = datetime.datetime.now() cash_event.event_amount = Decimal(0) cash_event.save() #添加推荐记录 if cash_event.introducer != "": introducer_num = UserProfile.objects.filter( wx_openid=cash_event.introducer).count() if introducer_num > 0: introducer = UserProfile.objects.filter( wx_openid=cash_event.introducer).first() #不能自己推荐自己 if introducer != cash_event.user: recommond_history = CashEventRecommondInfo() recommond_history.user = cash_event.user recommond_history.introducer = introducer.user #当月推荐人数封顶10人 start_date = datetime.date.today().replace( day=1) end_date = ( datetime.date.today().replace(day=1) + datetime.timedelta(31)).replace(day=1) if CashEventRecommondInfo.objects.filter( introducer=introducer, add_time__gte=start_date, add_time__lt=end_date).count() <= 10: recommond_history.amount = 500 recommond_history.save() #如果是基金客户直接给到10000虚拟货币 temp_user = UserProfile.objects.filter( user=cash_event.user).first() if temp_user.is_investment == 1: cash_event.event_amount = Decimal(10000) cash_event.save() return redirect('member.money') isSuccess = True return redirect('member.money') except Exception, e: messages.warning(request, e)
def join(request): c = {} c.update(csrf(request)) isvalid = True isSuccess = False member_apply = Apply() f = {} openid = request.session.get("openid", "") if openid == "": return redirect("/oauth/?refer=/member/join") openid_member_num = UserProfile.objects.filter(wx_openid=openid).count() if openid_member_num > 0: user_profile = UserProfile.objects.filter(wx_openid=openid).first() member_apply.user = user_profile.user f['username'] = user_profile.user.first_name f['mobile'] = user_profile.mobile f['address'] = user_profile.address f['idcard'] = user_profile.id_no if request.method == 'POST': username = request.POST['username'] mobile = request.POST['mobile'] address = request.POST['address'] idcard = request.POST['idcard'] amount = 0 if request.POST['amount'] != '' and request.POST['amount'].isdigit(): amount = int(request.POST['amount']) project = int(request.POST['project']) if username.strip() == "": isvalid = False messages.warning(request, "请输入联系人!") if mobile.strip() == "": isvalid = False messages.warning(request, "请输入您的手机!") if address.strip() == "": isvalid = False messages.warning(request, "请输入您的地址!") if idcard.strip() == "": isvalid = False messages.warning(request, "请输入您的证件号码!") if amount == 0: isvalid = False messages.warning(request, "请输入您要理财的金额!") if project == 0: isvalid = False messages.warning(request, "请选择您要参加的项目!") f['username'] = username f['mobile'] = mobile f['address'] = address f['idcard'] = idcard f['amount'] = amount f['project'] = project if isvalid: user_num = UserProfile.objects.filter(user__first_name=username, mobile=mobile).count() if user_num > 0: _user_profile = UserProfile.objects.filter( user__first_name=username, mobile=mobile).first() member_apply.user = _user_profile.user else: _user = User() max_id = User.objects.order_by('-id').first().id _user.username = "******" + str(max_id + 1) _user.first_name = username _user.password = make_password(_user.username) _user.save() _new_user = User.objects.filter( username=_user.username).order_by('-id').first() _profile = UserProfile() _profile.user = _new_user _profile.mobile = mobile _profile.address = address _profile.id_no = idcard _profile.wx_openid = openid _profile.source = 3 _profile.save() member_apply.user = _new_user member_apply.amount = amount member_apply.project = project try: member_apply.save() isSuccess = True #messages.success(request, "您的理财申请已经提交成功!我们的客户经理会尽快与您联系!") except Exception, e: messages.warning(request, e)
def user_add(request): c = {} c.update(csrf(request)) isvalid = True _user_info = UserProfile() if request.method == 'POST': username = request.POST['username'] gender = request.POST['gender'] is_investment = request.POST['is_investment'] contract_no = request.POST['contract_no'] fund_customer_number = request.POST['fund_customer_number'] fund_item_number = request.POST['fund_item_number'] amount = request.POST['amount'] currency = request.POST['currency'] borrowed_type = request.POST['borrowed_type'] assign_type = request.POST['assign_type'] id_type = request.POST['id_type'] id_no = request.POST['id_no'] birthday = request.POST['birthday'] email = request.POST['email'] address = request.POST['address'] postcode = request.POST['postcode'] contact = request.POST['contact'] mobile = request.POST['mobile'] tel = request.POST['tel'] bank_name = request.POST['bank_name'] bank_account = request.POST['bank_account'] borrowed_time = request.POST['borrowed_time'] borrowed_type = request.POST['borrowed_type'] company = request.POST['company'] job_title = request.POST['job_title'] signed_time = request.POST['signed_time'] contract_start_time = request.POST['contract_start_time'] contract_end_time = request.POST['contract_end_time'] family = request.POST['family'] hobby = request.POST['hobby'] memo = request.POST['memo'] if username.strip() == '': isvalid = False messages.warning(request, "请输入用户名!") _user = User() max_id = User.objects.order_by('-id').first().id _user.username = "******" + str(max_id + 1) _user.password = make_password(_user.username) _user.first_name = username _user.email = email _user_info.user = _user if gender != '': _user_info.gender = int(gender) if is_investment != '': _user_info.is_investment = int(is_investment) _user_info.contract_no = contract_no _user_info.fund_customer_number = fund_customer_number _user_info.fund_item_number = fund_item_number if currency != '': _user_info.currency = int(currency) if borrowed_type != '': _user_info.borrowed_type = int(borrowed_type) if id_type != '': _user_info.id_type = int(id_type) if assign_type != '': _user_info.assign_type = int(assign_type) _user_info.id_no = id_no if birthday != '': _user_info.birthday = datetime.datetime.strptime( birthday, '%m/%d/%Y') _user_info.address = address _user_info.postcode = postcode _user_info.contact = contact _user_info.mobile = mobile _user_info.tel = tel _user_info.bank_name = bank_name _user_info.bank_account = bank_account if borrowed_time != '': _user_info.borrowed_time = datetime.datetime.strptime( borrowed_time, '%m/%d/%Y') _user_info.company = company _user_info.job_title = job_title if signed_time != '': _user_info.signed_time = datetime.datetime.strptime( signed_time, '%m/%d/%Y') if contract_start_time != '': _user_info.contract_start_time = datetime.datetime.strptime( contract_start_time, '%m/%d/%Y') if contract_end_time != '': _user_info.contract_end_time = datetime.datetime.strptime( contract_end_time, '%m/%d/%Y') _user_info.family = family _user_info.hobby = hobby _user_info.memo = memo if amount != '': _user_info.amount = Decimal(amount) if isvalid: _user.save() _user_info.user = _user _user_info.save() return redirect('backend.user_list') c['f'] = _user_info return render_to_response("backend/user_edit.html", c, context_instance=RequestContext(request))