def pay_request(request): ''' 当面付请求逻辑 ''' amount = int(request.POST.get('num')) if amount < 1: info = { 'title': '失败', 'subtitle': '请保证金额大于1元', 'status': 'error', } else: req = PayRequest.make_pay_request(request.user, amount) if req is not None: info = { 'title': '请求成功!', 'subtitle': '支付宝扫描下方二维码付款,付款完成记得按确认哟!', 'status': 'success', } else: info = { 'title': '糟糕,当面付插件可能出现问题了', 'subtitle': '如果一直失败,请后台联系站长', 'status': 'error', } return JsonResponse({'info': info})
def check_pay_request(): '''定时检查支付请求''' # 每次检查新的五条记录 querys = PayRequest.objects.order_by('-time')[:5] for req in querys: user = User.objects.filter(username=req.username).first() paid = PayRequest.pay_query(user, req.info_code) if paid is True: print('用户:{} 掉单,已经补偿'.format(user.username)) print('{} 检查过支付请求'.format(timezone.now().strftime("%Y-%m-%d %H:%M")))
def pay_query(request): ''' 当面付结果查询逻辑 ''' user = request.user info_code = PayRequest.get_user_recent_pay_req(user).info_code paid = PayRequest.pay_query(user, info_code) if paid in (True, -1): info = { 'title': '充值成功!', 'subtitle': '请去商品界面购买商品!', 'status': 'success', } else: info = { 'title': '支付查询失败!请稍候再试', 'subtitle': '亲,确认支付了么?', 'status': 'error', } return JsonResponse({'info': info})
def pay_query(request): ''' 当面付结果查询逻辑 ''' user = request.user info_code = PayRequest.get_user_recent_pay_req(user).info_code paid = PayRequest.pay_query(user, info_code) if paid: info = { 'title': '充值成功!', 'subtitle': '请去商品界面购买商品!', 'status': 'success', } else: info = { 'title': '支付查询失败!请稍候再试', 'subtitle': '亲,确认支付了么?', 'status': 'error', } return JsonResponse({'info': info})