six_001
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
from datetime import datetime
|
||||
from typing import cast
|
||||
|
||||
from channels.layers import BaseChannelLayer, get_channel_layer
|
||||
from django.db.models import Case, Count, IntegerField, Sum, When
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.viewsets import ViewSet
|
||||
|
||||
from wechat_数据库.用户数据库.小程序积分数据库 import share积分表
|
||||
from wechat_项目工具包.数据库的工具包.更新用户积分 import miniUser提现状态
|
||||
|
||||
default_channel_layer = cast(BaseChannelLayer, get_channel_layer(alias="default"))
|
||||
|
||||
from functools import wraps
|
||||
import threading
|
||||
|
||||
|
||||
def sync_lock(lock):
|
||||
def decorator(fn):
|
||||
@wraps(fn)
|
||||
def wrapper(*args, **kwargs):
|
||||
with lock:
|
||||
return fn(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
class 积分查询接口ViewSets(ViewSet):
|
||||
lock = threading.Lock() # 所有请求 共享这一个 lock对象
|
||||
|
||||
@sync_lock(lock=lock) # 锁住这个接口所有并发请求,
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="统计积分查询")
|
||||
def 统计积分查询(self, request: Request):
|
||||
""""""
|
||||
"""这里查询的数据,用于在商品详情页面 显示的 点击次数+累计积分总和"""
|
||||
pass
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None, ) # 这里的查询者,就是积分表中的分享者
|
||||
查询当前用户是否有记录结果 = share积分表.objects.filter(share分享者unionid=self_mini_unionid, ).exists()
|
||||
if 查询当前用户是否有记录结果 is False:
|
||||
pass
|
||||
return Response(data={"share分享者unionid": self_mini_unionid, "share总积分": 0, "share分享点击人数": 0, "share不可提现积分": 0, "share已提现积分": 0}, )
|
||||
else:
|
||||
xiaozizidata = (
|
||||
share积分表.objects
|
||||
.filter(share分享者unionid="oy4Jw6P1FnuTNF-hSoJHNztSAoQ0")
|
||||
.aggregate(
|
||||
share总积分=Sum("share分享者积分值"),
|
||||
share可提现积分=Sum(
|
||||
Case(
|
||||
When(share积分是否可以提现的状态=miniUser提现状态().可提现, then="share分享者积分值"),
|
||||
default=0,
|
||||
output_field=IntegerField()
|
||||
)
|
||||
),
|
||||
|
||||
share不可提现积分=Sum(
|
||||
Case(
|
||||
When(share积分是否可以提现的状态=miniUser提现状态().不可提现, then="share分享者积分值"
|
||||
),
|
||||
default=0,
|
||||
output_field=IntegerField()
|
||||
)
|
||||
),
|
||||
share已提现积分=Sum(
|
||||
Case(
|
||||
When(share积分是否可以提现的状态="已提现", then="share分享者积分值"
|
||||
),
|
||||
default=0,
|
||||
output_field=IntegerField()
|
||||
)
|
||||
),
|
||||
share点击次数=Count("id_主键")
|
||||
)
|
||||
)
|
||||
xiaozizidata["unionid"] = self_mini_unionid
|
||||
print(xiaozizidata)
|
||||
return Response(data=xiaozizidata)
|
||||
|
||||
@action(detail=False, methods=["get", "post", "put", "delete"], url_path="查询当前用户积列详情列表数据")
|
||||
def 查询当前用户积列详情列表数据(self, request: Request):
|
||||
"""本接口处理的: 当用户进入积分详情页面时候, 返回给当前用户所有的积分列表详情"""
|
||||
pass
|
||||
self_mini_openid = request.data.get("self_mini_openid", None)
|
||||
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||||
当前的月份 = datetime.now().month
|
||||
shareDaat = share积分表.objects.filter(share分享者unionid=self_mini_unionid, ).order_by("-dateAndTime").values()
|
||||
return Response(data=shareDaat)
|
||||
Reference in New Issue
Block a user