def post(self, request, *args, **kwargs): if not request.user.has_perms(self.permission_required): return JSONResponse(success=False, msg='您无此操作权限!') form = ConfigEditForm(request.POST) if not form.is_valid(): error = form.errors.values()[0] return JSONResponse(success=False, msg=error) data = form.cleaned_data configs = SysConfig.objects.all() config_names = [ 'REWARD_LEVEL', 'FIRST_AWARD', 'SECOND_AWARD', 'THREE_AWARD', 'WITHDRAW_HOW_DAYS', 'WITHDRAW_RATE' ] for item in config_names: config = single_config(configs, item) config.configKey = item config.configValue = data.get(item) config.status = 0 config.createdTime = datetime.now( ) if not config.createdTime else config.createdTime config.createdUser = request.user.username if not config.createdUser else config.createdUser config.save() return JSONResponse()
def delete_shopimg(request): try: imgId = request.POST.get('imgId') shopId = request.POST.get('shopId') ShopImg.objects.filter(imgId=imgId).update(status=1) except Exception as e: return JSONResponse(msg='删除失败!', success=False) return JSONResponse()
def delete_user(request): try: data = json.loads(request.body.decode()) ids = data.get('ids') User.objects.filter(userId__in=ids).update(status=F('status').bitand(4) + F('status').bitand(2) + 1) post_logic_delete.send(sender='delete_user', app_label='user', model_name='user', ids=ids, update_user_id=request.user.id) except Exception as e: return JSONResponse(msg='删除失败!', success=False) return JSONResponse()
def delete_shopmanager(request): try: data = json.loads(request.body.decode()) ids = data.get('ids') AuthShopManager.objects.filter(id__in=ids).update(is_staff=False) post_logic_delete.send(sender='delete_auth_shopmanager', app_label='shop', model_name='auth_shopmanager', ids=ids, update_user_id=request.user.id) except Exception as e: return JSONResponse(msg='删除失败!', success=False) return JSONResponse()
def audit_withdraworder(request): id = request.POST.get('id') flag = request.POST.get('flag') try: order = WithdrawOrder.objects.get(wrId=id) if order.orderStatus != 0: return JSONResponse(msg='无法审核', success=False) order.orderStatus = 1 if flag else 0 order.save() return JSONResponse(msg='操作成功', success=True) except: return JSONResponse(msg='无法审核', success=False)
def delete_obd(request): try: data = json.loads(request.body.decode()) ids = data.get('ids') ObdDevice.objects.filter(sn__in=ids).delete() post_logic_delete.send(sender='delete_obd', app_label='obd', model_name='obddevice', ids=ids, update_user_id=request.user.id) except Exception as e: return JSONResponse(msg='删除失败!', success=False) return JSONResponse()
def delete_product(request): try: data = json.loads(request.body.decode()) ids = data.get('ids') # 逻辑删除 PayInfo.objects.filter(piId__in=ids).update( status=F('status').bitand(2) + 1) post_logic_delete.send(sender='delete_product', app_label='account', model_name='payinfo', ids=ids, update_user_id=request.user.id) except Exception as e: return JSONResponse(msg='删除失败!') return JSONResponse()
def get_month_orderstats(request): '''月充值、提现''' year = now().year month = now().month # 月充值数据 m_payCharts = cache.get('m_payCharts') if m_payCharts is None: m_payCharts = raw_sql("""SELECT date_format(dday, '%Y-%m-%d') payDate, sum(payAmount) as amount FROM (SELECT datelist as dday ,'payAmount' FROM calendar where year(datelist) = {0} and month(datelist) = {1} UNION ALL SELECT date(payTime),payAmount FROM payOrder where year(payTime) = {0} and month(payTime) = {1}) a GROUP BY payDate""".format(year, month)) cache.set('m_payCharts', m_payCharts, t_expires) # 月提现数据 m_withdrawCharts = cache.get('m_withdrawCharts') if m_withdrawCharts is None: m_withdrawCharts = raw_sql("""SELECT date_format(dday, '%Y-%m-%d') payDate, sum(wrMoney) as amount FROM (SELECT datelist as dday ,'wrMoney' FROM calendar where year(datelist) = {0} and month(datelist) = {1} UNION ALL SELECT date(wrTime),wrMoney FROM withdrawOrder where year(wrTime) = {0} and month(wrTime) = {1}) a GROUP BY payDate""".format(year, month)) cache.set('m_withdrawCharts', m_withdrawCharts, t_expires) data = {'payAmounts': m_payCharts, 'withdrawAmounts': m_withdrawCharts} return JSONResponse(data)
def delete_shop(request): try: data = json.loads(request.body.decode()) ids = data.get('ids') Shop.objects.filter(shopId__in=ids).update( status=1, updatedUser=request.user.username) post_logic_delete.send(sender='delete_shop', app_label='shop', model_name='shop', ids=ids, update_user_id=request.user.id) except Exception as e: return JSONResponse(msg='删除失败!', success=False) return JSONResponse()
def set_status(request): try: id = request.POST.get('id') opt = request.POST.get('opt') flag = int(request.POST.get('flag')) if int(flag) not in [0, 1]: raise # opt ['activate', 'shop'] user = AuthUser.objects.get(id=id) if opt == 'activate': # 激活 user.is_active = True if flag == 1 else False user.updatedUser = request.user.username user.save() return JSONResponse(success=True) except: return JSONResponse(success=False)
def set_status(request): try: id = request.POST.get('id') opt = request.POST.get('opt') flag = int(request.POST.get('flag')) # if int(flag) not in [0, 1]: raise # opt ['top'] headline = Headline.objects.get(headlineId=id) if opt == 'top': # 置顶 Headline.objects.extra(where=['status & 2 = 2']).update(status=F('status').bitand(1)) headline.status = 2 + (headline.status & 1) headline.updatedUser = request.user.username headline.save() return JSONResponse(success=True) except: return JSONResponse(success=False)
def set_status(request): try: id = request.POST.get('id') opt = request.POST.get('opt') flag = int(request.POST.get('flag')) if int(flag) not in [0, 1]: raise # opt ['activate'] adposition = Adposition.objects.get(posiId=id) if opt == 'activate': # 激活 adposition.status = (flag << 1) + (adposition.status & 1) adposition.updatedUser = request.user.username adposition.save() return JSONResponse(success=True) except: return JSONResponse(success=False)
def get_shopimgs(request): ''' 获取门店图片列表 ''' shopId = request.GET.get('shopId') shop = Shop.objects.get(shopId=shopId) shopImgs = list( shop.shopimg_set.filter(status=0).values('imgId', 'imgUrl')) result = json.dumps(shopImgs) return JSONResponse(result)
def set_status(request): try: id = request.POST.get('id') opt = request.POST.get('opt') flag = int(request.POST.get('flag')) if int(flag) not in [0, 1]: raise # opt ['activate', 'shop'] user = User.objects.get(userId=id) if opt == 'activate': # 激活 user.status = (user.status & 4) + (flag << 1) + (user.status & 1) if opt == 'shop': # 设置、取消店长 user.status = (flag << 2) + (user.status & 2) + (user.status & 1) user.updatedUser = request.user.username user.save() return JSONResponse(success=True) except: return JSONResponse(success=False)
def delete_group(request): try: data = json.loads(request.body.decode()) ids = data.get('ids') with transaction.atomic(): groups = Group.objects.filter(id__in=ids) users = AuthUser.objects.filter(groups=groups) # 删除关联角色权限 for item in groups: item.permissions.all().delete() # 删除关联用户角色 for item in users: item.groups.all().delete() # 删除角色 groups.delete() post_logic_delete.send(sender='delete_group', app_label='auth', model_name='group', ids=ids, update_user_id=request.user.id) except Exception as e: return JSONResponse(msg='删除失败!') return JSONResponse()
def get_month_userstats(request): '''月注册用户''' year = now().year month = now().month # 月注册数据 m_registCharts = cache.get('m_registCharts') if m_registCharts is None: m_registCharts = raw_sql("""SELECT date_format(dday,'%Y-%m-%d') registerDate,count(*)-1 as num FROM( SELECT datelist as dday FROM calendar where year(datelist)={0} and month(datelist)={1} UNION ALL SELECT date(registerTime) FROM user where year(registerTime)={0} and month(registerTime)={1} ) a GROUP BY registerDate""".format(year, month)) cache.set('m_registCharts', m_registCharts, t_expires) return JSONResponse(m_registCharts)
def _wrapped_view(request, *args, **kwargs): if test_func(request.user): return view_func(request, *args, **kwargs) path = request.build_absolute_uri() resolved_login_url = resolve_url(login_url or settings.LOGIN_URL) # If the login url is the same scheme and net location then just # use the path as the "next" url. login_scheme, login_netloc = urlparse(resolved_login_url)[:2] current_scheme, current_netloc = urlparse(path)[:2] if ((not login_scheme or login_scheme == current_scheme) and (not login_netloc or login_netloc == current_netloc)): path = request.get_full_path() from django.contrib.auth.views import redirect_to_login if request.is_ajax(): return JSONResponse(success=False, msg='您无此操作权限!') return redirect_to_login(path, resolved_login_url, redirect_field_name)
def get_main_stats(request): start = now().date() end = start + timedelta(days=1) y_start = start + timedelta(days=-1) y_end = end + timedelta(days=-1) tomorrow = datetime(start.year, start.month, start.day) + timedelta(days=1) y_expires = (tomorrow - datetime.now()).seconds # 昨日数据 缓存过期时间 data = dict() # 昨日注册用户数 y_registCount = cache.get('y_registCount') if y_registCount is None: y_registCount = User.objects.filter(registerTime__range=(y_start, y_end)).count() cache.set('y_registCount', y_registCount, y_expires) # 今日注册用户数 t_registCount = cache.get('t_registCount') if t_registCount is None: t_registCount = User.objects.filter(registerTime__range=(start, end)).count() cache.set('t_registCount', t_registCount, t_expires) data['registCount'] = t_registCount data['registRate'] = increase_rate(y_registCount, t_registCount) # 昨日日活 y_dau = cache.get('y_dau') if y_dau is None: y_dau = data['y_dau'] = User.objects.filter(lastLoginTime__range=(y_start, y_end)).count() cache.set('y_dau', y_dau, y_expires) # 今日日活 t_dau = cache.get('t_dau') if t_dau is None: t_dau = User.objects.filter(lastLoginTime__range=(start, end)).count() cache.set('t_dau', t_dau, t_expires) data['dau'] = t_dau data['dauRate'] = increase_rate(y_dau, t_dau) # 昨日充值金额 y_payamount = cache.get('y_payamount') if y_payamount is None: y_payamount = PayOrder.objects.filter(payTime__range=(y_start, y_end), orderStatus=2) \ .aggregate(payAmount=Sum('payAmount'))['payAmount'] cache.set('y_payamount', cast_none(y_payamount), y_expires) # 今日充值金额 t_payamount = cache.get('t_payamount') if t_payamount is None: t_payamount = PayOrder.objects.filter(payTime__range=(start, end), orderStatus=2) \ .aggregate(payAmount=Sum('payAmount'))['payAmount'] cache.set('t_payamount', cast_none(t_payamount), t_expires) data['payAmount'] = thousandth(t_payamount) data['payRate'] = increase_rate(y_payamount, t_payamount) # 昨日提现金额 y_withdrawamount = cache.get('y_withdraw_amount') if y_withdrawamount is None: y_withdrawamount = WithdrawOrder.objects.filter(wrTime__range=(y_start, y_end), orderStatus=1) \ .aggregate(withdrawAmount=Sum('wrMoney'))['withdrawAmount'] cache.set('y_withdraw_amount', cast_none(y_withdrawamount), y_expires) # 今日提现金额 t_withdrawamount = cache.get('t_withdrawamount') if t_withdrawamount is None: t_withdrawamount = WithdrawOrder.objects.filter(wrTime__range=(start, end), orderStatus=1) \ .aggregate(withdrawAmount=Sum('wrMoney'))['withdrawAmount'] cache.set('t_withdrawamount', cast_none(t_withdrawamount), t_expires) data['withdrawAmount'] = thousandth(t_withdrawamount) data['withdrawRate'] = increase_rate(y_withdrawamount, t_withdrawamount) return JSONResponse(data)
def get_month_totalstats(request): '''月总的数据''' year = now().year month = now().month weeks, days = calendar.monthrange(year, month) month_end = datetime(year, month, days, 23, 58) lastmonth_expires = (month_end - datetime.now()).seconds data = dict() # 上月注册用户数 lastmonth_registcount = cache.get('lastmonth_registcount') if lastmonth_registcount is None: lastmonth_registcount = User.objects.raw("""select userId,count(userId) as num from user \ where date_format(registerTime,'%%Y-%%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%%Y-%%m') """)[0].num cache.set('lastmonth_registcount', cast_none(lastmonth_registcount), lastmonth_expires) # 本月注册用户数 registcount = cache.get('registcount') if registcount is None: registcount = User.objects.filter(registerTime__year=year, registerTime__month=month).count() cache.set('registcount', registcount, t_expires) data['registCount'] = registcount data['registRate'] = increase_rate(lastmonth_registcount, registcount) # 上月充值金额 lastmonth_pay = cache.get('lastmonth_pay') if lastmonth_pay is None: lastmonth_pay = PayOrder.objects.raw("""select poId,SUM(payAmount) as total from payOrder \ where date_format(payTime,'%%Y-%%m')=date_format(DATE_SUB(curdate(), INTERVAL 1 MONTH),'%%Y-%%m')""")[0].total cache.set('lastmonth_pay', cast_none(lastmonth_pay), lastmonth_expires) # 本月充值金额 payamount = cache.get('payamount') if payamount is None: payamount = PayOrder.objects.filter(payTime__year=year, payTime__month=month, orderStatus=2) \ .aggregate(payAmount=Sum('payAmount'))['payAmount'] cache.set('payamount', cast_none(payamount), t_expires) data['payAmount'] = thousandth(payamount) data['payRate'] = increase_rate(lastmonth_pay, payamount) # 上月提现金额 lastmonth_withdraw = cache.get('lastmonth_withdraw') if lastmonth_withdraw is None: lastmonth_withdraw = WithdrawOrder.objects.raw("""SELECT wrId,SUM(wrMoney) AS total FROM withdrawOrder \ WHERE DATE_FORMAT(wrTime,'%%Y-%%m')=DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 MONTH),'%%Y-%%m')""")[0].total cache.set('lastmonth_withdraw', cast_none(lastmonth_withdraw), lastmonth_expires) # 本月提现金额 withdrawamount = cache.get('withdrawamount') if withdrawamount is None: withdrawamount = WithdrawOrder.objects.filter(wrTime__year=year, wrTime__month=month, orderStatus=1) \ .aggregate(withdrawAmount=Sum('wrMoney'))['withdrawAmount'] cache.set('withdrawamount', cast_none(withdrawamount), t_expires) data['withdrawAmount'] = thousandth(withdrawamount) data['withdrawRate'] = increase_rate(lastmonth_withdraw, withdrawamount) return JSONResponse(data)