|
@@ -20,13 +20,14 @@ from utils.jgpush import send_notification_by_registration_ids
|
|
|
import wzhifuSDK as wxpay
|
|
|
from utils.exceltool import ExcelTool
|
|
|
from utils.qrcodetool import gen_general_qrcode
|
|
|
-from django.db.models import Q,Sum,Count
|
|
|
+from django.db.models import Q,Sum,Count,F
|
|
|
from PIL import Image
|
|
|
from PIL import Image,ImageDraw,ImageFont
|
|
|
from django.db import transaction
|
|
|
from threading import Thread
|
|
|
#from django.core.cache import cache
|
|
|
from django.db import connection
|
|
|
+import calendar
|
|
|
|
|
|
import xlrd
|
|
|
import xlwt
|
|
@@ -43,6 +44,7 @@ def async(f):
|
|
|
|
|
|
|
|
|
def get_today_date():
|
|
|
+ return '2021-11-25'
|
|
|
if datetime.datetime.now().strftime("%H:%M") < "15:00":
|
|
|
if datetime.datetime.now().weekday() in [5,6] or datetime.datetime.now().strftime("%Y-%m-%d") in MISS_DATES:
|
|
|
today = cm.PlayerRecord.objects.all().order_by("-stock_date").first().stock_date
|
|
@@ -79,7 +81,7 @@ def update_group_rank(match_id,match_group,stock_date):
|
|
|
def get_notices():
|
|
|
"""
|
|
|
"""
|
|
|
- notices = list(cm.Article.objects.filter(status=2).values())
|
|
|
+ notices = list(cm.Article.objects.filter(status=2,type="notice").values())
|
|
|
return notices
|
|
|
|
|
|
def get_index_data(request):
|
|
@@ -159,9 +161,11 @@ def get_player_match_detail(request):
|
|
|
"""
|
|
|
qdata = request.json
|
|
|
player_id = request.player.id
|
|
|
+ org_player_id = request.player.id
|
|
|
match_group = request.player.match_group
|
|
|
match_id = qdata.get("id")
|
|
|
record_id = qdata.get("record_id")
|
|
|
+
|
|
|
if record_id:
|
|
|
records_set = cm.PlayerRecord.objects.filter(id=record_id)
|
|
|
match_id = records_set.first().match_id
|
|
@@ -169,18 +173,21 @@ def get_player_match_detail(request):
|
|
|
player_id = records_set.first().player_id
|
|
|
records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date")
|
|
|
else:
|
|
|
+ if qdata.get("player_id"):
|
|
|
+ player_id = qdata.get("player_id")
|
|
|
+ match_group = cm.Player.objects.filter(id=player_id).first().match_group
|
|
|
records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date")
|
|
|
|
|
|
+
|
|
|
match = cm.Match.objects.filter(id=match_id).values().first()
|
|
|
groups = list(cm.MatchGroup.objects.filter(match_id=match_id).values_list("name",flat=True))
|
|
|
match["groups"] = groups
|
|
|
if records_set:
|
|
|
- #today_record = records_set.values().first()
|
|
|
records = list(records_set.values())
|
|
|
else:
|
|
|
- #today_record = {}
|
|
|
records = []
|
|
|
- today = get_today_date()
|
|
|
+
|
|
|
+ today = records_set.first().stock_date
|
|
|
today_record = get_today_record(player_id,int(match_id),int(match_group),today)
|
|
|
|
|
|
for item in records:
|
|
@@ -191,31 +198,56 @@ def get_player_match_detail(request):
|
|
|
item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
if today_record:
|
|
|
+ today_record["today_stock_img"] = json.loads(today_record["today_stock_img"]) if today_record["today_stock_img"] else []
|
|
|
+ today_record["today_stock"] = json.loads(today_record["today_stock"]) if today_record["today_stock"] else []
|
|
|
today_record["today_income"] = "{}%".format(today_record["today_income"]*100)
|
|
|
today_record["total_income"] = "{}%".format(today_record["total_income"]*100)
|
|
|
today_record["match_group_name"] = cm.MatchGroup.objects.filter(id=today_record["match_group"]).first().name
|
|
|
+ today_record["players_num"] = cm.Player.objects.filter(match_group=today_record["match_group"]).count()
|
|
|
+ today_record["win_rate"] = calc_win_rate(player_id,today_record["match_id"])
|
|
|
+ badest = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("today_income").first()
|
|
|
+ if badest:
|
|
|
+ today_record["badest_income"] = "{}%".format(badest.today_income*100)
|
|
|
+
|
|
|
match["groups"] = [today_record["match_group_name"]] if today_record else []
|
|
|
- records = sorted(records,key=lambda x:x["stock_date"],reverse=True)
|
|
|
- ret = {"match":match,"today_record":today_record,"records":records}
|
|
|
+ records = sorted(records,key=lambda x:x["stock_date"],reverse=True)[:5]
|
|
|
+ if cm.UserFollows.objects.filter(user_id=org_player_id,follow_id=player_id).exists():
|
|
|
+ is_follow = 1
|
|
|
+ else:
|
|
|
+ is_follow = 0
|
|
|
+ ret = {"match":match,"today_record":today_record,"records":records,"is_follow":is_follow}
|
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
-#@ccc.cache_data()
|
|
|
-#def get_today_record(player_id,match_id,match_group,today):
|
|
|
-# records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id,match_group=match_group,stock_date=today)
|
|
|
-# if records_set:
|
|
|
-# today_record = records_set.values().first()
|
|
|
-# else:
|
|
|
-# today_record = {}
|
|
|
-# return today_record
|
|
|
-
|
|
|
def get_today_record(player_id,match_id,match_group,today):
|
|
|
"""
|
|
|
"""
|
|
|
key = "%s_%s_%s_%s" % (player_id,match_id,match_group,today)
|
|
|
today_record = ccc.cache.get(key)
|
|
|
today_record = json.loads(today_record) if today_record else {}
|
|
|
+
|
|
|
+ try:
|
|
|
+ if today_record:
|
|
|
+ user_info = get_user_info(today_record["user_id"])
|
|
|
+ if user_info:
|
|
|
+ user_info.pop("id")
|
|
|
+ today_record.update(user_info)
|
|
|
+
|
|
|
+ #仓位
|
|
|
+ today_stock_total = 0
|
|
|
+ today_stock = json.loads(today_record["today_stock"])
|
|
|
+ for ts in today_stock:
|
|
|
+ if ts["fund"]:
|
|
|
+ try:
|
|
|
+ today_stock_total += float(ts["fund"])
|
|
|
+ except Exception as e:
|
|
|
+ print e
|
|
|
+ today_record["cangwei"] = "{}%".format(round(today_stock_total/today_record["today_fund"],4)*100)
|
|
|
+ today_record["today_stock_total"] = today_stock_total
|
|
|
+ except Exception as e:
|
|
|
+ import traceback
|
|
|
+ traceback.print_exc()
|
|
|
return today_record
|
|
|
|
|
|
@ccc.cache_data()
|
|
@@ -232,7 +264,7 @@ def get_match_groups(match_id):
|
|
|
return match,groups
|
|
|
|
|
|
#@ccc.cache_data()
|
|
|
-def get_cache_rank_list(player_id,match_id):
|
|
|
+def get_cache_rank_list(player_id,match_id,today):
|
|
|
"""
|
|
|
"""
|
|
|
match,groups = get_match_groups(match_id)
|
|
@@ -241,7 +273,6 @@ def get_cache_rank_list(player_id,match_id):
|
|
|
# today = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
#else:
|
|
|
# today = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
- today = get_today_date()
|
|
|
|
|
|
for item in groups:
|
|
|
new_players = []
|
|
@@ -257,13 +288,21 @@ def get_cache_rank_list(player_id,match_id):
|
|
|
if today_record:
|
|
|
player.update(today_record)
|
|
|
player["username"] = username
|
|
|
+ player["org_today_income"] = player["today_income"]
|
|
|
player["total_income"] = "{}%".format(today_record["total_income"]*100)
|
|
|
+ player["today_income"] = "{}%".format(today_record["today_income"]*100)
|
|
|
|
|
|
player["fund"] = round(player["fund"],4)
|
|
|
player["init_fund"] = round(player["init_fund"],4)
|
|
|
player["today_fund"] = round(player["today_fund"],4)
|
|
|
new_players.append(player)
|
|
|
new_players = sorted(new_players,key=lambda x:x["group_rank"])
|
|
|
+ win_count = filter(lambda x:x["org_today_income"]>=0.05,new_players)
|
|
|
+ loss_count = filter(lambda x:x["org_today_income"]<=-0.05,new_players)
|
|
|
+ #item["players_num"] = cm.Player.objects.filter(match_group=item["id"]).count()
|
|
|
+ item["players_num"] = len(players)
|
|
|
+ item["win_count"] = len(win_count)
|
|
|
+ item["loss_count"] = len(loss_count)
|
|
|
item["players"] = new_players[:3]
|
|
|
return match,groups
|
|
|
|
|
@@ -274,7 +313,9 @@ def get_rank_list(request):
|
|
|
qdata = request.json
|
|
|
player_id = request.player.id
|
|
|
match_id = request.player.match_id
|
|
|
- match,groups = get_cache_rank_list(player_id,match_id)
|
|
|
+ today = qdata.get("stock_date")
|
|
|
+
|
|
|
+ match,groups = get_cache_rank_list(player_id,match_id,today)
|
|
|
|
|
|
ret = {"match":match,"groups":groups}
|
|
|
|
|
@@ -284,6 +325,14 @@ def get_rank_list(request):
|
|
|
@ccc.cache_data()
|
|
|
def get_user_info(uid):
|
|
|
user = cm.UserInfo.objects.filter(id=uid).values().first()
|
|
|
+ if user:
|
|
|
+ user["style"] = []
|
|
|
+ if user["zq"]:
|
|
|
+ user["style"].append(user["zq"])
|
|
|
+ if user["cw"]:
|
|
|
+ user["style"].append(user["cw"])
|
|
|
+ if user["df"]:
|
|
|
+ user["style"].append(user["df"])
|
|
|
return user
|
|
|
|
|
|
@ccc.cache_data()
|
|
@@ -294,6 +343,7 @@ def get_match_info(match_id):
|
|
|
@ccc.cache_data()
|
|
|
def get_group_info(group_id):
|
|
|
group = cm.MatchGroup.objects.filter(id=group_id).values().first()
|
|
|
+ group["players_num"] = cm.Player.objects.filter(match_group=group["id"]).count()
|
|
|
return group
|
|
|
|
|
|
|
|
@@ -306,17 +356,11 @@ def get_group_rank_list(request):
|
|
|
group_id = qdata.get("id")
|
|
|
player_id = request.player.id
|
|
|
match_id = request.player.match_id
|
|
|
+ today = qdata.get("stock_date")
|
|
|
|
|
|
match = get_match_info(match_id)
|
|
|
group = get_group_info(group_id)
|
|
|
|
|
|
- #if datetime.datetime.now().hour < 15:
|
|
|
- # today = (datetime.datetime.now()-datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
- #else:
|
|
|
- # today = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
-
|
|
|
- today = get_today_date()
|
|
|
- #players = list(cm.Player.objects.filter(match_id=match_id,match_group=group_id).values())
|
|
|
players = get_match_group_players(match_id,group_id)
|
|
|
new_players = []
|
|
|
for player in players:
|
|
@@ -331,12 +375,24 @@ def get_group_rank_list(request):
|
|
|
if today_record:
|
|
|
player.update(today_record)
|
|
|
player["username"] = username
|
|
|
+ player["org_today_income"] = player["today_income"]
|
|
|
+ player["org_total_income"] = player["total_income"]
|
|
|
player["total_income"] = "{}%".format(player["total_income"]*100)
|
|
|
+ player["today_income"] = "{}%".format(player["today_income"]*100)
|
|
|
player["fund"] = round(player["fund"],4)
|
|
|
player["init_fund"] = round(player["init_fund"],4)
|
|
|
player["today_fund"] = round(player["today_fund"],4)
|
|
|
new_players.append(player)
|
|
|
- new_players = sorted(new_players,key=lambda x:x["group_rank"])
|
|
|
+ if kwargs.get("order_by") == "today_income__asc":
|
|
|
+ new_players = sorted(new_players,key=lambda x:x["org_today_income"])
|
|
|
+ elif kwargs.get("order_by") == "today_income__desc" :
|
|
|
+ new_players = sorted(new_players,key=lambda x:x["org_today_income"],reverse=True)
|
|
|
+ elif kwargs.get("order_by") == "total_income__asc":
|
|
|
+ new_players = sorted(new_players,key=lambda x:x["org_total_income"])
|
|
|
+ elif kwargs.get("order_by") == "total_income__desc":
|
|
|
+ new_players = sorted(new_players,key=lambda x:x["org_total_income"],reverse=True)
|
|
|
+ else:
|
|
|
+ new_players = sorted(new_players,key=lambda x:x["group_rank"])
|
|
|
|
|
|
#分页
|
|
|
page = int(kwargs.get("page",0))
|
|
@@ -346,7 +402,16 @@ def get_group_rank_list(request):
|
|
|
total,new_players = ccf.get_page_list(new_players,page,page_size)
|
|
|
else:
|
|
|
total = len(new_players)
|
|
|
- ret = {"group":group,"players":new_players,"total":total}
|
|
|
+ #应到、实到、请假人数
|
|
|
+ total_person = cm.Player.objects.filter(match_group=group_id,match_status=1).count()
|
|
|
+ actual_person = cm.PlayerRecord.objects.filter(match_group=group_id,stock_date=today).count()
|
|
|
+ leave_person = total_person - actual_person
|
|
|
+
|
|
|
+ win_person = cm.PlayerRecord.objects.filter(match_group=group_id,stock_date=today,total_income__gte=0).count()
|
|
|
+ loss_person = cm.PlayerRecord.objects.filter(match_group=group_id,stock_date=today,total_income__lt=0).count()
|
|
|
+
|
|
|
+ ret = {"group":group,"players":new_players,"total":total,"total_person":total_person,
|
|
|
+ "actual_person":actual_person,"leave_person":leave_person,"win_person":win_person,"loss_person":loss_person}
|
|
|
|
|
|
return ret
|
|
|
|
|
@@ -423,6 +488,11 @@ def add_model(cls,**kwargs):
|
|
|
username = user.username
|
|
|
usercode = user.usercode
|
|
|
match_group = player.match_group
|
|
|
+ zq = user.zq
|
|
|
+ cw = user.cw
|
|
|
+ df = user.df
|
|
|
+ badge = player.badge
|
|
|
+
|
|
|
match = cm.Match.objects.filter(id=match_id).first()
|
|
|
if player.match_status < 1:
|
|
|
raise ce.TipException(u"该账号已暂停/退出比赛,如有疑问请联系管理员获取详情信息!")
|
|
@@ -445,6 +515,24 @@ def add_model(cls,**kwargs):
|
|
|
yesterday_stock_img = ""
|
|
|
yesterday_is_markt = 0
|
|
|
with transaction.atomic():
|
|
|
+ #记录持股情况
|
|
|
+ new_stock_list = []
|
|
|
+ today_stock_list = json.loads(today_stock)
|
|
|
+ for ts in today_stock_list:
|
|
|
+ if ts["name"]:
|
|
|
+ stock,flag = cm.Stock.objects.get_or_create(
|
|
|
+ name = ts["name"]
|
|
|
+ )
|
|
|
+ stock_id = stock.id
|
|
|
+ usobj,flag = cm.UserStock.objects.get_or_create(
|
|
|
+ player_id = player_id,
|
|
|
+ stock_id = stock_id,
|
|
|
+ stock_date = stock_date
|
|
|
+ )
|
|
|
+ ts["stock_id"] = stock_id
|
|
|
+ new_stock_list.append(ts)
|
|
|
+ today_stock = json.dumps(new_stock_list)
|
|
|
+
|
|
|
obj,flag = cm.PlayerRecord.objects.get_or_create(
|
|
|
player_id=player_id,
|
|
|
match_id=match_id,
|
|
@@ -462,6 +550,10 @@ def add_model(cls,**kwargs):
|
|
|
obj.match_group = match_group
|
|
|
obj.is_markt = is_markt
|
|
|
obj.yesterday_is_markt = yesterday_is_markt
|
|
|
+ obj.zq = zq
|
|
|
+ obj.cw = cw
|
|
|
+ obj.df = df
|
|
|
+ obj.badge = badge
|
|
|
#计算今日和昨日盈亏
|
|
|
if float(today_fund)>9999 or float(today_fund)<=0:
|
|
|
raise ce.TipException(u"数据错误,今日净资产不能超过9999万元,不能低于0万元,请仔细核对数据!")
|
|
@@ -477,8 +569,11 @@ def add_model(cls,**kwargs):
|
|
|
obj.ctime = datetime.datetime.now()
|
|
|
obj.save()
|
|
|
|
|
|
+ #更新股票持股人数
|
|
|
+ for stock in new_stock_list:
|
|
|
+ cm.Stock.objects.filter(id=stock["stock_id"]).update(user_num=F("user_num")+1)
|
|
|
+
|
|
|
#更新group_rank
|
|
|
- #update_group_rank(match_id,match_group,obj.stock_date)
|
|
|
ccc.cache.lpush(settings.RANK_LIST,obj.id)
|
|
|
return obj.id
|
|
|
|
|
@@ -515,14 +610,21 @@ def get_search_list(cls,**kwargs):
|
|
|
model_name = re.search(r'.*\.(\w+)SearchView',str(cls.__class__)).groups()[0]
|
|
|
model = getattr(cm,model_name)
|
|
|
qset = model.objects.all()
|
|
|
- if kwargs.get("name"):
|
|
|
- qset = qset.filter(name__icontains=kwargs.get("name"))
|
|
|
+ if model_name == "Stock":
|
|
|
+ if kwargs.get("name"):
|
|
|
+ qset = qset.filter(Q(name__icontains=kwargs.get("name"))|Q(code__icontains=kwargs.get("name")))
|
|
|
+ else:
|
|
|
+ if kwargs.get("name"):
|
|
|
+ qset = qset.filter(name__icontains=kwargs.get("name"))
|
|
|
if model_name == "Player":
|
|
|
data = list(qset.values("id","username"))
|
|
|
if model_name == "Stock":
|
|
|
data = list(qset.values("id","name","code"))
|
|
|
for item in data:
|
|
|
- item["label"] = "%s(%s)" % (item["name"],item["code"])
|
|
|
+ if item["code"]:
|
|
|
+ item["label"] = "%s(%s)" % (item["name"],item["code"])
|
|
|
+ else:
|
|
|
+ item["label"] = "%s" % item["name"]
|
|
|
else:
|
|
|
data = list(qset.values("id","name"))
|
|
|
return data
|
|
@@ -552,6 +654,8 @@ def get_detail_info(cls,**kwargs):
|
|
|
|
|
|
# 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")
|
|
|
return rst
|
|
|
|
|
|
#@ccc.cache_data()
|
|
@@ -656,6 +760,25 @@ def add_player_record_single(**kwargs):
|
|
|
yesterday_fund = init_fund
|
|
|
yesterday_stock = ""
|
|
|
yesterday_stock_img = ""
|
|
|
+
|
|
|
+ #记录持股情况
|
|
|
+ new_stock_list = []
|
|
|
+ today_stock_list = json.loads(today_stock)
|
|
|
+ for ts in today_stock_list:
|
|
|
+ if ts["name"]:
|
|
|
+ stock,flag = cm.Stock.objects.get_or_create(
|
|
|
+ name = ts["stock"]
|
|
|
+ )
|
|
|
+ stock_id = stock.id
|
|
|
+ usobj,flag = cm.UserStock.objects.get_or_create(
|
|
|
+ player_id = player_id,
|
|
|
+ stock_id = stock_id,
|
|
|
+ stock_date = stock_date
|
|
|
+ )
|
|
|
+ ts["stock_id"] = stock_id
|
|
|
+ new_stock_list.append(ts)
|
|
|
+ today_stock = json.dumps(new_stock_list)
|
|
|
+
|
|
|
obj,flag = cm.PlayerRecord.objects.get_or_create(
|
|
|
player_id=player_id,
|
|
|
match_id=match_id,
|
|
@@ -676,15 +799,20 @@ def add_player_record_single(**kwargs):
|
|
|
today_income = (today_fund - yesterday_fund)/float(yesterday_fund)
|
|
|
total_income = (today_fund - init_fund)/float(init_fund)
|
|
|
if int(today_fund)>9999 or int(today_fund)<0:
|
|
|
- raise ce.TipException(u"数据错误,今日净资产不能超过9999万元,不能低于0万元,请仔细核对数据!")
|
|
|
+ raise ce.TipException(u"数据错误,今日净资产不能超过9999万元,不能低于0万元,请仔细核对数据!")
|
|
|
if int(today_income)>2:
|
|
|
raise ce.TipException(u"数据错误,今日盈利已超过2倍,请仔细核对数据!")
|
|
|
+
|
|
|
obj.today_income = round(today_income,4)
|
|
|
obj.total_income = round(total_income,4)
|
|
|
if not flag:
|
|
|
obj.ctime = datetime.datetime.now()
|
|
|
obj.save()
|
|
|
|
|
|
+ #更新股票持股人数
|
|
|
+ for stock in new_stock_list:
|
|
|
+ cm.Stock.objects.filter(id=stock["id"]).update(user_num=F("user_num")+1)
|
|
|
+
|
|
|
#更新group_rank
|
|
|
#update_group_rank(match_id,match_group,obj.stock_date)
|
|
|
ccc.cache.lpush(settings.RANK_LIST,obj.id)
|
|
@@ -719,3 +847,562 @@ def get_cur_record(request):
|
|
|
data["today_stock"] = json.loads(data["today_stock"]) if data["today_stock"] else []
|
|
|
return data
|
|
|
|
|
|
+
|
|
|
+def follow_player(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ user_id = kwargs.get("player_id")
|
|
|
+ follow_id = kwargs.get("follow_id")
|
|
|
+ if kwargs.get("action") == "cancel":
|
|
|
+ cm.UserFollows.objects.filter(user_id=user_id,follow_id=follow_id).delete()
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ obj,flag = cm.UserFollows.objects.get_or_create(user_id=user_id,follow_id=follow_id)
|
|
|
+ return obj.id
|
|
|
+
|
|
|
+def calc_win_rate(player_id,match_id):
|
|
|
+ """计算胜率
|
|
|
+ """
|
|
|
+ qset = cm.PlayerRecord.objects.filter(match_id=match_id,player_id=player_id)
|
|
|
+ win_rate = qset.filter(today_income__gte=0).count()/float(qset.count()) if qset else 0.0
|
|
|
+ win_rate = round(win_rate,3)
|
|
|
+ win_rate = "{}%".format(win_rate*100)
|
|
|
+ return win_rate
|
|
|
+
|
|
|
+
|
|
|
+def get_user_follows(request):
|
|
|
+ """获取用户关注的选手列表
|
|
|
+ """
|
|
|
+ user_id = request.player.id
|
|
|
+ print user_id
|
|
|
+ match_id = request.player.match_id
|
|
|
+ match_group = request.player.match_group
|
|
|
+ qdata = request.json
|
|
|
+ today = get_today_date()
|
|
|
+ print today
|
|
|
+
|
|
|
+ data = []
|
|
|
+
|
|
|
+ qset = cm.UserFollows.objects.filter(user_id=user_id)
|
|
|
+ follow_ids = list(qset.values_list("follow_id",flat=True))
|
|
|
+
|
|
|
+ for player_id in follow_ids:
|
|
|
+ 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_record = get_today_record(player_id,match_id,last.match_group,today)
|
|
|
+ if today_record:
|
|
|
+ data.append(today_record)
|
|
|
+ data = sorted(data,key=lambda x:x["group_rank"])
|
|
|
+ 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:
|
|
|
+ item["today_stock"] = json.loads(item["today_stock"])
|
|
|
+ item["today_stock_img"] = json.loads(item["today_stock_img"])
|
|
|
+ item["win_rate"] = calc_win_rate(item["player_id"],item["match_id"])
|
|
|
+ item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
+ item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
+ return total,data
|
|
|
+ else:
|
|
|
+ return len(data),data
|
|
|
+
|
|
|
+
|
|
|
+def get_hot_stock_rank(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ data = {
|
|
|
+ "hot_buy":[
|
|
|
+ {"stock_name":u"创业黑马","count":12}
|
|
|
+ ],
|
|
|
+ "hot_sell":[
|
|
|
+ {"stock_name":u"创业黑马","count":12}
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ return data
|
|
|
+
|
|
|
+
|
|
|
+def get_hot_stock_buy(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ stock_date = kwargs.get("stock_date")
|
|
|
+ qset = cm.UserStock.objects.filter(stock_date=stock_date)
|
|
|
+ qset = qset.values("stock_id").annotate(count=Count("stock_id")).order_by("-count")
|
|
|
+ data = []
|
|
|
+ for q in qset:
|
|
|
+ stock_id = q["stock_id"]
|
|
|
+ count = q["count"]
|
|
|
+ data.append(
|
|
|
+ {
|
|
|
+ "stock_name":cm.Stock.objects.filter(id=stock_id).first().name,
|
|
|
+ "count":count,
|
|
|
+ "id":stock_id
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ if kwargs.get("name"):
|
|
|
+ data = filter(lambda x:kwargs.get("name") in x["stock_name"],data)
|
|
|
+
|
|
|
+ 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)
|
|
|
+ return total,data
|
|
|
+ else:
|
|
|
+ return len(data),data
|
|
|
+ return data
|
|
|
+
|
|
|
+
|
|
|
+def get_hot_follow(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ stock_date = kwargs.get("stock_date")
|
|
|
+ #qset = cm.UserFollows.objects.filter(stock_date=stock_date)
|
|
|
+ qset = cm.UserFollows.objects.all()
|
|
|
+ qset = qset.values("follow_id").annotate(count=Count("follow_id")).order_by("-count")
|
|
|
+ data = []
|
|
|
+ for q in qset:
|
|
|
+ player_id = q["follow_id"]
|
|
|
+ count = q["count"]
|
|
|
+ player = cm.Player.objects.filter(id=player_id).first()
|
|
|
+ today = cm.PlayerRecord.objects.filter(player_id=player_id).order_by("-stock_date").first().stock_date
|
|
|
+ badest_income = cm.PlayerRecord.objects.filter(player_id=player_id).order_by("-today_income").first().today_income
|
|
|
+ today_record = get_today_record(player_id,int(player.match_id),int(player.match_group),today)
|
|
|
+ userinfo = get_user_info(today_record["user_id"])
|
|
|
+
|
|
|
+ data.append(
|
|
|
+ {
|
|
|
+ "player_name":player.username,
|
|
|
+ "count":count,
|
|
|
+ "id":player_id,
|
|
|
+ "today_fund":today_record["today_fund"],
|
|
|
+ "total_income":"{}%".format(today_record["total_income"]*100),
|
|
|
+ "today_income":"{}%".format(today_record["today_income"]*100),
|
|
|
+ "badest_income":"{}%".format(badest_income*100),
|
|
|
+ "style":userinfo.get("style"),
|
|
|
+ "badge":userinfo.get("badge"),
|
|
|
+ "match_id":player.match_id,
|
|
|
+ "win_rate":calc_win_rate(player_id,player.match_id)
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ if kwargs.get("name"):
|
|
|
+ data = filter(lambda x:kwargs.get("name") in x["player_name"],data)
|
|
|
+
|
|
|
+ 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)
|
|
|
+ return total,data
|
|
|
+ else:
|
|
|
+ return len(data),data
|
|
|
+ return data
|
|
|
+
|
|
|
+
|
|
|
+def get_hot_stock_sell(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ stock_date = kwargs.get("stock_date")
|
|
|
+ stock_date_time = ccf.str_to_datetime(kwargs.get("stock_date"),"%Y-%m-%d")
|
|
|
+ yesterday = (stock_date_time - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
+
|
|
|
+ ##昨天所有股票
|
|
|
+ #yes_stock_ids = list(cm.UserStock.objects.filter(stock_date=yesterday).values_list("stock_id",flat=True))
|
|
|
+ #yes_stock_ids = list(set(yes_stock_ids))
|
|
|
+ #data = []
|
|
|
+ #for ysi in yes_stock_ids:
|
|
|
+ # yes_count = cm.UserStock.objects.filter(stock_date=yesterday,stock_id=ysi).count()
|
|
|
+ # td_count = cm.UserStock.objects.filter(stock_date=stock_date,stock_id=ysi).count()
|
|
|
+ # if td_count < yes_count:
|
|
|
+ # stock_name = cm.Stock.objects.filter(id=ysi).first().name
|
|
|
+ # data.append({"stock_name":stock_name,"count":yes_count-td_count,"id":ysi})
|
|
|
+ qset = cm.HotStockSellCount.objects.filter(stock_date=stock_date).order_by("-count")
|
|
|
+
|
|
|
+ data = list(qset.values("stock_name","stock_id","count"))
|
|
|
+ for item in data:
|
|
|
+ item["id"] = item["stock_id"]
|
|
|
+
|
|
|
+ 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)
|
|
|
+ return total,data
|
|
|
+ else:
|
|
|
+ return len(data),data
|
|
|
+ return data
|
|
|
+
|
|
|
+
|
|
|
+def get_stock_info(_id):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ data = cm.Stock.objects.filter(id=_id).values().first()
|
|
|
+ return data
|
|
|
+
|
|
|
+
|
|
|
+def get_hot_stock_sell_players(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ _id = kwargs.get("id")
|
|
|
+ stock_date = kwargs.get("stock_date")
|
|
|
+ stock_date_time = ccf.str_to_datetime(kwargs.get("stock_date"),"%Y-%m-%d")
|
|
|
+ yesterday = (stock_date_time - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
|
|
|
+
|
|
|
+ #昨天持股选手
|
|
|
+ yes_players = list(cm.UserStock.objects.filter(stock_date=yesterday,stock_id=_id).values_list("player_id",flat=True))
|
|
|
+ td_players = list(cm.UserStock.objects.filter(stock_date=stock_date,stock_id=_id).values_list("player_id",flat=True))
|
|
|
+ sell_players = list(set(yes_players)-set(td_players))
|
|
|
+
|
|
|
+ data = []
|
|
|
+ for player_id in sell_players:
|
|
|
+ player = cm.Player.objects.filter(id=player_id).first()
|
|
|
+ if player:
|
|
|
+ match_id = player.match_id
|
|
|
+ match_group = player.match_group
|
|
|
+ today_record = get_today_record(player_id,match_id,match_group,stock_date)
|
|
|
+
|
|
|
+ if today_record:
|
|
|
+ today_record["today_stock_img"] = json.loads(today_record["today_stock_img"]) if today_record["today_stock_img"] else []
|
|
|
+ today_record["today_stock"] = json.loads(today_record["today_stock"]) if today_record["today_stock"] else []
|
|
|
+ today_record["today_income"] = "{}%".format(today_record["today_income"]*100)
|
|
|
+ today_record["total_income"] = "{}%".format(today_record["total_income"]*100)
|
|
|
+ data.append(today_record)
|
|
|
+
|
|
|
+ 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)
|
|
|
+ return total,data
|
|
|
+ else:
|
|
|
+ return len(data),data
|
|
|
+ return data
|
|
|
+
|
|
|
+
|
|
|
+def get_win_rate_rank(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ player_id = request.player.id
|
|
|
+ match_id = request.player.match_id
|
|
|
+ match_group = request.player.match_group
|
|
|
+ kwargs = request.json
|
|
|
+
|
|
|
+ qset = cm.WinDefendRank.objects.filter(match_id=match_id).order_by("-win_rate")
|
|
|
+ data = list(qset.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)
|
|
|
+ for item in data:
|
|
|
+ item["win_rate"] = "{}%".format(item["win_rate"]*100)
|
|
|
+ item["badest_income"] = "{}%".format(item["badest_income"]*100)
|
|
|
+ item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
+ userinfo = get_user_info(item["user_id"])
|
|
|
+ item["badge"] = userinfo.get("badge")
|
|
|
+ item["style"] = userinfo.get("style")
|
|
|
+
|
|
|
+
|
|
|
+ return total,data
|
|
|
+
|
|
|
+
|
|
|
+def get_defend_rank(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ player_id = request.player.id
|
|
|
+ match_id = request.player.match_id
|
|
|
+ match_group = request.player.match_group
|
|
|
+ kwargs = request.json
|
|
|
+
|
|
|
+ qset = cm.WinDefendRank.objects.filter(match_id=match_id).order_by("-badest_income")
|
|
|
+ data = list(qset.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)
|
|
|
+ for item in data:
|
|
|
+ item["win_rate"] = "{}%".format(item["win_rate"]*100)
|
|
|
+ item["badest_income"] = "{}%".format(item["badest_income"]*100)
|
|
|
+ item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
+ item["style"] = []
|
|
|
+ if item["zq"]:
|
|
|
+ item["style"].apepnd(item["zq"])
|
|
|
+ if item["cw"]:
|
|
|
+ item["style"].apepnd(item["cw"])
|
|
|
+ if item["df"]:
|
|
|
+ item["style"].apepnd(item["df"])
|
|
|
+ item["badge"] = cm.Player.objects.filter(id=item["player_id"]).first().badge
|
|
|
+
|
|
|
+ return total,data
|
|
|
+
|
|
|
+
|
|
|
+def get_champion_articles_list(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ kwargs = request.json
|
|
|
+ qset = cm.Article.objects.filter(status=2,type="champion")
|
|
|
+
|
|
|
+ page = int(kwargs.get("page",0))
|
|
|
+ page_size = int(kwargs.get("page_size",20))
|
|
|
+
|
|
|
+ if page and page_size:
|
|
|
+ total,qset = ccf.get_page_qset(qset,page,page_size)
|
|
|
+ else:
|
|
|
+ total = qset.count()
|
|
|
+ data = list(qset.values())
|
|
|
+ for item in data:
|
|
|
+ item["ctime"] = ccf.datetime_to_str(item["ctime"],"%Y-%m-%d")
|
|
|
+ return total,data
|
|
|
+
|
|
|
+def get_wanzhu_comment(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ group_id = kwargs.get("group_id")
|
|
|
+ print match_id
|
|
|
+ today = get_today_date()
|
|
|
+ players = get_match_group_players(match_id,group_id)
|
|
|
+ new_players = []
|
|
|
+ for player in players:
|
|
|
+ user_id = player["user_id"]
|
|
|
+ user = get_user_info(user_id)
|
|
|
+ username = user["username"] if user else ""
|
|
|
+
|
|
|
+ player_id = player["id"]
|
|
|
+ match_group = group_id
|
|
|
+ today_record = get_today_record(player_id,match_id,int(match_group),today)
|
|
|
+ if today_record and today_record.get("wanzhu_comment"):
|
|
|
+ player.update(today_record)
|
|
|
+ player["username"] = username
|
|
|
+ player["total_income"] = "{}%".format(player["total_income"]*100)
|
|
|
+ player["fund"] = round(player["fund"],4)
|
|
|
+ player["init_fund"] = round(player["init_fund"],4)
|
|
|
+ player["today_fund"] = round(player["today_fund"],4)
|
|
|
+ player["today_stock"] = json.loads(player["today_stock"]) if player["today_stock"] else []
|
|
|
+ new_players.append(player)
|
|
|
+ new_players = sorted(new_players,key=lambda x:x["group_rank"])
|
|
|
+ data = new_players
|
|
|
+
|
|
|
+ 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)
|
|
|
+ else:
|
|
|
+ total = len(data)
|
|
|
+
|
|
|
+ return total,data
|
|
|
+
|
|
|
+
|
|
|
+def get_enum_list(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ data = {
|
|
|
+ "zq":[
|
|
|
+ u"短线博弈",
|
|
|
+ u"长线价投",
|
|
|
+ u"长短兼备"
|
|
|
+ ],
|
|
|
+ "cw":[
|
|
|
+ u"分仓开超市",
|
|
|
+ u"重仓押注",
|
|
|
+ u"全仓单钓",
|
|
|
+ u"融资加倍"
|
|
|
+ ],
|
|
|
+ "df":[
|
|
|
+ u"低吸",
|
|
|
+ u"半路",
|
|
|
+ u"首板",
|
|
|
+ u"接力",
|
|
|
+ u"撬板",
|
|
|
+ u"T加0",
|
|
|
+ u"隔夜卖",
|
|
|
+ u"格局锁仓",
|
|
|
+ u"核按钮"
|
|
|
+ ],
|
|
|
+ "pz":[
|
|
|
+ u"N/C字头新股",
|
|
|
+ u"次新股",
|
|
|
+ u"可转债",
|
|
|
+ u"港股",
|
|
|
+ u"基金",
|
|
|
+ u"逆回购"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ return data
|
|
|
+
|
|
|
+def get_player_list(**kwargs):
|
|
|
+ """选手列表
|
|
|
+ """
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ today = get_today_date()
|
|
|
+
|
|
|
+ qset = cm.Player.objects.filter(match_id=match_id,match_status=1)
|
|
|
+ if kwargs.get("name"):
|
|
|
+ qset = qset.filter(username__icontains=kwargs.get("name"))
|
|
|
+ data = list(qset.values())
|
|
|
+
|
|
|
+ for item in data:
|
|
|
+ match_id = item["match_id"]
|
|
|
+ match_group = item["match_group"]
|
|
|
+ user_id = item["user_id"]
|
|
|
+ player_id = item["id"]
|
|
|
+ #user = cm.UserInfo.objects.filter(id=user_id).first()
|
|
|
+ today_record = get_today_record(player_id,match_id,match_group,today)
|
|
|
+ if today_record:
|
|
|
+ today_record.pop("id")
|
|
|
+ item.update(today_record)
|
|
|
+ user_info = get_user_info(user_id)
|
|
|
+ if user_info:
|
|
|
+ user_info.pop("id")
|
|
|
+ item.update(user_info)
|
|
|
+
|
|
|
+ if kwargs.get("zq"):
|
|
|
+ data = filter(lambda x:kwargs.get("zq") == x["zq"],data)
|
|
|
+ if kwargs.get("cw"):
|
|
|
+ data = filter(lambda x:kwargs.get("cw") == x["cw"],data)
|
|
|
+ if kwargs.get("df"):
|
|
|
+ data = filter(lambda x:kwargs.get("df") == x["df"],data)
|
|
|
+
|
|
|
+ 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)
|
|
|
+ else:
|
|
|
+ total = len(data)
|
|
|
+
|
|
|
+ return total,data
|
|
|
+
|
|
|
+
|
|
|
+def get_mine_style(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ user = request.user
|
|
|
+ player = request.player
|
|
|
+ data = {
|
|
|
+ "zq":user.zq,
|
|
|
+ "cw":user.cw,
|
|
|
+ "df":user.df,
|
|
|
+ "pz":user.pz,
|
|
|
+ "join_time":user.join_time,
|
|
|
+ "account_img":user.account_img,
|
|
|
+ }
|
|
|
+ if player:
|
|
|
+ data["is_player"] = 1
|
|
|
+ data["init_fund"] = player.fund
|
|
|
+ else:
|
|
|
+ data["is_player"] = 0
|
|
|
+ data["init_fund"] = None
|
|
|
+ return data
|
|
|
+
|
|
|
+
|
|
|
+def update_user_style(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ user_id = kwargs.pop("user_id")
|
|
|
+ player_id = kwargs.pop("player_id")
|
|
|
+ init_fund = kwargs.pop("init_fund")
|
|
|
+ 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)
|
|
|
+ return True
|
|
|
+
|
|
|
+
|
|
|
+def get_stock_players(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ stock_id = kwargs.get("stock_id")
|
|
|
+ stock_date = kwargs.get("stock_date")
|
|
|
+ data = []
|
|
|
+ user_stocks = cm.UserStock.objects.filter(stock_id=stock_id,stock_date=stock_date)
|
|
|
+ for us in user_stocks:
|
|
|
+ player_id = us.player_id
|
|
|
+ player = cm.Player.objects.filter(id=player_id).first()
|
|
|
+ if player:
|
|
|
+ match_id = player.match_id
|
|
|
+ match_group = player.match_group
|
|
|
+ if stock_date:
|
|
|
+ today_record = get_today_record(player_id,match_id,match_group,stock_date)
|
|
|
+ else:
|
|
|
+ today_record = get_today_record(player_id,match_id,match_group,us.stock_date)
|
|
|
+ if today_record:
|
|
|
+ today_record["today_stock_img"] = json.loads(today_record["today_stock_img"]) if today_record["today_stock_img"] else []
|
|
|
+ today_record["today_stock"] = json.loads(today_record["today_stock"]) if today_record["today_stock"] else []
|
|
|
+ today_record["today_income"] = "{}%".format(today_record["today_income"]*100)
|
|
|
+ today_record["total_income"] = "{}%".format(today_record["total_income"]*100)
|
|
|
+ data.append(today_record)
|
|
|
+
|
|
|
+ #分页
|
|
|
+ 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 data
|
|
|
+
|
|
|
+
|
|
|
+def update_user_fund(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ user_id = kwargs.pop("user_id")
|
|
|
+ player_id = kwargs.pop("player_id")
|
|
|
+ init_fund = kwargs.pop("init_fund")
|
|
|
+ if player_id and init_fund:
|
|
|
+ cm.Player.objects.filter(id=player_id).update(fund=init_fund)
|
|
|
+ return True
|
|
|
+
|
|
|
+
|
|
|
+def get_player_match_calendar(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ player_id = kwargs.get("player_id")
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ month = kwargs.get("month")
|
|
|
+
|
|
|
+ print kwargs
|
|
|
+
|
|
|
+ week,eday = calendar.monthrange(int(month.split("-")[0]),int(month.split("-")[1]))
|
|
|
+ sday = "01"
|
|
|
+ eday = str(eday).zfill(2)
|
|
|
+ sdate = month + "-" + sday
|
|
|
+ edate = month + "-" + eday
|
|
|
+
|
|
|
+ print sdate,edate
|
|
|
+
|
|
|
+ qset = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id)\
|
|
|
+ .filter(stock_date__gte=sdate,stock_date__lte=edate)
|
|
|
+ data = list(qset.values())
|
|
|
+
|
|
|
+ dct = {}
|
|
|
+ for item in data:
|
|
|
+ item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
+ dct[item["stock_date"]] = item["today_income"]
|
|
|
+
|
|
|
+ newdata = []
|
|
|
+ for i in range(1,int(eday)+1):
|
|
|
+ stock_date = month + "-" + str(i).zfill(2)
|
|
|
+ newdata.append({
|
|
|
+ "stock_date":stock_date,
|
|
|
+ "today_income":dct.get(stock_date,""),
|
|
|
+ })
|
|
|
+
|
|
|
+ return newdata
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|