2 Revize 266deee526 ... d37124b701

Autor SHA1 Zpráva Datum
  xjc d37124b701 update před 3 měsíci
  xjc 067ab96369 删除和获取资源出入金 před 4 měsíci

+ 2 - 0
src/common/models.py

@@ -116,6 +116,8 @@ class PlayerRecord(models.Model):
     comments_count = models.IntegerField(u"点赞数", blank=True,null=True,default=0)
     opmode_group = models.IntegerField(u"操作模式分组", blank=True,null=True)
     opmode_group_name = models.CharField(u"操作模式分组名称", max_length=255,blank=True,null=True)
+    today_stock_total = models.FloatField(u"今日持仓总额",blank=True,null=True)
+    today_cangwei = models.FloatField(u"今日仓位",blank=True,null=True)
 
     ctime = models.DateTimeField(u"创建时间", auto_now_add=True)
 

+ 3 - 3
src/manage/controls.py

@@ -341,11 +341,11 @@ def delete_model(cls,**kwargs):
             rst = model.objects.filter(id__in=ids).delete()
         if model_name == "UserInfo":
             cm.Player.objects.filter(user_id__in=ids).delete()
-            cm.PlayerRecord.objects.filter(user_id__in=ids).delete()
+            cm.PlayerRecord.get_db_model(match_id).objects.filter(user_id__in=ids).delete()
         if model_name == "Player":
-            cm.PlayerRecord.objects.filter(player_id__in=ids).delete()
+            cm.PlayerRecord.get_db_model(match_id).objects.filter(player_id__in=ids).delete()
         if model_name == "Match":
-            cm.PlayerRecord.objects.filter(match_id__in=ids).delete()
+            cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id__in=ids).delete()
             cm.Player.objects.filter(match_id__in=ids).delete()
             cm.MatchGroup.objects.filter(match_id__in=ids).delete()
         if model_name == "MatchGroup":

+ 2 - 0
src/settings/settings_online.py

@@ -75,5 +75,7 @@ LOGGING = {
 
 RANK_LIST = "RANK_LIST"
 
+FORBID_NAME = r"实盘|公众号|公号|工号|gzh|作手|游资".decode("utf-8")
+
 HOST = "https://www.hunanwanzhu.com"
 PROJECT_NAME = u"顽主杯"

+ 29 - 1
src/tools/update_records.py

@@ -1,5 +1,5 @@
 #coding:utf-8
-import os
+import os,json
 import time
 import datetime
 import sys
@@ -56,12 +56,40 @@ def get_all_choices():
         ccc.cache.incr("%s_choices" % stock_id,1)
 
 
+def update_cangwei():
+    """
+    """
+    match_id = 30
+    qset = cm.PlayerRecord.get_db_model(match_id).objects.all().order_by("-id")
+    for obj in qset:
+        today_fund = obj.today_fund
+        #记录持股情况
+        today_stock_fund = 0
+        today_stock_list = json.loads(obj.today_stock)
+        for ts in today_stock_list:
+            print(ts)
+            if ts["name"] and ts["fund"]:
+                if ts.get("fund"):
+                    try:
+                        today_stock_fund += float(ts["fund"])
+                    except:
+                        pass
+        #计算仓位
+        today_cangwei = round(today_stock_fund/today_fund,4)*100
+        print(obj.id,today_cangwei)
+
+        obj.today_stock_total = today_stock_fund
+        obj.today_cangwei = today_cangwei
+        obj.save()
+        #break
+
 
 if __name__ == "__main__":
     print "start update group rank..."
     st = time.time()
     #get_all_stock_comments()
     #get_all_choices()
+    update_cangwei()
     print "time cost:",time.time()-st
 
 

+ 6 - 0
src/weixin/control_auth.py

@@ -1,9 +1,11 @@
 #coding=utf-8
 '''
 '''
+import re
 import json,time,random,datetime
 from django.db import transaction
 from django.db.models import Q
+from django.conf import settings
 import common.models as cm
 import common.error_info as ce
 import common.common_functions as ccf
@@ -120,6 +122,10 @@ def login_user_v3(request):
     if not openid and not phone:
         raise ce.TipException(u"缺少openid!")
 
+    print(nickname)
+    if re.search(settings.FORBID_NAME,nickname):
+        raise ce.TipException(u"名字中包含特殊关键字,请更换名称后重试!")
+
     #if not ccc.cache.get(openid):
     #    raise ce.TipException(u"非法openid!")
 

+ 41 - 2
src/weixin/controls.py

@@ -833,12 +833,16 @@ def add_model(cls,**kwargs):
                             user_id=user_id,
                             match_id=match_id,
                             stock_date=stock_date)
+            #计算仓位
+            today_cangwei = round(today_stock_fund/today_fund,4)*100
 
             obj.init_fund = init_fund
             obj.yesterday_fund = yesterday_fund
             obj.yesterday_stock = yesterday_stock
             obj.yesterday_stock_img = yesterday_stock_img
             obj.today_fund = today_fund
+            obj.today_stock_total = today_stock_fund
+            obj.today_cangwei = today_cangwei
             obj.today_stock = today_stock
             obj.today_stock_img = today_stock_img
             obj.username = username
@@ -1912,11 +1916,15 @@ def update_user_style(**kwargs):
         print(e)
     #avatar = kwargs.pop("avatar")
 
+    if re.search(settings.FORBID_NAME,kwargs.get("username")):
+        raise ce.TipException(u"名字中包含特殊关键字,请更换名称后重试!")
+
     cm.UserInfo.objects.filter(id=user_id).update(**kwargs)
     #if player_id and init_fund:
     #    cm.Player.objects.filter(id=player_id).update(fund=init_fund)
 
     if kwargs.get("username"):
+
         cm.Player.objects.filter(user_id=user_id).update(username=kwargs.get("username"))
         match_id = ccc.get_cur_match().id
         upset = cm.PlayerRecord.get_db_model(match_id).objects.filter(user_id=user_id)
@@ -2191,6 +2199,10 @@ def do_wx_pay(request):
 
     orgcode = ccc.cache.get(phone)
 
+    print(signup_name)
+    if re.search(settings.FORBID_NAME,signup_name):
+        raise ce.TipException(u"名字中包含特殊关键字,请更换名称后重试!")
+
     if not phone == "13883187629":
         if not phcode == orgcode:
             raise ce.TipException(u"验证码不正确!")
@@ -3983,7 +3995,7 @@ def get_user_fundinout(request):
         user_id = 0
     if not user_id:
         user_id = qdata.get("user_id")
-    qdata = request.json()
+    qdata = request.json
     stock_date = qdata.get("stock_date")
 
     rst = cm.FundInOut.objects.filter(user_id = user_id,stock_date=stock_date).values().first()
@@ -3998,7 +4010,7 @@ def delete_user_fundinout(request):
     if not user_id:
         user_id = qdata.get("user_id")
     match_id = ccc.get_cur_match().id
-    qdata = request.json()
+    qdata = request.json
     stock_date = qdata.get("stock_date")
 
     #删除出入资金
@@ -4017,3 +4029,30 @@ def delete_user_fundinout(request):
         #    #    player.fund = yesterday.init_fund
         #    #    player.save()
 
+
+
+#@ccc.cache_data_kw(5*60)
+def get_match_cangwei_avg_allday(**qdata):
+    """每天人均仓位情况
+    """
+    match_id = qdata.get("match_id")
+
+    allday_cangwei_avg_list = []
+    prset = cm.PlayerRecord.get_db_model(match_id).objects.filter(match_id=match_id).values("stock_date")\
+        .annotate(cnt=Count("stock_date"),total=Sum("today_cangwei"))
+    for item in prset:
+        stock_date = item["stock_date"]
+        cnt = item["cnt"]
+        total = item["total"]
+
+        if cnt and total:
+            today_cangwei_avg = "{}%".format(round(total/cnt,2)) if cnt>0 else 0.0
+
+            allday_cangwei_avg_list.append({
+                "stock_date":stock_date,     
+                "today_cangwei_avg":today_cangwei_avg
+            })
+
+    allday_cangwei_avg_list = sorted(allday_cangwei_avg_list,key=lambda x:x["stock_date"],reverse=True)
+    rst = {"list":allday_cangwei_avg_list}
+    return rst

+ 3 - 2
src/weixin/urls_backstage.py

@@ -130,7 +130,8 @@ urlpatterns = [
     url(r'^v3/msg/content/check$', views.MsgContentCheck.as_view()),
 
     url(r'^v3/userstock/delete$', views.DeleteUserStock.as_view()),
-    url(r'^v3/fundintout/get$', views.GetUserFundInOut.as_view()),
-    url(r'^v3/fundintout/delete$', views.DeleteUserFundInOut.as_view()),
+    url(r'^v3/fundinout/get$', views.GetUserFundInOut.as_view()),
+    url(r'^v3/fundinout/delete$', views.DeleteUserFundInOut.as_view()),
+    url(r'^v3/match/cangwei/avg/allday$', views.MatchCangweiAvgAllDayView.as_view()),
 ]
 

+ 15 - 0
src/weixin/views.py

@@ -1891,6 +1891,7 @@ class GetUserFundInOut(cv.AuthView):
             rst = ctl.get_user_fundinout(request)
             return cv.to_suc(rst)
         except Exception as e: 
+            cv.tracefail()
             return cv.to_fail(e)
 
 
@@ -1902,4 +1903,18 @@ class DeleteUserFundInOut(cv.AuthView):
             rst = ctl.delete_user_fundinout(request)
             return cv.to_suc(rst)
         except Exception as e: 
+            cv.tracefail()
+            return cv.to_fail(e)
+
+
+class MatchCangweiAvgAllDayView(cv.BaseView):
+    def get(self, request):
+        """#获取每日人均仓位
+        """
+        qdata = request.json
+        try:
+            rst = ctl.get_match_cangwei_avg_allday(**qdata)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
             return cv.to_fail(e)