xjconline 2 years ago
parent
commit
ac0858a820

+ 4 - 0
src/common/core_views.py

@@ -36,6 +36,7 @@ class CusDjangoJSONEncoder(json.JSONEncoder):
     JSONEncoder subclass that knows how to encode date/time, decimal types and UUIDs.
     """
     def default(self, o):
+        print(o)
         # See "Date Time String Format" in the ECMA-262 specification.
         if isinstance(o, datetime.datetime):
             r = datetime.datetime.strftime(o,'%Y-%m-%d %H:%M:%S')
@@ -55,6 +56,8 @@ class CusDjangoJSONEncoder(json.JSONEncoder):
             return str(o)
         elif isinstance(o, uuid.UUID):
             return str(o)
+        elif isinstance(o, None):
+            return ""
         else:
             return super(DjangoJSONEncoder, self).default(o)
 
@@ -193,6 +196,7 @@ def to_suc(data={},code=0):
     info = {}
     info["data"] = data
     info["code"] = code
+    info = eval(str(info).replace("None",'""'))
     return JsonResponse(info,encoder=CusDjangoJSONEncoder)
 
 def to_fail(e=None):

+ 1 - 0
src/common/models.py

@@ -327,6 +327,7 @@ class UserStock(models.Model):
     stock_id = models.IntegerField(u"股票id", blank=True,null=True)
     stock_date = models.CharField(u"持股日期", max_length=255,blank=True,null=True)
     stock_name = models.CharField(u"股票名称", max_length=255,blank=True,null=True)
+    fund = models.FloatField(u"持股金额",blank=True,null=True)
 
     ctime = models.DateTimeField(u"创建时间", auto_now_add=True)
 

+ 20 - 0
src/nohup.out

@@ -0,0 +1,20 @@
+/tmp/wanzb_v3_api/src/utils/aestool.py:2: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
+  from cryptography.hazmat.primitives import padding
+[16/Feb/2023 15:54:26] "GET /api/wx/v3/user/follow/list?page=1&page_size=50 HTTP/1.1" 200 19120
+[16/Feb/2023 15:55:11] "GET /api/wx/v3/user/follow/list?page=1&page_size=50 HTTP/1.1" 200 19120
+2023-02-16 15:55:13,749 [django.request:152] [base:get_response] [WARNING]- Not Found: /http://47.107.124.163:8068//api/wx/v3/match/latest
+[16/Feb/2023 15:55:13] "GET /http://47.107.124.163:8068//api/wx/v3/match/latest HTTP/1.1" 404 124
+[16/Feb/2023 15:55:13] "GET /api/wx/v3/user/follow/list?page=1&page_size=50 HTTP/1.1" 200 19120
+[16/Feb/2023 15:57:17] "GET /api/wx/v3/user/follow/list?page=1&page_size=50 HTTP/1.1" 200 19120
+2023-02-16 15:57:29,910 [django.request:152] [base:get_response] [WARNING]- Not Found: //api/wx/v3/match/latest
+[16/Feb/2023 15:57:29] "GET //api/wx/v3/match/latest HTTP/1.1" 404 97
+[16/Feb/2023 15:57:30] "GET /api/wx/v3/user/follow/list?page=1&page_size=50 HTTP/1.1" 200 19120
+[16/Feb/2023 15:57:45] "GET /api/wx/v3/user/follow/list?page=1&page_size=50 HTTP/1.1" 200 19120
+Traceback (most recent call last):
+  File "/tmp/wanzb_v3_api/src/weixin/views.py", line 1110, in get
+    rst = ctl.get_latest_match_info(request)
+  File "/tmp/wanzb_v3_api/src/weixin/controls.py", line 2647, in get_latest_match_info
+    groups = list(cm.MatchGroup.objects.filter(match_id=match_id,is_active=1).order_by("order").values())
+NameError: global name 'match_id' is not defined
+[16/Feb/2023 15:57:47] "GET /api/wx/v3/match/latest HTTP/1.1" 200 66
+[16/Feb/2023 15:57:47] "GET /api/wx/v3/user/follow/list?page=1&page_size=50 HTTP/1.1" 200 19120

+ 36 - 0
src/utils/aliyunpush.py

@@ -0,0 +1,36 @@
+#-*-coding:utf-8 -*-
+
+from aliyunsdkcore.client import AcsClient
+from aliyunsdkcore.acs_exception.exceptions import ClientException
+from aliyunsdkcore.acs_exception.exceptions import ServerException
+from aliyunsdkpush.request.v20160801.PushRequest import PushRequest
+
+client = AcsClient('LTAI5t8bioQxGXB1jtVugJcU', 'OdGWSBRjkJxaPjgmE38eQ8nzkI6nRk', 'cn-shenzhen')
+
+request = PushRequest()
+request.set_accept_format('json')
+
+print(dir(request))
+request.set_iOSApnsEnv('DEV')
+request.set_AppKey("333793060")
+request.set_PushType("NOTICE")
+request.set_DeviceType("ALL")
+#request.set_Target("DEVICE")
+#request.set_Target("ALL")
+request.set_Target("ACCOUNT")
+
+request.set_TargetValue("6209")
+
+request.set_Body("测试推送")
+request.set_Title("测试通过account推送")
+
+response = client.do_action_with_exception(request)
+print(response)
+
+# python2:  print(response)
+#print(str(response, encoding='utf-8'))
+
+if __name__ == "__main__":
+    pass
+    #send_notification_by_registration_ids()
+

+ 11 - 4
src/weixin/control_auth.py

@@ -104,17 +104,24 @@ def login_user_v3(request):
     openid = info.get('openid')
     avatar = info.get('avatarUrl')
     nickname = info.get('nickName')
-    phone = info.get('phone','11111111111')
+    phone = info.get('phone','')
     phcode = info.get('phcode')
-    unionid = info.get('unionid')
+    unionid = info.get('unionid','')
 
-    if not openid and not unionid:
+    #if not openid and not unionid:
+    #    raise ce.TipException(u"缺少openid!")
+    if not openid and not phone:
         raise ce.TipException(u"缺少openid!")
 
     #if not ccc.cache.get(openid):
     #    raise ce.TipException(u"非法openid!")
 
-    user = cm.UserInfo.objects.filter(Q(openid=openid)|Q(phone=phone)).first()
+    print(phone,openid)
+    if phone:
+        user = cm.UserInfo.objects.filter(Q(phone=phone)).order_by("-id").first()
+    else:
+        user = cm.UserInfo.objects.filter(Q(openid=openid)).order_by("-id").first()
+    print(user.id)
     if not user:
         #新用户
         usercode = gen_code()

+ 114 - 2
src/weixin/controls.py

@@ -571,8 +571,6 @@ def get_group_rank_list(request):
     else:
         new_players = sorted(new_players,key=lambda x:x["org_total_income"],reverse=True)
 
-    #new_players = []
-
     #分页
     page = int(kwargs.get("page",0))
     page_size = int(kwargs.get("page_size",50))
@@ -733,6 +731,8 @@ def add_model(cls,**kwargs):
                             player_id = player.id,
                             stock_date = stock_date
                         )
+                        usobj.fund = ts["fund"]
+                        usobj.save()
                         ts["stock_id"] = stock_id
                         new_stock_list.append(ts)
                     except Exception as e:
@@ -2639,3 +2639,115 @@ def get_user_follows_v3(request):
         return total,data
     else:
         return len(data),data
+
+
+def get_latest_match_info(request):
+    """
+    """
+    cur_match = cm.Match.objects.filter(match_status=3).order_by("-id").values().first()
+    cur_match_id = cur_match.get("id")
+    groups = list(cm.MatchGroup.objects.filter(match_id=cur_match_id,is_active=1).order_by("order").values())
+    cur_match["groups"] = groups
+    return cur_match
+
+def get_article_info(**kwargs):
+    """
+    """
+    _id = kwargs.get("id")
+    rst = cm.Article.objects.filter(id=_id).values().first()
+    rst["url"] = "https://www.hunanwanzhu.com/topic/article.html?id="+str(_id)
+    return rst
+
+
+def get_profit_list(**kwargs):
+    """盈亏列表
+    """
+    stock_date = kwargs.get("stock_date")
+    match_id = kwargs.get("match_id")
+    _type = kwargs.get("type")
+
+    if not stock_date:
+        stock_date = get_today_date()
+
+    qset = cm.PlayerRecord.get_db_model(match_id).objects.filter(stock_date=stock_date)
+    if _type == "win":
+        qset = qset.filter(today_income__gte=0).order_by("-today_income")
+    if _type == "loss":
+        qset = qset.filter(today_income__lt=0).order_by("today_income")
+
+    page = int(kwargs.get("page",0))
+    page_size = int(kwargs.get("page_size",20))
+
+    if page and page_size:
+        total,qset = ccc.get_page_qset(qset,page,page_size)
+    else:
+        total = qset.count()
+    data = list(qset.values())
+
+    return total,data
+
+
+def get_group_rank_list_v3(request):
+    """排名列表
+    """
+    qdata = request.json
+    kwargs = qdata
+
+    group_id = qdata.get("id")
+    match_id = qdata.get("match_id")
+
+    match_id = cm.MatchGroup.objects.filter(id=group_id).first().match_id
+
+    today = qdata.get("stock_date")
+    if not today:
+        today = get_today_date()
+
+    match = get_match_info(match_id)
+    group = get_group_info(group_id)
+    players = get_match_group_users(match_id,group_id)
+    new_players = []
+    for player in players:
+        user_id = player["user_id"]
+        username = player["username"]
+        match_group = group_id
+        today_record = ccc.get_today_record(user_id,match_id,match_group,today)
+
+        if today_record:
+            player.update(today_record)
+            player["username"] = username
+            player["org_today_income"] = player["today_income"]
+            player["org_total_income"] = player["total_income"]
+            player["total_income"] = "{}%".format(player["total_income"]*100)
+            player["today_income"] = "{}%".format(player["today_income"]*100)
+            player["fund"] = round(player["fund"],4)
+            player["init_fund"] = round(player["init_fund"],4)
+            player["today_fund"] = round(player["today_fund"],4)
+            player["today_stock_img"] = json.loads(player["today_stock_img"]) if player["today_stock_img"] else []
+            #player["win_rate"] = calc_win_rate(user_id,match_id)
+            player["zan_count"] = player["zans"]
+            new_players.append(player)
+
+    if kwargs.get("order_by") == "today_income__asc":
+        new_players = sorted(new_players,key=lambda x:x["org_today_income"])
+    elif kwargs.get("order_by") == "today_income__desc" :
+        new_players = sorted(new_players,key=lambda x:x["org_today_income"],reverse=True)
+    elif kwargs.get("order_by") == "total_income__asc": 
+        new_players = sorted(new_players,key=lambda x:x["org_total_income"])
+    elif kwargs.get("order_by") == "total_income__desc": 
+        new_players = sorted(new_players,key=lambda x:x["org_total_income"],reverse=True)
+    else:
+        new_players = sorted(new_players,key=lambda x:x["org_total_income"],reverse=True)
+
+    #分页
+    page = int(kwargs.get("page",0))
+    page_size = int(kwargs.get("page_size",50))
+    if page and page_size:
+        total,new_players = ccf.get_page_list(new_players,page,page_size)
+    else:
+        total = len(new_players)
+    return total,new_players
+
+
+def get_article_type_list(**kwargs):
+    rst = [u"每日点评",u"冠军心得",u"腰斩心得",u"牛人专访"]
+    return rst

+ 8 - 0
src/weixin/urls_backstage.py

@@ -73,6 +73,14 @@ urlpatterns = [
     url(r'^v3/stock/user/list$', views.StockUserListView.as_view()),
     url(r'^v3/user/inout/list$', views.UserInOutListView.as_view()),
     url(r'^v3/user/follow/list$', views.V3FollowUserListView.as_view()),
+    #3.0app
+    url(r'^v3/match/latest$', views.V3LatestMatchView.as_view()),
+    url(r'^v3/stock$', views.V3StockView.as_view()),
+    url(r'^v3/stock/players/list$', views.V3StockPlayersListView.as_view()),
+    url(r'^v3/article/detail$', views.V3ArticleDetailView.as_view()),
+    url(r'^v3/profit/rank/list$', views.ProfitRankListView.as_view()),
+    url(r'^v3/group/rank$', views.V3GroupRankView.as_view()),
+    url(r'^v3/article/type/list$', views.V3ArticleTypeListView.as_view()),
 
 ]
 

+ 116 - 0
src/weixin/views.py

@@ -1100,3 +1100,119 @@ class V3FollowUserListView(cv.AuthView):
         except Exception as e:                                                     
             cv.tracefail()                                                         
             return cv.to_fail(e)
+
+
+class V3LatestMatchView(cv.AuthView):
+    def get(self, request):
+        """#最新赛事与分组信息(3.0app)
+        """
+        try:
+            rst = ctl.get_latest_match_info(request)
+            return cv.to_suc(rst)
+        except Exception as e: 
+            cv.tracefail()
+            return cv.to_fail(e)
+
+
+class V3StockView(cv.AuthView):
+    def get(self, request):
+        """#股票詳情(3.0小程序)
+        @id:1
+        """
+        qdata = request.json
+        need_params = ["id"]
+        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.get("id")
+            stock_id = vals.get("id")
+            rst = ctl.get_stock_info(stock_id)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)
+
+
+class V3StockPlayersListView(cv.AuthView):
+    def get(self, request):
+        """#股票持仓列表(3.0小程序)
+        @id:1
+        @page:1
+        @page_size:1
+        """
+        qdata = request.json
+        need_params = ["id"]
+        mse = ccf.check_params(*need_params,**qdata)
+        if mse:
+            raise ce.TipException(mse)
+        try:
+            need_params.extend(["page","page_size","stock_date"])
+            vals = ccf.get_need_params(*need_params,**qdata)
+            vals["user_id"] = request.user.get("id")
+            vals["stock_id"] = vals.get("id")
+            rst = ctl.get_stock_players(**vals)
+            return cv.to_suc(rst)
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)
+
+
+class V3ArticleDetailView(cv.BaseView):                                                    
+    def get(self, request):                                                        
+        """#文章详情(APP)                                                       
+        @id:1                                                                      
+        """                                                                        
+        qdata = request.json                                                       
+        need_params = ["id"]                                                       
+        mse = ccf.check_params(*need_params,**qdata)                               
+        if mse:                                                                    
+            raise ce.TipException(mse)                                             
+        try:                                                                       
+            vals = ccf.get_need_params(*need_params,**qdata)                       
+            rst = ctl.get_article_info(**vals)                                 
+            return cv.to_suc(rst)                                                  
+        except Exception as e:                                                     
+            cv.tracefail()                                                         
+            return cv.to_fail(e)
+
+
+class ProfitRankListView(cv.BaseView):                                                    
+    def get(self, request):                                                        
+        """#盈亏列表(小程序)                                                       
+        @id:1                                                                      
+        """                                                                        
+        qdata = request.json                                                       
+        try:                                                                       
+            total,rst = ctl.get_profit_list(**qdata)                                 
+            return cv.to_suc({"total":total,"list":rst})
+        except Exception as e:                                                     
+            cv.tracefail()                                                         
+            return cv.to_fail(e)
+
+
+class V3GroupRankView(cv.AuthView):
+    def get(self, request):
+        """#分组排名(小程序)
+        """
+        try:
+            total,rst = ctl.get_group_rank_list_v3(request)
+            return cv.to_suc({"total":total,"list":rst})
+        except Exception as e:
+            cv.tracefail()
+            return cv.to_fail(e)
+
+
+class V3ArticleTypeListView(cv.BaseView):                                                    
+    def get(self, request):                                                        
+        """#盈亏列表(小程序)                                                       
+        @id:1                                                                      
+        """                                                                        
+        qdata = request.json                                                       
+        try:                                                                       
+            rst = ctl.get_article_type_list(**qdata)                                 
+            return cv.to_suc(rst)
+        except Exception as e:                                                     
+            cv.tracefail()                                                         
+            return cv.to_fail(e)