83 lines
4.4 KiB
Python
83 lines
4.4 KiB
Python
from typing import cast
|
|||
|
|
|
||
|
|
from channels.layers import BaseChannelLayer, get_channel_layer
|
||
|
|
from django.forms import model_to_dict
|
||
|
|
from rest_framework import status
|
||
|
|
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 sixGuoDjango import BaseResponse, ResData
|
||
|
|
from wechat_数据库.洗衣液商品数据库.六果洗衣液商品 import Goods
|
||
|
|
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):
|
||
|
|
""""""
|
||
|
|
self_mini_openid = request.data.get("self_mini_openid", None)
|
||
|
|
self_mini_unionid = request.data.get("self_mini_unionid", None)
|
||
|
|
print('每日签到接口', self_mini_openid, self_mini_unionid)
|
||
|
|
miniUser积分(share分享者unionidID=self_mini_unionid, click点击者unionidID=self_mini_unionid).add添加每日积分(share积分类型="每日签到", share分享者积分值=50)
|
||
|
|
httpResData = BaseResponse(resData=ResData(listData=[""], dictData={}), ).model_dump()
|
||
|
|
return Response(data=httpResData, status=status.HTTP_200_OK)
|
||
|
|
|
||
|
|
@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分享者_unionid = request.data.get("share分享者_unionid", None)
|
||
|
|
miniUser积分(share分享者unionidID=share分享者_unionid, click点击者unionidID=self_mini_unionid).add添加通知好友积分(share积分类型="发券奖励", share分享者积分值=10)
|
||
|
|
return Response(data={})
|
||
|
|
|
||
|
|
@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分享者_unionid = request.data.get("share分享者_unionid", None)
|
||
|
|
share分享的商品ID = request.data.get("share分享的商品ID", None)
|
||
|
|
miniUser积分(share分享者unionidID=share分享者_unionid, click点击者unionidID=self_mini_unionid).add添加用户分享商品推荐的积分(
|
||
|
|
share积分类型="好物推荐", share分享者积分值=10, share分享的商品ID=share分享的商品ID,
|
||
|
|
)
|
||
|
|
currend当前商品的数据 = Goods.objects.get(idKey=share分享的商品ID) # 拿到当前分享的商品ID,返回给前端,前端用户点击后,会直接进入分享页面
|
||
|
|
data = model_to_dict(instance=currend当前商品的数据, fields=None, exclude=None)
|
||
|
|
return Response(data=data)
|
||
|
|
|
||
|
|
@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分享者_unionid = request.data.get("share分享者_unionid", None)
|
||
|
|
print(share分享者_unionid, self_mini_unionid, self_mini_openid)
|
||
|
|
miniUser积分(share分享者unionidID=share分享者_unionid, click点击者unionidID=self_mini_unionid).add添加小程序推荐积分(
|
||
|
|
share分享者积分值=10, share积分类型="小程序推荐",
|
||
|
|
)
|
||
|
|
return Response(data={})
|