|
@@ -36,6 +36,7 @@ from xltpl.writer import BookWriter
|
|
|
from django_redis import get_redis_connection
|
|
|
from constants import *
|
|
|
from utils.aliyun_sms import send_verify_code,send_signup_success
|
|
|
+from utils.wxSubscribeMessage import send_consult_reply_message
|
|
|
|
|
|
def async(f):
|
|
|
def wrapper(*args, **kwargs):
|
|
@@ -166,7 +167,7 @@ def get_player_match_detail(request):
|
|
|
"""
|
|
|
qdata = request.json
|
|
|
player_id = request.player.id
|
|
|
- user_id = request.player.user_id
|
|
|
+ user_id = request.user.id
|
|
|
org_player_id = request.player.id
|
|
|
match_group = request.player.match_group
|
|
|
match_id = qdata.get("id")
|
|
@@ -178,6 +179,10 @@ def get_player_match_detail(request):
|
|
|
if not cur_player_id:
|
|
|
cur_player_id = player_id
|
|
|
|
|
|
+ #if match_id != ccc.get_cur_match().id:
|
|
|
+ if qdata.get("user_id"):
|
|
|
+ cur_player_id = cm.Player.objects.filter(user_id=qdata.get("user_id"),match_id=match_id).first().id
|
|
|
+
|
|
|
today = get_today_date()
|
|
|
|
|
|
ismine = True if int(cur_player_id) == player_id else False
|
|
@@ -191,14 +196,11 @@ def get_player_match_detail(request):
|
|
|
match_id = records_set.first().match_id
|
|
|
match_group = records_set.first().match_group
|
|
|
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")
|
|
|
+ records_set = cm.PlayerRecord.objects.filter(player_id=cur_player_id,match_id=match_id).order_by("-stock_date")
|
|
|
today = records_set.first().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_group = cm.Player.objects.filter(id=cur_player_id).first().match_group
|
|
|
+ records_set = cm.PlayerRecord.objects.filter(player_id=cur_player_id,match_id=match_id).order_by("-stock_date")
|
|
|
|
|
|
|
|
|
match = cm.Match.objects.filter(id=match_id).values().first()
|
|
@@ -220,15 +222,12 @@ def get_player_match_detail(request):
|
|
|
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)
|
|
|
- #if not today_record:
|
|
|
- # today_record = get_today_record_actual(player_id,match_id,today)
|
|
|
if record_id:
|
|
|
today = records_set.filter(id=record_id).first().stock_date
|
|
|
if ismine:
|
|
|
- today_record = get_today_record_actual(player_id,match_id,match_group,today)
|
|
|
+ today_record = get_today_record_actual(cur_player_id,match_id,match_group,today)
|
|
|
else:
|
|
|
- today_record = get_today_record(player_id,int(match_id),int(match_group),today)
|
|
|
+ today_record = get_today_record(cur_player_id,int(match_id),int(match_group),today)
|
|
|
|
|
|
if today_record:
|
|
|
today_record["today_stock_img"] = json.loads(today_record["today_stock_img"]) if today_record["today_stock_img"] else []
|
|
@@ -238,7 +237,7 @@ def get_player_match_detail(request):
|
|
|
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()
|
|
|
+ badest = cm.PlayerRecord.objects.filter(player_id=cur_player_id,match_id=match_id).order_by("today_income").first()
|
|
|
if badest:
|
|
|
today_record["badest_income"] = "{}%".format(badest.today_income*100)
|
|
|
today_record["today_stock_total"] = round(today_record["today_stock_total"],4)
|
|
@@ -256,20 +255,24 @@ def get_player_match_detail(request):
|
|
|
|
|
|
match["groups"] = [today_record["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=org_player_id,follow_id=player_id).exists():
|
|
|
+ if cm.UserFollows.objects.filter(user_id=request.user.id,follow_id=cur_player_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
|
|
|
+ try:
|
|
|
+ cur_user_id = cm.Player.objects.filter(id=cur_player_id).first().user_id
|
|
|
+ except:
|
|
|
+ pass
|
|
|
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(),
|
|
|
+ "fans":cm.UserFollows.objects.filter(follow_id=cur_player_id).count(),
|
|
|
+ "followers":cm.UserFollows.objects.filter(user_id=cur_user_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))
|
|
|
}
|
|
@@ -551,9 +554,14 @@ def get_player_match_records(request):
|
|
|
qdata = request.json
|
|
|
player_id = request.player.id
|
|
|
match_id = qdata.get("id")
|
|
|
+ user_id = qdata.get("user_id")
|
|
|
q_player_id = qdata.get("player_id")
|
|
|
if q_player_id:
|
|
|
player_id = q_player_id
|
|
|
+ try:
|
|
|
+ player_id = cm.Player.objects.filter(match_id=match_id,user_id=user_id).first().id
|
|
|
+ except:
|
|
|
+ pass
|
|
|
page = int(qdata.get("page",0))
|
|
|
page_size = int(qdata.get("page_size",20))
|
|
|
|
|
@@ -695,24 +703,28 @@ def add_model(cls,**kwargs):
|
|
|
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_name = ts["name"],
|
|
|
- stock_date = stock_date
|
|
|
- )
|
|
|
- ts["stock_id"] = stock_id
|
|
|
- new_stock_list.append(ts)
|
|
|
+ try:
|
|
|
+ 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_name = ts["name"],
|
|
|
+ stock_date = stock_date
|
|
|
+ )
|
|
|
+ ts["stock_id"] = stock_id
|
|
|
+ new_stock_list.append(ts)
|
|
|
+ except Exception as e:
|
|
|
+ print(e)
|
|
|
today_stock = json.dumps(new_stock_list)
|
|
|
|
|
|
obj,flag = cm.PlayerRecord.objects.get_or_create(
|
|
|
player_id=player_id,
|
|
|
match_id=match_id,
|
|
|
stock_date=stock_date)
|
|
|
+
|
|
|
obj.init_fund = init_fund
|
|
|
obj.yesterday_fund = yesterday_fund
|
|
|
obj.yesterday_stock = yesterday_stock
|
|
@@ -737,7 +749,7 @@ def add_model(cls,**kwargs):
|
|
|
raise ce.TipException(u"数据错误,今日净资产不能超过9999万元,不能低于0万元,请仔细核对数据!")
|
|
|
|
|
|
#有资金出入
|
|
|
- if cm.FundInOut.objects.filter(user_id=user_id,stock_date=stock_date).exists():
|
|
|
+ if cm.FundInOut.objects.filter(user_id=user_id,stock_date=stock_date).exists() and flag:
|
|
|
fundinout = cm.FundInOut.objects.filter(user_id=user_id,stock_date=stock_date).first()
|
|
|
fundin = fundinout.fundin
|
|
|
fundout = fundinout.fundout
|
|
@@ -752,16 +764,23 @@ def add_model(cls,**kwargs):
|
|
|
obj.yesterday_fund = obj.yesterday_fund + fundin
|
|
|
#出资金
|
|
|
else:
|
|
|
+ #fundout = fundout - fundin
|
|
|
+ #today_income = (today_fund-(yesterday_fund-fundout))/float(yesterday_fund)
|
|
|
+ #total_income = (today_fund+fundout)/init_fund - 1
|
|
|
+
|
|
|
+ #cm.Player.objects.filter(id=player_id).update(fund=round(today_fund/(1+total_income),4))
|
|
|
+ #obj.init_fund = round(today_fund/(1+total_income),4)
|
|
|
+ #obj.yesterday_fund = obj.yesterday_fund - fundout
|
|
|
fundout = fundout - fundin
|
|
|
today_income = (today_fund-(yesterday_fund-fundout))/float(yesterday_fund)
|
|
|
- total_income = (today_fund+fundout)/init_fund - 1
|
|
|
+ total_income = (today_fund+fundout-init_fund)/init_fund
|
|
|
|
|
|
cm.Player.objects.filter(id=player_id).update(fund=round(today_fund/(1+total_income),4))
|
|
|
obj.init_fund = round(today_fund/(1+total_income),4)
|
|
|
- obj.yesterday_fund = obj.yesterday_fund - fundout
|
|
|
+ obj.yesterday_fund = round(today_fund/(1+today_income),4)
|
|
|
|
|
|
- if float(today_income)>0.4:
|
|
|
- raise ce.TipException(u"今日盈利已超过40%,请仔细核对数据或直接联系顽主!")
|
|
|
+ if float(today_income)>0.6:
|
|
|
+ raise ce.TipException(u"今日盈利已超过60%,请仔细核对数据或直接联系顽主!")
|
|
|
|
|
|
if float(total_income)>8:
|
|
|
raise ce.TipException(u"请仔细核对数据或直接联系顽主!")
|
|
@@ -786,9 +805,9 @@ 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)
|
|
|
+ ##更新股票持股人数
|
|
|
+ #for stock in new_stock_list:
|
|
|
+ # cm.Stock.objects.filter(id=stock["stock_id"]).update(user_num=F("user_num")+1)
|
|
|
|
|
|
#更新group_rank
|
|
|
ccc.cache.lpush(settings.RANK_LIST,obj.id)
|
|
@@ -860,7 +879,8 @@ def get_detail_info(cls,**kwargs):
|
|
|
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()
|
|
|
+ rst["choiced"] = ccc.cache.get("%s_choices" % id)
|
|
|
+ rst["user_num"] = ccc.cache.get("%s_choices" % id)
|
|
|
return rst
|
|
|
|
|
|
#@ccc.cache_data()
|
|
@@ -1073,7 +1093,7 @@ def get_cur_record(request):
|
|
|
def follow_player(**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
- user_id = kwargs.get("player_id")
|
|
|
+ user_id = kwargs.get("user_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()
|
|
@@ -1095,7 +1115,8 @@ def calc_win_rate(player_id,match_id):
|
|
|
def get_user_follower(request):
|
|
|
"""获取用户列表
|
|
|
"""
|
|
|
- user_id = request.player.id
|
|
|
+ user_id = request.user.id
|
|
|
+ player_id = request.player.id
|
|
|
match_id = request.player.match_id
|
|
|
cur_match_id = match_id
|
|
|
match_group = request.player.match_group
|
|
@@ -1103,15 +1124,19 @@ def get_user_follower(request):
|
|
|
qdata = request.json
|
|
|
today = get_today_date()
|
|
|
if qdata.get("player_id"):
|
|
|
- user_id = int(qdata.get("player_id"))
|
|
|
+ player_id = int(qdata.get("player_id"))
|
|
|
|
|
|
data = []
|
|
|
|
|
|
- qset = cm.UserFollows.objects.filter(follow_id=user_id)
|
|
|
+ qset = cm.UserFollows.objects.filter(follow_id=player_id)
|
|
|
follow_ids = list(qset.values_list("user_id",flat=True))
|
|
|
|
|
|
_today = today
|
|
|
for player_id in follow_ids:
|
|
|
+ try:
|
|
|
+ player_id = cm.Player.objects.filter(match_id=match_id,user_id=player_id).first().id
|
|
|
+ except:
|
|
|
+ pass
|
|
|
_match_id = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"match_id")
|
|
|
|
|
|
_today = ccc.cache.hget("PLAYER_LATEST_%d"%player_id,"stock_date")
|
|
@@ -1126,7 +1151,7 @@ def get_user_follower(request):
|
|
|
|
|
|
_today = ccc.cache.hget("PLAYER_LATEST_%d"%user_id,"stock_date")
|
|
|
|
|
|
- cur_today_record = get_today_record(user_id,match_id,match_group,_today)
|
|
|
+ cur_today_record = get_today_record(player_id,match_id,match_group,_today)
|
|
|
if cur_today_record:
|
|
|
data.insert(0,cur_today_record)
|
|
|
|
|
@@ -1166,7 +1191,11 @@ def get_user_follows(request):
|
|
|
qdata = request.json
|
|
|
today = get_today_date()
|
|
|
if qdata.get("player_id"):
|
|
|
- user_id = int(qdata.get("player_id"))
|
|
|
+ player_id = int(qdata.get("player_id"))
|
|
|
+ try:
|
|
|
+ user_id = cm.Player.objects.filter(id=player_id).first().user_id
|
|
|
+ except:
|
|
|
+ pass
|
|
|
|
|
|
data = []
|
|
|
|
|
@@ -1259,8 +1288,12 @@ def get_hot_stock_buy(**kwargs):
|
|
|
stock_id = q["stock_id"]
|
|
|
count = q["count"]
|
|
|
stock_name = q.get("stock_name")
|
|
|
- comments_count = cm.Comments.objects.filter(stock_id=stock_id).count()
|
|
|
- choice_count = cm.UserChoice.objects.filter(stock_id=stock_id).count()
|
|
|
+
|
|
|
+ comments_count = ccc.cache.get("%s_comments" % stock_id)
|
|
|
+ choice_count = ccc.cache.get("%s_choices" % stock_id)
|
|
|
+ comments_count = comments_count if comments_count else 0
|
|
|
+ choice_count = choice_count if choice_count else 0
|
|
|
+
|
|
|
data.append({"stock_name":stock_name,"id":stock_id,"count":count,"comments_count":comments_count,"choice_count":choice_count})
|
|
|
|
|
|
|
|
@@ -1312,7 +1345,7 @@ def get_hot_follow(**kwargs):
|
|
|
"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),
|
|
|
+ "badest_income":"{}%".format(badest_income*100) if badest_income else "0.0%",
|
|
|
"style":userinfo.get("style"),
|
|
|
"badge":userinfo.get("badge"),
|
|
|
"match_id":match_id,
|
|
@@ -1500,9 +1533,10 @@ def get_champion_articles_list(request):
|
|
|
page_size = int(kwargs.get("page_size",20))
|
|
|
|
|
|
if page and page_size:
|
|
|
- total,qset = ccf.get_page_qset(qset,page,page_size)
|
|
|
+ total,qset = ccc.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")
|
|
@@ -1736,6 +1770,12 @@ def get_player_match_calendar(**kwargs):
|
|
|
player_id = kwargs.get("player_id")
|
|
|
match_id = kwargs.get("match_id")
|
|
|
month = kwargs.get("month")
|
|
|
+ user_id = kwargs.get("user_id")
|
|
|
+
|
|
|
+ try:
|
|
|
+ player_id = cm.Player.objects.filter(match_id=match_id,user_id=user_id).first().id
|
|
|
+ except:
|
|
|
+ pass
|
|
|
|
|
|
print kwargs
|
|
|
|
|
@@ -1825,6 +1865,7 @@ def get_mine_latest(request):
|
|
|
print(e)
|
|
|
return {"player_id":player_id,"match_id":match_id}
|
|
|
|
|
|
+@ccc.cache_data()
|
|
|
def get_match_validdates(match_id):
|
|
|
"""
|
|
|
"""
|
|
@@ -2076,21 +2117,29 @@ def get_user_comments(request):
|
|
|
def get_user_choices(request):
|
|
|
"""
|
|
|
"""
|
|
|
+ user_id = request.user.id
|
|
|
player_id = request.player.id
|
|
|
+ match_id = request.player.match_id
|
|
|
kwargs = request.json
|
|
|
stock_id = kwargs.get("stock_id")
|
|
|
- qset = cm.UserChoice.objects.filter(player_id=player_id)
|
|
|
+ if stock_id:
|
|
|
+ qset = cm.UserChoice.objects.filter(stock_id=stock_id)
|
|
|
+ else:
|
|
|
+ qset = cm.UserChoice.objects.filter(user_id=user_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()
|
|
|
+
|
|
|
+ comments_count = ccc.cache.get("%s_comments" % stock_id)
|
|
|
+ choice_count = ccc.cache.get("%s_choices" % stock_id)
|
|
|
+ comments_count = comments_count if comments_count else 0
|
|
|
+ choice_count = choice_count if choice_count else 0
|
|
|
+
|
|
|
+ item["count"] = choice_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
|
|
|
|
|
|
#分页
|
|
@@ -2116,7 +2165,7 @@ def get_user_consult_list(request):
|
|
|
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.extend(cm.WanzhuConsult.objects.filter(Q(pid=item["id"])|Q(reply_user_id=player_id)).values())
|
|
|
|
|
|
data = sorted(data,key=lambda x:x["id"])
|
|
|
#分页
|
|
@@ -2155,6 +2204,7 @@ def add_wanzhu_consult(request):
|
|
|
user_id = request.user.id
|
|
|
user_name = request.user.username
|
|
|
user_avatar = request.user.avatar
|
|
|
+ openid = request.user.openid
|
|
|
qdata = request.json
|
|
|
content = qdata.get("cotent")
|
|
|
pid = qdata.get("pid")
|
|
@@ -2174,7 +2224,22 @@ def add_wanzhu_consult(request):
|
|
|
obj.content = content
|
|
|
obj.view_status = 0
|
|
|
obj.reply_status = 0
|
|
|
+ obj.ctime = datetime.datetime.now()
|
|
|
obj.save()
|
|
|
+ #自动回复
|
|
|
+ if cm.WanzhuConsult.objects.filter(user_id=user_id).count() <=1:
|
|
|
+ content = u"您好,后台消息一般三小时内回复,如果超出时间请加微信destination8888"
|
|
|
+ cm.WanzhuConsult.objects.create(
|
|
|
+ pid = pid,
|
|
|
+ reply_content = content,
|
|
|
+ user_id = 0,
|
|
|
+ player_id = 0,
|
|
|
+ reply_user_id = user_id
|
|
|
+ )
|
|
|
+ #发送消息提醒
|
|
|
+ if cm.UserInfo.objects.filter(id=user_id).exists():
|
|
|
+ user = cm.UserInfo.objects.filter(id=user_id).first()
|
|
|
+ send_consult_reply_message(openid,user_name)
|
|
|
|
|
|
|
|
|
|
|
@@ -2209,6 +2274,8 @@ def add_comments(request):
|
|
|
stock_id = stock_id
|
|
|
)
|
|
|
cm.PlayerRecord.objects.filter(id=record_id).update(comments_count=F("comments_count")+1)
|
|
|
+ if stock_id:
|
|
|
+ ccc.cache.incr("%s_comments" % stock_id,1)
|
|
|
|
|
|
|
|
|
def add_choice(request):
|
|
@@ -2230,6 +2297,8 @@ def add_choice(request):
|
|
|
stock_id = stock_id,
|
|
|
stock_name = stock_name
|
|
|
)
|
|
|
+ if stock_id:
|
|
|
+ ccc.cache.incr("%s_choices" % stock_id,1)
|
|
|
|
|
|
|
|
|
def add_zan(request):
|
|
@@ -2247,34 +2316,27 @@ def get_experience_list(request):
|
|
|
#return 0,[]
|
|
|
kwargs = request.json
|
|
|
today = get_today_date()
|
|
|
- print(today,22222222222)
|
|
|
match_id = ccc.get_cur_match().id
|
|
|
#冠军组、千万组、百万组
|
|
|
qbw_ids = list(cm.MatchGroup.objects.filter(match_id=match_id).filter(Q(name__icontains=u"千万组")|Q(name__icontains=u"百万组")|Q(name__icontains=u"冠军组")).values_list("id",flat=True))
|
|
|
|
|
|
- qset = cm.PlayerRecord.objects.filter(match_id=match_id,stock_date=today,match_group__in=qbw_ids).filter(Q(experience__isnull=False)&~Q(experience="")).order_by("-total_income")[:100]
|
|
|
+ qset = cm.PlayerRecord.objects.filter(match_id=match_id,stock_date=today,match_group__in=qbw_ids).filter(Q(experience__isnull=False)&~Q(experience="")).order_by("-total_income")
|
|
|
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"))
|
|
|
|
|
|
- qset1 = cm.PlayerRecord.objects.filter(match_id=match_id,stock_date=today).exclude(match_group__in=qbw_ids).filter(Q(experience__isnull=False)&~Q(experience="")).order_by("-total_income")[:100]
|
|
|
- data1 = list(qset1.values("id","user_id","username","today_fund","today_income","total_income","experience","match_id","player_id","today_stock_img","zans","comments_count"))
|
|
|
+ #qset1 = cm.PlayerRecord.objects.filter(match_id=match_id,stock_date=today).exclude(match_group__in=qbw_ids).filter(Q(experience__isnull=False)&~Q(experience="")).order_by("-total_income")
|
|
|
+ #data1 = list(qset1.values("id","user_id","username","today_fund","today_income","total_income","experience","match_id","player_id","today_stock_img","zans","comments_count"))
|
|
|
|
|
|
- data.extend(data1)
|
|
|
+ #data.extend(data1)
|
|
|
|
|
|
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)+"%"
|
|
@@ -2285,7 +2347,6 @@ def get_experience_list(request):
|
|
|
|
|
|
#分页
|
|
|
page = int(kwargs.get("page",1))
|
|
|
- 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)
|
|
@@ -2307,12 +2368,19 @@ def delete_choice(request):
|
|
|
|
|
|
cm.UserChoice.objects.filter(stock_id=stock_id,player_id=player_id).delete()
|
|
|
|
|
|
+ if ccc.cache.get("%s_choices" % stock_id) and int(ccc.cache.get("%s_choices" % stock_id)) >= 1:
|
|
|
+ ccc.cache.decr("%s_choices" % stock_id)
|
|
|
+
|
|
|
|
|
|
def delete_comments(request):
|
|
|
"""
|
|
|
"""
|
|
|
qdata = request.json
|
|
|
id = qdata.get("id")
|
|
|
+ if cm.Comments.objects.filter(id=id,stock_id__isnull=False).exists():
|
|
|
+ stock_id = cm.Comments.objects.filter(id=id).first().stock_id
|
|
|
+ if ccc.cache.get("%s_comments" % stock_id) and int(ccc.cache.get("%s_comments" % stock_id)) >= 1:
|
|
|
+ ccc.cache.decr("%s_comments" % stock_id)
|
|
|
cm.Comments.objects.filter(id=id).delete()
|
|
|
|
|
|
|
|
@@ -2331,6 +2399,55 @@ def modify_user_fund(request):
|
|
|
fundout = float(fundout) if fundout else 0.0
|
|
|
account_img = qdata.get("account_img")
|
|
|
init_fund = player.fund
|
|
|
+ trycalc = qdata.get("trycalc")
|
|
|
+ today_fund = qdata.get("today_fund")
|
|
|
+ today_fund = float(today_fund) if today_fund else 0.0
|
|
|
+
|
|
|
+ if trycalc:
|
|
|
+ stock_date = get_today_date()
|
|
|
+ validdates = get_match_validdates(match_id)
|
|
|
+ today_index = validdates.index(stock_date)
|
|
|
+ yesterday_index = today_index -1 if today_index >=1 else 0
|
|
|
+ yesterday_date = validdates[yesterday_index]
|
|
|
+
|
|
|
+ yesterday = cm.PlayerRecord.objects.filter(
|
|
|
+ match_id=match_id,player_id=player_id,stock_date=yesterday_date).exclude(stock_date=stock_date).first()
|
|
|
+ if yesterday:
|
|
|
+ yesterday_fund = yesterday.today_fund
|
|
|
+ yesterday_stock = yesterday.today_stock
|
|
|
+ yesterday_stock_img = yesterday.today_stock_img
|
|
|
+ yesterday_is_markt = yesterday.is_markt
|
|
|
+ else:
|
|
|
+ yesterday_fund = today_fund
|
|
|
+ yesterday_stock = ""
|
|
|
+ yesterday_stock_img = ""
|
|
|
+ yesterday_is_markt = 0
|
|
|
+
|
|
|
+ #入资金
|
|
|
+ if fundin > fundout:
|
|
|
+ fundin = fundin - fundout
|
|
|
+ today_income = round((today_fund-(yesterday_fund+fundin))/(float(yesterday_fund) + fundin),4)
|
|
|
+ total_income = round((today_fund-init_fund-fundin)/(init_fund+fundin),4)
|
|
|
+
|
|
|
+ init_fund = init_fund + fundin
|
|
|
+ yesterday_fund = yesterday_fund + fundin
|
|
|
+ #出资金
|
|
|
+ else:
|
|
|
+ fundout = fundout - fundin
|
|
|
+ today_income = round((today_fund-(yesterday_fund-fundout))/float(yesterday_fund),4)
|
|
|
+ total_income = round((today_fund+fundout-init_fund)/init_fund,4)
|
|
|
+
|
|
|
+ init_fund = round(today_fund/(1+total_income),4)
|
|
|
+ yesterday_fund = round(today_fund/(1+today_income),4)
|
|
|
+
|
|
|
+ today_income = "{}%".format(today_income*100)
|
|
|
+ total_income = "{}%".format(total_income*100)
|
|
|
+
|
|
|
+ return {"yesterday_fund":yesterday_fund,
|
|
|
+ "today_fund":today_fund,
|
|
|
+ "today_income":today_income,
|
|
|
+ "total_income":total_income,
|
|
|
+ "init_fund":init_fund}
|
|
|
|
|
|
stock_date = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
|
|
@@ -2348,62 +2465,6 @@ def modify_user_fund(request):
|
|
|
account_img = account_img
|
|
|
)
|
|
|
|
|
|
- ##资金出入后修改数据
|
|
|
- #if cm.PlayerRecord.objects.filter(user_id=user_id,stock_date=stock_date).exists():
|
|
|
-
|
|
|
- # record = cm.PlayerRecord.objects.filter(user_id=user_id,stock_date=stock_date).first()
|
|
|
- # today_fund = record.today_fund
|
|
|
-
|
|
|
- # yesterday = cm.PlayerRecord.objects.filter(
|
|
|
- # match_id=match_id,player_id=player_id,stock_date=yesterday_date).exclude(stock_date=stock_date).first()
|
|
|
- # if yesterday:
|
|
|
- # yesterday_fund = yesterday.today_fund
|
|
|
- # yesterday_stock = yesterday.today_stock
|
|
|
- # yesterday_stock_img = yesterday.today_stock_img
|
|
|
- # yesterday_is_markt = yesterday.is_markt
|
|
|
- # else:
|
|
|
- # #yesterday_fund = init_fund #today_fund
|
|
|
- # yesterday_fund = record.today_fund
|
|
|
- # yesterday_stock = ""
|
|
|
- # yesterday_stock_img = ""
|
|
|
- # yesterday_is_markt = 0
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- # fundin = fundinout.fundin
|
|
|
- # fundout = fundinout.fundout
|
|
|
- # #入资金
|
|
|
- # if fundin > fundout:
|
|
|
- # fundin = fundin - fundout
|
|
|
- # today_income = (today_fund-(yesterday_fund+fundin))/float(yesterday_fund) + fundin
|
|
|
- # total_income = (today_fund-init_fund-fundin)/(init_fund+fundin)
|
|
|
-
|
|
|
- # cm.Player.objects.filter(id=player_id).update(fund=init_fund+fundin)
|
|
|
- #
|
|
|
- # record.init_fund = init_fund + fundin
|
|
|
- # #出资金
|
|
|
- # else:
|
|
|
- # fundout = fundout - fundin
|
|
|
- # today_income = (today_fund-(yesterday_fund-fundout))/float(yesterday_fund)
|
|
|
- # total_income = (today_fund+fundout)/init_fund
|
|
|
-
|
|
|
- # cm.Player.objects.filter(id=player_id).update(fund=init_fund/(1+total_income))
|
|
|
-
|
|
|
- # record.init_fund = init_fund/(1+today_income)
|
|
|
-
|
|
|
- # if float(today_income)>0.4:
|
|
|
- # raise ce.TipException(u"今日盈利已超过40%,请仔细核对数据或直接联系顽主!")
|
|
|
-
|
|
|
- # if float(total_income)>8:
|
|
|
- # raise ce.TipException(u"请仔细核对数据或直接联系顽主!")
|
|
|
-
|
|
|
- # record.today_income = round(today_income,4)
|
|
|
- # record.total_income = round(total_income,4)
|
|
|
- # record.save()
|
|
|
-
|
|
|
- # #更新group_rank
|
|
|
- # ccc.cache.lpush(settings.RANK_LIST,record.id)
|
|
|
- # return fundinout.id
|
|
|
|
|
|
|
|
|
|