xjc преди 2 години
родител
ревизия
e36d6633e1
променени са 9 файла, в които са добавени 366 реда и са изтрити 266 реда
  1. 3 1
      src/common/models.py
  2. 80 86
      src/manage/controls.py
  3. 2 1
      src/settings/settings_online.py
  4. 33 0
      src/tools/del_repeat.py
  5. 45 53
      src/tools/rank_server.py
  6. 18 1
      src/tools/update_records.py
  7. 183 122
      src/weixin/controls.py
  8. 1 1
      src/weixin/views.py
  9. 1 1
      templates/index.html

+ 3 - 1
src/common/models.py

@@ -173,7 +173,9 @@ class Stock(models.Model):
     code = models.CharField(u"代码", max_length=255, blank=True,null=True)
     img = models.TextField(u"封面图",blank=True,null=True)                       
     desc = models.TextField(u"内容",blank=True,null=True)                       
-    user_num = models.IntegerField(u"排序字段",blank=False,null=False,default=0)
+    user_num = models.IntegerField(u"持股人数",blank=False,null=False,default=0)
+    comments_num = models.IntegerField(u"留言条数",blank=False,null=False,default=0)
+    choice_num = models.IntegerField(u"自选人数",blank=False,null=False,default=0)
 
     ctime = models.DateTimeField(u"创建时间", auto_now_add=True)
 

+ 80 - 86
src/manage/controls.py

@@ -46,41 +46,17 @@ def get_user_info(uid):
             user["style"].append(user["df"])
     return user
 
+@ccc.cache_data()
+def get_match_info(match_id):
+    match = cm.Match.objects.filter(id=match_id).values().first()
+    return match
+
 def async(f):
     def wrapper(*args, **kwargs):
         thr = Thread(target=f, args=args, kwargs=kwargs)
         thr.start()
     return wrapper
 
-def update_group_rank_day(match_id,match_group,stock_date):
-    #return
-    #ccc.cache.delete("*_"+stock_date)
-    prset = cm.PlayerRecord.objects.filter(match_id=match_id,match_group=match_group,stock_date=stock_date).order_by("-total_income")
-    records = prset.values()
-    case_id = " case id "
-    cases = []
-    where = []
-    #
-    delkey = "*_%s_%s_%s" % (match_id,match_group,stock_date)
-    del_keys = ccc.cache.keys(delkey)
-    #ccc.cache.delete(*del_keys)
-    for index,pr in enumerate(prset):
-        case = "WHEN %s THEN %s" % (pr.id,index+1)
-        cases.append(case)
-        where.append(str(pr.id))
-        #
-        record = records[index]
-        record.update({"group_rank":index+1})
-        key = "%s_%s_%s_%s" % (pr.player_id,match_id,match_group,stock_date)
-        ccc.pl.set(key,json.dumps(record,cls=ccc.CusJSONEncoder))
-    ccc.pl.execute()
-
-    case = case_id + " ".join(cases)
-    where = ",".join(where)
-    sql = "update player_record set group_rank = %s ELSE 0 END where id in (%s)" % (case,where)
-    cursor = connection.cursor()
-    cursor.execute(sql)
-    cursor.close()
 
 def add_model(cls,**kwargs):
     """
@@ -119,6 +95,7 @@ def add_model(cls,**kwargs):
         kwargs["usercode"] = usercode
 
     if model_name == "PlayerRecord":
+        #return None
         match_id = kwargs.get("match_id")
         stock_date = kwargs.get("stock_date")
         today_stock = json.dumps(kwargs.get("today_stock"))
@@ -181,7 +158,6 @@ def add_model(cls,**kwargs):
         obj.save()
 
         #更新group_rank
-        update_group_rank_day(match_id,match_group,obj.stock_date)
 
         return obj.id
 
@@ -217,13 +193,17 @@ def update_model(cls,**kwargs):
     if model_name == "Player":
         user_id = kwargs.get("user_id")
         match_id = kwargs.get("match_id")
+        match_group = kwargs.get("match_group")
         if cm.Player.objects.exclude(id=id).filter(user_id=user_id,match_id=match_id).exists():
             raise ce.TipException(u"重复添加选手!")
         user =cm.UserInfo.objects.filter(id=user_id).first()
         username = user.username if user else ""
         usercode = user.usercode if user else ""
-        #kwargs["username"] = username
-        #kwargs["usercode"] = usercode
+        try:
+            match_group_name = cm.MatchGroup.objects.filter(id=match_group).first().name
+        except Exception as e:
+            match_group_name = ""
+        kwargs["match_group_name"] = match_group_name
 
     if model_name == "PlayerRecord":
         is_markt = int(kwargs.get("is_markt",0))
@@ -254,7 +234,8 @@ def update_model(cls,**kwargs):
         cm.Player.objects.filter(id=player_id).update(fund=init_fund)
 
         ##更新group_rank
-        #update_group_rank_day(obj.match_id,obj.match_group,obj.stock_date)
+        update_group_rank(obj.stock_date,obj.match_group,obj.match_id)
+
     if model_name == "UserInfo":
         ccc.del_cache("cdata_get_user_info_(%s,)"%id)
 
@@ -283,8 +264,10 @@ def delete_model(cls,**kwargs):
         if model_name == "MatchGroup":
             cm.PlayerRecord.objects.filter(match_group__in=ids).delete()
             cm.Player.objects.filter(match_group__in=ids).delete()
-    #更新group_rank
-    update_group_rank()
+        if model_name == "PlayerRecord":
+            obj = cm.PlayerRecord.objects.filter(id__in=ids).first()
+            ##更新group_rank
+            update_group_rank(obj.stock_date,obj.match_group,obj.match_id)
     return ids
 
 
@@ -295,11 +278,13 @@ def get_search_list(cls,**kwargs):
     model = getattr(cm,model_name)
     qset = model.objects.all().order_by("-id")
     if model_name == "Player":
-        data = list(qset.values("id","user_id","username"))
+        data = list(qset.values("id","user_id","username","usercode"))
         for item in data:
-            user = cm.UserInfo.objects.filter(id=item["user_id"]).first()
-            item["username"] = user.username
-            item["usercode"] = user.usercode
+            #user = cm.UserInfo.objects.filter(id=item["user_id"]).first()
+            #if user:
+            #    item["username"] = user.username
+            #    item["usercode"] = user.usercode
+            #    item["label"] = "%s(%s)" % (item["username"],item["usercode"])
             item["label"] = "%s(%s)" % (item["username"],item["usercode"])
     elif model_name == "Stock":
         data = list(qset.values("id","name","code"))
@@ -324,11 +309,12 @@ def get_detail_info(cls,**kwargs):
     rst = list(model.objects.filter(id=id).values())
     rst = rst[0] if rst else {}
     if model_name == "Player":
-        user = cm.UserInfo.objects.filter(id=rst["user_id"]).first()
-        match = cm.Match.objects.filter(id=rst["match_id"]).first()
-        rst["username"] = user.username
-        rst["usercode"] = user.usercode
-        rst["match_name"] = match.name if match else ""
+        user = get_user_info(rst["user_id"])
+        match = get_match_info(rst["match_id"])
+
+        rst["username"] = user["username"]
+        rst["usercode"] = user["usercode"]
+        rst["match_name"] = match["name"] if match else ""
         rst["match_group"] = int(rst["match_group"]) if rst["match_group"] else 0
     if model_name == "PlayerRecord":
         rst["today_stock"] = json.loads(rst["today_stock"]) if rst["today_stock"] else []
@@ -420,21 +406,19 @@ def get_list_info(cls,**kwargs):
         total,data = ccf.get_page_list(data,page,page_size)
         if model_name == "Player":
             for item in data:
-                user = cm.UserInfo.objects.filter(id=item["user_id"]).first()
+                user = get_user_info(item["user_id"])
                 if user:
-                    match = cm.Match.objects.filter(id=item["match_id"]).first()
-                    #item["username"] = user.username
-                    #item["usercode"] = user.usercode
-                    item["nickname"] = user.nickname
-                    item["match_name"] = match.name if match else ""
-                    item["openid"] = user.openid
-                    item["player_type"] = user.player_type
-                    item["phone"] = user.phone
-                    try:
-                        item["match_group"] = int(item["match_group"])
-                        item["match_group_name"] = cm.MatchGroup.objects.filter(id=int(item["match_group"])).first().name
-                    except:
-                        pass
+                    match = get_match_info(item["match_id"])
+                    item["nickname"] = user["nickname"]
+                    item["match_name"] = match["name"] if match else ""
+                    item["openid"] = user["openid"]
+                    item["player_type"] = user["player_type"]
+                    item["phone"] = user["phone"]
+                    #try:
+                    #    item["match_group"] = int(item["match_group"])
+                    #    item["match_group_name"] = cm.MatchGroup.objects.filter(id=int(item["match_group"])).first().name
+                    #except:
+                    #    pass
                 #cm.Player.objects.filter(id=item["id"]).update(username=user.username,usercode=user.usercode)
         if model_name == "PlayerRecord":
             for item in data:
@@ -495,9 +479,14 @@ def get_list_info(cls,**kwargs):
                 user = cm.UserInfo.objects.filter(id=item["user_id"]).first()
 
                 item["username"] = user.username
+                item["usercode"] = user.usercode
 
             if kwargs.get("username"):
-                data = filter(lambda x:kwargs.get("username") in x["username"],data)
+                print(111111111111111111)
+                print(data)
+                print(kwargs.get("username"))
+                data = filter(lambda x:x["username"] == str(kwargs.get("username")) or kwargs.get("username") ==x["usercode"],data)
+                print(data,22222222222222)
 
         return (total,data)
     else:
@@ -601,64 +590,59 @@ def fast_save_player(**kwargs):
 def update_player_latest(record):
     """更新选手最后一次数据
     """
-    player_id=record["player_id"]
+    player_id = record["player_id"]
     match_id = record["match_id"]
+    stock_date = record["stock_date"]
+    match_group = record["match_group"]
 
-    latest = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date").first()
-    if latest:
+    if record:
         key = "PLAYER_LATEST_{}".format(player_id)
-        ccc.cache.hset(key,"stock_date",latest.stock_date)
-        ccc.cache.hset(key,"match_id",latest.match_id)
-        ccc.cache.hset(key,"match_group",latest.match_group)
+        ccc.cache.hset(key,"stock_date",stock_date)
+        ccc.cache.hset(key,"match_id",match_id)
+        ccc.cache.hset(key,"match_group",match_group)
         #更新胜率
-        qset = cm.PlayerRecord.objects.filter(match_id=latest.match_id,player_id=latest.player_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)
         ccc.cache.hset(key,"win_rate",win_rate)
-    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=player_id,match_id=match_id).order_by("today_income").first()
     if badest:
         key = "PLAYER_LATEST_{}".format(player_id)
-        ccc.cache.hset(key,"badest_income",latest.today_income)
+        ccc.cache.hset(key,"badest_income",badest.today_income)
 
 
 def update_group_rank(stock_date=None,match_id=None,group_id=None):
     """
     """
-    #ccc.cache.delete("cdata_*")
     if stock_date:
         stock_date = stock_date
     else:
         stock_date = datetime.datetime.now().strftime("%Y-%m-%d")
-    #ccc.cache.delete("*_"+stock_date)
-    #groups = cm.MatchGroup.objects.filter(match_id=match_id)
+
     groups = cm.MatchGroup.objects.filter(id=group_id)
     for gp in groups:
         match_id = gp.match_id
         match_group = gp.id
         delkey = "*_%s_%s_%s" % (match_id,match_group,stock_date)
-        del_keys = ccc.cache.keys(delkey)
+        #del_keys = ccc.cache.keys(delkey)
         #if del_keys:
-        #    ccc.cache.delete(*del_keys)
-        if del_keys:
-            for key in del_keys:
-                ccc.cache.delete(key)
+        #    for key in del_keys:
+        #        ccc.cache.delete(key)
         prset = cm.PlayerRecord.objects.filter(match_id=match_id,match_group=match_group,stock_date=stock_date).order_by("-total_income")
         if prset:
             records = prset.values()
             case_id = " case id "
             cases = []
             where = []
-            for index,pr in enumerate(prset):
-                case = "WHEN %s THEN %s" % (pr.id,index+1)
+            for index,pr in enumerate(records):
+                case = "WHEN %s THEN %s" % (pr["id"],index+1)
                 cases.append(case)
-                where.append(str(pr.id))
+                where.append(str(pr["id"]))
                 #
-                key = "%s_%s_%s_%s" % (pr.player_id,match_id,match_group,stock_date)
-                record = records[index]
-                record.update({"group_rank":index+1})
-                ccc.pl.set(key,json.dumps(record,cls=ccc.CusJSONEncoder))
-                #更新最后一次数据
-                update_player_latest(record)
+                key = "%s_%s_%s_%s" % (pr["player_id"],match_id,match_group,stock_date)
+                pr.update({"group_rank":index+1})
+                ccc.pl.set(key,json.dumps(pr,cls=ccc.CusJSONEncoder))
             ccc.pl.execute()
             if cases and where:
                 case = case_id + " ".join(cases)
@@ -668,6 +652,9 @@ def update_group_rank(stock_date=None,match_id=None,group_id=None):
                 cursor.execute(sql)
                 cursor.close()
 
+            #更新最后一次数据
+            update_player_latest(pr)
+
 
 def update_comment(**kwargs):
     """
@@ -730,7 +717,14 @@ def get_wanzhu_consult_list(**kwargs):
         qset = qset.filter(user_name__icontains=kwargs.get("username"))
     if kwargs.get("reply_status"):
         qset = qset.filter(reply_status=kwargs.get("reply_status"))
+    if kwargs.get("content"):
+        qset = qset.filter(Q(content__icontains=kwargs.get("content"))|Q(reply_content__icontains=kwargs.get("content")))
     data = list(qset.values())
+    for item in data:
+        user_id = item["user_id"]
+        userinfo = get_user_info(user_id)
+        if userinfo:
+            item["user_code"] = userinfo.get("usercode")
 
     #分页
     page = int(kwargs.get("page",1))
@@ -767,7 +761,7 @@ def reply_wanzhu_consult(**kwargs):
         player_id = 0,
         reply_user_id = user_id
     )
-    cm.Consult.objects.filter(user_id=user_id).update(reply_status=1,reply_content=content)
+    cm.Consult.objects.filter(user_id=user_id).update(reply_status=1,reply_content=content,ctime=datetime.datetime.now())
     #发送消息提醒
     if cm.UserInfo.objects.filter(id=user_id).exists():
         user = cm.UserInfo.objects.filter(id=user_id).first()

+ 2 - 1
src/settings/settings_online.py

@@ -30,7 +30,8 @@ DATABASES = {
         'PASSWORD': 'wanzb890*()',
         'HOST': '172.29.110.52',
         'PORT': '3306',
-        'OPTIONS':{'charset':'utf8mb4'}
+        'OPTIONS':{'charset':'utf8mb4'},
+        'CONN_MAX_AGE': 9
     }
 }
 

+ 33 - 0
src/tools/del_repeat.py

@@ -0,0 +1,33 @@
+#coding:utf-8
+import os
+import time
+import datetime
+import sys
+import django
+from django.core.cache import cache
+from django.db import connection
+
+sys.path.append('/mnt/wzbapi/src')
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+django.setup()
+
+import common.models as cm
+import common.common_control as ccc
+
+def del_repeat():
+    """
+    """
+    stock_date = "2022-07-06"
+    qset = cm.PlayerRecord.objects.filter(stock_date=stock_date).order_by("-id")
+    dct = {}
+    for obj in qset:
+        user_id = obj.user_id
+        if not dct.get(user_id):
+            dct[user_id] = 1
+        else:
+            print(user_id)
+            dct[user_id] += 1
+            cm.PlayerRecord.objects.filter(id=obj.id).delete()
+
+if __name__ == "__main__":
+    del_repeat()

+ 45 - 53
src/tools/rank_server.py

@@ -19,24 +19,26 @@ def rank_server():
     """
     """
     rcid = ccc.cache.rpop(settings.RANK_LIST)
-    #rcid = 117904
-    print rcid,99999999999999999
-    record = cm.PlayerRecord.objects.filter(id=rcid).first()
-    if record:
-        match_id = int(record.match_id)
-        match_group = int(record.match_group)
-        stock_date = record.stock_date
-        print match_id,match_group,stock_date
-        if "15:00"<datetime.datetime.now().strftime("%H:%M") < "15:30":
-            update_cache_rank(match_id,match_group,stock_date)
-        else:
-            update_cache_rank(match_id,match_group,stock_date)
-            sync_group_rank(match_id,match_group,stock_date)
-            #update_hot_seller(record)
-        #更新胜率榜
-        update_win_defend_rank(record)
-        #更新最值
-        update_player_latest(record)
+    if rcid:
+        django.db.close_old_connections()
+        record = cm.PlayerRecord.objects.filter(id=rcid).first()
+        if record:
+            match_id = int(record.match_id)
+            match_group = int(record.match_group)
+            stock_date = record.stock_date
+            username = record.username
+            usercode = record.usercode
+            player_id = record.player_id
+            print(player_id,match_id,match_group,usercode,stock_date)
+            if "15:00"<datetime.datetime.now().strftime("%H:%M") < "15:30":
+                update_cache_rank(match_id,match_group,stock_date)
+            else:
+                st = time.time()
+                sync_group_rank(match_id,match_group,stock_date)
+            #更新胜率榜
+            update_win_defend_rank(record)
+            #更新最值
+            update_player_latest(record)
 
 def update_win_defend_rank(record):
     """更新胜率防守榜
@@ -89,21 +91,12 @@ def update_cache_rank(match_id,match_group,stock_date):
     print "update cache rank..."
     delkey = "*_%s_%s_%s" % (match_id,match_group,stock_date)
     del_keys = ccc.cache.keys(delkey)
-    #if del_keys:
-    #    ccc.cache.delete(*del_keys)
-
     prset = cm.PlayerRecord.objects.filter(match_id=match_id,match_group=match_group,stock_date=stock_date).order_by("-total_income")
     records = prset.values()
-    case_id = " case id "
-    cases = []
-    where = []
-    for index,pr in enumerate(prset):
-        key = "%s_%s_%s_%s" % (pr.player_id,match_id,match_group,stock_date)
-        print(key)
-        record = records[index]
-        record.update({"group_rank":index+1})
-        #ccc.cache.delete(key)
-        ccc.pl.set(key,json.dumps(record,cls=ccc.CusJSONEncoder))
+    for index,pr in enumerate(records):
+        key = "%s_%s_%s_%s" % (pr["player_id"],match_id,match_group,stock_date)
+        pr.update({"group_rank":index+1})
+        ccc.pl.set(key,json.dumps(pr,cls=ccc.CusJSONEncoder))
     ccc.pl.execute()
 
 def sync_group_rank(match_id,match_group,stock_date):
@@ -112,24 +105,20 @@ def sync_group_rank(match_id,match_group,stock_date):
     print "sync group rank..."
     delkey = "*_%s_%s_%s" % (match_id,match_group,stock_date)
     del_keys = ccc.cache.keys(delkey)
-    #if del_keys:
-    #    ccc.cache.delete(*del_keys)
 
     prset = cm.PlayerRecord.objects.filter(match_id=match_id,match_group=match_group,stock_date=stock_date).order_by("-total_income")
     records = prset.values()
     case_id = " case id "
     cases = []
     where = []
-    for index,pr in enumerate(prset):
-        case = "WHEN %s THEN %s" % (pr.id,index+1)
+    for index,pr in enumerate(records):
+        case = "WHEN %s THEN %s" % (pr["id"],index+1)
         cases.append(case)
-        where.append(str(pr.id))
+        where.append(str(pr["id"]))
         #
-        key = "%s_%s_%s_%s" % (pr.player_id,match_id,match_group,stock_date)
-        record = records[index]
-        record.update({"group_rank":index+1})
-        #ccc.cache.delete(key)
-        ccc.pl.set(key,json.dumps(record,cls=ccc.CusJSONEncoder))
+        key = "%s_%s_%s_%s" % (pr["player_id"],match_id,match_group,stock_date)
+        pr.update({"group_rank":index+1})
+        ccc.pl.set(key,json.dumps(pr,cls=ccc.CusJSONEncoder))
     ccc.pl.execute()
     #同步数据库
     if cases and where:
@@ -177,30 +166,33 @@ def update_hot_seller(record):
 def update_player_latest(record):
     """更新选手最后一次数据
     """
-    player_id=record.player_id
+    player_id = record.player_id
     match_id = record.match_id
+    stock_date = record.stock_date
+    match_group = record.match_group
 
-    latest = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date").first()
-    if latest:
+    if record:
         key = "PLAYER_LATEST_{}".format(player_id)
-        ccc.cache.hset(key,"stock_date",latest.stock_date)
-        ccc.cache.hset(key,"match_id",latest.match_id)
-        ccc.cache.hset(key,"match_group",latest.match_group)
+        ccc.cache.hset(key,"stock_date",stock_date)
+        ccc.cache.hset(key,"match_id",match_id)
+        ccc.cache.hset(key,"match_group",match_group)
         #更新胜率
-        qset = cm.PlayerRecord.objects.filter(match_id=latest.match_id,player_id=latest.player_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)
         ccc.cache.hset(key,"win_rate",win_rate)
-    badest = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-today_income").first()
-    if badest:
-        key = "PLAYER_LATEST_{}".format(player_id)
-        ccc.cache.hset(key,"badest_income",latest.today_income)
+
+        #badest = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("today_income").first()
+        #if badest:
+        #    key = "PLAYER_LATEST_{}".format(player_id)
+        #    ccc.cache.hset(key,"badest_income",badest.today_income)
+        print("rank done!")
 
 if __name__ == "__main__":
     print "start update group rank..."
     while True:
         rank_server()
-        time.sleep(1)
+        time.sleep(0.1)
 
 
 

+ 18 - 1
src/tools/update_records.py

@@ -12,6 +12,8 @@ os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
 django.setup()
 
 import common.models as cm
+import common.common_control as ccc
+import common.common_functions as ccf
 
 def update_records():
     """
@@ -39,12 +41,27 @@ def update_records():
 
             pr.save()
 
+def get_all_stock_comments():
+    """
+    """
+    qset = cm.Comments.objects.filter(stock_id__isnull=False)
+    for obj in qset:
+        stock_id = obj.stock_id
+        ccc.cache.incr("%s_comments" % stock_id,1)
+
+def get_all_choices():
+    qset = cm.UserChoice.objects.all()
+    for obj in qset:
+        stock_id = obj.stock_id
+        ccc.cache.incr("%s_choices" % stock_id,1)
+
 
 
 if __name__ == "__main__":
     print "start update group rank..."
     st = time.time()
-    update_records()
+    #get_all_stock_comments()
+    #get_all_choices()
     print "time cost:",time.time()-st
 
 

+ 183 - 122
src/weixin/controls.py

@@ -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
 
 
 

+ 1 - 1
src/weixin/views.py

@@ -389,7 +389,7 @@ class FollowUserView(cv.AuthView):
         try:                                                                       
             need_params.extend(["action"])
             vals = ccf.get_need_params(*need_params,**qdata)                       
-            vals["player_id"] = request.user.id
+            vals["user_id"] = request.user.id
             rst = ctl.follow_player(**vals)
             return cv.to_suc(rst)                                                  
         except Exception as e:                                                     

Файловите разлики са ограничени, защото са твърде много
+ 1 - 1
templates/index.html