xjc 5 месяцев назад
Родитель
Сommit
e0f2f1b0fc
3 измененных файлов с 78 добавлено и 10 удалено
  1. 49 8
      src/weixin/controls.py
  2. 3 0
      src/weixin/urls_backstage.py
  3. 26 2
      src/weixin/views.py

+ 49 - 8
src/weixin/controls.py

@@ -21,7 +21,7 @@ from utils.jgpush import send_notification_by_registration_ids
 import wzhifuSDK as wxpay
 from utils.exceltool import ExcelTool
 from utils.qrcodetool import gen_general_qrcode
-from django.db.models import Q,Sum,Count,F
+from django.db.models import Q,Sum,Count,F,Avg
 from PIL import Image
 from PIL import Image,ImageDraw,ImageFont
 from django.db import transaction
@@ -279,6 +279,11 @@ def get_player_match_detail(request):
     user_info = get_user_info(cur_user_id)
     if user_info.get("phone"):
         del user_info["phone"]
+    #查询出入资金
+    fund_inout_list = []
+    if cm.FundInOut.objects.filter(user_id = cur_user_id,stock_date=today_record["stock_date"]).exists():
+        fund_inout_list = list(cm.FundInOut.objects.filter(user_id=cur_user_id,stock_date=today_record["stock_date"]).values())
+
     ret = {
         "match":match,
         "today_record":today_record,
@@ -289,7 +294,8 @@ def get_player_match_detail(request):
         "fans":cm.UserFollows.objects.filter(follow_id=cur_user_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(user_id=cur_user_id).values_list("stock_name",flat=True))
+        "stock_follow":list(cm.UserChoice.objects.filter(user_id=cur_user_id).values_list("stock_name",flat=True)),
+        "fund_inout":fund_inout_list[0] if len(fund_inout_list) > 0 else {}
         }
 
     return ret
@@ -790,16 +796,18 @@ def add_model(cls,**kwargs):
                         )
                         stock_id = stock.id
                         usobj,flag = cm.UserStock.objects.get_or_create(
-                            user_id = user_id, 
                             stock_id = stock_id,
-                            stock_name = ts["name"],
                             player_id = player.id,
-                            stock_date = stock_date,
-                            match_group = match_group,
-                            opmode_group = opmode_group
+                            stock_date = stock_date
                         )
                         if ts.get("fund"):
                             usobj.fund = ts["fund"]
+                        if ts.get("name"):
+                            usobj.stock_name = ts.get("name")
+                        if match_group:
+                            usobj.match_group = match_group
+                        if opmode_group:
+                            usobj.opmode_group = opmode_group
                         usobj.save()
                         ts["stock_id"] = stock_id
                         new_stock_list.append(ts)
@@ -1408,10 +1416,16 @@ def get_hot_stock_buy(**kwargs):
     """
     """
     stock_date = kwargs.get("stock_date")
+
     qset = cm.UserStock.objects.filter(stock_date=stock_date,fund__gt=0)
     if kwargs.get("name"):
         qset = cm.UserStock.objects.filter(stock_name__icontains=kwargs.get("name"),stock_date=stock_date)
-    qset = qset.values("stock_id","stock_name").annotate(count=Count("stock_id"),total_fund=Sum("fund")).order_by("-count")
+    
+    if int(kwargs.get("fund_rank",0)) == 1:
+        qset = qset.values("stock_id","stock_name").annotate(count=Count("stock_id"),total_fund=Sum("fund")).order_by("-total_fund")
+    else:
+        qset = qset.values("stock_id","stock_name").annotate(count=Count("stock_id"),total_fund=Sum("fund")).order_by("-count")
+
     data = []
     for q in qset:
         stock_id = q["stock_id"]
@@ -3706,4 +3720,31 @@ def get_oss2_policy_sign(request):
     rst = get_signature(policy)
     return rst
 
+def get_match_group_list(**kwargs):
+    """
+    """
+    match_id = kwargs.get("match_id")
+    match,groups = get_match_groups(match_id)
+    return groups
+
+    
+
+def get_user_markscore_week_avg(request):
+    """
+    """
+    pass
+    now = datetime.datetime.now().date()
+    data = []
+    for i in range(1,5):
+        item_list = []
+        for j in range(1,8):
+            now = now + datetime.timedelta(days=-1)
+            now_str = ccf.datetime_to_str(now,"%Y-%m-%d")
+            qset = cm.UserMarkScore.objects.filter(stock_date=now_str).aggregate(avg_score=Avg("score"))
+            item_list.append({"stock_date":now_str,"avg_score":qset.get("avg_score",0)})
+        data.append(item_list)
+
+    return data
+            
+
 

+ 3 - 0
src/weixin/urls_backstage.py

@@ -119,6 +119,9 @@ urlpatterns = [
     url(r'^v2/player/match/calendar/external$', views.PlayerMatchCalendarExternalView.as_view()),
     url(r'^v3/user/match/stock/winlossrank/list$', views.UserMatchStockWinLossListView.as_view()),
     url(r'^oss2/uploadfile/sign$', views.OSS2PolicyAndSignView.as_view()),
+
+    url(r'^v3/match/group/list$', views.MatchGroupListView.as_view()),
     
+    url(r'^v3/user/markscore/weekavg$', views.UserMarkWekkAvgView.as_view()),
 ]
 

+ 26 - 2
src/weixin/views.py

@@ -452,7 +452,7 @@ class HotFollowListView(cv.AuthView):
             cv.tracefail()                                                         
             return cv.to_fail(e)
 
-class HotStockBuyListView(cv.AuthView):                                                    
+class HotStockBuyListView(cv.BaseView):                                                    
     def get(self, request):                                                        
         """#热门持仓股票(2.0小程序)
         @stock_date:"",持股日期
@@ -465,7 +465,7 @@ class HotStockBuyListView(cv.AuthView):
         if mse:                                                                    
             raise ce.TipException(mse)                                             
         try:                                                                       
-            need_params.extend(["name","page","page_size"])
+            need_params.extend(["name","fund_rank","page","page_size"])
             vals = ccf.get_need_params(*need_params,**qdata)                       
             total,rst = ctl.get_hot_stock_buy(**vals)                                 
             return cv.to_suc({"total":total,"list":rst})
@@ -1628,6 +1628,17 @@ class MatchGroupWinloseStatisticView(cv.BaseView):
             cv.tracefail()
             return cv.to_fail(e)
 
+class MatchGroupListView(cv.BaseView):
+    def get(self, request):
+        """#获取比赛分组
+        """
+        qdata = request.json
+        try:
+            rst = ctl.get_match_group_list(**qdata)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)
 
 class UserMarkScoreView(cv.AuthView):
 
@@ -1763,3 +1774,16 @@ class OSS2PolicyAndSignView(cv.BaseView):
         except Exception as e:
             cv.tracefail()
             return cv.to_fail(e)
+
+
+
+class UserMarkWekkAvgView(cv.BaseView):
+    def get(self, request):
+        """#用户每周平均值
+        """
+        try:
+            rst = ctl.get_user_markscore_week_avg(request)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)