|
@@ -35,6 +35,7 @@ from xlutils.copy import copy
|
|
|
from xltpl.writer import BookWriter
|
|
|
from django_redis import get_redis_connection
|
|
|
from constants import *
|
|
|
+from utils.aliyun_sms import send_verify_code
|
|
|
|
|
|
def async(f):
|
|
|
def wrapper(*args, **kwargs):
|
|
@@ -137,9 +138,7 @@ def get_player_match_list(request):
|
|
|
"""
|
|
|
uid = request.user.id
|
|
|
now_str = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
- cur_match_id = cm.Match.objects.filter(start_time__lte=now_str).first().id
|
|
|
- cur_match_id = 7
|
|
|
- #match_ids = list(cm.Player.objects.filter(user_id=uid,match_id=cur_match_id).values_list("match_id",flat=True))
|
|
|
+ cur_match_id = ccc.get_cur_match().id
|
|
|
match_ids = list(cm.Player.objects.filter(user_id=uid).values_list("match_id",flat=True))
|
|
|
matchs = list(cm.Match.objects.filter(id__in=match_ids).values())
|
|
|
for item in matchs:
|
|
@@ -173,10 +172,17 @@ def get_player_match_detail(request):
|
|
|
match_group = request.player.match_group
|
|
|
match_id = qdata.get("id")
|
|
|
record_id = qdata.get("record_id")
|
|
|
+ userinfo = {}
|
|
|
+ cur_user_id = user_id
|
|
|
cur_player_id = qdata.get("player_id")
|
|
|
+ if not cur_player_id:
|
|
|
+ cur_player_id = player_id
|
|
|
|
|
|
ismine = True if int(cur_player_id) == player_id else False
|
|
|
-
|
|
|
+ if not match_id:
|
|
|
+ player = cm.Player.objects.filter(id=cur_player_id).first()
|
|
|
+ match_id =player.match_id
|
|
|
+ cur_user_id = player.user_id
|
|
|
if record_id:
|
|
|
records_set = cm.PlayerRecord.objects.filter(id=record_id)
|
|
|
if records_set:
|
|
@@ -188,9 +194,7 @@ def get_player_match_detail(request):
|
|
|
if qdata.get("player_id"):
|
|
|
player_id = qdata.get("player_id")
|
|
|
match_group = cm.Player.objects.filter(id=player_id).first().match_group
|
|
|
- else:
|
|
|
- #为了兼容老版本没有传player_id要获取用户的某届赛事player_id
|
|
|
- player_id = cm.Player.objects.filter(user_id=user_id,match_id=match_id).first().id
|
|
|
+
|
|
|
records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date")
|
|
|
|
|
|
|
|
@@ -211,6 +215,7 @@ def get_player_match_detail(request):
|
|
|
item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
|
|
|
today = get_today_date()
|
|
|
+ today_record = {}
|
|
|
if records_set.first():
|
|
|
today = records_set.first().stock_date
|
|
|
#today_record = get_today_record(player_id,int(match_id),int(match_group),today)
|
|
@@ -234,8 +239,15 @@ def get_player_match_detail(request):
|
|
|
today_record["today_stock_total"] = round(today_record["today_stock_total"],4)
|
|
|
userinfo = get_user_info(today_record["user_id"])
|
|
|
today_record["style"] = userinfo.get("style")
|
|
|
- else:
|
|
|
+ if not today_record:
|
|
|
+ player_info = get_player_info(cur_player_id)
|
|
|
today_record = {}
|
|
|
+ today_record["stock_date"] = today
|
|
|
+ today_record.update(player_info)
|
|
|
+ today_record["player_id"] = player_info["id"]
|
|
|
+ today_record["avatar"] = get_user_info(player_info["user_id"])["avatar"]
|
|
|
+ userinfo = get_user_info(today_record["user_id"])
|
|
|
+ today_record["style"] = userinfo.get("style")
|
|
|
|
|
|
match["groups"] = [today_record["match_group_name"]] if today_record else []
|
|
|
records = sorted(records,key=lambda x:x["stock_date"],reverse=True)
|
|
@@ -243,7 +255,19 @@ def get_player_match_detail(request):
|
|
|
is_follow = 1
|
|
|
else:
|
|
|
is_follow = 0
|
|
|
- ret = {"match":match,"today_record":today_record,"records":records,"is_follow":is_follow}
|
|
|
+ if today_record and today_record.get("today_fund"):
|
|
|
+ today_record["today_income_fund"] = round((today_record["today_fund"] - today_record["yesterday_fund"]),2)*10000 if today_record["yesterday_fund"] else 0.00
|
|
|
+ ret = {
|
|
|
+ "match":match,
|
|
|
+ "today_record":today_record,
|
|
|
+ "userinfo":get_user_info(cur_user_id),
|
|
|
+ "records":records,
|
|
|
+ "is_follow":is_follow,
|
|
|
+ "fans":cm.UserFollows.objects.filter(follow_id=player_id).count(),
|
|
|
+ "followers":cm.UserFollows.objects.filter(user_id=player_id).count(),
|
|
|
+ "stock_age":datetime.datetime.now().year - int(userinfo.get("join_time")) if userinfo.get("join_time") else 0,
|
|
|
+ "stock_follow":list(cm.UserChoice.objects.filter(player_id=cur_player_id).values_list("stock_name",flat=True))
|
|
|
+ }
|
|
|
|
|
|
return ret
|
|
|
|
|
@@ -287,6 +311,8 @@ def get_today_record_actual(player_id,match_id,match_group,today=None):
|
|
|
else:
|
|
|
qset = cm.PlayerRecord.objects.filter(match_id=match_id,match_group=match_group,player_id=player_id).order_by("-stock_date")
|
|
|
today_record = qset.values().first()
|
|
|
+ print(player_id,match_id,match_group,today,4444444444444444444)
|
|
|
+ print(today_record,1111111111)
|
|
|
|
|
|
if today_record:
|
|
|
user_info = get_user_info(today_record["user_id"])
|
|
@@ -417,6 +443,12 @@ def get_user_info(uid):
|
|
|
user["style"].append(user["df"])
|
|
|
return user
|
|
|
|
|
|
+
|
|
|
+#@ccc.cache_data()
|
|
|
+def get_player_info(player_id):
|
|
|
+ player = cm.Player.objects.filter(id=player_id).values().first()
|
|
|
+ return player
|
|
|
+
|
|
|
@ccc.cache_data()
|
|
|
def get_match_info(match_id):
|
|
|
match = cm.Match.objects.filter(id=match_id).values().first()
|
|
@@ -520,12 +552,6 @@ def get_player_match_records(request):
|
|
|
page = int(qdata.get("page",0))
|
|
|
page_size = int(qdata.get("page_size",20))
|
|
|
|
|
|
- #if int(match_id) == 7:
|
|
|
- # player = cm.Player.objects.filter(match_id=match_id,usercode=request.user.usercode).first()
|
|
|
- # if player:
|
|
|
- # player_id = player.id
|
|
|
- # match_group = player.match_group
|
|
|
-
|
|
|
records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date")
|
|
|
data = list(records_set.values())
|
|
|
for item in data:
|
|
@@ -539,6 +565,8 @@ def get_player_match_records(request):
|
|
|
item["yesterday_stock_img"] = json.loads(item["yesterday_stock_img"]) if item["yesterday_stock_img"] else []
|
|
|
item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
+ item["zans_count"] = item.get("zans",0)
|
|
|
+ item["comments_count"] = cm.Comments.objects.filter(player_id=item.get("id",0)).count()
|
|
|
if page and page_size:
|
|
|
total,data = ccf.get_page_list(data,page,page_size)
|
|
|
return total,data
|
|
@@ -577,6 +605,7 @@ def add_model(cls,**kwargs):
|
|
|
if now_time<"15:00" or now_time > "23:50":
|
|
|
raise ce.TipException(u"当日数据请在当日15:00以后23:50以前提交数据!")
|
|
|
|
|
|
+
|
|
|
match_id = kwargs.get("match_id")
|
|
|
stock_date = kwargs.get("stock_date")
|
|
|
#stock_date = "2022-04-26"
|
|
@@ -588,6 +617,9 @@ def add_model(cls,**kwargs):
|
|
|
is_markt = int(kwargs.get("is_markt",0))
|
|
|
experience = kwargs.get("experience")
|
|
|
|
|
|
+ if not ccc.get_cur_match().id == match_id:
|
|
|
+ raise ce.TipException(u"非当前赛事参赛选手不能提交作业!")
|
|
|
+
|
|
|
#计算今日和昨日盈亏
|
|
|
if float(today_fund)>9999 or float(today_fund)<=0:
|
|
|
raise ce.TipException(u"数据错误,今日净资产不能超过9999万元,不能低于0万元,请仔细核对数据!")
|
|
@@ -773,25 +805,10 @@ def get_detail_info(cls,**kwargs):
|
|
|
id = kwargs.get("id")
|
|
|
rst = list(model.objects.filter(id=id).values())
|
|
|
rst = rst[0] if rst else {}
|
|
|
- #if model_name == "PlayerRecord":
|
|
|
- # rst["match_group"] = cm.MatchGroup.objects.filter(id=rst["match_group"]).first().name
|
|
|
- # today_stock = json.loads(rst["today_stock"]) if rst["today_stock"] else []
|
|
|
- # today_stock = filter(lambda x:x["fund"] and x["name"],today_stock if today_stock else [])
|
|
|
- # rst["today_stock"] = today_stock
|
|
|
- # today_stock_img = json.loads(rst["today_stock_img"]) if rst["today_stock_img"] else []
|
|
|
- # rst["today_stock_img"] = today_stock_img
|
|
|
-
|
|
|
- # yesterday_stock = json.loads(rst["yesterday_stock"]) if rst["yesterday_stock"] else []
|
|
|
- # yesterday_stock = filter(lambda x:x["fund"] and x["name"],yesterday_stock if yesterday_stock else [])
|
|
|
- # rst["yesterday_stock"] = yesterday_stock
|
|
|
- #
|
|
|
- # yesterday_stock_img = json.loads(rst["yesterday_stock_img"]) if rst["yesterday_stock_img"] else []
|
|
|
- # rst["yesterday_stock_img"] = yesterday_stock_img
|
|
|
-
|
|
|
- # rst["today_income"] = "{}%".format(rst["today_income"]*100)
|
|
|
- # rst["total_income"] = "{}%".format(rst["total_income"]*100)
|
|
|
if model_name == "Article":
|
|
|
rst["ctime"] = ccf.datetime_to_str(rst["ctime"],"%Y-%m-%d")
|
|
|
+ if model_name == "Stock":
|
|
|
+ rst["choiced"] = cm.UserChoice.objects.filter(player_id=kwargs.get("player_id"),stock_id=rst["id"]).count()
|
|
|
return rst
|
|
|
|
|
|
#@ccc.cache_data()
|
|
@@ -1023,8 +1040,8 @@ def calc_win_rate(player_id,match_id):
|
|
|
return win_rate
|
|
|
|
|
|
|
|
|
-def get_user_follows(request):
|
|
|
- """获取用户关注的选手列表
|
|
|
+def get_user_follower(request):
|
|
|
+ """获取用户列表
|
|
|
"""
|
|
|
user_id = request.player.id
|
|
|
match_id = request.player.match_id
|
|
@@ -1033,36 +1050,31 @@ def get_user_follows(request):
|
|
|
cur_match_group = match_group
|
|
|
qdata = request.json
|
|
|
today = get_today_date()
|
|
|
+ if qdata.get("player_id"):
|
|
|
+ user_id = int(qdata.get("player_id"))
|
|
|
|
|
|
data = []
|
|
|
|
|
|
- qset = cm.UserFollows.objects.filter(user_id=user_id)
|
|
|
- follow_ids = list(qset.values_list("follow_id",flat=True))
|
|
|
+ qset = cm.UserFollows.objects.filter(follow_id=user_id)
|
|
|
+ follow_ids = list(qset.values_list("user_id",flat=True))
|
|
|
|
|
|
_today = today
|
|
|
for player_id in follow_ids:
|
|
|
_match_id = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"match_id")
|
|
|
|
|
|
- #last = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=_match_id).order_by("-stock_date").first()
|
|
|
- #if last:
|
|
|
- # _today = last.stock_date
|
|
|
-
|
|
|
_today = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"stock_date")
|
|
|
_match_group = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"match_group")
|
|
|
|
|
|
today_record = get_today_record(player_id,_match_id,_match_group,_today)
|
|
|
- #today_record = get_today_record_actual(player_id,_match_id,_match_group,_today)
|
|
|
if today_record:
|
|
|
data.append(today_record)
|
|
|
|
|
|
data = sorted(data,key=lambda x:x["stock_date"],reverse=True)
|
|
|
|
|
|
|
|
|
- _match_id = ccc.cache.hget("PLAYER_LATEST_%d"%user_id,"match_id")
|
|
|
_today = ccc.cache.hget("PLAYER_LATEST_%d"%user_id,"stock_date")
|
|
|
- _match_group = ccc.cache.hget("PLAYER_LATEST_%d"%user_id,"match_group")
|
|
|
|
|
|
- cur_today_record = get_today_record(user_id,_match_id,_match_group,_today)
|
|
|
+ cur_today_record = get_today_record(user_id,match_id,match_group,_today)
|
|
|
if cur_today_record:
|
|
|
data.insert(0,cur_today_record)
|
|
|
|
|
@@ -1090,6 +1102,74 @@ def get_user_follows(request):
|
|
|
return len(data),data
|
|
|
|
|
|
|
|
|
+def get_user_follows(request):
|
|
|
+ """获取用户关注的选手列表
|
|
|
+ """
|
|
|
+ if request.player:
|
|
|
+ user_id = request.player.id
|
|
|
+ match_id = request.player.match_id
|
|
|
+ cur_match_id = match_id
|
|
|
+ match_group = request.player.match_group
|
|
|
+ cur_match_group = match_group
|
|
|
+ qdata = request.json
|
|
|
+ today = get_today_date()
|
|
|
+ if qdata.get("player_id"):
|
|
|
+ user_id = int(qdata.get("player_id"))
|
|
|
+
|
|
|
+ data = []
|
|
|
+
|
|
|
+ qset = cm.UserFollows.objects.filter(user_id=user_id)
|
|
|
+ follow_ids = list(qset.values_list("follow_id",flat=True))
|
|
|
+
|
|
|
+ _today = today
|
|
|
+ for player_id in follow_ids:
|
|
|
+ _match_id = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"match_id")
|
|
|
+
|
|
|
+ _today = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"stock_date")
|
|
|
+ _match_group = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"match_group")
|
|
|
+
|
|
|
+ today_record = get_today_record(player_id,_match_id,_match_group,_today)
|
|
|
+ if today_record:
|
|
|
+ today_record["zan_count"] = today_record.get("zans",0) if today_record.get("zans") else 0
|
|
|
+ today_record["comments_count"] = cm.Comments.objects.filter(record_id=today_record.get("id",0)).count()
|
|
|
+ data.append(today_record)
|
|
|
+
|
|
|
+ data = sorted(data,key=lambda x:x["stock_date"],reverse=True)
|
|
|
+
|
|
|
+
|
|
|
+ _today = ccc.cache.hget("PLAYER_LATEST_%d"%user_id,"stock_date")
|
|
|
+
|
|
|
+ cur_today_record = get_today_record(user_id,match_id,match_group,_today)
|
|
|
+ if cur_today_record:
|
|
|
+ data.insert(0,cur_today_record)
|
|
|
+
|
|
|
+ page = int(qdata.get("page",1))
|
|
|
+ page_size = int(qdata.get("page_size",20))
|
|
|
+
|
|
|
+ if page and page_size:
|
|
|
+ total,data = ccf.get_page_list(data,page,page_size)
|
|
|
+ for item in data:
|
|
|
+ if item:
|
|
|
+ today_stock = json.loads(item["today_stock"])
|
|
|
+ today_stock = filter(lambda x:x["name"] and x["fund"],today_stock)
|
|
|
+ item["today_stock"] = today_stock
|
|
|
+ item["today_stock_img"] = json.loads(item["today_stock_img"])
|
|
|
+ #item["win_rate"] = calc_win_rate(item["player_id"],item["match_id"])
|
|
|
+ win_rate = ccc.cache.hget("PLAYER_LATEST_%d"%item["player_id"],"win_rate")
|
|
|
+ if win_rate:
|
|
|
+ item["win_rate"] = str(float(win_rate)*100)+"%"
|
|
|
+ else:
|
|
|
+ item["win_rate"] = "0.0%"
|
|
|
+ item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
+ item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
+ item["zans_count"] = item.get("zans",0)
|
|
|
+ item["comments_count"] = cm.Comments.objects.filter(record_id=item.get("id",0)).count()
|
|
|
+ return total,data
|
|
|
+ else:
|
|
|
+ return len(data),data
|
|
|
+ return 0,[]
|
|
|
+
|
|
|
+
|
|
|
def get_hot_stock_rank(**kwargs):
|
|
|
"""
|
|
|
"""
|
|
@@ -1103,7 +1183,7 @@ def get_hot_stock_rank(**kwargs):
|
|
|
}
|
|
|
return data
|
|
|
|
|
|
-@ccc.cache_data()
|
|
|
+#@ccc.cache_data()
|
|
|
def get_stock_info(stock_id):
|
|
|
"""
|
|
|
"""
|
|
@@ -1117,17 +1197,19 @@ def get_hot_stock_buy(**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
stock_date = kwargs.get("stock_date")
|
|
|
- qset = cm.UserStock.objects.filter(stock_date=stock_date)
|
|
|
- if kwargs.get("name"):
|
|
|
- qset = qset.filter(stock_name__icontains=kwargs.get("name"))
|
|
|
+ if not kwargs.get("name"):
|
|
|
+ qset = cm.UserStock.objects.filter(stock_date=stock_date)
|
|
|
+ else:
|
|
|
+ qset = cm.UserStock.objects.filter(stock_name__icontains=kwargs.get("name"))
|
|
|
qset = qset.values("stock_id","stock_name").annotate(count=Count("stock_id")).order_by("-count")
|
|
|
data = []
|
|
|
for q in qset:
|
|
|
stock_id = q["stock_id"]
|
|
|
count = q["count"]
|
|
|
stock_name = q.get("stock_name")
|
|
|
- #stock = get_stock_info(stock_id)
|
|
|
- data.append({"stock_name":stock_name,"id":stock_id,"count":count})
|
|
|
+ comments_count = cm.Comments.objects.filter(stock_id=stock_id).count()
|
|
|
+ choice_count = cm.UserChoice.objects.filter(stock_id=stock_id).count()
|
|
|
+ data.append({"stock_name":stock_name,"id":stock_id,"count":count,"comments_count":comments_count,"choice_count":choice_count})
|
|
|
|
|
|
|
|
|
page = int(kwargs.get("page",1))
|
|
@@ -1145,8 +1227,7 @@ def get_hot_follow(**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
stock_date = kwargs.get("stock_date")
|
|
|
- #qset = cm.UserFollows.objects.filter(stock_date=stock_date)
|
|
|
- cur_match_id = 9
|
|
|
+ cur_match_id = ccc.get_cur_match().id
|
|
|
player_ids = list(cm.Player.objects.filter(match_id=cur_match_id,match_status=1).values_list("id",flat=True))
|
|
|
qset = cm.UserFollows.objects.filter(follow_id__in=player_ids)
|
|
|
qset = qset.values("follow_id").annotate(count=Count("follow_id")).order_by("-count")
|
|
@@ -1289,18 +1370,11 @@ def get_win_rate_rank(request):
|
|
|
match_id = request.player.match_id
|
|
|
match_group = request.player.match_group
|
|
|
kwargs = request.json
|
|
|
- match_id = 9
|
|
|
+ match_id = ccc.get_cur_match().id
|
|
|
|
|
|
qset = cm.WinDefendRank.objects.filter(match_id=match_id,auto_complete__lt=5,match_status=1).order_by("-win_rate")
|
|
|
data = list(qset.values())
|
|
|
|
|
|
- #data = []
|
|
|
- #for item in datas:
|
|
|
- # player = cm.Player.objects.filter(id=item["player_id"]).first()
|
|
|
- # item["match_status"] = player.match_status if player else -1
|
|
|
- # if item["match_status"] > -1:
|
|
|
- # data.append(item)
|
|
|
-
|
|
|
page = int(kwargs.get("page",1))
|
|
|
page_size = int(kwargs.get("page_size",20))
|
|
|
|
|
@@ -1520,6 +1594,7 @@ def get_mine_style(request):
|
|
|
"df":user.df,
|
|
|
"pz":user.pz,
|
|
|
"join_time":user.join_time,
|
|
|
+ "username":user.username,
|
|
|
"account_img":user.account_img,
|
|
|
}
|
|
|
if player:
|
|
@@ -1540,6 +1615,9 @@ def update_user_style(**kwargs):
|
|
|
cm.UserInfo.objects.filter(id=user_id).update(**kwargs)
|
|
|
if player_id and init_fund:
|
|
|
cm.Player.objects.filter(id=player_id).update(fund=init_fund)
|
|
|
+ if kwargs.get("username"):
|
|
|
+ cm.Player.objects.filter(id=player_id).update(username=kwargs.get("username"))
|
|
|
+ ccc.cache.delete("cdata_get_user_info_(%sL,)"%user_id)
|
|
|
return True
|
|
|
|
|
|
|
|
@@ -1547,9 +1625,11 @@ def get_stock_players(**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
stock_id = kwargs.get("stock_id")
|
|
|
- stock_date = kwargs.get("stock_date")
|
|
|
+ stock_date = kwargs.get("stock_date",get_today_date())
|
|
|
data = []
|
|
|
user_stocks = cm.UserStock.objects.filter(stock_id=stock_id,stock_date=stock_date)
|
|
|
+ #user_stocks = cm.UserStock.objects.filter(stock_id=stock_id)
|
|
|
+ #user_stocks = cm.UserStock.objects.all()
|
|
|
for us in user_stocks:
|
|
|
player_id = us.player_id
|
|
|
player = cm.Player.objects.filter(id=player_id).first()
|
|
@@ -1568,7 +1648,7 @@ def get_stock_players(**kwargs):
|
|
|
data.append(today_record)
|
|
|
data = sorted(data,key=lambda x:x["today_fund"],reverse=True)
|
|
|
#分页
|
|
|
- page = int(kwargs.get("page",1))
|
|
|
+ page = int(kwargs.get("page",0))
|
|
|
page_size = int(kwargs.get("page_size",20))
|
|
|
if page and page_size:
|
|
|
total,data = ccf.get_page_list(data,page,page_size)
|
|
@@ -1661,32 +1741,28 @@ def get_stock_search(**kwargs):
|
|
|
def get_mine_latest(request):
|
|
|
"""
|
|
|
"""
|
|
|
- player_id = request.player.id
|
|
|
- match_id = request.player.match_id
|
|
|
- match_group = request.player.match_group
|
|
|
-
|
|
|
- today = get_today_date()
|
|
|
-
|
|
|
- _match_id = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"match_id")
|
|
|
- if _match_id:
|
|
|
- match_id = _match_id
|
|
|
- _today = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"stock_date")
|
|
|
- if _today:
|
|
|
- today = _today
|
|
|
- _match_group = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"match_group")
|
|
|
- if _match_group:
|
|
|
- match_group = _match_group
|
|
|
-
|
|
|
- #rst = get_today_record(player_id,match_id,match_group,today)
|
|
|
try:
|
|
|
- rst = get_today_record_actual(player_id,match_id,match_group)
|
|
|
-
|
|
|
- rst["today_income"] = "{}%".format(rst["today_income"]*100)
|
|
|
- rst["total_income"] = "{}%".format(rst["total_income"]*100)
|
|
|
+ player_id = request.player.id
|
|
|
+ match_id = request.player.match_id
|
|
|
+ match_group = request.player.match_group
|
|
|
+ today = get_today_date()
|
|
|
|
|
|
- return rst
|
|
|
- except:
|
|
|
- return {}
|
|
|
+ _today = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"stock_date")
|
|
|
+ if _today:
|
|
|
+ today = _today
|
|
|
+ rst = get_today_record_actual(player_id,match_id,match_group)
|
|
|
+ if rst:
|
|
|
+ rst["today_income_fund"] = round((rst["today_fund"] - rst["yesterday_fund"]),2)*10000 if rst["yesterday_fund"] else 0.00
|
|
|
+
|
|
|
+ rst["today_income"] = "{}%".format(rst["today_income"]*100)
|
|
|
+ rst["total_income"] = "{}%".format(rst["total_income"]*100)
|
|
|
+ rst["zan_count"] = rst.get("zans",0)
|
|
|
+ rst["comments_count"] = cm.Comments.objects.filter(record_id=rst.get("id",0)).count()
|
|
|
+
|
|
|
+ return rst
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return {"player_id":player_id,"match_id":match_id}
|
|
|
|
|
|
def get_match_validdates(match_id):
|
|
|
"""
|
|
@@ -1700,3 +1776,438 @@ def get_match_validdates(match_id):
|
|
|
validdates.sort()
|
|
|
return validdates
|
|
|
return []
|
|
|
+
|
|
|
+
|
|
|
+def send_phcode(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ phone = qdata.get("phone")
|
|
|
+ import random
|
|
|
+ code = "%s%s%s%s" % (random.randint(0,9),random.randint(0,9),random.randint(0,9),random.randint(0,9))
|
|
|
+ send_verify_code(phone,code)
|
|
|
+ ccc.cache.set(phone,code,120)
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+def get_signup_info(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ user_id = request.user.id
|
|
|
+ try:
|
|
|
+ match_id = ccc.get_signup_match().id
|
|
|
+ match = cm.Match.objects.filter(id=match_id).values().first()
|
|
|
+ #
|
|
|
+ match_groups = list(cm.MatchGroup.objects.filter(match_id=match_id,is_active=1).values())
|
|
|
+ match["groups"] = match_groups
|
|
|
+ #报名状态
|
|
|
+ now = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
+ signup_start_time = match["signup_start_time"]
|
|
|
+ signup_end_time = match["signup_end_time"]
|
|
|
+ if signup_start_time <= now and signup_end_time >= now:
|
|
|
+ match["signup_status"] = 1
|
|
|
+ else:
|
|
|
+ match["signup_status"] = 0
|
|
|
+
|
|
|
+ if cm.Player.objects.filter(match_id=match_id,user_id=user_id).exists():
|
|
|
+ match["signup_done"] = 1
|
|
|
+ else:
|
|
|
+ match["signup_done"] = 0
|
|
|
+
|
|
|
+ return match
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
+ return {}
|
|
|
+
|
|
|
+def do_wx_pay(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ user = request.user
|
|
|
+ user_id = request.user.id
|
|
|
+ user_name = request.user.username
|
|
|
+ openid = request.user.openid
|
|
|
+ qdata = request.json
|
|
|
+
|
|
|
+ match_id = qdata.get("match_id")
|
|
|
+ match_name = qdata.get("match_name")
|
|
|
+ signup_type = qdata.get("signup_type")
|
|
|
+ total_fee = str(qdata.get("total_fee"))
|
|
|
+ phone = qdata.get("phone")
|
|
|
+ phcode = qdata.get("phcode")
|
|
|
+ match_group = qdata.get("match_group")
|
|
|
+
|
|
|
+ orgcode = ccc.cache.get(phone)
|
|
|
+ if not phcode == orgcode and False:
|
|
|
+ raise ce.TipException(u"验证码不正确!")
|
|
|
+
|
|
|
+ if int(signup_type) == 1:
|
|
|
+ if not match_group:
|
|
|
+ match_group = cm.MatchGroup.objects.filter(match_id=match_id,charge=0).first().id
|
|
|
+
|
|
|
+ out_trade_no = datetime.datetime.now().strftime("%Y%m%d%H%M%S") + str(int(time.time()*1000))
|
|
|
+
|
|
|
+ phone_user = cm.UserInfo.objects.filter(phone=phone).first()
|
|
|
+ phone_user_player_type = phone_user.player_type if phone_user else 0
|
|
|
+ #游客和普通选手付费报名
|
|
|
+ if user.player_type in [0,1] and phone_user_player_type in [0,1]:
|
|
|
+ #生成订单
|
|
|
+ order = cm.SignupOrder.objects.create(
|
|
|
+ user_id = user_id,
|
|
|
+ user_name = user_name,
|
|
|
+ match_id = match_id,
|
|
|
+ match_name = match_name,
|
|
|
+ signup_type = signup_type,
|
|
|
+ total_fee = total_fee,
|
|
|
+ out_trade_no = out_trade_no,
|
|
|
+ phone = phone,
|
|
|
+ match_group = match_group
|
|
|
+ )
|
|
|
+ #支付
|
|
|
+ total_fee = str(int(float(order.total_fee)*100))
|
|
|
+ prepayinfo = wxpay.get_wx_unifiedorder(out_trade_no,total_fee,openid)
|
|
|
+ prepayinfo["key"] = wxpay.WxPayConf_pub.KEY
|
|
|
+ return prepayinfo
|
|
|
+ #种子选手和开户选手免费报名
|
|
|
+ else:
|
|
|
+ #生成订单
|
|
|
+ order = cm.SignupOrder.objects.create(
|
|
|
+ user_id = user_id,
|
|
|
+ user_name = user_name,
|
|
|
+ match_id = match_id,
|
|
|
+ match_name = match_name,
|
|
|
+ signup_type = signup_type,
|
|
|
+ total_fee = total_fee,
|
|
|
+ out_trade_no = out_trade_no,
|
|
|
+ phone = phone,
|
|
|
+ match_group = match_group
|
|
|
+ )
|
|
|
+ if phone_user:
|
|
|
+ if user.id != phone_user.id:
|
|
|
+ user.phone = phone
|
|
|
+ user.player_type = phone_user_player_type
|
|
|
+ user.save()
|
|
|
+ #生成选手信息
|
|
|
+ cur_match = cm.Match.objects.filter(id=match_id).first()
|
|
|
+ visit_group = cm.MatchGroup.objects.filter(id=match_group).first()
|
|
|
+ player,flag = cm.Player.objects.get_or_create(
|
|
|
+ user_id = user.id,
|
|
|
+ match_id = cur_match.id,
|
|
|
+ match_name = cur_match.name,
|
|
|
+ match_group = visit_group.id,
|
|
|
+ match_group_name = visit_group.name
|
|
|
+ )
|
|
|
+ player.username = request.user.nickname
|
|
|
+ player.usercode = request.user.usercode
|
|
|
+ player.role = 2
|
|
|
+ player.match_status = 1
|
|
|
+ player.save()
|
|
|
+ #
|
|
|
+ order.player_id = player.id
|
|
|
+ order.save()
|
|
|
+ if phone_user:
|
|
|
+ cm.UserInfo.objects.filter(id=phone_user.id).delete()
|
|
|
+ cm.Player.objects.filter(user_id=phone_user.id).delete()
|
|
|
+ return {"free":1}
|
|
|
+
|
|
|
+
|
|
|
+def do_wxpay_notify(request):
|
|
|
+ qdata = request.json
|
|
|
+ flag,res = wxpay.check_notify_valid(request.body)
|
|
|
+ if flag:
|
|
|
+ out_trade_no = res.get("out_trade_no")
|
|
|
+ transaction_id = res.get("transaction_id")
|
|
|
+ pay_time = res.get("time_end")
|
|
|
+ try:
|
|
|
+ sorder = cm.SignupOrder.objects.filter(out_trade_no=out_trade_no).first()
|
|
|
+ if sorder and not sorder.transaction_id:
|
|
|
+ now = datetime.datetime.now()
|
|
|
+ cm.SignupOrder.objects.filter(out_trade_no=out_trade_no).update(order_status=1,pay_status=1,pay_time=now,transaction_id=transaction_id)
|
|
|
+ #生成选手信息
|
|
|
+ user = cm.UserInfo.objects.filter(id=sorder.user_id).first()
|
|
|
+ visit_group = cm.MatchGroup.objects.filter(id=sorder.match_group).first()
|
|
|
+ player,flag = cm.Player.objects.get_or_create(
|
|
|
+ user_id = sorder.user_id,
|
|
|
+ match_id = sorder.match_id,
|
|
|
+ match_name = sorder.match_name,
|
|
|
+ match_group = visit_group.id,
|
|
|
+ match_group_name = visit_group.name
|
|
|
+ )
|
|
|
+ player.username = user.nickname
|
|
|
+ player.usercode = user.usercode
|
|
|
+ if sorder.signup_type == 2:
|
|
|
+ player.role = 2
|
|
|
+ else:
|
|
|
+ player.role = 1
|
|
|
+ player.save()
|
|
|
+ #
|
|
|
+ sorder.player_id = player.id
|
|
|
+ sorder.save()
|
|
|
+
|
|
|
+ if sorder.signup_type == 2:
|
|
|
+ player_id = sorder.player_id
|
|
|
+ user_id = sorder.user_id
|
|
|
+ match_group = sorder.match_group
|
|
|
+ match_group_name = cm.MatchGroup.objects.filter(id=match_group).first().name
|
|
|
+ cm.Player.objects.filter(id=player_id).update(role=2,match_group=match_group,match_group_name=match_group_name,match_status=1)
|
|
|
+ cm.UserInfo.objects.filter(id=user_id).update(role=2)
|
|
|
+ if sorder.signup_type == 1:
|
|
|
+ player_id = sorder.player_id
|
|
|
+ user_id = sorder.user_id
|
|
|
+ cm.Player.objects.filter(id=player_id).update(role=1,match_status=1)
|
|
|
+ cm.UserInfo.objects.filter(id=user_id).update(role=1)
|
|
|
+ return True
|
|
|
+ except Exception as e:
|
|
|
+ import traceback
|
|
|
+ traceback.print_exc()
|
|
|
+ print(e,111111111111)
|
|
|
+ return False
|
|
|
+
|
|
|
+def get_user_comments(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ player_id = request.player.id
|
|
|
+ kwargs = request.json
|
|
|
+ stock_id = kwargs.get("stock_id")
|
|
|
+ record_id = kwargs.get("record_id")
|
|
|
+ if record_id:
|
|
|
+ qset = cm.Comments.objects.filter(record_id=record_id,pid__isnull=True)
|
|
|
+ else:
|
|
|
+ qset = cm.Comments.objects.filter(stock_id=stock_id,pid__isnull=True)
|
|
|
+ data = list(qset.values())
|
|
|
+ for item in data:
|
|
|
+ if record_id:
|
|
|
+ subcomments = cm.Comments.objects.filter(record_id=record_id,pid=item["id"])
|
|
|
+ else:
|
|
|
+ subcomments = cm.Comments.objects.filter(stock_id=stock_id,pid=item["id"])
|
|
|
+ item["children"] = list(subcomments.values())
|
|
|
+
|
|
|
+ #分页
|
|
|
+ page = int(kwargs.get("page",1))
|
|
|
+ page_size = int(kwargs.get("page_size",20))
|
|
|
+ if page and page_size:
|
|
|
+ total,data = ccf.get_page_list(data,page,page_size)
|
|
|
+ else:
|
|
|
+ total = len(data)
|
|
|
+
|
|
|
+ return total,data
|
|
|
+
|
|
|
+
|
|
|
+def get_user_choices(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ player_id = request.player.id
|
|
|
+ kwargs = request.json
|
|
|
+ stock_id = kwargs.get("stock_id")
|
|
|
+ qset = cm.UserChoice.objects.filter(player_id=player_id)
|
|
|
+
|
|
|
+ data = list(qset.values())
|
|
|
+ for item in data:
|
|
|
+ stock_id = item["stock_id"]
|
|
|
+ item["count"] = cm.UserChoice.objects.filter(player_id=player_id,stock_id=stock_id).count()
|
|
|
+ comments_count = cm.Comments.objects.filter(stock_id=stock_id).count()
|
|
|
+ choice_count = cm.UserChoice.objects.filter(stock_id=stock_id).count()
|
|
|
+ item["comments_count"] = comments_count
|
|
|
+ item["choice_count"] = choice_count
|
|
|
+ player_id = item["player_id"]
|
|
|
+ match_id = cm.Player.objects.filter(id=player_id).first().match_id
|
|
|
+ item["match_id"] = match_id
|
|
|
+
|
|
|
+ #分页
|
|
|
+ page = int(kwargs.get("page",1))
|
|
|
+ page_size = int(kwargs.get("page_size",20))
|
|
|
+ if page and page_size:
|
|
|
+ total,data = ccf.get_page_list(data,page,page_size)
|
|
|
+ else:
|
|
|
+ total = len(data)
|
|
|
+
|
|
|
+ return total,data
|
|
|
+
|
|
|
+
|
|
|
+def get_user_consult_list(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ player_id = request.user.id if request.user else 0
|
|
|
+ if not player_id:
|
|
|
+ return 0,[]
|
|
|
+ kwargs = request.json
|
|
|
+ record_id = kwargs.get("record_id")
|
|
|
+ qset = cm.WanzhuConsult.objects.filter(user_id=player_id)
|
|
|
+ data = list(qset.values())
|
|
|
+ for item in data:
|
|
|
+ if cm.WanzhuConsult.objects.filter(pid=item["id"]):
|
|
|
+ data.extend(cm.WanzhuConsult.objects.filter(pid=item["id"]).values())
|
|
|
+
|
|
|
+ data = sorted(data,key=lambda x:x["id"])
|
|
|
+ #分页
|
|
|
+ page = int(kwargs.get("page",1))
|
|
|
+ page_size = int(kwargs.get("page_size",20))
|
|
|
+ if page and page_size:
|
|
|
+ total,data = ccf.get_page_list(data,page,page_size)
|
|
|
+ else:
|
|
|
+ total = len(data)
|
|
|
+
|
|
|
+ return total,data
|
|
|
+
|
|
|
+def get_user_zans(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ player_id = request.player.id
|
|
|
+ qdata = request.json
|
|
|
+ record_id = qdata.get("record_id")
|
|
|
+ zans = cm.PlayerRecord.objects.filter(id=record_id).first().zans
|
|
|
+ return zans
|
|
|
+
|
|
|
+
|
|
|
+def get_user_comments_count(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ player_id = request.player.id
|
|
|
+ qdata = request.json
|
|
|
+ record_id = qdata.get("record_id")
|
|
|
+ count = cm.Comments.objects.filter(record_id=record_id).count()
|
|
|
+ return count
|
|
|
+
|
|
|
+
|
|
|
+def add_wanzhu_consult(request):
|
|
|
+ """咨询顽主
|
|
|
+ """
|
|
|
+ user_id = request.user.id
|
|
|
+ user_name = request.user.username
|
|
|
+ user_avatar = request.user.avatar
|
|
|
+ qdata = request.json
|
|
|
+ content = qdata.get("cotent")
|
|
|
+ pid = qdata.get("pid")
|
|
|
+
|
|
|
+ obj = cm.WanzhuConsult.objects.create(
|
|
|
+ user_id = user_id,
|
|
|
+ user_name = user_name,
|
|
|
+ user_avatar = user_avatar,
|
|
|
+ content = content,
|
|
|
+ pid = pid
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def add_comments(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ user_id = request.user.id
|
|
|
+ user_name = request.user.username
|
|
|
+ player_id = request.player.id
|
|
|
+ user_avatar = request.user.avatar
|
|
|
+ qdata = request.json
|
|
|
+ content = qdata.get("cotent")
|
|
|
+ record_id = qdata.get("record_id")
|
|
|
+ stock_id = qdata.get("stock_id")
|
|
|
+ pid = qdata.get("pid")
|
|
|
+
|
|
|
+ ip = ccf.get_ip(request)
|
|
|
+ location = ccf.get_city_from_ip(ip)
|
|
|
+
|
|
|
+ obj = cm.Comments.objects.create(
|
|
|
+ user_id = user_id,
|
|
|
+ user_name = user_name,
|
|
|
+ user_avatar = user_avatar,
|
|
|
+ player_id = player_id,
|
|
|
+ content = content,
|
|
|
+ record_id = record_id,
|
|
|
+ pid = pid,
|
|
|
+ location = location,
|
|
|
+ stock_id = stock_id
|
|
|
+ )
|
|
|
+ cm.PlayerRecord.objects.filter(id=record_id).update(comments_count=F("comments_count")+1)
|
|
|
+
|
|
|
+
|
|
|
+def add_choice(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ user_id = request.user.id
|
|
|
+ user_name = request.user.username
|
|
|
+ player_id = request.player.id
|
|
|
+ user_avatar = request.user.avatar
|
|
|
+ qdata = request.json
|
|
|
+ stock_id = qdata.get("stock_id")
|
|
|
+ stock_name = cm.Stock.objects.filter(id=stock_id).first().name
|
|
|
+
|
|
|
+ obj = cm.UserChoice.objects.create(
|
|
|
+ user_id = user_id,
|
|
|
+ user_name = user_name,
|
|
|
+ user_avatar = user_avatar,
|
|
|
+ player_id = player_id,
|
|
|
+ stock_id = stock_id,
|
|
|
+ stock_name = stock_name
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def add_zan(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ record_id = qdata.get("record_id")
|
|
|
+ cm.PlayerRecord.objects.filter(id=record_id).update(zans=F("zans")+1)
|
|
|
+ zans = cm.PlayerRecord.objects.filter(id=record_id).first().zans
|
|
|
+ return zans
|
|
|
+
|
|
|
+def get_experience_list(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ kwargs = request.json
|
|
|
+ today = get_today_date()
|
|
|
+ match_id = ccc.get_cur_match().id
|
|
|
+ qset = cm.PlayerRecord.objects.filter(match_id=match_id,experience__isnull=False,stock_date=today).order_by("-total_income")[:100]
|
|
|
+
|
|
|
+ data = list(qset.values("id","user_id","username","today_fund","today_income","total_income","experience","match_id","player_id","today_stock_img","zans","comments_count"))
|
|
|
+
|
|
|
+ for item in data:
|
|
|
+ record_id = item["id"]
|
|
|
+ user_id = item["user_id"]
|
|
|
+ #user = cm.UserInfo.objects.filter(id=user_id).first()
|
|
|
+ #if user:
|
|
|
+ # item["user_avatar"] = user.avatar
|
|
|
+ # #item["comments_count"] = cm.Comments.objects.filter(record_id=record_id).count()
|
|
|
+ try:
|
|
|
+ item["user_avatar"] = get_user_info(user_id)["avatar"]
|
|
|
+ except:
|
|
|
+ item["user_avatar"] = ""
|
|
|
+ #item["comments_count"] = 0
|
|
|
+ item["zans_count"] = item["zans"]
|
|
|
+ item["today_stock_img"] = json.loads(item["today_stock_img"])
|
|
|
+ #item["win_rate"] = calc_win_rate(item["player_id"],item["match_id"])
|
|
|
+ win_rate = ccc.cache.hget("PLAYER_LATEST_%d"%item["player_id"],"win_rate")
|
|
|
+ if win_rate:
|
|
|
+ item["win_rate"] = str(float(win_rate)*100)+"%"
|
|
|
+ else:
|
|
|
+ item["win_rate"] = "0.0%"
|
|
|
+ item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
+ item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
+
|
|
|
+ #分页
|
|
|
+ page = int(kwargs.get("page",1))
|
|
|
+ page_size = int(kwargs.get("page_size",20))
|
|
|
+ if page and page_size:
|
|
|
+ total,data = ccf.get_page_list(data,page,page_size)
|
|
|
+ else:
|
|
|
+ total = len(data)
|
|
|
+
|
|
|
+ return total,data
|
|
|
+
|
|
|
+
|
|
|
+def delete_choice(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ user_id = request.user.id
|
|
|
+ user_name = request.user.username
|
|
|
+ player_id = request.player.id
|
|
|
+ user_avatar = request.user.avatar
|
|
|
+ qdata = request.json
|
|
|
+ stock_id = qdata.get("stock_id")
|
|
|
+
|
|
|
+ cm.UserChoice.objects.filter(stock_id=stock_id,player_id=player_id).delete()
|
|
|
+
|
|
|
+
|
|
|
+def delete_comments(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ id = qdata.get("id")
|
|
|
+ cm.Comments.objects.filter(id=id).delete()
|