|
|
@@ -43,6 +43,7 @@ from utils.aliyunpush import aliyunpush
|
|
|
from utils.wxpay.pay import WechatPayDAL
|
|
|
#import logging
|
|
|
#log = logging.getLogger("myerror")
|
|
|
+from utils.upload_to_oss import get_signature
|
|
|
|
|
|
def async(f):
|
|
|
def wrapper(*args, **kwargs):
|
|
|
@@ -182,7 +183,10 @@ def get_player_match_detail(request):
|
|
|
"""选手参赛详情数据
|
|
|
"""
|
|
|
qdata = request.json
|
|
|
- user_id = request.user.get("id",0)
|
|
|
+ try:
|
|
|
+ user_id = request.user.get("id",0)
|
|
|
+ except:
|
|
|
+ user_id = 0
|
|
|
|
|
|
match_id = qdata.get("id")
|
|
|
record_id = qdata.get("record_id")
|
|
|
@@ -265,18 +269,21 @@ def get_player_match_detail(request):
|
|
|
|
|
|
match["groups"] = [today_record.get("match_group_name","")] if today_record else []
|
|
|
records = sorted(records,key=lambda x:x["stock_date"],reverse=True)
|
|
|
- if cm.UserFollows.objects.filter(user_id=request.user.get("id"),follow_id=cur_user_id).exists():
|
|
|
+ if cm.UserFollows.objects.filter(user_id=cur_user_id,follow_id=cur_user_id).exists():
|
|
|
is_follow = 1
|
|
|
else:
|
|
|
is_follow = 0
|
|
|
if today_record and today_record.get("today_fund"):
|
|
|
today_record["today_income_fund"] = round((today_record["today_fund"] - today_record["yesterday_fund"])*10000,2) if today_record["yesterday_fund"] else 0.00
|
|
|
today_record["zan_count"] = today_record.get("zans",0)
|
|
|
+ user_info = get_user_info(cur_user_id)
|
|
|
+ if user_info.get("phone"):
|
|
|
+ del user_info["phone"]
|
|
|
ret = {
|
|
|
"match":match,
|
|
|
"today_record":today_record,
|
|
|
"match_group_info":get_group_info(today_record.get("match_group")) if today_record.get("match_group") else {},
|
|
|
- "userinfo":get_user_info(cur_user_id),
|
|
|
+ "userinfo":user_info,
|
|
|
"records":records,
|
|
|
"is_follow":is_follow,
|
|
|
"fans":cm.UserFollows.objects.filter(follow_id=cur_user_id).count(),
|
|
|
@@ -536,6 +543,8 @@ def get_user_info(uid):
|
|
|
user["style"].append(user["cw"])
|
|
|
if user["df"]:
|
|
|
user["style"].append(user["df"])
|
|
|
+ if user.get("phone"):
|
|
|
+ del user["phone"]
|
|
|
return user
|
|
|
|
|
|
|
|
|
@@ -549,6 +558,8 @@ def get_user_info_actual(uid):
|
|
|
user["style"].append(user["cw"])
|
|
|
if user["df"]:
|
|
|
user["style"].append(user["df"])
|
|
|
+ if user.get("phone"):
|
|
|
+ del user["phone"]
|
|
|
return user
|
|
|
|
|
|
|
|
|
@@ -772,7 +783,7 @@ def add_model(cls,**kwargs):
|
|
|
new_stock_list = []
|
|
|
today_stock_list = json.loads(today_stock)
|
|
|
for ts in today_stock_list:
|
|
|
- if ts["name"]:
|
|
|
+ if ts["name"] and ts["fund"]:
|
|
|
try:
|
|
|
stock,flag = cm.Stock.objects.get_or_create(
|
|
|
name = ts["name"]
|
|
|
@@ -904,7 +915,11 @@ def add_model(cls,**kwargs):
|
|
|
|
|
|
obj = model.objects.create(**kwargs)
|
|
|
|
|
|
- return obj.id
|
|
|
+ if model_name == "PlayerRecord":
|
|
|
+ rst = {"id":obj.id,"user_id":obj.user_id,"match_id":match_id}
|
|
|
+ return rst
|
|
|
+ else:
|
|
|
+ return obj.id
|
|
|
|
|
|
def update_model(cls,**kwargs):
|
|
|
"""
|
|
|
@@ -1277,6 +1292,8 @@ def get_user_follower(request):
|
|
|
item["win_rate"] = "0.0%"
|
|
|
item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
+ if item.get("phone"):
|
|
|
+ del item["phone"]
|
|
|
return total,data
|
|
|
else:
|
|
|
return len(data),data
|
|
|
@@ -1301,6 +1318,9 @@ def get_user_follows(request):
|
|
|
|
|
|
if page and page_size:
|
|
|
total,data = ccf.get_page_list(data,page,page_size)
|
|
|
+ for item in data:
|
|
|
+ if item.get("phone"):
|
|
|
+ del item["phone"]
|
|
|
return total,data
|
|
|
else:
|
|
|
return len(data),data
|
|
|
@@ -1349,6 +1369,7 @@ def get_user_follows(request):
|
|
|
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()
|
|
|
+ del item["phone"]
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
return total,data
|
|
|
@@ -1387,7 +1408,7 @@ def get_hot_stock_buy(**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
stock_date = kwargs.get("stock_date")
|
|
|
- qset = cm.UserStock.objects.filter(stock_date=stock_date)
|
|
|
+ qset = cm.UserStock.objects.filter(stock_date=stock_date,fund__gt=0)
|
|
|
if kwargs.get("name"):
|
|
|
qset = cm.UserStock.objects.filter(stock_name__icontains=kwargs.get("name"),stock_date=stock_date)
|
|
|
qset = qset.values("stock_id","stock_name").annotate(count=Count("stock_id"),total_fund=Sum("fund")).order_by("-count")
|
|
|
@@ -1411,6 +1432,11 @@ def get_hot_stock_buy(**kwargs):
|
|
|
|
|
|
if page and page_size:
|
|
|
total,data = ccf.get_page_list(data,page,page_size)
|
|
|
+ for item in data:
|
|
|
+ stock = cm.Stock.objects.filter(id=item["id"]).first()
|
|
|
+ if stock:
|
|
|
+ item["stock_code"] = stock.code
|
|
|
+ item["stock_desc"] = stock.desc
|
|
|
return total,data
|
|
|
else:
|
|
|
return len(data),data
|
|
|
@@ -1869,7 +1895,7 @@ def get_stock_players(**kwargs):
|
|
|
stock_id = kwargs.get("stock_id")
|
|
|
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,stock_date=stock_date,fund__gt=0.0)
|
|
|
for us in user_stocks:
|
|
|
player_id = us.player_id
|
|
|
player = cm.Player.objects.filter(id=player_id).first()
|
|
|
@@ -1883,16 +1909,20 @@ def get_stock_players(**kwargs):
|
|
|
today_record = get_today_record(user_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_stock = json.loads(today_record["today_stock"]) if today_record["today_stock"] else []
|
|
|
+ today_stock = list(filter(lambda x:float(x.get("fund",0))>0.0,today_stock))
|
|
|
+ today_record["today_stock"] = today_stock
|
|
|
today_record["today_income"] = "{}%".format(today_record["today_income"]*100)
|
|
|
today_record["total_income"] = "{}%".format(today_record["total_income"]*100)
|
|
|
#today_record["cur_stock_fund"] = 0.0
|
|
|
for item in today_record["today_stock"]:
|
|
|
if int(item["stock_id"]) == int(stock_id):
|
|
|
today_record["cur_stock_fund"] = float(item["fund"]) if item["fund"] else 0.0
|
|
|
+ else:
|
|
|
+ today_record["cur_stock_fund"] = 0.0
|
|
|
data.append(today_record)
|
|
|
#data = sorted(data,key=lambda x:x["today_fund"],reverse=True)
|
|
|
- data = sorted(data,key=lambda x:x["cur_stock_fund"],reverse=True)
|
|
|
+ data = sorted(data,key=lambda x:x.get("cur_stock_fund",0),reverse=True)
|
|
|
#分页
|
|
|
page = int(kwargs.get("page",0))
|
|
|
page_size = int(kwargs.get("page_size",20))
|
|
|
@@ -2753,7 +2783,6 @@ def get_format_user_info(request):
|
|
|
userinfo = get_user_info_actual(q_user_id)
|
|
|
userinfo["fans"] = cm.UserFollows.objects.filter(follow_id=user_id).count()
|
|
|
userinfo["followers"] = cm.UserFollows.objects.filter(user_id=user_id).count()
|
|
|
- del userinfo["phone"]
|
|
|
if cm.UserFollows.objects.filter(user_id=cur_user_id,follow_id=user_id).exists():
|
|
|
userinfo["is_follow"] = 1
|
|
|
else:
|
|
|
@@ -2762,6 +2791,8 @@ def get_format_user_info(request):
|
|
|
userinfo["is_black"] = 1
|
|
|
else:
|
|
|
userinfo["is_black"] = 0
|
|
|
+ if userinfo.get("phone"):
|
|
|
+ del userinfo["phone"]
|
|
|
return userinfo
|
|
|
|
|
|
def get_day_inout_rank_list(request):
|
|
|
@@ -3221,7 +3252,7 @@ def get_match_winlost_top5(**kwargs):
|
|
|
get_user_avatar(total_win_down)
|
|
|
valid_dates = json.loads(match.valid_dates) if match.valid_dates else []
|
|
|
|
|
|
- data.append({"valid_dates":valid_dates,"date":end_time,"match_id":match_id,"match_name":match_name,"total_income_up":total_income_up,"total_income_down":total_income_down,"total_win_up":total_win_up,"total_win_down":total_win_down})
|
|
|
+ data.append({"valid_dates":valid_dates,"date":end_time,"start_time":match.start_time,"end_time":match.end_time,"match_id":match_id,"match_name":match_name,"total_income_up":total_income_up,"total_income_down":total_income_down,"total_win_up":total_win_up,"total_win_down":total_win_down})
|
|
|
|
|
|
if int(kwargs.get("new",0)) == 1:
|
|
|
break
|
|
|
@@ -3478,9 +3509,11 @@ def get_match_group_winlose_statistic(**qdata):
|
|
|
#今日全部人均收益率
|
|
|
total = prset.aggregate(total=Sum("today_income")).get("total")
|
|
|
today_win_lose_avg = "{}%".format(round(total/prset.count()*100,2)) if prset.count()>0 else 0.0
|
|
|
+ total_fund = prset.aggregate(total=Sum("today_fund")).get("total")
|
|
|
|
|
|
rst = {"group_win_lose_list":group_win_lose_list,
|
|
|
"win_cnt":win_cnt,"lose_cnt":lose_cnt,
|
|
|
+ "total_fund":total_fund,
|
|
|
"today_win_lose_avg":today_win_lose_avg}
|
|
|
|
|
|
return rst
|
|
|
@@ -3549,20 +3582,25 @@ def get_match_group_winlose_allday(**qdata):
|
|
|
|
|
|
group_win_lose_list = []
|
|
|
prdata = prset.values("match_group","stock_date").annotate(today_fund=Sum("today_fund"),
|
|
|
- today_income=Sum("today_income"),cnt=Count("today_income")).order_by("match_group").order_by("-stock_date")
|
|
|
-
|
|
|
+ today_income=Sum("today_income"),cnt=Count("today_income")).order_by("match_group").order_by("stock_date")
|
|
|
+ money = 10000.0
|
|
|
for item in prdata:
|
|
|
group_id = int(item["match_group"])
|
|
|
stock_date = item["stock_date"]
|
|
|
+
|
|
|
+ money += money * (item["today_income"]/item["cnt"] if item["cnt"] else 0)
|
|
|
+ total_income = (money-10000.0)/10000.0
|
|
|
+ total_avg = "{}%".format(round(total_income*100,2))
|
|
|
group_win_lose_list.append({
|
|
|
"stock_date":stock_date,
|
|
|
"match_group":group_id,
|
|
|
"name":match_group_dct.get(group_id),
|
|
|
"today_fund":"{}".format(round(item["today_fund"],2)),
|
|
|
- "total_income":"{}%".format(round(item["today_income"]/item["cnt"]*100,2)) if item["cnt"] else 0.0,
|
|
|
+ "total_income":total_avg,
|
|
|
"today_income":"{}%".format(round(item["today_income"]/item["cnt"]*100,2)) if item["cnt"] else 0.0
|
|
|
})
|
|
|
|
|
|
+ group_win_lose_list = sorted(group_win_lose_list,key=lambda x:x["stock_date"],reverse=True)
|
|
|
rst = {"list":group_win_lose_list}
|
|
|
return rst
|
|
|
|
|
|
@@ -3577,17 +3615,68 @@ def get_match_group_winlose_avg_allday(**qdata):
|
|
|
|
|
|
all_day = list(set(prset.values_list("stock_date",flat=True)))
|
|
|
|
|
|
+ nall_day = sorted(all_day,reverse=False)
|
|
|
+
|
|
|
allday_winlose_avg_list = []
|
|
|
- for stock_date in all_day:
|
|
|
+ money = 10000.0
|
|
|
+ for stock_date in nall_day:
|
|
|
#今日全部人均收益率
|
|
|
prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id,stock_date=stock_date)
|
|
|
total = prset.aggregate(total=Sum("today_income")).get("total")
|
|
|
today_win_lose_avg = "{}%".format(round(total/prset.count()*100,2)) if prset.count()>0 else 0.0
|
|
|
+ money += money * (total/prset.count() if prset.count() > 0 else 0)
|
|
|
+ total_income = (money-10000.0)/10000.0
|
|
|
+ total_avg = "{}%".format(round(total_income*100,2))
|
|
|
allday_winlose_avg_list.append({
|
|
|
"stock_date":stock_date,
|
|
|
"today_income":today_win_lose_avg,
|
|
|
- "total_income":today_win_lose_avg
|
|
|
+ "total_income":total_avg,
|
|
|
})
|
|
|
allday_winlose_avg_list = sorted(allday_winlose_avg_list,key=lambda x:x["stock_date"],reverse=True)
|
|
|
rst = {"list":allday_winlose_avg_list}
|
|
|
return rst
|
|
|
+
|
|
|
+
|
|
|
+def get_user_match_stock_winloss_rank_list(**kwargs):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ user_id = kwargs.get("user_id")
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ rank_type = kwargs.get("rank_type")
|
|
|
+ data = []
|
|
|
+
|
|
|
+ qset = cm.PlayerRecord.get_db_model(match_id).objects.filter(user_id=user_id,match_id=match_id).exclude(today_stock="[]").order_by("-stock_date")
|
|
|
+ for index,qitem in enumerate(qset):
|
|
|
+ today_stock = qitem.today_stock
|
|
|
+ today_stock = json.loads(today_stock) if today_stock else []
|
|
|
+ stock_date = qitem.stock_date
|
|
|
+ if index == 0:
|
|
|
+ for sitem in today_stock:
|
|
|
+ sitem["stock_date"] = stock_date
|
|
|
+ data.append(sitem)
|
|
|
+ else:
|
|
|
+ for sitem in today_stock:
|
|
|
+ if sitem["fund"] in ["0.0","0",""]:
|
|
|
+ sitem["stock_date"] = stock_date
|
|
|
+ data.append(sitem)
|
|
|
+
|
|
|
+ if rank_type == "win":
|
|
|
+ data = filter(lambda x:float(x.get("money",0))>0,data)
|
|
|
+ data = sorted(data,key=lambda x:float(x.get("money",0)),reverse=True)
|
|
|
+ else:
|
|
|
+ data = filter(lambda x:float(x.get("money",0))<0,data)
|
|
|
+ data = sorted(data,key=lambda x:float(x.get("money",0)),reverse=True)
|
|
|
+
|
|
|
+ return data
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def get_oss2_policy_sign(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ policy = qdata.get("policy")
|
|
|
+ rst = get_signature(policy)
|
|
|
+ return rst
|
|
|
+
|
|
|
+
|