|
|
@@ -1,511 +1,540 @@
|
|
|
-# coding=utf-8
|
|
|
+#coding=utf-8
|
|
|
'''
|
|
|
'''
|
|
|
-import os
|
|
|
+import os,re,random
|
|
|
import json,time,datetime
|
|
|
+import shutil
|
|
|
+import tempfile
|
|
|
+import zipfile
|
|
|
+from docxtpl import DocxTemplate,InlineImage
|
|
|
+from docx.shared import Mm
|
|
|
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
|
|
|
import common.common_control as ccc
|
|
|
+import account.password_handle as ph
|
|
|
+from utils.exceltool import ExcelTool
|
|
|
+from utils.jgpush import send_notification_by_registration_ids
|
|
|
import wzhifuSDK as wxpay
|
|
|
-from django.conf import settings
|
|
|
+from utils.exceltool import ExcelTool
|
|
|
+from utils.qrcodetool import gen_general_qrcode
|
|
|
+from django.db.models import Q,Sum,Count
|
|
|
+from PIL import Image
|
|
|
from PIL import Image,ImageDraw,ImageFont
|
|
|
|
|
|
+import xlrd
|
|
|
+import xlwt
|
|
|
+from xlutils.copy import copy
|
|
|
+from xltpl.writer import BookWriter
|
|
|
+
|
|
|
def get_index_data(request):
|
|
|
+ """首页数据
|
|
|
"""
|
|
|
- """
|
|
|
- qset = cm.Category.objects.all()
|
|
|
- qdata = list(qset.values())
|
|
|
- for i,qd in enumerate(qdata):
|
|
|
- if i<6:
|
|
|
- qd["type"] = "nav"
|
|
|
+ player = request.player
|
|
|
+ if not player:
|
|
|
+ raise ce.TipException(u"该账号未参加任何赛事!")
|
|
|
+ player_id = player.id
|
|
|
+ match_id = player.match_id
|
|
|
+ match_name = cm.Match.objects.filter(id=match_id).first().name
|
|
|
+ records_set = cm.PlayerRecord.objects.filter(player_id=player_id,match_id=match_id).order_by("-stock_date")
|
|
|
+ if records_set:
|
|
|
+ today_record = records_set.first()
|
|
|
+ cur_rank = records_set.first().rank
|
|
|
+ group_income = get_group_income(today_record.match_id,today_record.match_group)
|
|
|
+ if today_record.total_income in group_income:
|
|
|
+ cur_rank = group_income.index(today_record.total_income)+1
|
|
|
else:
|
|
|
- qd["type"] = "article"
|
|
|
- qd["list"] = list(cm.Article.objects.filter(category__id=qd["id"]).values())
|
|
|
- if qd["name"]==u"头条通知":
|
|
|
- qd["type"] = "notice"
|
|
|
- qd["list"] = list(cm.Article.objects.filter(category__id=qd["id"]).values())
|
|
|
- if "{id}" in qd["path"]:
|
|
|
- artcs = list(cm.Article.objects.filter(category__id=qd["id"]).order_by("order").values())
|
|
|
- aid = artcs[0]["id"] if artcs else 0
|
|
|
- qd["path"] = qd["path"].replace("{id}",str(aid))
|
|
|
- return qdata
|
|
|
-
|
|
|
-
|
|
|
-def get_article_info(request):
|
|
|
- qdata = request.json
|
|
|
- need_params = ["id"]
|
|
|
- mse = ccf.check_params(*need_params,**qdata)
|
|
|
- if mse:
|
|
|
- raise ce.TipException(mse)
|
|
|
- id = qdata.get("id")
|
|
|
- data = list(cm.Article.objects.filter(id=id).values())
|
|
|
- data = data[0] if data else {}
|
|
|
- data["imgs"] = json.loads(data["imgs"]) if data["imgs"] else []
|
|
|
- return data
|
|
|
-
|
|
|
-def get_intro_info(request):
|
|
|
- """考场和联系我们专用
|
|
|
+ cur_rank = 1
|
|
|
+ records = list(records_set.values())[:10]
|
|
|
+ else:
|
|
|
+ cur_rank = 0
|
|
|
+ records = []
|
|
|
+ for item in records:
|
|
|
+ today_stock = json.loads(item["today_stock"]) if item["today_stock"] else []
|
|
|
+ today_stock = filter(lambda x:x["name"],today_stock)
|
|
|
+ item["today_stock"] = today_stock
|
|
|
+ item["today_stock_img"] = json.loads(item["today_stock_img"]) if item["today_stock_img"] else []
|
|
|
+ yesterday_stock = json.loads(item["yesterday_stock"]) if item["yesterday_stock"] else []
|
|
|
+ yesterday_stock = filter(lambda x:x["name"],yesterday_stock)
|
|
|
+ item["yesterday_stock"] = yesterday_stock
|
|
|
+ item["yesterday_stock_img"] = json.loads(item["yesterday_stock_img"]) if item["yesterday_stock_img"] else []
|
|
|
+ item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
+ item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
+ ret = {"match_name":match_name,"cur_rank":cur_rank,"records":records}
|
|
|
+
|
|
|
+ return ret
|
|
|
+
|
|
|
+
|
|
|
+def get_player_match_list(request):
|
|
|
+ """选手参赛列表数据
|
|
|
"""
|
|
|
- qdata = request.json
|
|
|
- need_params = ["id"]
|
|
|
- mse = ccf.check_params(*need_params,**qdata)
|
|
|
- if mse:
|
|
|
- raise ce.TipException(mse)
|
|
|
- id = qdata.get("id")
|
|
|
- data = {"id":"1","title":"sfsfd","content":"","ctime":"2020-01-01 00:00:01"}
|
|
|
- data = {"id":1,"title":u"联系我们","phone":"0827-8589102","address":u"巴中市江北车站三楼(体检门诊第一个办公室)","imgs":["https://www.scxjc.club/images/jgjj.png","https://www.scxjc.club/images/jgjj.png"],"content":u"详情...."}
|
|
|
- return data
|
|
|
+ uid = request.user.id
|
|
|
+ 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())
|
|
|
|
|
|
-def get_signup_list(request):
|
|
|
+ return matchs
|
|
|
+
|
|
|
+def get_group_income(match_id,match_group):
|
|
|
"""
|
|
|
"""
|
|
|
- uid = request.user.id
|
|
|
- qset = cm.SignupOrders.objects.filter(user_id=uid).order_by("-id")
|
|
|
- qdata = list(qset.values())
|
|
|
- for qd in qdata:
|
|
|
- try:
|
|
|
- qd["class_name"] = cm.Class.objects.filter(id=qd["class_id"]).first().name
|
|
|
- except:
|
|
|
- qd["class_name"] = ""
|
|
|
- try:
|
|
|
- qd["signup_limit"] = cm.Class.objects.filter(id=qd["class_id"]).first().signup_limit
|
|
|
- except:
|
|
|
- qd["signup_limit"] = 0
|
|
|
- try:
|
|
|
- qd["class_hour"] = cm.Class.objects.filter(id=qd["class_id"]).first().class_hour
|
|
|
- except:
|
|
|
- qd["class_hour"] = 0
|
|
|
- qd["signup_count"] = cm.SignupOrders.objects.filter(class_id=qd["class_id"]).count()
|
|
|
- return qdata
|
|
|
-
|
|
|
-def get_signup_info(request):
|
|
|
- qdata = request.json
|
|
|
- need_params = ["id"]
|
|
|
- mse = ccf.check_params(*need_params,**qdata)
|
|
|
- if mse:
|
|
|
- raise ce.TipException(mse)
|
|
|
- id = qdata.get("id")
|
|
|
- data = list(cm.SignupOrders.objects.filter(id=id).values())
|
|
|
- data = data[0] if data else {}
|
|
|
- data["device_cats"] = json.loads(data["device_cats"]) if data["device_cats"] else []
|
|
|
+ data = []
|
|
|
+ player_ids = list(cm.Player.objects.filter(match_group=match_group).values_list("id",flat=True))
|
|
|
+ for player_id in player_ids:
|
|
|
+ today_record = cm.PlayerRecord.objects.filter(match_id=match_id,match_group=match_group,player_id=player_id).order_by("-stock_date").first()
|
|
|
+ if today_record:
|
|
|
+ data.append(today_record.total_income)
|
|
|
+ data = sorted(data,key=lambda x:x,reverse=True)
|
|
|
return data
|
|
|
|
|
|
-def get_class_list(request):
|
|
|
- """
|
|
|
+
|
|
|
+def get_player_match_detail(request):
|
|
|
+ """选手参赛详情数据
|
|
|
"""
|
|
|
qdata = request.json
|
|
|
- qset = cm.Class.objects.filter(status=1)
|
|
|
- if qdata.get("subject_item0"):
|
|
|
- qset = qset.filter(subject_item__icontains=qdata.get("subject_item0"))
|
|
|
- if qdata.get("subject_item0") and qdata.get("subject_item1"):
|
|
|
- subject_item = u"{}|{}".format(qdata.get("subject_item0"),qdata.get("subject_item1"))
|
|
|
- qset = qset.filter(subject_item__icontains=subject_item)
|
|
|
- if qdata.get("subject_item0") and qdata.get("subject_item1") and qdata.get("subject_item2"):
|
|
|
- subject_item = u"{}|{}|{}".format(qdata.get("subject_item0"),qdata.get("subject_item1"),qdata.get("subject_item2"))
|
|
|
- qset = qset.filter(subject_item__icontains=subject_item)
|
|
|
- qdata = list(qset.values())
|
|
|
- dct = {}
|
|
|
- data = []
|
|
|
- if request.json.get("signup"):
|
|
|
- for qd in qdata:
|
|
|
- qd["price_new"] = 1000.00
|
|
|
- qd["price_re"] = 1000.00
|
|
|
- qd["price_change"] = 2000.00
|
|
|
- qd["class_time"] = qd["signup_time"]
|
|
|
- qd["thresh_count"] = qd["signup_limit"]
|
|
|
- qd["signuped_count"] = cm.SignupOrders.objects.filter(class_id=qd["id"]).count()
|
|
|
- data.append(qd)
|
|
|
+ player_id = request.player.id
|
|
|
+ match_id = qdata.get("id")
|
|
|
+ record_id = qdata.get("record_id")
|
|
|
+ if record_id:
|
|
|
+ records_set = cm.PlayerRecord.objects.filter(id=record_id)
|
|
|
+ match_id = records_set.first().match_id
|
|
|
+ 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:
|
|
|
+ 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()
|
|
|
+ groups = list(cm.MatchGroup.objects.filter(match_id=match_id).values_list("name",flat=True))
|
|
|
+ match["groups"] = groups
|
|
|
+ if records_set:
|
|
|
+ today_record = records_set.values().first()
|
|
|
+ records = list(records_set.values())[:10]
|
|
|
else:
|
|
|
- for qd in qdata:
|
|
|
- qd["price_new"] = 1000.00
|
|
|
- qd["price_re"] = 1000.00
|
|
|
- qd["price_change"] = 2000.00
|
|
|
- qd["class_time"] = qd["signup_time"]
|
|
|
- qd["thresh_count"] = qd["signup_limit"]
|
|
|
- qd["signuped_count"] = cm.SignupOrders.objects.filter(class_id=qd["id"]).count()
|
|
|
- if dct.has_key(qd["subject_name"]):
|
|
|
- dct[qd["subject_name"]].append(qd)
|
|
|
+ today_record = {}
|
|
|
+ records = []
|
|
|
+
|
|
|
+ for item in records:
|
|
|
+ item["today_stock"] = json.loads(item["today_stock"]) if item["today_stock"] else []
|
|
|
+ item["today_stock_img"] = json.loads(item["today_stock_img"]) if item["today_stock_img"] else []
|
|
|
+ item["yesterday_stock"] = json.loads(item["yesterday_stock"]) if item["yesterday_stock"] else []
|
|
|
+ item["yesterday_stock_img"] = json.loads(item["yesterday_stock_img"]) if item["yesterday_stock_img"] else []
|
|
|
+ item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
+ item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
+ if today_record:
|
|
|
+ group_income = get_group_income(today_record["match_id"],today_record["match_group"])
|
|
|
+ group_rank = group_income.index(today_record["total_income"])+1
|
|
|
+ today_record["group_rank"] = group_rank
|
|
|
+
|
|
|
+ today_record["today_income"] = "{}%".format(today_record["today_income"]*100)
|
|
|
+ today_record["total_income"] = "{}%".format(today_record["total_income"]*100)
|
|
|
+ today_record["match_group_name"] = cm.MatchGroup.objects.filter(id=today_record["match_group"]).first().name
|
|
|
+ match["groups"] = [today_record["match_group_name"]] if today_record else []
|
|
|
+ records = sorted(records,key=lambda x:x["stock_date"],reverse=True)
|
|
|
+ ret = {"match":match,"today_record":today_record,"records":records}
|
|
|
+
|
|
|
+ return ret
|
|
|
+
|
|
|
+
|
|
|
+def get_rank_list(request):
|
|
|
+ """排名列表
|
|
|
+ """
|
|
|
+ qdata = request.json
|
|
|
+ player_id = request.player.id
|
|
|
+ match_id = request.player.match_id
|
|
|
+ match = cm.Match.objects.filter(id=match_id).values().first()
|
|
|
+
|
|
|
+ groups = list(cm.MatchGroup.objects.filter(match_id=match_id).values())
|
|
|
+
|
|
|
+ for item in groups:
|
|
|
+ new_players = []
|
|
|
+ players = list(cm.Player.objects.filter(match_id=match_id,match_group=item["id"]).values())
|
|
|
+ for player in players:
|
|
|
+ user_id = player["user_id"]
|
|
|
+ user = cm.UserInfo.objects.filter(id=user_id).first()
|
|
|
+ username = user.username if user else ""
|
|
|
+ records_set = cm.PlayerRecord.objects.filter(player_id=player["id"],match_id=match_id,match_group=item["id"]).order_by("-stock_date")
|
|
|
+ if records_set:
|
|
|
+ today_record = records_set.values().first()
|
|
|
else:
|
|
|
- dct[qd["subject_name"]] = [qd]
|
|
|
- for k,v in dct.items():
|
|
|
- data.append({"type":k,"classes":v})
|
|
|
- return data
|
|
|
-
|
|
|
-
|
|
|
-def get_training_list(request):
|
|
|
+ today_record = {}
|
|
|
+ if today_record:
|
|
|
+ player.update(today_record)
|
|
|
+ player["username"] = username
|
|
|
+ player["total_income"] = "{}%".format(today_record["total_income"]*100)
|
|
|
+ #计算分组排名
|
|
|
+ group_income = get_group_income(today_record["match_id"],today_record["match_group"])
|
|
|
+ if today_record["total_income"] in group_income:
|
|
|
+ group_rank = group_income.index(today_record["total_income"])+1
|
|
|
+ else:
|
|
|
+ group_rank = 1
|
|
|
+ player["group_rank"] = group_rank
|
|
|
+ player["fund"] = round(player["fund"],2)
|
|
|
+ player["init_fund"] = round(player["init_fund"],2)
|
|
|
+ player["today_fund"] = round(player["today_fund"],2)
|
|
|
+ new_players.append(player)
|
|
|
+ new_players = sorted(new_players,key=lambda x:x["group_rank"])
|
|
|
+ item["players"] = new_players[:3]
|
|
|
+
|
|
|
+ ret = {"match":match,"groups":groups}
|
|
|
+
|
|
|
+ return ret
|
|
|
+
|
|
|
+
|
|
|
+def get_group_rank_list(request):
|
|
|
+ """排名列表
|
|
|
"""
|
|
|
+ qdata = request.json
|
|
|
+ group_id = qdata.get("id")
|
|
|
+
|
|
|
+ player_id = request.player.id
|
|
|
+ match_id = request.player.match_id
|
|
|
+ match = cm.Match.objects.filter(id=match_id).values().first()
|
|
|
+
|
|
|
+ group = cm.MatchGroup.objects.filter(id=group_id).values().first()
|
|
|
+
|
|
|
+ players = list(cm.Player.objects.filter(match_id=match_id,match_group=group_id).values())
|
|
|
+ new_players = []
|
|
|
+ for player in players:
|
|
|
+ user_id = player["user_id"]
|
|
|
+ user = cm.UserInfo.objects.filter(id=user_id).first()
|
|
|
+ username = user.username if user else ""
|
|
|
+ records_set = cm.PlayerRecord.objects.filter(player_id=player["id"],match_id=match_id,match_group=group_id).order_by("-stock_date")
|
|
|
+ if records_set:
|
|
|
+ today_record = records_set.values().first()
|
|
|
+ else:
|
|
|
+ today_record = {}
|
|
|
+ if today_record:
|
|
|
+ player.update(today_record)
|
|
|
+ group_income = get_group_income(today_record["match_id"],today_record["match_group"])
|
|
|
+ group_rank = group_income.index(today_record["total_income"])+1
|
|
|
+ player["group_rank"] = group_rank
|
|
|
+ player["username"] = username
|
|
|
+ player["total_income"] = "{}%".format(player["total_income"]*100)
|
|
|
+ player["fund"] = round(player["fund"],2)
|
|
|
+ player["init_fund"] = round(player["init_fund"],2)
|
|
|
+ player["today_fund"] = round(player["today_fund"],2)
|
|
|
+ new_players.append(player)
|
|
|
+ new_players = sorted(new_players,key=lambda x:x["group_rank"])
|
|
|
+ ret = {"group":group,"players":new_players}
|
|
|
+
|
|
|
+ return ret
|
|
|
+
|
|
|
+
|
|
|
+def get_player_match_records(request):
|
|
|
+ """选手参赛每日持股
|
|
|
"""
|
|
|
- #获取视频信息
|
|
|
- uid = request.user.id
|
|
|
- #获取已报科目
|
|
|
- subject_ids = list(cm.SignupOrders.objects.filter(order_status=2,user_id=uid).values_list("subject_id",flat=True))
|
|
|
- if subject_ids:
|
|
|
- vset = cm.Videos.objects.filter(subject_id__in=subject_ids)
|
|
|
- videos = list(vset.values())
|
|
|
- for video in videos:
|
|
|
- video["class_hour"] = 20
|
|
|
- video["total_time"] = "45:32"
|
|
|
- video["finished_time"] = "55:32"
|
|
|
- video["image"] = video["img"]
|
|
|
- video["status"] = 1
|
|
|
- #获取试卷信息
|
|
|
- pset = cm.Papers.objects.filter(subject_id__in=subject_ids)
|
|
|
- papers = list(pset.values())
|
|
|
- for paper in papers:
|
|
|
- sub = cm.Subject.objects.filter(id=paper["subject_id"]).first()
|
|
|
- class_hour = sub.class_hour if sub else 0
|
|
|
- paper["class_hour"] = class_hour
|
|
|
- paper["time_limit"] = paper["total_time"]
|
|
|
- paper["full_mark"] = paper["total_score"]
|
|
|
- paper["mark"] = 0
|
|
|
- paper["status"] = 1
|
|
|
+ qdata = request.json
|
|
|
+ player_id = request.player.id
|
|
|
+ match_id = qdata.get("id")
|
|
|
+ q_player_id = qdata.get("player_id")
|
|
|
+ if q_player_id:
|
|
|
+ player_id = q_player_id
|
|
|
+ page = int(qdata.get("page",0))
|
|
|
+ page_size = int(qdata.get("page_size",20))
|
|
|
+
|
|
|
+ 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:
|
|
|
+ today_stock = json.loads(item["today_stock"]) if item["today_stock"] else []
|
|
|
+ today_stock = filter(lambda x:x["name"],today_stock)
|
|
|
+ item["today_stock"] = today_stock
|
|
|
+ item["today_stock_img"] = json.loads(item["today_stock_img"]) if item["today_stock_img"] else []
|
|
|
+ yesterday_stock = json.loads(item["yesterday_stock"]) if item["yesterday_stock"] else []
|
|
|
+ yesterday_stock = filter(lambda x:x["name"],yesterday_stock)
|
|
|
+ item["yesterday_stock"] = yesterday_stock
|
|
|
+ item["yesterday_stock_img"] = json.loads(item["yesterday_stock_img"]) if item["yesterday_stock_img"] else []
|
|
|
+ item["today_income"] = "{}%".format(item["today_income"]*100)
|
|
|
+ item["total_income"] = "{}%".format(item["total_income"]*100)
|
|
|
+ if page and page_size:
|
|
|
+ total,data = ccf.get_page_list(data,page,page_size)
|
|
|
+ return total,data
|
|
|
else:
|
|
|
- papers = []
|
|
|
- videos = []
|
|
|
- data = {"papers":papers,"videos":videos}
|
|
|
- return data
|
|
|
+ return len(data),data
|
|
|
|
|
|
|
|
|
-def get_paper_info(request):
|
|
|
- qdata = request.json
|
|
|
- need_params = ["id"]
|
|
|
- mse = ccf.check_params(*need_params,**qdata)
|
|
|
- if mse:
|
|
|
- raise ce.TipException(mse)
|
|
|
- id = qdata.get("id")
|
|
|
- paperset = cm.Papers.objects.filter(id=id)
|
|
|
- paper = paperset.values().first() if paperset else {}
|
|
|
- paper["full_mark"] = paper.get("total_score")
|
|
|
- paper["time_limit"] = paper.get("total_time")
|
|
|
- questions = list(paperset.first().questions.all().values())
|
|
|
- for que in questions:
|
|
|
- que["options"] = filter(lambda x:x,que["options"].split(" "))
|
|
|
- paper["questions"] = questions
|
|
|
- return paper
|
|
|
-
|
|
|
-
|
|
|
-def add_signup(request):
|
|
|
+def add_model(cls,**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
- uid = request.user.id
|
|
|
- qdata = request.json
|
|
|
- need_params = ["name","sex","idno","education","phone",
|
|
|
- "train_type","receive_card","price"]
|
|
|
- mse = ccf.check_params(*need_params,**qdata)
|
|
|
- if mse:
|
|
|
- raise ce.TipException(mse)
|
|
|
- need_params.extend(["company","class_id","remark","idnoimg_face","idnoimg_back",
|
|
|
- "halfbody_img","education_img","oldcard_img","area","address","subject_id","subject_item","device_cats"])
|
|
|
- vals = ccf.get_need_params(*need_params,**qdata)
|
|
|
- if vals.get("device_cats"):
|
|
|
- vals["device_cats"] = json.dumps(vals["device_cats"])
|
|
|
- vals["cid"] = uid
|
|
|
- vals["user_id"] = uid
|
|
|
- vals["order_status"] = -1
|
|
|
- if vals["class_id"]:
|
|
|
- vals["subject_item"] = cm.Class.objects.filter(id=vals["class_id"]).first().subject_item
|
|
|
- else:
|
|
|
- vals["subject_item"] = vals["subject_item"]
|
|
|
- obj = cm.SignupOrders.objects.create(**vals)
|
|
|
- #更新用户信息
|
|
|
- userinfo = cm.UserInfo.objects.filter(id=uid).first().userinfo
|
|
|
- userinfo = json.loads(userinfo) if userinfo else {}
|
|
|
- #if userinfo:
|
|
|
- # vals.update(userinfo)
|
|
|
- userinfo.update(vals)
|
|
|
- cm.UserInfo.objects.filter(id=uid).update(userinfo=json.dumps(userinfo))
|
|
|
- return obj.id
|
|
|
+ model_name = re.search(r'.*\.(\w+)View',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ if model_name == "Match":
|
|
|
+ name = kwargs.get("name")
|
|
|
+ if cm.Match.objects.filter(name=name).exists():
|
|
|
+ raise ce.TipException(u"比赛名称重复!")
|
|
|
+ if model_name == "MatchGoup":
|
|
|
+ name = kwargs.get("name")
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ if cm.MatchGroup.objects.filter(name=name,match_id=match_id).exists():
|
|
|
+ raise ce.TipException(u"分组名称重复!")
|
|
|
+
|
|
|
+ if model_name == "Player":
|
|
|
+ user_id = kwargs.get("user_id")
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ if cm.Player.objects.filter(user_id=user_id,match_id=match_id).exists():
|
|
|
+ raise ce.TipException(u"重复添加选手!")
|
|
|
+
|
|
|
+ if model_name == "PlayerRecord":
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ stock_date = kwargs.get("stock_date")
|
|
|
+ today_stock = json.dumps(kwargs.get("today_stock"))
|
|
|
+ today_stock_img = json.dumps(kwargs.get("today_stock_img"))
|
|
|
+ player_id = kwargs.get("player_id")
|
|
|
+ today_fund = float(kwargs.get("today_fund"))
|
|
|
+ is_markt = int(kwargs.get("is_markt",0))
|
|
|
+
|
|
|
+ player = cm.Player.objects.filter(id=player_id).first()
|
|
|
+ user_id = player.user_id
|
|
|
+ init_fund = player.fund
|
|
|
+ user = cm.UserInfo.objects.filter(id=user_id).first()
|
|
|
+ username = user.username
|
|
|
+ usercode = user.usercode
|
|
|
+ match_group = player.match_group
|
|
|
+ match = cm.Match.objects.filter(id=match_id).first()
|
|
|
+ if player.match_status < 1:
|
|
|
+ raise ce.TipException(u"该账号已暂停/退出比赛,如有疑问请联系管理员获取详情信息!")
|
|
|
+ now_date = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
+ if match.end_time < now_date:
|
|
|
+ raise ce.TipException(u"该比赛已结束!")
|
|
|
+
|
|
|
+ yesterday = cm.PlayerRecord.objects.filter(
|
|
|
+ match_id=match_id,player_id=player_id).order_by("-id").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
|
|
|
+ yesterday_stock = ""
|
|
|
+ yesterday_stock_img = ""
|
|
|
+ yesterday_is_markt = 0
|
|
|
+ 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
|
|
|
+ obj.yesterday_stock_img = yesterday_stock_img
|
|
|
+ obj.today_fund = today_fund
|
|
|
+ obj.today_stock = today_stock
|
|
|
+ obj.today_stock_img = today_stock_img
|
|
|
+ obj.user_id = user_id
|
|
|
+ obj.username = username
|
|
|
+ obj.usercode = usercode
|
|
|
+ obj.match_group = match_group
|
|
|
+ obj.is_markt = is_markt
|
|
|
+ obj.yesterday_is_markt = yesterday_is_markt
|
|
|
+ #计算今日和昨日盈亏
|
|
|
+ today_income = (today_fund - yesterday_fund)/float(yesterday_fund)
|
|
|
+ total_income = (today_fund - init_fund)/float(init_fund)
|
|
|
+ obj.today_income = round(today_income,4)
|
|
|
+ obj.total_income = round(total_income,4)
|
|
|
+ if not flag:
|
|
|
+ obj.ctime = datetime.datetime.now()
|
|
|
+ obj.save()
|
|
|
+ #更新排名
|
|
|
+ records_set = cm.PlayerRecord.objects.filter(match_id=match_id).order_by("-total_income")
|
|
|
+ for index,item in enumerate(records_set):
|
|
|
+ item.rank = index+1
|
|
|
+ item.save()
|
|
|
+ return obj.id
|
|
|
+
|
|
|
+
|
|
|
+ obj = model.objects.create(**kwargs)
|
|
|
|
|
|
+ return obj.id
|
|
|
|
|
|
-def update_signup(request):
|
|
|
+def update_model(cls,**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
- uid = request.user.id
|
|
|
- qdata = request.json
|
|
|
- need_params = ["id"]
|
|
|
- mse = ccf.check_params(*need_params,**qdata)
|
|
|
- if mse:
|
|
|
- raise ce.TipException(mse)
|
|
|
- need_params.extend(["name","sex","idno","education","phone","train_type",
|
|
|
- "receive_card","area","price","company","class_id","remark",
|
|
|
- "idnoimg_face","idnoimg_back","halfbody_img","education_img","oldcard_img",
|
|
|
- "subject_item","subject_id","address","device_cats"])
|
|
|
- vals = ccf.get_need_params(*need_params,**qdata)
|
|
|
- if vals.get("device_cats"):
|
|
|
- vals["device_cats"] = json.dumps(vals["device_cats"])
|
|
|
- id = vals.pop("id")
|
|
|
- vals["cid"] = uid
|
|
|
- if vals.get("idnoimg_face") and vals.get("idnoimg_back") and vals.get("halfbody_img"):
|
|
|
- vals["order_status"] = 0
|
|
|
- vals["update_time"] = datetime.datetime.now()
|
|
|
- subject_id = vals.get("subject_id")
|
|
|
- train_type = vals.get("train_type")
|
|
|
- subject_obj = cm.Subject.objects.filter(id=subject_id).first()
|
|
|
- if train_type == u"新办":
|
|
|
- vals["price"] = subject_obj.price_new
|
|
|
- if train_type == u"复审":
|
|
|
- vals["price"] = subject_obj.price_re
|
|
|
- if train_type == u"换证":
|
|
|
- vals["price"] = subject_obj.price_change
|
|
|
- obj = cm.SignupOrders.objects.filter(id=id).update(**vals)
|
|
|
- vals.pop("update_time")
|
|
|
- #更新用户信息
|
|
|
- userinfo = cm.UserInfo.objects.filter(id=uid).first().userinfo
|
|
|
- userinfo = json.loads(userinfo) if userinfo else {}
|
|
|
- #if userinfo:
|
|
|
- # vals.update(userinfo)
|
|
|
- userinfo.update(vals)
|
|
|
- cm.UserInfo.objects.filter(id=uid).update(userinfo=json.dumps(userinfo))
|
|
|
- return obj
|
|
|
-
|
|
|
-
|
|
|
-def get_yrxindex(request):
|
|
|
+ model_name = re.search(r'.*\.(\w+)View',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ id = kwargs.pop("id")
|
|
|
+ rst = model.objects.filter(id=id).update(**kwargs)
|
|
|
+ if model_name == "Match":
|
|
|
+ for item in kwargs.get("groups").split(","):
|
|
|
+ cm.MatchGroup.objects.get_or_create(match_id=obj.id,name=item)
|
|
|
+ return rst
|
|
|
+
|
|
|
+def delete_model(cls,**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
- recs = cm.ClassRoom.objects.all()
|
|
|
- recs = list(recs.values())
|
|
|
- teachers = [{
|
|
|
- "name":u"肖老师",
|
|
|
- "avatar":"肖老师",
|
|
|
- "lessons_count":2,
|
|
|
- "students":200
|
|
|
- }]
|
|
|
- data = {
|
|
|
- "rec":recs,
|
|
|
- "lessons":recs,
|
|
|
- "teachers":teachers
|
|
|
- }
|
|
|
- return data
|
|
|
+ model_name = re.search(r'.*\.(\w+)View',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ ids = str(kwargs.get("id")).split(",")
|
|
|
+ rst = model.objects.filter(id__in=ids).delete()
|
|
|
+ return ids
|
|
|
|
|
|
|
|
|
-def get_yrxlist(request):
|
|
|
+def get_search_list(cls,**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
- recs = cm.ClassRoom.objects.all()
|
|
|
- recs = list(recs.values())
|
|
|
- teachers = [{
|
|
|
- "name":u"肖老师",
|
|
|
- "avatar":"肖老师",
|
|
|
- "lessons_count":2,
|
|
|
- "students":200
|
|
|
- }]
|
|
|
- data = {
|
|
|
- "rec":recs,
|
|
|
- "lessons":recs,
|
|
|
- "teachers":teachers
|
|
|
- }
|
|
|
- return recs
|
|
|
-
|
|
|
-
|
|
|
-def get_yrxdetail(request):
|
|
|
- qdata = request.json
|
|
|
- need_params = ["id"]
|
|
|
- mse = ccf.check_params(*need_params,**qdata)
|
|
|
- if mse:
|
|
|
- raise ce.TipException(mse)
|
|
|
- id = qdata.get("id")
|
|
|
- data = list(cm.ClassRoom.objects.filter(id=id).values())
|
|
|
- data = data[0] if data else {}
|
|
|
- if data:
|
|
|
- lessons = list(cm.Lessons.objects.filter(classroom_id=id).values())
|
|
|
- data["lessons"] = lessons
|
|
|
+ model_name = re.search(r'.*\.(\w+)SearchView',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ qset = model.objects.all()
|
|
|
+ if kwargs.get("name"):
|
|
|
+ qset = qset.filter(name__icontains=kwargs.get("name"))
|
|
|
+ if model_name == "Player":
|
|
|
+ data = list(qset.values("id","username"))
|
|
|
+ if model_name == "Stock":
|
|
|
+ data = list(qset.values("id","name","code"))
|
|
|
+ for item in data:
|
|
|
+ item["label"] = "%s(%s)" % (item["name"],item["code"])
|
|
|
+ else:
|
|
|
+ data = list(qset.values("id","name"))
|
|
|
return data
|
|
|
|
|
|
-
|
|
|
-def get_subject_tree(sub=None,data=None):
|
|
|
+def get_detail_info(cls,**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
- roots = list(cm.Subject.objects.filter(Q(pid=0)|Q(pid__isnull=True)).values())
|
|
|
- for citem in roots:
|
|
|
- citem["device_cats"] = json.loads(citem["device_cats"]) if citem["device_cats"] else []
|
|
|
- for rn in roots:
|
|
|
- children = list(cm.Subject.objects.filter(pid=rn["id"]).values())
|
|
|
- for citem in children:
|
|
|
- citem["device_cats"] = json.loads(citem["device_cats"]) if citem["device_cats"] else []
|
|
|
- rn["children"] = children
|
|
|
- for rnn in rn["children"]:
|
|
|
- children = list(cm.Subject.objects.filter(pid=rnn["id"]).values())
|
|
|
- for citem in children:
|
|
|
- citem["device_cats"] = json.loads(citem["device_cats"]) if citem["device_cats"] else []
|
|
|
- rnn["children"] = children
|
|
|
- return roots
|
|
|
-
|
|
|
-
|
|
|
-def get_subjectitem_tree(request):
|
|
|
+ model_name = re.search(r'.*\.(\w+)View',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ id = kwargs.get("id")
|
|
|
+ rst = list(model.objects.filter(id=id).values())
|
|
|
+ rst = rst[0] if rst else {}
|
|
|
+ if model_name == "PlayerRecord":
|
|
|
+ group_income = get_group_income(rst["match_id"],rst["match_group"])
|
|
|
+ if rst["total_income"] in group_income:
|
|
|
+ group_rank = group_income.index(rst["total_income"])+1
|
|
|
+ else:
|
|
|
+ group_rank = 1
|
|
|
+
|
|
|
+ rst["group_rank"] = group_rank
|
|
|
+ rst["match_group"] = cm.MatchGroup.objects.filter(id=rst["match_group"]).first().name
|
|
|
+ today_stock = json.loads(rst["today_stock"]) if rst["today_stock"] else []
|
|
|
+ today_stock = filter(lambda x:x["fund"] and x["name"],today_stock)
|
|
|
+ rst["today_stock"] = today_stock
|
|
|
+ today_stock_img = json.loads(rst["today_stock_img"]) if rst["today_stock_img"] else []
|
|
|
+ rst["today_stock_img"] = today_stock_img
|
|
|
+
|
|
|
+ yesterday_stock = json.loads(rst["yesterday_stock"]) if rst["yesterday_stock"] else []
|
|
|
+ yesterday_stock = filter(lambda x:x["fund"] and x["name"],yesterday_stock)
|
|
|
+ rst["yesterday_stock"] = yesterday_stock
|
|
|
+
|
|
|
+ yesterday_stock_img = json.loads(rst["yesterday_stock_img"]) if rst["yesterday_stock_img"] else []
|
|
|
+ rst["yesterday_stock_img"] = yesterday_stock_img
|
|
|
+
|
|
|
+ rst["today_income"] = "{}%".format(rst["today_income"]*100)
|
|
|
+ rst["total_income"] = "{}%".format(rst["total_income"]*100)
|
|
|
+ return rst
|
|
|
+
|
|
|
+def get_list_info(cls,**kwargs):
|
|
|
"""
|
|
|
"""
|
|
|
- data = get_subject_tree()
|
|
|
- return data
|
|
|
-
|
|
|
+ model_name = re.search(r'.*\.(\w+)ListView',str(cls.__class__)).groups()[0]
|
|
|
+ model = getattr(cm,model_name)
|
|
|
+ qset = model.objects.all()
|
|
|
+ if kwargs.get("name"):
|
|
|
+ qset = qset.filter(name__icontains=kwargs.get("name"))
|
|
|
+ if model_name == "UserInfo":
|
|
|
+ if kwargs.get("username"):
|
|
|
+ qset = qset.filter(username__icontains=kwargs.get("username"))
|
|
|
+ if kwargs.get("usercode"):
|
|
|
+ qset = qset.filter(usercode=kwargs.get("usercode"))
|
|
|
+
|
|
|
+ data = list(qset.order_by("-id").values())
|
|
|
+ page = int(kwargs.get("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)
|
|
|
+ if model_name == "Player":
|
|
|
+ for item in data:
|
|
|
+ user = cm.UserInfo.objects.filter(id=item["user_id"]).first()
|
|
|
+ match = cm.Match.objects.filter(id=item["match_id"]).first()
|
|
|
+ print user
|
|
|
+ item["username"] = user.username
|
|
|
+ item["usercode"] = user.usercode
|
|
|
+ item["match_name"] = match.name if match else ""
|
|
|
+ return (total,data)
|
|
|
+ else:
|
|
|
+ return len(data),data
|
|
|
|
|
|
-def post_paper(request):
|
|
|
- qdata = request.json
|
|
|
- need_params = ["paper_id","questions"]
|
|
|
- mse = ccf.check_params(*need_params,**qdata)
|
|
|
- if mse:
|
|
|
- raise ce.TipException(mse)
|
|
|
- paper_id = qdata.get("paper_id")
|
|
|
- user_id = request.user.id
|
|
|
- title = cm.Papers.objects.filter(id=paper_id).first().title
|
|
|
- total_score = 0
|
|
|
- questions = qdata.get("questions")
|
|
|
- for ans in questions:
|
|
|
- que = cm.Questions.objects.filter(id=ans["id"]).first()
|
|
|
- std_ans = que.answer
|
|
|
- std_score = que.score if que.score else 0
|
|
|
- if ans["answer"] == std_ans:
|
|
|
- total_score += std_score
|
|
|
- obj,flag = cm.PostPapers.objects.get_or_create(
|
|
|
- title=title,
|
|
|
- paper_id=paper_id,
|
|
|
- user_id=user_id,
|
|
|
- )
|
|
|
- obj.questions = json.dumps(questions)
|
|
|
- obj.score = total_score
|
|
|
- obj.save()
|
|
|
- return total_score
|
|
|
+ return rst
|
|
|
|
|
|
|
|
|
-def save_video_time(request):
|
|
|
- qdata = request.json
|
|
|
- need_params = ["video_id","time"]
|
|
|
- mse = ccf.check_params(*need_params,**qdata)
|
|
|
- if mse:
|
|
|
- raise ce.TipException(mse)
|
|
|
- paper_id = qdata.get("paper_id")
|
|
|
- return True
|
|
|
-
|
|
|
-
|
|
|
-def get_docs_list(request):
|
|
|
- data = [{
|
|
|
- "name":u"报名表格",
|
|
|
- "url":u"https://www.scxjc.club/test.docx"
|
|
|
- }]
|
|
|
- qset = cm.Docs.objects.all().order_by("-id")
|
|
|
- data = list(qset.values())
|
|
|
- return data
|
|
|
-
|
|
|
-def do_signup_pay(request):
|
|
|
- qdata = request.json
|
|
|
- need_params = ["signup_id","total_fee"]
|
|
|
- mse = ccf.check_params(*need_params,**qdata)
|
|
|
- if mse:
|
|
|
- raise ce.TipException(mse)
|
|
|
- bill_mat = qdata.get("bill_mat")
|
|
|
- bill_type = qdata.get("bill_type")
|
|
|
- bill_no = qdata.get("bill_no")
|
|
|
- bill_name = qdata.get("bill_name")
|
|
|
- signup_order = cm.SignupOrders.objects.filter(id=qdata.get("signup_id")).first()
|
|
|
- if not signup_order:
|
|
|
- raise ce.TipException(u"订单不存在!")
|
|
|
- signup_order.bill_mat = bill_mat
|
|
|
- signup_order.bill_type = bill_type
|
|
|
- signup_order.bill_no = bill_no
|
|
|
- signup_order.bill_name = bill_name
|
|
|
- if not signup_order.out_trade_no:
|
|
|
- out_trade_no = str(qdata.get("signup_id"))+str(int(time.time()))
|
|
|
- signup_order.out_trade_no = out_trade_no
|
|
|
- else:
|
|
|
- out_trade_no = signup_order.out_trade_no
|
|
|
- signup_order.save()
|
|
|
- total_fee = str(qdata.get("total_fee")*100)
|
|
|
- openid = request.user.openid
|
|
|
- prepayinfo = wxpay.get_wx_unifiedorder(out_trade_no,total_fee,openid)
|
|
|
- prepayinfo["key"] = wxpay.WxPayConf_pub.KEY
|
|
|
- return prepayinfo
|
|
|
-
|
|
|
-def do_wxpay_notify(request):
|
|
|
- qdata = request.json
|
|
|
- flag,res = wxpay.check_notify_valid(request.body)
|
|
|
- if flag:
|
|
|
- out_trade_no = res.get("out_trade_no")
|
|
|
- transaction_id = res.get("transaction_id")
|
|
|
- pay_time = res.get("time_end")
|
|
|
- sorder = cm.SignupOrders.objects.filter(out_trade_no=out_trade_no).first()
|
|
|
- if sorder and not sorder.transaction_id:
|
|
|
- now = datetime.datetime.now()
|
|
|
- cm.SignupOrders.objects.filter(out_trade_no=out_trade_no)\
|
|
|
- .update(order_status=2,update_time=now,pay_status=1,pay_time=pay_time,transaction_id=transaction_id)
|
|
|
- #发送支付成功通知
|
|
|
- from utils.aliyun_sms import send_pay_notice
|
|
|
- import common.common_notice as cn
|
|
|
- phone = sorder.phone if sorder else None
|
|
|
- transaction_id = sorder.transaction_id
|
|
|
- user_id = sorder.user_id
|
|
|
- if phone and user_id and not transaction_id:
|
|
|
- send_pay_notice(phone)
|
|
|
- cn.send_pay_notice(user_id)
|
|
|
- return True
|
|
|
- return False
|
|
|
-
|
|
|
-def addText(img,orgpath,string,path,point=(100,100),size=32):
|
|
|
- draw = ImageDraw.Draw(img)
|
|
|
- fontpath = os.path.join(settings.BASE_DIR,"templates/font/simsun.ttc")
|
|
|
- font = ImageFont.truetype(fontpath, size,encoding="unic")
|
|
|
- draw.text(point,string,fill='black',font=font)
|
|
|
- img.save(path)
|
|
|
-
|
|
|
-def gen_classhour(request):
|
|
|
- """生成学时证明
|
|
|
+def add_player_record_single(**kwargs):
|
|
|
+ """用户单独上传数据
|
|
|
"""
|
|
|
- uid = request.user.id
|
|
|
- qdata = request.json
|
|
|
- signup_id = qdata.get("signup_id")
|
|
|
- userinfo = json.loads(request.user.userinfo) if request.user.userinfo else {}
|
|
|
- realname = json.loads(request.user.userinfo).get("name") if request.user.userinfo else ""
|
|
|
- subject_item = userinfo.get("subject_item")
|
|
|
- subject_item0 = userinfo.get("subject_item").split("|")[0]
|
|
|
- subject_item1 = userinfo.get("subject_item").split("|")[1]
|
|
|
- subject_item2 = userinfo.get("subject_item").split("|")[2]
|
|
|
- train_type = userinfo.get("train_type")
|
|
|
- name = userinfo.get("name")
|
|
|
- root_target = os.path.join(settings.BASE_DIR,"../static/upload")
|
|
|
- root = os.path.join(settings.BASE_DIR,"templates")
|
|
|
- class_hour_tpl = os.path.join(root,"classhour.png")
|
|
|
- class_hour_file = os.path.join(root_target,str(int(time.time()))+"classhour{}.png".format(uid))
|
|
|
- signup_order = cm.SignupOrders.objects.filter(id=signup_id).first()
|
|
|
- subject = cm.Subject.objects.filter(id=signup_order.subject_id).first()
|
|
|
- if train_type == u"新办":
|
|
|
- total_classhour = subject.class_hour
|
|
|
- elif train_type == u"复审":
|
|
|
- total_classhour = subject.update_class_hour
|
|
|
+ usercode = kwargs.get("usercode")
|
|
|
+ match_id = kwargs.get("match_id")
|
|
|
+ if not cm.Player.objects.filter(usercode=usercode,match_id=match_id).exists():
|
|
|
+ raise ce.TipException(u"用户代码错误")
|
|
|
+ stock_date = kwargs.get("stock_date")
|
|
|
+ today_stock = json.dumps(kwargs.get("today_stock"))
|
|
|
+ today_stock_img = json.dumps(kwargs.get("today_stock_img"))
|
|
|
+ today_fund = float(kwargs.get("today_fund"))
|
|
|
+ is_markt = int(kwargs.get("is_markt",0))
|
|
|
+
|
|
|
+ player = cm.Player.objects.filter(usercode=usercode,match_id=match_id).first()
|
|
|
+ player_id = player.id
|
|
|
+ user_id = player.user_id
|
|
|
+ init_fund = player.fund
|
|
|
+ user = cm.UserInfo.objects.filter(id=user_id).first()
|
|
|
+ username = user.username
|
|
|
+ usercode = user.usercode
|
|
|
+ match_group = player.match_group
|
|
|
+ match = cm.Match.objects.filter(id=match_id).first()
|
|
|
+
|
|
|
+ if player.match_status < 1:
|
|
|
+ raise ce.TipException(u"该账号已暂停/退出比赛,如有疑问请联系管理员获取详情信息!")
|
|
|
+ now_date = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
+ if match.end_time < now_date:
|
|
|
+ raise ce.TipException(u"该比赛已结束!")
|
|
|
+
|
|
|
+ yesterday = cm.PlayerRecord.objects.filter(
|
|
|
+ match_id=match_id,player_id=player_id).order_by("-id").first()
|
|
|
+ if yesterday:
|
|
|
+ yesterday_fund = yesterday.today_fund
|
|
|
+ yesterday_stock = yesterday.today_stock
|
|
|
+ yesterday_stock_img = yesterday.today_stock_img
|
|
|
else:
|
|
|
- total_classhour = subject.change_class_hour
|
|
|
- #
|
|
|
- img = Image.open(class_hour_tpl)
|
|
|
- addText(img,class_hour_tpl,unicode("巴中逸沣安全培训学时证明","utf-8"),class_hour_file,(160,65),24)
|
|
|
- addText(img,class_hour_tpl,unicode("姓名:{}".format(name),"utf-8"),class_hour_file,(80,100),20)
|
|
|
- addText(img,class_hour_tpl,unicode("工种:{}".format(subject_item0),"utf-8"),class_hour_file,(80,130),20)
|
|
|
- addText(img,class_hour_tpl,unicode("操作类型:{}".format(subject_item1),"utf-8"),class_hour_file,(80,160),20)
|
|
|
- addText(img,class_hour_tpl,unicode("准操项目:{}".format(subject_item2),"utf-8"),class_hour_file,(80,190),20)
|
|
|
- addText(img,class_hour_tpl,unicode("培训类型:{}".format(train_type),"utf-8"),class_hour_file,(80,220),20)
|
|
|
- addText(img,class_hour_tpl,unicode("总学时:{}".format(total_classhour),"utf-8"),class_hour_file,(80,250),20)
|
|
|
- addText(img,class_hour_tpl,unicode("已完成学时:{}".format(total_classhour),"utf-8"),class_hour_file,(80,280),20)
|
|
|
- #addText(class_hour_tpl,"请提供学时证明内容",class_hour_file)
|
|
|
- url = settings.HOST+"/upload" + class_hour_file.replace(root_target,"")
|
|
|
- cm.SignupOrders.objects.filter(id=signup_id).update(classhour_cert_url=url)
|
|
|
- return url
|
|
|
-
|
|
|
-
|
|
|
-def get_classhour_card(request):
|
|
|
- """获取学时证明
|
|
|
- """
|
|
|
- uid = request.user.id
|
|
|
- sorders = cm.SignupOrders.objects.filter(user_id=uid,classhour_cert_url__isnull=False)
|
|
|
- classhour_cards = list(sorders.values_list("classhour_cert_url",flat=True))
|
|
|
- classhour_cards = [{"url":x} for x in classhour_cards]
|
|
|
- return classhour_cards
|
|
|
+ yesterday_fund = init_fund
|
|
|
+ yesterday_stock = ""
|
|
|
+ yesterday_stock_img = ""
|
|
|
+ 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
|
|
|
+ obj.yesterday_stock_img = yesterday_stock_img
|
|
|
+ obj.today_fund = today_fund
|
|
|
+ obj.today_stock = today_stock
|
|
|
+ obj.today_stock_img = today_stock_img
|
|
|
+ obj.user_id = user_id
|
|
|
+ obj.username = username
|
|
|
+ obj.usercode = usercode
|
|
|
+ obj.match_group = match_group
|
|
|
+ obj.is_markt = is_markt
|
|
|
+ #计算今日和昨日盈亏
|
|
|
+ today_income = (today_fund - yesterday_fund)/float(yesterday_fund)
|
|
|
+ total_income = (today_fund - init_fund)/float(init_fund)
|
|
|
+ obj.today_income = round(today_income,4)
|
|
|
+ obj.total_income = round(total_income,4)
|
|
|
+ if not flag:
|
|
|
+ obj.ctime = datetime.datetime.now()
|
|
|
+ obj.save()
|
|
|
+ #更新排名
|
|
|
+ records_set = cm.PlayerRecord.objects.filter(match_id=match_id).order_by("-total_income")
|
|
|
+ for index,item in enumerate(records_set):
|
|
|
+ item.rank = index+1
|
|
|
+ item.save()
|
|
|
+ return obj.id
|
|
|
|
|
|
-def get_notice_list(request):
|
|
|
+
|
|
|
+def get_single_match_info(match_id):
|
|
|
"""
|
|
|
"""
|
|
|
- uid = request.user.id
|
|
|
- #uid = 21
|
|
|
- qset = cm.SysNotice.objects.filter(to=uid).order_by("-id")
|
|
|
- data = list(qset.values())
|
|
|
- return data
|
|
|
+ if not match_id:
|
|
|
+ match = cm.Match.objects.all().order_by("-id").values().first()
|
|
|
+ else:
|
|
|
+ match = cm.Match.objects.filter(id=match_id).values().first()
|
|
|
+ now_date = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
+ return now_date,match
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|