xjc il y a 3 ans
Parent
commit
cea3f6c903

+ 5 - 1
src/common/core_views.py

@@ -116,7 +116,11 @@ def api_wapper(handler, request, is_vauth, *args, **kwargs):
             if not user and False:
                 return JsonResponse({"code":403,"data":{}})
             #选手
-            player = cm.Player.objects.filter(user_id=id).order_by("-id").first()
+            cur_match_id = cm.Player.objects.filter(user_id=id).order_by("-match_id").first().match_id
+
+            player = cm.Player.objects.filter(user_id=id,match_id=cur_match_id).order_by("-id").first()
+
+
             setattr(request, "ip", get_ip(request))
             setattr(request, "user", user)
             setattr(request, "player", player)

+ 7 - 0
src/manage/controls.py

@@ -213,7 +213,14 @@ def update_model(cls,**kwargs):
         total_income = (today_fund - init_fund)/float(init_fund)
         obj.today_income = round(today_income,4)
         obj.total_income = round(total_income,4)
+        #
+        player = cm.Player.objects.filter(id=obj.player_id).first()
+        if player:
+            obj.match_group = player.match_group
+            obj.username = player.username
+            obj.usercode = player.usercode
         obj.save()
+
         #更新player的init_fund
         player_id = obj.player_id
         cm.Player.objects.filter(id=player_id).update(fund=init_fund)

+ 4 - 4
src/manage/views.py

@@ -185,12 +185,12 @@ class PlayerView(cv.AdminView):
         @match_group:"比赛分组"
         """
         qdata = request.json
-        need_params = ["user_id","fund","match_id","match_group"]
+        need_params = ["user_id","match_id","match_group"]
         mse = ccf.check_params(*need_params,**qdata)
         if mse:
             raise ce.TipException(mse)
         try:
-            need_params.extend(["match_status"])
+            need_params.extend(["match_status","fund"])
             vals = ccf.get_need_params(*need_params,**qdata)
             vals["fund"] = round(float(vals["fund"]),4)
             rst = ctl.add_model(self,**vals)
@@ -207,12 +207,12 @@ class PlayerView(cv.AdminView):
         @match_group:"比赛分组"
         """
         qdata = request.json
-        need_params = ["id","user_id","fund","match_id","match_group"]
+        need_params = ["id","user_id","match_id","match_group"]
         mse = ccf.check_params(*need_params,**qdata)
         if mse:
             raise ce.TipException(mse)
         try:
-            need_params.extend(["match_status"])
+            need_params.extend(["match_status","fund"])
             vals = ccf.get_need_params(*need_params,**qdata)
             vals["fund"] = round(float(vals["fund"]),4)
             rst = ctl.update_model(self,**vals)

+ 2 - 0
src/tools/rank_server.py

@@ -18,11 +18,13 @@ def rank_server():
     """
     """
     rcid = ccc.cache.rpop(settings.RANK_LIST)
+    print rcid
     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:

+ 29 - 0
src/tools/update_player_record.py

@@ -0,0 +1,29 @@
+#coding:utf-8
+import os
+import time
+import datetime
+import sys
+import django
+from django.db import connection
+
+sys.path.append('/mnt/wzbapi/src')
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+django.setup()
+
+import common.common_control as ccc
+import common.models as cm
+
+def update_player_record():
+    """
+    """
+    stock_date = "2021-12-15"
+    qset = cm.PlayerRecord.objects.filter(stock_date=stock_date)
+    for obj in qset:
+        obj.today_fund = obj.init_fund
+        obj.today_income = 0 
+        obj.total_income = 0 
+        obj.rank = 0
+        obj.group_rank = 0
+        obj.save()
+
+update_player_record()

+ 8 - 0
src/weixin/control_auth.py

@@ -35,6 +35,11 @@ def get_wxauth_info(request):
     print uid
     user = cm.UserInfo.objects.filter(id=uid).values().first()
     user["nickname"] = user["username"]
+    player = request.player
+    if player and not player.fund:                                                            
+        user["need_fill"] = 1                                                      
+    else:                                                                          
+        user["need_fill"] = 0                                                      
     return user
 
 
@@ -45,6 +50,9 @@ def update_wxauth_info(request):
     uid = request.user.id
     qdata = request.json
     cm.UserInfo.objects.filter(id=uid).update(userinfo=json.dumps(qdata))
+    return user                                                                    
+
+
 
 
 def login_user(request):

+ 54 - 10
src/weixin/controls.py

@@ -43,6 +43,7 @@ def async(f):
 
 
 def get_today_date():
+    #return "2021-12-10"
     if datetime.datetime.now().strftime("%H:%M") < "15:00":
         if datetime.datetime.now().weekday() in [5,6] or datetime.datetime.now().strftime("%Y-%m-%d") in MISS_DATES:
             today = cm.PlayerRecord.objects.all().order_by("-stock_date").first().stock_date
@@ -134,6 +135,10 @@ def get_player_match_list(request):
     """选手参赛列表数据
     """
     uid = request.user.id
+    now_str = datetime.datetime.now().strftime("%Y-%m-%d")
+    cur_match_id = cm.Match.objects.filter(start_time__lte=now_str).first().id
+    cur_match_id = 7
+    #match_ids = list(cm.Player.objects.filter(user_id=uid,match_id=cur_match_id).values_list("match_id",flat=True))
     match_ids = list(cm.Player.objects.filter(user_id=uid).values_list("match_id",flat=True))
     matchs = list(cm.Match.objects.filter(id__in=match_ids).values())
 
@@ -169,6 +174,11 @@ def get_player_match_detail(request):
         player_id = records_set.first().player_id
         records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date")
     else:
+        if int(match_id) == 7:
+            player = cm.Player.objects.filter(match_id=match_id,usercode=request.user.usercode).first()
+            if player:
+                player_id = player.id
+                match_group = player.match_group
         records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date")
 
     match = cm.Match.objects.filter(id=match_id).values().first()
@@ -181,6 +191,7 @@ def get_player_match_detail(request):
         #today_record = {}
         records = []
     today = get_today_date()
+    today = records_set.first().stock_date
     today_record = get_today_record(player_id,int(match_id),int(match_group),today)
 
     for item in records:
@@ -229,6 +240,7 @@ def get_match_groups(match_id):
     """
     match = cm.Match.objects.filter(id=match_id).values().first()
     groups = list(cm.MatchGroup.objects.filter(match_id=match_id,is_active=1).values())
+    #groups = list(cm.MatchGroup.objects.filter(match_id=match_id).values())
     return match,groups
 
 #@ccc.cache_data()
@@ -259,10 +271,15 @@ def get_cache_rank_list(player_id,match_id):
                 player["username"] = username
                 player["total_income"] = "{}%".format(today_record["total_income"]*100)
 
-                player["fund"] = round(player["fund"],4)
-                player["init_fund"] = round(player["init_fund"],4)
-                player["today_fund"] = round(player["today_fund"],4)
-                new_players.append(player)
+                try:
+                    player["fund"] = round(player["fund"],4) if player["fund"] else 0.0
+                    player["init_fund"] = round(player["init_fund"],4)
+                    player["fund"] = round(player["init_fund"],4)
+                    player["today_fund"] = round(player["today_fund"],4)
+                    new_players.append(player)
+                except Exception as e:    
+                    print player
+                    pass
         new_players = sorted(new_players,key=lambda x:x["group_rank"])
         item["players"] = new_players[:3]
     return match,groups
@@ -274,6 +291,7 @@ def get_rank_list(request):
     qdata = request.json
     player_id = request.player.id
     match_id = request.player.match_id
+    match_id = 8
     match,groups = get_cache_rank_list(player_id,match_id)
 
     ret = {"match":match,"groups":groups}
@@ -307,6 +325,8 @@ def get_group_rank_list(request):
     player_id = request.player.id
     match_id = request.player.match_id
 
+    match_id = 8
+
     match = get_match_info(match_id)
     group = get_group_info(group_id)
 
@@ -330,12 +350,16 @@ def get_group_rank_list(request):
 
         if today_record:
             player.update(today_record)
-            player["username"] = username
-            player["total_income"] = "{}%".format(player["total_income"]*100)
-            player["fund"] = round(player["fund"],4)
-            player["init_fund"] = round(player["init_fund"],4)
-            player["today_fund"] = round(player["today_fund"],4)
-            new_players.append(player)
+            try:
+                player["username"] = username
+                player["total_income"] = "{}%".format(player["total_income"]*100)
+                player["fund"] = round(player["fund"],4) if player["fund"] else 0
+                player["init_fund"] = round(player["init_fund"],4)
+                player["fund"] = round(player["init_fund"],4)
+                player["today_fund"] = round(player["today_fund"],4)
+                new_players.append(player)
+            except Exception as e:
+                print e
     new_players = sorted(new_players,key=lambda x:x["group_rank"])
 
     #分页
@@ -363,6 +387,12 @@ def get_player_match_records(request):
     page = int(qdata.get("page",0))
     page_size = int(qdata.get("page_size",20))
 
+    if int(match_id) == 7:
+        player = cm.Player.objects.filter(match_id=match_id,usercode=request.user.usercode).first()
+        if player:
+            player_id = player.id
+            match_group = player.match_group
+
     records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date")
     data = list(records_set.values())
     for item in data:
@@ -417,6 +447,8 @@ def add_model(cls,**kwargs):
         is_markt = int(kwargs.get("is_markt",0))
 
         player = cm.Player.objects.filter(id=player_id).first()
+        if player.fund <= 0:
+            raise ce.TipException(u"请先输入您的初始资金后再提交数据!")
         user_id = player.user_id
         init_fund = player.fund
         user = cm.UserInfo.objects.filter(id=user_id).first()
@@ -629,6 +661,8 @@ def add_player_record_single(**kwargs):
     is_markt = int(kwargs.get("is_markt",0))
 
     player = cm.Player.objects.filter(usercode=usercode,match_id=match_id).first()
+    if player.fund <=0 :
+        raise ce.TipException(u"请先输入您的初始资金后再提交数据!")
     player_id = player.id
     user_id = player.user_id
     init_fund = player.fund
@@ -719,3 +753,13 @@ def get_cur_record(request):
         data["today_stock"] = json.loads(data["today_stock"]) if data["today_stock"] else []
     return data
 
+def update_user_fund(**kwargs):                                                     
+    """                                                                             
+    """                                                                             
+    user_id = kwargs.pop("user_id")                                                 
+    player_id = kwargs.pop("player_id")                                             
+    init_fund = kwargs.pop("init_fund")                                             
+    if player_id and init_fund:                                                     
+        cm.Player.objects.filter(id=player_id).update(fund=init_fund)               
+    return True                                                                     
+

+ 1 - 0
src/weixin/urls_backstage.py

@@ -24,6 +24,7 @@ urlpatterns = [
     url(r'^group/rank$', views.GroupRankView.as_view()),
     url(r'^player/currecord$', views.PlayerCurRecordView.as_view()),
     url(r'^article$', views.ArticleView.as_view()),
+    url(r'^player/fund$', views.PlayerFundView.as_view()),
 
 ]
 

+ 19 - 1
src/weixin/views.py

@@ -341,4 +341,22 @@ class ArticleView(cv.AuthView):
         except Exception as e:                                                     
             cv.tracefail()                                                         
             return cv.to_fail(e)                                                                                                                                                                                                                                              
-
+class PlayerFundView(cv.AuthView):                                                 
+    def put(self, request):                                                        
+        """#修改初始资金(小程序)                                                   
+        @init_fund:"",参数金额                                                     
+        """                                                                        
+        qdata = request.json                                                       
+        need_params = ["init_fund"]                                                 
+        mse = ccf.check_params(*need_params,**qdata)                               
+        if mse:                                                                    
+            raise ce.TipException(mse)                                             
+        try:                                                                       
+            vals = ccf.get_need_params(*need_params,**qdata)                       
+            vals["user_id"] = request.user.id                                      
+            vals["player_id"] = request.player.id if request.player else None   
+            rst = ctl.update_user_fund(**vals)                                     
+            return cv.to_suc(rst)                                                  
+        except Exception as e:                                                     
+            cv.tracefail()                                                         
+            return cv.to_fail(e)