def get_lottery(request): if request.method != "POST" or not request.is_ajax(): logger.warning("Experience refused no-ajax request!!!") raise Http404 result = {} if not request.user.is_authenticated() and not is_authenticated_app( request): result['code'] = -1 result['url'] = reverse('login') + "?next=" + reverse( 'activity_lottery') return JsonResponse(result) if request.user.scores < 10: result['code'] = -2 return JsonResponse(result) trans = charge_score(request.user, '1', 10, u"积分抽奖") if not trans: result['code'] = -3 logger.error("lottery 10 scores charge error!") return JsonResponse(result) event = UserEvent.objects.create(user=request.user, event_type='7', audit_state='1') trans.user_event = event trans.save(update_fields=['user_event']) award_list = [ (1, 61), (2, 30), (3, 6), (4, 2), (5, 1), (6, 0), ] itemid = weighted_random(award_list) translist = None if itemid == 2: translist = charge_score(request.user, '0', 10, u'抽奖获奖') elif itemid == 3: translist = charge_score(request.user, '0', 50, u'抽奖获奖') elif itemid == 4: translist = charge_money(request.user, '0', 80, u'抽奖获奖') elif itemid == 5: translist = charge_money(request.user, '0', 200, u'抽奖获奖') if itemid != 1 and not translist: result['code'] = 4 logger.error("Get lottery award charge error!") result['msg'] = "记账失败!" else: result['code'] = 0 result['itemid'] = itemid if itemid != 1: LotteryRecord.objects.create(user=request.user, award=AwardTable.get(itemid, u'未知')) translist.user_event = event translist.save(update_fields=['user_event']) return JsonResponse(result)
def get_vip_bonus(user, amount, type): if user.is_channel: return else: level = user.level cash = amount * VIP_BONUS[level][type] translist = charge_money(user, '0', cash, u'vip奖励')
def get_vip_bonus(user, amount, type): if user.is_channel: return else: level = user.level cash = amount*VIP_BONUS[level][type] translist = charge_money(user, '0', cash, u'vip奖励')
def vip_judge(user, with_amount): obj, created = UserStatis.objects.get_or_create(user=user) obj.week_statis = F('week_statis') + with_amount obj.month_statis = F('month_statis') + with_amount obj.save(update_fields=['week_statis', 'month_statis']) if user.is_channel: return level = user.level total = user.with_total ntotal = user.with_total + with_amount user.with_total = ntotal keys = sorted(VIP_AMOUNT.keys()) for key in keys: value = VIP_AMOUNT[key] if ntotal >= value and total < value: if key > level: user.level = key charge_money(user, '0', VIP_BONUS[key]['money'], u'VIP升级奖励') msg_content = u'恭喜您的会员等级提升为VIP' + str(key) + u'!' Message.objects.create(user=user, content=msg_content, title=u"会员升级") user.save(update_fields=['level', 'with_total'])
def handle(self, *args, **options): logger.info("******Auto-withdrawing is beginning*********") begin_time = time.time() channels = Channel.objects.filter(user__balance__gte=50000) for ch in channels: user = ch.user card = user.user_bankcard.first() if not card: continue translist = charge_money(user, '1', user.balance, u'系统自动提现') if translist: event = UserEvent.objects.create(user=user, event_type='2', invest_account=card.card_number, invest_amount=user.balance, audit_state='1') translist.user_event = event translist.save(update_fields=['user_event']) end_time = time.time() logger.info("******Auto-withdrawing is finished, time:%s*********",end_time-begin_time)
def consume(user): try: obj = User_Envelope.objects.get(user=user) except: return -1 else: if obj.envelope_left < 1: return -2 obj.envelope_left = F('envelope_left') - 1 obj.save(update_fields=['envelope_left']) amount = random.randint(1,20) event = UserEvent.objects.create(user=user, event_type='8', audit_state='1',invest_amount=amount) translist = charge_money(user, '0', amount, u'节日红包') if not translist: return -3 else: translist.user_event = event translist.save(update_fields=['user_event']) return amount
def handle(self, *args, **options): logger.info("******Auto-withdrawing is beginning*********") begin_time = time.time() channels = Channel.objects.filter(user__balance__gte=50000) for ch in channels: user = ch.user card = user.user_bankcard.first() if not card: continue translist = charge_money(user, '1', user.balance, u'系统自动提现') if translist: event = UserEvent.objects.create( user=user, event_type='2', invest_account=card.card_number, invest_amount=user.balance, audit_state='1') translist.user_event = event translist.save(update_fields=['user_event']) end_time = time.time() logger.info("******Auto-withdrawing is finished, time:%s*********", end_time - begin_time)
def invite_to_balance(request): inviter = request.user left_award = inviter.invite_account result = {} if left_award == 0: result['code'] = 1 result['msg'] = u'邀请奖励结余为0' else: translist = charge_money(inviter, '0', left_award, u'邀请奖励') if translist: inviter.invite_account = 0 inviter.save(update_fields=['invite_account']) event = UserEvent.objects.create(user=inviter, event_type='5', invest_amount=left_award, audit_state='1') translist.user_event = event translist.save(update_fields=['user_event']) result['code'] = 0 else: result['code'] = 2 result['msg'] = u'操作失败,请联系客服!' return JsonResponse(result)
def withdraw(request): user = request.user result = {'code': -1, 'msg': ''} withdraw_amount = request.POST.get("amount", None) if not withdraw_amount: result['code'] = 3 result['msg'] = u'传入参数不足!' return JsonResponse(result) try: withdraw_amount = int(withdraw_amount) except ValueError: result['code'] = -1 result['msg'] = u'参数不合法!' return JsonResponse(result) if withdraw_amount < 1000 or withdraw_amount > user.balance: result['code'] = -1 result['msg'] = u'余额不足!' return JsonResponse(result) if not user.zhifubao or not user.zhifubao_name: result['code'] = -1 result['msg'] = u'请先绑定支付宝!' else: translist = charge_money(user, '1', withdraw_amount, u'提现') if translist: event = UserEvent.objects.create(user=user, event_type='2', invest_account=user.zhifubao, invest_amount=withdraw_amount, audit_state='1') translist.user_event = event translist.save(update_fields=['user_event']) result['code'] = 0 result['msg'] = u'提交成功,请耐心等待审核通过!' else: result['code'] = -2 result['msg'] = u'提交失败!' return JsonResponse(result)
for row in rtable: with transaction.atomic(): id = row[0] result = row[1] reason = row[3] event = UserEvent.objects.get(id=id) if event.audit_state != '1' or event.translist.exists(): continue log = AuditLog(user=admin_user,item=event) event_user = event.user translist = None if result: amount = int(row[2]*100) log.audit_result = True project = event.content_object.project translist = charge_money(event_user, '0', amount, project.title) if project.is_vip_bonus: get_vip_bonus(event_user, amount, 'finance') if translist: event.audit_state = '0' translist.user_event = event translist.save(update_fields=['user_event']) # Invest_Record.objects.create(invest_date=event.time,invest_company=event.content_object.company.name, # user_name=event_user.zhifubao_name,zhifubao=event_user.zhifubao, # invest_mobile=event.invest_account,invest_period=event.invest_term, # invest_amount=event.invest_amount,return_amount=amount/100.0,wafuli_account=event_user.mobile, # return_date=datetime.date.today(),remark=event.remark) else: logger.error(u"Charging cash is failed!!!") logger.error("UserEvent:" + str(id) + u" 现金记账失败,请检查原因!!!!") continue
for row in rtable: with transaction.atomic(): id = row[0] result = row[1] reason = row[3] event = UserEvent.objects.get(id=id) if event.audit_state != '1' or event.translist.exists(): continue log = AuditLog(user=admin_user, item=event) event_user = event.user translist = None if result: amount = int(row[2] * 100) log.audit_result = True project = event.content_object.project translist = charge_money(event_user, '0', amount, project.title) if project.is_vip_bonus: get_vip_bonus(event_user, amount, 'finance') if translist: event.audit_state = '0' translist.user_event = event translist.save(update_fields=['user_event']) # Invest_Record.objects.create(invest_date=event.time,invest_company=event.content_object.company.name, # user_name=event_user.zhifubao_name,zhifubao=event_user.zhifubao, # invest_mobile=event.invest_account,invest_period=event.invest_term, # invest_amount=event.invest_amount,return_amount=amount/100.0,wafuli_account=event_user.mobile, # return_date=datetime.date.today(),remark=event.remark) else: logger.error(u"Charging cash is failed!!!") logger.error("UserEvent:" + str(id) + u" 现金记账失败,请检查原因!!!!")
def admin_withdraw(request): admin_user = request.user if request.method == "GET": if not (admin_user.is_authenticated() and admin_user.is_staff): return redirect( reverse('admin:login') + "?next=" + reverse('admin_withdraw')) return render(request, "admin_withdraw.html") if request.method == "POST": res = {} if not admin_user.has_admin_perms('004'): res['code'] = -5 res['res_msg'] = u'您没有操作权限!' return JsonResponse(res) if not request.is_ajax(): raise Http404 if not (admin_user.is_authenticated() and admin_user.is_staff): res['code'] = -1 res['url'] = reverse('admin:login') + "?next=" + reverse( 'admin_user') return JsonResponse(res) event_id = request.POST.get('id', None) type = request.POST.get('type', None) if not event_id or not type: res['code'] = -2 res['res_msg'] = u'传入参数不足,请联系技术人员!' return JsonResponse(res) type = int(type) event_id = int(event_id) event = UserEvent.objects.get(id=event_id) if event.audit_state != '1': res['code'] = -3 res['res_msg'] = u'该项目已审核过,不要重复审核!' return JsonResponse(res) log = AuditLog(user=admin_user, item=event) if type == 1: event.audit_state = '0' log.audit_result = True res['code'] = 0 #用户提现成功,立即发放邀请人100积分奖励 inviter = event.user.inviter if inviter: if not UserEvent.objects.filter(user=event.user, event_type='2', audit_state='0').exists(): invite_award_scores = settings.AWARD_SCORES inviter.invite_scores += invite_award_scores translist = charge_score(inviter, '0', invite_award_scores, u"邀请奖励") if translist: logger.debug( 'Inviting Award scores is successfully payed!') inviter.save(update_fields=['invite_scores']) translist.user_event = event translist.save(update_fields=['user_event']) else: logger.debug( 'Inviting Award scores is failed to pay!!!') elif type == 2: reason = request.POST.get('reason', '') if not reason: res['code'] = -2 res['res_msg'] = u'传入参数不足,请联系技术人员!' return JsonResponse(res) event.audit_state = '2' log.reason = reason log.audit_result = False translist = charge_money(event.user, '0', event.invest_amount, u'冲账') if translist: translist.user_event = event translist.save(update_fields=['user_event']) res['code'] = 0 else: logger.critical(u"Charging cash is failed!!!") res['code'] = -2 res['res_msg'] = u"现金记账失败,请检查输入合法性后再次提交!" return JsonResponse(res) admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=event.user, event_type='2') log.admin_item = admin_event log.save() event.audit_time = log.time event.save(update_fields=['audit_state', 'audit_time']) return JsonResponse(res)
def admin_user(request): admin_user = request.user if request.method == "GET": if not (admin_user.is_authenticated() and admin_user.is_staff): return redirect( reverse('admin:login') + "?next=" + reverse('admin_user')) return render(request, "admin_user.html") if request.method == "POST": res = {} if not admin_user.has_admin_perms('005'): res['code'] = -5 res['res_msg'] = u'您没有操作权限!' return JsonResponse(res) if not request.is_ajax(): raise Http404 if not (admin_user.is_authenticated() and admin_user.is_staff): res['code'] = -1 res['url'] = reverse('admin:login') + "?next=" + reverse( 'admin_user') return JsonResponse(res) user_id = request.POST.get('id', None) type = request.POST.get('type', None) type = int(type) # if not user_id or type==1 and not (cash and score) or type==2 and not reason or type!=1 and type!=2: # res['code'] = -2 # res['res_msg'] = u'传入参数不足,请联系技术人员!' # return JsonResponse(res) obj_user = MyUser.objects.get(id=user_id) if type == 1: pcash = request.POST.get('pcash', 0) mcash = request.POST.get('mcash', 0) if not pcash: pcash = 0 if not mcash: mcash = 0 reason = request.POST.get('reason', '') if not pcash and not mcash or pcash and mcash or not reason: res['code'] = -2 res['res_msg'] = u'传入参数不足,请联系技术人员!' return JsonResponse(res) try: pcash = Decimal(pcash) mcash = Decimal(mcash) except: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) if pcash < 0 or mcash < 0: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) translist = None if pcash > 0: translist = charge_money(obj_user, '0', pcash, reason) elif mcash > 0: translist = charge_money(obj_user, '1', mcash, reason) if translist: admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=obj_user, remark=reason, event_type='4') translist.admin_event = admin_event translist.save(update_fields=['admin_event']) res['code'] = 0 else: res['code'] = -4 res['res_msg'] = "现金记账失败,请检查输入合法性后再次提交!" elif type == 2: pscore = request.POST.get('pscore', 0) mscore = request.POST.get('mscore', 0) if not pscore: pscore = 0 if not mscore: mscore = 0 reason = request.POST.get('reason', '') if not pscore and not mscore or pscore and mscore or not reason: res['code'] = -2 res['res_msg'] = u'传入参数不足,请联系技术人员!' return JsonResponse(res) try: pscore = int(pscore) mscore = int(mscore) except: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) if pscore < 0 or mscore < 0: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) scoretranslist = None if pscore > 0: scoretranslist = charge_score(obj_user, '0', pscore, reason) elif mscore > 0: scoretranslist = charge_score(obj_user, '1', mscore, reason) if scoretranslist: admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=obj_user, remark=reason, event_type='5') scoretranslist.admin_event = admin_event scoretranslist.save(update_fields=['admin_event']) res['code'] = 0 else: res['code'] = -4 res['res_msg'] = "积分记账失败,请检查输入合法性后再次提交!" elif type == 3: obj_user.is_active = False obj_user.save(update_fields=['is_active']) admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=obj_user, event_type='6', remark=u"加黑") res['code'] = 0 elif type == 4: obj_user.is_active = True obj_user.save(update_fields=['is_active']) admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=obj_user, event_type='6', remark=u"去黑") res['code'] = 0 return JsonResponse(res)
def admin_return(request): admin_user = request.user if request.method == "GET": if not (admin_user.is_authenticated() and admin_user.is_staff): return redirect( reverse('admin:login') + "?next=" + reverse('admin_return')) return render(request, "admin_return.html") if request.method == "POST": res = {} if not admin_user.has_admin_perms('002'): res['code'] = -5 res['res_msg'] = u'您没有操作权限!' return JsonResponse(res) if not request.is_ajax(): raise Http404 if not (admin_user.is_authenticated() and admin_user.is_staff): res['code'] = -1 res['url'] = reverse('admin:login') + "?next=" + reverse( 'admin_return') return JsonResponse(res) event_id = request.POST.get('id', None) cash = request.POST.get('cash', None) score = request.POST.get('score', None) type = request.POST.get('type', None) reason = request.POST.get('reason', None) type = int(type) if not event_id or type == 1 and not ( cash and score) or type == 2 and not reason or type != 1 and type != 2: res['code'] = -2 res['res_msg'] = u'传入参数不足,请联系技术人员!' return JsonResponse(res) event = UserEvent.objects.get(id=event_id) event_user = event.user log = AuditLog(user=admin_user, item=event) translist = None scoretranslist = None if type == 1: try: cash = Decimal(cash) score = int(score) except: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) if cash < 0 or score < 0: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) if event.audit_state != '1': res['code'] = -3 res['res_msg'] = u'该项目已审核过,不要重复审核!' return JsonResponse(res) if event.translist.exists(): logger.critical("Returning cash is repetitive!!!") res['code'] = -3 res['res_msg'] = u"操作失败,返现重复!" else: log.audit_result = True translist = charge_money(event_user, '0', cash, u'福利返现') scoretranslist = charge_score(event_user, '0', score, u'福利返现(积分)') if translist and scoretranslist: event.audit_state = '0' translist.user_event = event translist.save(update_fields=['user_event']) scoretranslist.user_event = event scoretranslist.save(update_fields=['user_event']) res['code'] = 0 else: res['code'] = -4 res['res_msg'] = "注意,重复提交时只提交失败项目,成功的可以输入0。\n" if not translist: logger.error(u"Charging cash is failed!!!") res['res_msg'] += u"现金记账失败,请检查输入合法性后再次提交!" if not scoretranslist: logger.error(u"Charging score is failed!!!") res['res_msg'] += u"积分记账失败,请检查输入合法性后再次提交!" else: event.audit_state = '2' log.audit_result = False log.reason = reason res['code'] = 0 if res['code'] == 0: admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=event_user, event_type='1') if translist: translist.admin_event = admin_event translist.save(update_fields=['admin_event']) if scoretranslist: scoretranslist.admin_event = admin_event scoretranslist.save(update_fields=['admin_event']) log.admin_item = admin_event log.save() event.audit_time = log.time event.save(update_fields=['audit_state', 'audit_time']) return JsonResponse(res)
def admin_withdraw(request): admin_user = request.user if request.method == "GET": if not ( admin_user.is_authenticated() and admin_user.is_staff): return redirect(reverse('admin:login') + "?next=" + reverse('admin_withdraw')) return render(request,"admin_withdraw.html") if request.method == "POST": res = {} if not admin_user.has_admin_perms('004'): res['code'] = -5 res['res_msg'] = u'您没有操作权限!' return JsonResponse(res) if not request.is_ajax(): raise Http404 if not ( admin_user.is_authenticated() and admin_user.is_staff): res['code'] = -1 res['url'] = reverse('admin:login') + "?next=" + reverse('admin_user') return JsonResponse(res) event_id = request.POST.get('id', None) type = request.POST.get('type', None) if not event_id or not type: res['code'] = -2 res['res_msg'] = u'传入参数不足,请联系技术人员!' return JsonResponse(res) type = int(type) event_id = int(event_id) event = UserEvent.objects.get(id=event_id) if event.audit_state != '1': res['code'] = -3 res['res_msg'] = u'该项目已审核过,不要重复审核!' return JsonResponse(res) log = AuditLog(user=admin_user,item=event) if type==1: event.audit_state = '0' log.audit_result = True res['code'] = 0 #用户提现成功,立即发放邀请人100积分奖励 inviter = event.user.inviter if inviter: if not UserEvent.objects.filter(user=event.user, event_type='2', audit_state='0').exists(): invite_award_scores = settings.AWARD_SCORES inviter.invite_scores += invite_award_scores translist = charge_score(inviter, '0', invite_award_scores, u"邀请奖励") if translist: logger.debug('Inviting Award scores is successfully payed!') inviter.save(update_fields=['invite_scores']) translist.user_event = event translist.save(update_fields=['user_event']) else: logger.debug('Inviting Award scores is failed to pay!!!') elif type == 2: reason = request.POST.get('reason', '') if not reason: res['code'] = -2 res['res_msg'] = u'传入参数不足,请联系技术人员!' return JsonResponse(res) event.audit_state = '2' log.reason = reason log.audit_result = False translist = charge_money(event.user, '0', event.invest_amount, u'冲账') if translist: translist.user_event = event translist.save(update_fields=['user_event']) res['code'] = 0 else: logger.critical(u"Charging cash is failed!!!") res['code'] = -2 res['res_msg'] = u"现金记账失败,请检查输入合法性后再次提交!" return JsonResponse(res) admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=event.user, event_type='2') log.admin_item = admin_event log.save() event.audit_time = log.time event.save(update_fields=['audit_state','audit_time']) return JsonResponse(res)
def admin_user(request): admin_user = request.user if request.method == "GET": if not ( admin_user.is_authenticated() and admin_user.is_staff): return redirect(reverse('admin:login') + "?next=" + reverse('admin_user')) return render(request,"admin_user.html") if request.method == "POST": res = {} if not admin_user.has_admin_perms('005'): res['code'] = -5 res['res_msg'] = u'您没有操作权限!' return JsonResponse(res) if not request.is_ajax(): raise Http404 if not ( admin_user.is_authenticated() and admin_user.is_staff): res['code'] = -1 res['url'] = reverse('admin:login') + "?next=" + reverse('admin_user') return JsonResponse(res) user_id = request.POST.get('id', None) type = request.POST.get('type', None) type = int(type) # if not user_id or type==1 and not (cash and score) or type==2 and not reason or type!=1 and type!=2: # res['code'] = -2 # res['res_msg'] = u'传入参数不足,请联系技术人员!' # return JsonResponse(res) obj_user = MyUser.objects.get(id=user_id) if type==1: pcash = request.POST.get('pcash', 0) mcash = request.POST.get('mcash', 0) if not pcash: pcash = 0 if not mcash: mcash = 0 reason = request.POST.get('reason', '') if not pcash and not mcash or pcash and mcash or not reason: res['code'] = -2 res['res_msg'] = u'传入参数不足,请联系技术人员!' return JsonResponse(res) try: pcash = Decimal(pcash) mcash = Decimal(mcash) except: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) if pcash < 0 or mcash < 0: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) translist = None if pcash > 0: translist = charge_money(obj_user, '0', pcash, reason) elif mcash > 0: translist = charge_money(obj_user, '1', mcash, reason) if translist: admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=obj_user, remark=reason, event_type='4') translist.admin_event = admin_event translist.save(update_fields=['admin_event']) res['code'] = 0 else: res['code'] = -4 res['res_msg'] = "现金记账失败,请检查输入合法性后再次提交!" elif type == 2: pscore = request.POST.get('pscore', 0) mscore = request.POST.get('mscore', 0) if not pscore: pscore = 0 if not mscore: mscore = 0 reason = request.POST.get('reason', '') if not pscore and not mscore or pscore and mscore or not reason: res['code'] = -2 res['res_msg'] = u'传入参数不足,请联系技术人员!' return JsonResponse(res) try: pscore = int(pscore) mscore = int(mscore) except: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) if pscore < 0 or mscore < 0: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) scoretranslist = None if pscore > 0: scoretranslist = charge_score(obj_user, '0', pscore, reason) elif mscore > 0: scoretranslist = charge_score(obj_user, '1', mscore, reason) if scoretranslist: admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=obj_user, remark=reason,event_type='5') scoretranslist.admin_event = admin_event scoretranslist.save(update_fields=['admin_event']) res['code'] = 0 else: res['code'] = -4 res['res_msg'] = "积分记账失败,请检查输入合法性后再次提交!" elif type == 3: obj_user.is_active = False obj_user.save(update_fields=['is_active']) admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=obj_user, event_type='6', remark=u"加黑") res['code'] = 0 elif type == 4: obj_user.is_active = True obj_user.save(update_fields=['is_active']) admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=obj_user, event_type='6', remark=u"去黑") res['code'] = 0 return JsonResponse(res)
def admin_return(request): admin_user = request.user if request.method == "GET": if not ( admin_user.is_authenticated() and admin_user.is_staff): return redirect(reverse('admin:login') + "?next=" + reverse('admin_return')) return render(request,"admin_return.html") if request.method == "POST": res = {} if not admin_user.has_admin_perms('002'): res['code'] = -5 res['res_msg'] = u'您没有操作权限!' return JsonResponse(res) if not request.is_ajax(): raise Http404 if not ( admin_user.is_authenticated() and admin_user.is_staff): res['code'] = -1 res['url'] = reverse('admin:login') + "?next=" + reverse('admin_return') return JsonResponse(res) event_id = request.POST.get('id', None) cash = request.POST.get('cash', None) score = request.POST.get('score', None) type = request.POST.get('type', None) reason = request.POST.get('reason', None) type = int(type) if not event_id or type==1 and not (cash and score) or type==2 and not reason or type!=1 and type!=2: res['code'] = -2 res['res_msg'] = u'传入参数不足,请联系技术人员!' return JsonResponse(res) event = UserEvent.objects.get(id=event_id) event_user = event.user log = AuditLog(user=admin_user,item=event) translist = None scoretranslist = None if type==1: try: cash = Decimal(cash) score = int(score) except: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) if cash < 0 or score < 0: res['code'] = -2 res['res_msg'] = u"操作失败,输入不合法!" return JsonResponse(res) if event.audit_state != '1': res['code'] = -3 res['res_msg'] = u'该项目已审核过,不要重复审核!' return JsonResponse(res) if event.translist.exists(): logger.critical("Returning cash is repetitive!!!") res['code'] = -3 res['res_msg'] = u"操作失败,返现重复!" else: log.audit_result = True translist = charge_money(event_user, '0', cash, u'福利返现') scoretranslist = charge_score(event_user, '0', score, u'福利返现(积分)') if translist and scoretranslist: event.audit_state = '0' translist.user_event = event translist.save(update_fields=['user_event']) scoretranslist.user_event = event scoretranslist.save(update_fields=['user_event']) res['code'] = 0 else: res['code'] = -4 res['res_msg'] = "注意,重复提交时只提交失败项目,成功的可以输入0。\n" if not translist: logger.error(u"Charging cash is failed!!!") res['res_msg'] += u"现金记账失败,请检查输入合法性后再次提交!" if not scoretranslist: logger.error(u"Charging score is failed!!!") res['res_msg'] += u"积分记账失败,请检查输入合法性后再次提交!" else: event.audit_state = '2' log.audit_result = False log.reason = reason res['code'] = 0 if res['code'] == 0: admin_event = AdminEvent.objects.create(admin_user=admin_user, custom_user=event_user, event_type='1') if translist: translist.admin_event = admin_event translist.save(update_fields=['admin_event']) if scoretranslist: scoretranslist.admin_event = admin_event scoretranslist.save(update_fields=['admin_event']) log.admin_item = admin_event log.save() event.audit_time = log.time event.save(update_fields=['audit_state','audit_time']) return JsonResponse(res)