def update(self, request, *args, **kwargs): user = self.request.user code = 201 serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) password = self.request.data.get('password') password2 = self.request.data.get('password2') auth_code = serializer.validated_data.get('auth_code') original_safe_code = self.request.data.get('original_safe_code') safe_code = self.request.data.get('safe_code') safe_code2 = self.request.data.get('safe_code2') # tuoxie001 修改自己 if password: if password == password2: user.set_password(password) elif password != password2: code = 400 if auth_code: user.auth_code = make_auth_code() if original_safe_code: if make_md5(original_safe_code) == user.safe_code: if safe_code == safe_code2: if safe_code: print('tuoxie001修改操作密码中..........') safe_code = make_md5(safe_code) self.request.user.safe_code = safe_code else: code = 400 else: code = 400 user.save() serializer = UserDetailSerializer(user) return Response(data=serializer.data, status=code)
def post(self, request): processed_dict = {} resp = {'msg': '操作成功'} for key, value in request.data.items(): processed_dict[key] = value uid = processed_dict.get('uid', '') real_money = order_money = processed_dict.get('money', '') remark = processed_dict.get('remark', '') order_id = processed_dict.get('order_id', '') key = processed_dict.get('key', '') return_url = processed_dict.get('return_url', '') notify_url = processed_dict.get('notify_url', '') channel = processed_dict.get('channel', '') plat_type = processed_dict.get('plat_type', '1') print('plat_type', plat_type) # if not str(real_money) > '1': # resp['msg'] = '金额必须大于1' # return Response(resp, status=404) if not order_id: resp['msg'] = '请填写订单号~~' return Response(resp, status=404) if not return_url: resp['msg'] = '请填写正确跳转url~~' return Response(resp, status=404) if not notify_url: resp['msg'] = '请填写正确回调url~~' return Response(resp, status=404) user_queryset = UserProfile.objects.filter(uid=uid, is_active=True) if not user_queryset: resp['msg'] = 'uid或者auth_code错误,请重试~~' return Response(resp, status=404) if not re.match( r'(^[1-9]([0-9]{1,4})?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)', str(real_money)): resp['msg'] = '金额输入错误,请重试~~0.01到5万间' return Response(resp, status=404) # 识别出 用户 user = user_queryset[0] auth_code = user.auth_code # 加密 uid + auth_code + real_money + notify_url + order_id new_temp = str( str(uid) + str(auth_code) + str(real_money) + str(notify_url) + str(order_id)) my_key = make_md5(new_temp) if key == my_key: # 关闭超时订单 now_time = datetime.datetime.now() - datetime.timedelta( minutes=CLOSE_TIME) OrderInfo.objects.filter( pay_status=0, add_time__lte=now_time).update(pay_status=2) pay = MakePay(user, order_money, real_money, channel, remark, order_id, notify_url, plat_type, return_url) resp = pay.choose_pay() return Response(resp, status=200) resp['msg'] = 'key匹配错误' return Response(resp, status=400)
def update(self, request, *args, **kwargs): user = self.get_object() resp = {} serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) password = self.request.data.get('password') password2 = self.request.data.get('password2') auth_code = serializer.validated_data.get('auth_code') original_safe_code = self.request.data.get('original_safe_code') safe_code = self.request.data.get('safe_code') safe_code2 = self.request.data.get('safe_code2') code = 400 if password: if password == password2: user.set_password(password) user.save() resp['pwd'] = '密码修改成功' code = 200 elif password != password2: resp['pwd'] = '密码不一致' code = 400 if auth_code: user.auth_code = make_auth_code() user.save() resp['auth_code'] = '授权码修改成功' if original_safe_code: if make_md5(original_safe_code) == user.safe_code: if safe_code == safe_code2: if safe_code: safe_code = make_md5(safe_code) user.safe_code = safe_code user.save() resp['safe_code'] = '安全码修改成功' code = 200 else: resp['safe_code'] = '安全码输入不一致' code = 400 else: resp['safe_code'] = '原始安全码输入不一致' code = 400 return Response(data=resp, status=code)
def destroy(self, request, *args, **kwargs): user = self.request.user resp = {'msg': '操作成功'} processed_dict = {} for key, value in self.request.data.items(): processed_dict[key] = value serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) s_time = serializer.validated_data.get('start_time', '') e_time = serializer.validated_data.get('end_time', '') dele_type = serializer.validated_data.get('dele_type', '') safe_code = serializer.validated_data.get('safe_code', '') proxy_id = serializer.validated_data.get('proxy_id', '') new_key = make_md5(safe_code) if new_key == user.safe_code: if dele_type == 'order': order_queryset = OrderInfo.objects.filter( add_time__range=(s_time, e_time), proxy=proxy_id) # elif dele_type == 'money': # order_queryset = WithDrawInfo.objects.filter(add_time__range=(s_time, e_time)) # elif dele_type == 'log': # order_queryset = LogInfo.objects.filter(add_time__range=(s_time, e_time)) else: code = 400 resp['msg'] = '类型错误' return Response(data=resp, status=code) if order_queryset: for obj in order_queryset: print(obj.id) obj.delete() else: code = 400 resp['msg'] = '暂无可清除数据' return Response(data=resp, status=code) code = 200 return Response(data=resp, status=code) else: code = 400 resp['msg'] = '操作密码错误' return Response(data=resp, status=code)
def create(self, request, *args, **kwargs): user = self.request.user resp = {} serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) safe_code = serializer.validated_data.get('safe_code') if make_md5(safe_code) == user.safe_code: resp['msg'] = '谷歌验证绑定成功' code = 201 base_32_secret = base64.b32encode( codecs.decode( codecs.encode('{0:020x}'.format(random.getrandbits(80))), 'hex_codec')) totp_obj = googletotp.TOTP(base_32_secret.decode("utf-8")) qr_code = re.sub( r'=+$', '', totp_obj.provisioning_uri(request.user.username, issuer_name="帅气的验证码")) key = str(base_32_secret, encoding="utf-8") try: g = Google2Auth() g.user = user g.key = key g.save() user.is_google = True user.save() resp['key'] = key resp['qrcode'] = qr_code return Response(data=resp, status=code) except Exception: resp['msg'] = '令牌已绑定' code = 400 return Response(data=resp, status=code) # Google2Auth.objects.create(user=user) else: resp['msg'] = '操作码错误' code = 400 return Response(data=resp, status=code)
def update(self, request, *args, **kwargs): resp = {'msg': []} code = 200 serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) password = self.request.data.get('password', '') password2 = self.request.data.get('password2', '') operatepw = self.request.data.get('operatepw', '') notify_url = self.request.data.get('notify_url', '') get_proxyid = self.request.data.get('id', '') add_money = self.request.data.get('add_money', '') minus_money = self.request.data.get('minus_money', '') auth_code = self.request.data.get('auth_code', '') is_active = self.request.data.get('is_active', '') original_safe_code = self.request.data.get('original_safe_code', '') safe_code = self.request.data.get('safe_code', '') safe_code2 = self.request.data.get('safe_code2', '') proxy_id = self.request.data.get('proxy_id', '') service_rate = self.request.data.get('service_rate', '') ramark_info = self.request.data.get('remark_info', '无备注!') print('ramark_info', ramark_info) if self.request.user.is_superuser: if get_proxyid: user_queryset = UserProfile.objects.filter(id=get_proxyid) if user_queryset: # 引入日志 log = MakeLogs() user = user_queryset[0] daili_queryset = UserProfile.objects.filter(id=user.proxy_id) if daili_queryset: daili_obj = daili_queryset[0] if add_money: user.total_money = '%.2f' % (Decimal(user.total_money) + Decimal(add_money)) resp['msg'].append('加款成功') # 加日志 if not ramark_info: ramark_info = '无备注!' content = '用户:' + str(self.request.user.username) + ' 对 ' + str( user.username) + ' 加款 ' + ' 金额 ' + str(add_money) + ' 元。' + ' 备注:' + str(ramark_info) log.add_logs('3', content, self.request.user.id) # 更新代理余额 daili_obj.total_money = '%.2f' % (Decimal(daili_obj.total_money) + Decimal(add_money)) daili_obj.save() if minus_money: if Decimal(minus_money) <= Decimal(user.total_money) and Decimal(daili_obj.total_money) >= Decimal(minus_money): user.total_money = '%.2f' % (Decimal(user.total_money) - Decimal(minus_money)) resp['msg'].append('扣款成功') # 加日志 if not ramark_info: ramark_info = '无备注!' content = '用户:' + str(self.request.user.username) + ' 对 ' + str( user.username) + ' 扣款 ' + ' 金额 ' + str(minus_money) + ' 元。' + ' 备注:' + str( ramark_info) log.add_logs('3', content, self.request.user.id) # 更新代理余额 daili_obj.total_money = '%.2f' % ( Decimal(daili_obj.total_money) - Decimal(minus_money)) daili_obj.save() else: code = 400 resp['msg'].append('余额不足,扣款失败') else: # code = 400 resp['msg'].append('余额处理失败,代理不存在') if password == password2: if password: user.set_password(password) resp['msg'].append('密码修改成功') # 加日志 content = '用户:' + str(self.request.user.username) + ' 对 ' + str(user.username) + '修改密码' log.add_logs('3', content, self.request.user.id) else: resp['msg'].append('输入密码不一致') # if safe_code == safe_code2: # if password: # print('admin修改用户操作密码中..........') # user.safe_code = make_md5(safe_code) # resp['msg'].append('操作密码修改成功') # else: # resp['msg'].append('操作输入密码不一致') if str(is_active): if is_active == 'true': is_active = True if is_active == 'false': is_active = False resp['msg'].append('用户状态修改成功') user.is_active = is_active if service_rate: resp['msg'].append('费率修改成功') old_c = user.service_rate user.service_rate = float(service_rate) # 加日志 content = '用户:' + str(self.request.user.username) + ' 对 ' + str(user.username) + ' 原费率_' + str( old_c) + ' 改为_' + str(service_rate) log.add_logs('3', content, self.request.user.id) if notify_url: user.notify_url = notify_url resp['msg'].append('回调修改成功') if operatepw: print('operatepw', operatepw) user.safe_code = make_md5(operatepw) resp['msg'].append('操作密码修改成功') if auth_code: user.auth_code = make_auth_code() resp['msg'].append('秘钥修改成功') resp['auth_code'] = user.auth_code if proxy_id: user_proxy = UserProfile.objects.filter(id=proxy_id, is_proxy=False, is_active=True) if user_proxy: new_user = user_proxy[0] new_c = new_user.username old_c = user.username old_user = UserProfile.objects.filter(id=user.proxy_id) if old_user: old_user_name = old_user[0].username else: old_user_name = '' user.proxy_id = proxy_id resp['msg'].append('商户调整成功') user.save() serializer = UserDetailSerializer(user) resp['data'] = serializer.data content = '商户调整:' + str(old_c) + '属:' + str(old_user_name) + ' 调整给:' + str(new_c) log.add_logs('3', content, self.request.user.id) else: resp['msg'].append('调整失败,代理不存在') # code = 200 user.save() else: code = 404 resp['msg'].append('操作对象不存在') else: if password == password2: if password: print('admin修改密码中..........') self.request.user.set_password(password) code = 200 resp['msg'].append('密码修改成功') self.request.user.save() else: code = 404 resp['msg'].append('输入密码不一致') if original_safe_code: if make_md5(original_safe_code) == self.request.user.safe_code: if safe_code == safe_code2: if safe_code: print('admin修改操作密码中..........') safe_code = make_md5(safe_code) self.request.user.safe_code = safe_code code = 200 resp['msg'].append('操作密码修改成功') self.request.user.save() else: code = 404 resp['msg'].append('操作密码输入不一致') else: code = 404 resp['msg'].append('操作密码错误') else: code = 404 resp['msg'].append('操作密码错误1') # tuoxie 修改 tuoxie001 if not self.request.user.is_proxy and not self.request.user.is_superuser: id_list = [user_obj.id for user_obj in UserProfile.objects.filter(proxy_id=self.request.user.id)] if get_proxyid: if int(get_proxyid) in id_list: user = UserProfile.objects.filter(id=get_proxyid)[0] # 引入日志 log = MakeLogs() if add_money: user.total_money = '%.2f' % (Decimal(user.total_money) + Decimal(add_money)) resp['msg'].append('加款成功') # 加日志 if not ramark_info: ramark_info = '无备注!' content = '用户:' + str(self.request.user.username) + ' 对 ' + str( user.username) + ' 加款 ' + ' 金额 ' + str(add_money) + ' 元。' + ' 备注:' + str(ramark_info) log.add_logs('3', content, self.request.user.id) # 更新代理余额 self.request.user.total_money = '%.2f' % ( Decimal(self.request.user.total_money) - Decimal(add_money)) self.request.user.save() if minus_money: if Decimal(minus_money) <= Decimal(user.total_money) and Decimal(self.request.user.total_money) >= Decimal(minus_money): user.total_money = '%.2f' % (Decimal(user.total_money) - Decimal(minus_money)) resp['msg'].append('扣款成功') # 加日志 if not ramark_info: ramark_info = '无备注!' content = '用户:' + str(self.request.user.username) + ' 对 ' + str( user.username) + ' 扣款 ' + ' 金额 ' + str(minus_money) + ' 元。' + ' 备注:' + str(ramark_info) log.add_logs('3', content, self.request.user.id) # 更新代理余额 self.request.user.total_money = '%.2f' % ( Decimal(self.request.user.total_money) - Decimal(minus_money)) self.request.user.save() else: code = 404 resp['msg'].append('余额不足,扣款失败') if password == password2: if password: user.set_password(password) resp['msg'].append('密码修改成功') # 加日志 content = '用户:' + str(self.request.user.username) + ' 对 ' + str(user.username) + '修改密码' log.add_logs('3', content, self.request.user.id) else: # code = 404 resp['msg'].append('输入密码不一致') if notify_url: user.notify_url = notify_url resp['msg'].append('回调修改成功') if auth_code: user.auth_code = make_auth_code() resp['msg'].append('秘钥修改成功') resp['auth_code'] = user.auth_code # resp['auth_code'].append(str(user.auth_code)) if str(is_active): if is_active == 'true': is_active = True if is_active == 'false': is_active = False resp['msg'].append('用户状态修改成功') user.is_active = is_active if service_rate: resp['msg'].append('费率修改成功') old_c = user.service_rate user.service_rate = float(service_rate) # 加日志 content = '用户:' + str(self.request.user.username) + ' 对 ' + str(user.username) + ' 原费率_' + str( old_c) + ' 改为_' + str(service_rate) log.add_logs('3', content, self.request.user.id) if safe_code == safe_code2: if password: print('代理修改商户操作密码中..........') self.request.user.safe_code = make_md5(safe_code) resp['msg'].append('操作密码修改成功') else: # code = 404 resp['msg'].append('操作输入密码不一致') # code = 200 user.save() else: code = 404 resp['msg'].append('修改代理号不存在') # 修改tuoxie本身数据 if not get_proxyid and not self.request.user.is_proxy: qq = self.request.data.get('qq', '') user = self.request.user # if add_money: # user.total_money = '%.2f' % (Decimal(user.total_money) + Decimal(add_money)) # resp['msg'].append('加款成功') # if minus_money: # if Decimal(minus_money) < Decimal(user.total_money): # user.total_money = '%.2f' % (Decimal(user.total_money) - Decimal(minus_money)) # resp['msg'].append('扣款成功') # else: # code = 404 # resp['msg'].append('余额不足,扣款失败') if password == password2: if password: user.set_password(password) resp['msg'].append('密码修改成功') else: code = 404 resp['msg'].append('输入密码不一致') if notify_url: user.notify_url = notify_url resp['msg'].append('回调修改成功') if qq: user.qq = qq if auth_code: user.auth_code = make_auth_code() resp['msg'].append(user.auth_code) if service_rate: resp['msg'].append('费率修改成功') user.service_rate = service_rate user.save() # tuoxie001 修改自己 if self.request.user.is_proxy: user = self.get_object() if password: if password == password2: user.set_password(password) resp['msg'].append('密码修改成功') elif password != password2: code = 404 resp['msg'].append('输入密码不一致') else: code = 403 resp['msg'].append('改账号无权限') if notify_url: user.notify_url = notify_url resp['msg'].append('回调修改成功') if auth_code: user.auth_code = make_auth_code() resp['msg'].append(user.auth_code) if service_rate: resp['msg'].append('费率修改失败') if original_safe_code: if make_md5(original_safe_code) == self.request.user.safe_code: if safe_code == safe_code2: if safe_code: print('admin修改操作密码中..........') safe_code = make_md5(safe_code) self.request.user.safe_code = safe_code resp['msg'].append('操作密码修改成功') else: code = 404 resp['msg'].append('操作密码输入不一致') else: code = 404 resp['msg'].append('操作密码错误') user.save() return Response(data=resp, status=code)
def create(self, request, *args, **kwargs): resp = {'msg': []} serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) proxy_user = self.request.user validated_data = serializer.validated_data withdraw_no = generate_order_no(proxy_user.id) validated_data['withdraw_no'] = withdraw_no bankid = validated_data.get('bank') safe_code = validated_data.get('safe_code') googel_code = validated_data.get('googel_code') if proxy_user.is_google: try: # 判断用户是否已经绑定Google令牌 key = Google2Auth.objects.get(user_id=self.request.user.id).key except: raise Http404("未绑定令牌") if not Google_Verify_Result(key, googel_code): # 验证令牌 return Response({"msg": "令牌失效"}, status=400) if make_md5(safe_code) == proxy_user.safe_code: with_banklist = [ wd.id for wd in WithDrawBankInfo.objects.filter( user_id=proxy_user.id) ] if bankid in with_banklist: # 更新商户余额 withdraw_money = validated_data.get('withdraw_money') proxy_user.money = '%.2f' % ( Decimal(proxy_user.money) - Decimal(validated_data.get('withdraw_money', ''))) # 更新代理余额 daili_queryset = UserProfile.objects.filter( id=proxy_user.proxy_id) if daili_queryset: daili_obj = daili_queryset[0] daili_obj.money = '%.2f' % ( Decimal(daili_obj.money) - Decimal(validated_data.get('withdraw_money', ''))) proxy_user.save() daili_obj.save() # 引入日志 log = MakeLogs() content = '用户:' + str( proxy_user.username) + '创建提现_' + '订单号_ ' + str( withdraw_no) + ' 金额 ' + str(withdraw_money) + ' 元' log.add_logs('2', content, proxy_user.id) bank_queryset = WithDrawBankInfo.objects.filter(id=bankid) if bank_queryset: bank_obj = bank_queryset[0] validated_data['bank'] = bank_obj del validated_data['safe_code'] del validated_data['googel_code'] withdraw_obj = WithDrawInfo.objects.create( **validated_data) code = 200 resp['msg'] = '创建成功' serializer = UserWithDrawListSerializer(withdraw_obj) return Response(data=serializer.data, status=code) else: code = 400 resp['msg'] = '创建失败,不存在代理收款银行卡' return Response(data=resp, status=code) else: code = 400 resp['msg'] = '创建失败' return Response(data=resp, status=code) else: code = 400 resp['msg'] = '绑定的银行卡id不存在' return Response(data=resp, status=code) else: code = 400 resp['msg'] = '操作密码错误' return Response(data=resp, status=code)
def update(self, request, *args, **kwargs): admin_user = self.request.user user = self.get_object() resp = {'msg': []} code = 200 serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) password = self.request.data.get('password', '') password2 = self.request.data.get('password2', '') auth_code = self.request.data.get('auth_code', '') safe_code = self.request.data.get('safe_code', '') safe_code2 = self.request.data.get('safe_code2', '') add_money = serializer.validated_data.get('add_money') desc_money = serializer.validated_data.get('desc_money') remark = serializer.validated_data.get('remark') is_active = serializer.validated_data.get('is_active', '') is_google = serializer.validated_data.get('is_google', '') proxy_q = UserProfile.objects.filter(id=user.proxy_id) print(type(user.total_money), 99) if not proxy_q: code = 400 resp['msg'] = '对应代理不存在' return Response(data=resp, status=code) proxy_user = proxy_q[0] log = MakeLogs() if add_money: print('add_money', add_money) # user.total_money = '%.2f' % (Decimal(user.total_money) + add_money) # user.money = '%.2f' % (Decimal(user.total_money) + add_money) user.total_money = ((user.total_money) + add_money) user.money = ((user.total_money) + add_money) # 加日志 if not remark: remark = '无备注!' content = '用户:' + str(admin_user.username) + ' 对 ' + str( user.username) + ' 加款 ' + ' 金额 ' + str( add_money) + ' 元。' + ' 备注:' + str(remark) log.add_logs('3', content, admin_user.id) # 更新代理余额 # proxy_user.total_money = '%.2f' % (proxy_user.total_money + add_money) # proxy_user.money = '%.2f' % (proxy_user.money + add_money) proxy_user.total_money = (proxy_user.total_money + add_money) proxy_user.money = (proxy_user.money + add_money) user.save() proxy_user.save() if desc_money: print(type(desc_money), type(user.total_money)) if desc_money <= (user.total_money) and ( proxy_user.total_money) >= desc_money: # user.total_money = '%.2f' % (Decimal(user.total_money) - desc_money) # user.money = '%.2f' % (user.money - desc_money) user.total_money = ((user.total_money) - desc_money) user.money = (user.money - desc_money) # 加日志 if not remark: remark = '无备注!' content = '用户:' + str(admin_user.username) + ' 对 ' + str( user.username) + ' 扣款 ' + ' 金额 ' + str( desc_money) + ' 元。' + ' 备注:' + str(remark) log.add_logs('3', content, admin_user.id) # 更新代理余额 # proxy_user.total_money = '%.2f' % (proxy_user.total_money - desc_money) # proxy_user.money = '%.2f' % (proxy_user.money - desc_money) proxy_user.total_money = (proxy_user.total_money - desc_money) proxy_user.money = (proxy_user.money - desc_money) proxy_user.save() else: code = 400 resp['msg'] = '对应代理不存在' return Response(data=resp, status=code) if password: if password == password2: user.set_password(password) elif password != password2: code = 400 if auth_code: user.auth_code = make_auth_code() if safe_code == safe_code2: if safe_code: print('admin修改 商户 操作密码中..........') safe_code = make_md5(safe_code) user.safe_code = safe_code else: code = 400 if str(is_active): if is_active: user.is_active = is_active if is_active == False: user.is_active = is_active if str(is_google): if is_google: pass # user.is_active = is_active if is_google == False: user.is_google = is_google user.save() g_q = Google2Auth.objects.filter(user_id=user.id) if g_q: g_q[0].delete() user.save() serializer = AdminUserDetailSerializer(user) return Response(data=serializer.data, status=code)
def nsmbackcall(request): order_no = request.GET.get('order_no', None) if order_no: order_queryset = OrderInfo.objects.filter(pay_status=0, order_no=order_no, trade_no__isnull=False) if order_queryset: postdata = {} order_obj = order_queryset[0] mchid = order_obj.nsm.appid notify = order_obj.notify_url postdata['msg'] = '订单处理成功!' postdata['pay_status'] = 1 postdata['add_time'] = str(order_obj.add_time) postdata['order_money'] = order_obj.order_money postdata['real_money'] = order_obj.real_money postdata['order_id'] = order_obj.order_id postdata['order_no'] = order_obj.order_no postdata['channel'] = order_obj.channel.channel_name postdata['remark'] = order_obj.remark print('postdata', postdata) key = str(order_obj.user.uid + order_obj.order_no + str(order_obj.order_money) + order_obj.user.auth_code) postdata['key'] = make_md5(key) try: r = requests.get( 'https://spay3.swiftpass.cn/spay/getCallbackUrl?mchId=' + order_obj.nsm.appid + '&userId=&outTradeNo=' + order_obj.out_trade_no) if r.status_code == 200: money_pattern = re.compile(r'<p id="money">(.*?)</p>') orderNoMch_pattern = re.compile( r'<p id="orderNoMch">(.*?)</p>') outTradeNo_pattern = re.compile( r'<p id="outTradeNo">(.*?)</p>') money = money_pattern.findall(r.text) orderNoMch = orderNoMch_pattern.findall(r.text) outTradeNo = outTradeNo_pattern.findall(r.text) print('农商回调', money, orderNoMch, outTradeNo) if money[0] and outTradeNo[ 0] == order_obj.out_trade_no and orderNoMch[0]: print('8888') # 修改商户金额 User_obj = UserProfile.objects.get( id=order_obj.user_id) proxy_id = User_obj.proxy_id User_obj.total_money = '%.2f' % ( Decimal(User_obj.total_money) + Decimal(order_obj.real_money)) User_obj.money = '%.2f' % ( Decimal(User_obj.money) + Decimal(order_obj.real_money) - Decimal(order_obj.service_money)) User_obj.save() # 修改代理金额 Proxy_obj = UserProfile.objects.get(id=proxy_id) Proxy_obj.total_money = '%.2f' % ( Decimal(Proxy_obj.total_money) + Decimal(order_obj.real_money)) Proxy_obj.money = '%.2f' % ( Decimal(Proxy_obj.money) + Decimal(order_obj.real_money) - Decimal(order_obj.service_money)) Proxy_obj.save() # 修改admin金额 admin_obj = UserProfile.objects.filter( is_superuser=1)[0] admin_obj.total_money = '%.2f' % ( Decimal(admin_obj.total_money) + Decimal(order_obj.real_money)) admin_obj.money = '%.2f' % ( Decimal(admin_obj.money) + Decimal(order_obj.real_money) - Decimal(order_obj.service_money)) admin_obj.save() # 修改农商收款 order_obj.nsm.money = (order_obj.nsm.money + order_obj.order_money).quantize( Decimal('0.00')) if order_obj.nsm.is_limit: order_obj.nsm.variable_money = ( order_obj.nsm.variable_money - order_obj.order_money).quantize( Decimal('0.00')) order_obj.nsm.save() # NsshInfo.objects.get(id=order_obj.nsm_id) # 回调用户 # 修改订单状态 postdata['pay_time'] = str( (datetime.datetime.now()).strftime( format('%Y-%m-%d %H:%M'))) order_obj.pay_time = postdata['pay_time'] headers = {'Content-Type': 'application/json'} data = json.dumps(postdata, cls=JsonCustomEncoder) print('notify', data) try: r = requests.post(notify, data=data, headers=headers, timeout=10) print(888, dir(r)) print(r.status_code) if r.status_code == 200: order_obj.pay_status = 1 order_obj.save() else: order_obj.pay_status = 3 order_obj.save() except Exception: order_obj.pay_status = 3 order_obj.save() if order_obj.nsm.variable_money <= 0 and order_obj.nsm.is_limit: order_obj.nsm.is_active = False order_obj.nsm.save() return HttpResponse('ok') except Exception: return JsonResponse(data={"msg": "验证失败"}, status=400) return JsonResponse(data={"msg": "验证失败"}, status=400)