def pay_book(billno, pay_way, payed_money, trade_no, pay_datetime): """ 填写订单支付信息:支付方式、支付金额,支付订单号,支付时间 验证信息:支付金额需要跟应付金额相同,否则列为异常订单 """ result = {} book = Book.objects.get(billno=billno) if book.status == Book.STATUS_CREATED: result['created'] = True result['book'] = book book.status = book.STATUS_PAYED book.money = payed_money book.pay_way = pay_way book.payed_money = payed_money book.trade_no = trade_no book.pay_datetime = pay_datetime result['status'] = 'ok' result['msg'] = "saved" book.save() result['book'] = book #返回成功页面 if 'created' in result: emailex = EmailEx() emailcontent = """ 您好! <br/> <br/> 您已成功预约ASU Watch,预约码为xxx,如有货会第一时间给您发短信/邮件通知。您在购买结算时输入预约码可直接抵扣200元现金。请妥善保留此邮件! <br/> <br/> 一数科技商城 """ smscontent = """您好,您已成功预约ASU Watch,预约码为xxx,如有货会第一时间给您发短信通知。您在购买结算时输入预约码可直接抵扣200元现金。请妥善保留此短信""" emailcontent = emailcontent.replace('xxx', book.billno) smscontent = smscontent.replace('xxx', book.billno) emailex.send_text_email("一数科技预约支付", emailcontent, book.email) sendsms(book.phone, smscontent) return result
class CodeManager(models.Manager): """ 验证码的manager """ email = EmailEx() def generate_code(self): code = ''.join(random.choice(string.digits) for i in range(4)) return code def send_code(self, email): result = {} if not self.email.EMAIL_REGEX.match(email): result['status'] = 1 result['msg'] = '电子邮件格式不正确' else: code = self.generate_code() Subject = settings.PROJECTNAME + '邮箱验证' content = '您好, 欢迎您注册' + settings.PROJECTNAME + ',您的邮箱验证码是: ' + code try: self.email.send_text_email(Subject, content, email) try: verify_code = self.model.objects.get(email__exact=email, type='0') verify_code.code = code verify_code.save() except self.model.DoesNotExist: verify_code = self.model(email=email, code=code, type='0') verify_code.save() result['status'] = 2 result['msg'] = '验证码已发至您的邮箱中, 请到邮箱中查看您的验证码!' except Exception as e: result['status'] = 3 result['msg'] = '发送邮件的过程中发生错误: ' + str(e) return result def veirfy_code(self, code, email): try: verify_code = self.model.objects.get(email__exact=email, code=code) return True except self.model.DoesNotExist: return False
def create(self, request): """申请经销商""" user = request.user result = {} isMble = dmb.process_request(request) if 'registered_name' in request.POST and \ 'registered_adress' in request.POST and 'bill_adress' in request.POST and \ 'receiving_adress' in request.POST and 'official_url' in request.POST and \ 'surname' in request.POST and \ 'position' in request.POST and 'phone_number' in request.POST and \ 'email' in request.POST : registered_name = request.POST['registered_name'].strip() registered_adress = request.POST['registered_adress'].strip() bill_adress = request.POST['bill_adress'].strip() receiving_adress = request.POST['receiving_adress'].strip() official_url = request.POST['official_url'].strip() surname = request.POST['surname'].strip() position = request.POST['position'].strip() phone_number = request.POST['phone_number'].strip() email = request.POST['email'].strip() stor_url = '' if 'stor_url' in request.POST: stor_url = request.POST['stor_url'].strip() other_url = '' if 'other_url' in request.POST: other_url = request.POST['other_url'].strip() emailex = EmailEx() emailcontent = """ 您好! <br/> <strong>申请企业基本信息</strong> <br/> 公司注册名称: registered_name <br/> <strong>申请企业基本信息</strong> <br/> 注册地址: registered_adress <br/> 现在办公地址: bill_adress <br/> 收货地址: receiving_adress <br/> <strong>企业网站信息</strong> <br/> 企业网站地址: official_url <br/> 电商网址: stor_url <br/> 其他: other_url <br/> <strong>企业网站信息</strong> <br/> 姓名: surname <br/> 职位: position <br/> 电话: phone_number <br/> 电子邮件: email <br/> <br/> <strong>一数科技</strong> """ emailcontent = emailcontent.replace('registered_name', registered_name) emailcontent = emailcontent.replace('registered_adress', registered_adress) emailcontent = emailcontent.replace('bill_adress', bill_adress) emailcontent = emailcontent.replace('receiving_adress', receiving_adress) emailcontent = emailcontent.replace('official_url', official_url) emailcontent = emailcontent.replace('stor_url', stor_url) emailcontent = emailcontent.replace('other_url', other_url) emailcontent = emailcontent.replace('surname', surname) emailcontent = emailcontent.replace('position', position) emailcontent = emailcontent.replace('phone_number', phone_number) emailcontent = emailcontent.replace('email', email) emailex.send_text_email("新的经销商申请", emailcontent, '*****@*****.**') if isMble: return render(request, 'bussiness/m_success.html', {}) else: return render(request, 'bussiness/success.html', {}) else: content['msg'] = "申请信息不完整" if isMble: return render(request, 'bussiness/new.html', content) else: return render(request, 'bussiness/new.html', content)