|
|
@@ -1,13 +1,17 @@
|
|
|
-#coding=utf-8
|
|
|
+# coding=utf-8
|
|
|
'''
|
|
|
'''
|
|
|
+import os
|
|
|
import json,time
|
|
|
from django.db import transaction
|
|
|
+from django.db.models import Q
|
|
|
import common.models as cm
|
|
|
import common.error_info as ce
|
|
|
import common.common_functions as ccf
|
|
|
import common.common_control as ccc
|
|
|
import wzhifuSDK as wxpay
|
|
|
+from django.conf import settings
|
|
|
+from PIL import Image,ImageDraw,ImageFont
|
|
|
|
|
|
def get_index_data(request):
|
|
|
"""
|
|
|
@@ -39,6 +43,7 @@ def get_article_info(request):
|
|
|
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):
|
|
|
@@ -57,26 +62,23 @@ def get_intro_info(request):
|
|
|
def get_signup_list(request):
|
|
|
"""
|
|
|
"""
|
|
|
- data = [
|
|
|
- {"relaname":u"肖小肖",
|
|
|
- "phone":"15982456282",
|
|
|
- "class_name":u"一班",
|
|
|
- "class_id":1,
|
|
|
- "subject_item":u"安全生产管理|电工作业|高压电工",
|
|
|
- "class_hour":30,
|
|
|
- "class_hour_finished":10,
|
|
|
- "train_type":u"新办",
|
|
|
- "order_status":0,
|
|
|
- "ctime":"2020-05-05 22:11:12",
|
|
|
- "id":1
|
|
|
- }
|
|
|
- ]
|
|
|
- qset = cm.SignupOrders.objects.filter(user_id=2)
|
|
|
+ uid = request.user.id
|
|
|
+ qset = cm.SignupOrders.objects.filter(user_id=uid).order_by("-id")
|
|
|
qdata = list(qset.values())
|
|
|
for qd in qdata:
|
|
|
- qd["subject_item"] = u"特种作业|电工|高压电工"
|
|
|
- qd["class_name"] = cm.Class.objects.filter(id=qd["class_id"]).first().name
|
|
|
- qd["class_hour"] = cm.Class.objects.filter(id=qd["class_id"]).first().class_hour
|
|
|
+ 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):
|
|
|
@@ -88,73 +90,82 @@ def get_signup_info(request):
|
|
|
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 []
|
|
|
return data
|
|
|
|
|
|
def get_class_list(request):
|
|
|
"""
|
|
|
"""
|
|
|
- data = [{
|
|
|
- "type":u"特种作业1",
|
|
|
- "classes":[
|
|
|
- {
|
|
|
- "id":1,
|
|
|
- "class_name":u"高压电一班",
|
|
|
- "price":1800.00,
|
|
|
- "class_time":"2020.04.01,2020.05.01",
|
|
|
- "thresh_count":100,
|
|
|
- "signuped_count":10},
|
|
|
- {
|
|
|
- "id":1,
|
|
|
- "class_name":u"高压电一班",
|
|
|
- "price":1800.00,
|
|
|
- "class_time":"2020.04.01,2020.05.01",
|
|
|
- "thresh_count":100,
|
|
|
- "signuped_count":10}
|
|
|
- ]
|
|
|
- }]
|
|
|
+ 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 = []
|
|
|
- print qdata,4444444444444
|
|
|
- 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"]
|
|
|
- if dct.has_key(qd["subject_name"]):
|
|
|
- dct[qd["subject_name"]].append(qd)
|
|
|
- else:
|
|
|
- dct[qd["subject_name"]] = [qd]
|
|
|
- for k,v in dct.items():
|
|
|
- data.append({"type":k,"classes":v})
|
|
|
+ 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)
|
|
|
+ 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)
|
|
|
+ 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):
|
|
|
"""
|
|
|
"""
|
|
|
- data = {
|
|
|
- "videos":[{
|
|
|
- "title":u"高压电工实操课程",
|
|
|
- "image":u"https://www.scxjc.club/images/jgjj.png",
|
|
|
- "url":u"https://www.scxjc.club/demo.mp4",
|
|
|
- "class_hour":20,
|
|
|
- "total_time":"45:32",
|
|
|
- "finished_time":"30:32",
|
|
|
- "status":1
|
|
|
- }],
|
|
|
- "papers":[{
|
|
|
- "id":1,
|
|
|
- "title":u"高压电工实操模拟试题",
|
|
|
- "class_hour":20,
|
|
|
- "full_mark":100,
|
|
|
- "time_limit":60,
|
|
|
- "mark":90,
|
|
|
- "status":1
|
|
|
- }]
|
|
|
- }
|
|
|
+ #获取视频信息
|
|
|
+ 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
|
|
|
+ else:
|
|
|
+ papers = []
|
|
|
+ videos = []
|
|
|
+ data = {"papers":papers,"videos":videos}
|
|
|
return data
|
|
|
|
|
|
|
|
|
@@ -165,74 +176,78 @@ def get_paper_info(request):
|
|
|
if mse:
|
|
|
raise ce.TipException(mse)
|
|
|
id = qdata.get("id")
|
|
|
- data = {
|
|
|
- "id":1,
|
|
|
- "title":u"高压电工实操模拟试题",
|
|
|
- "class_hour":20,
|
|
|
- "full_mark":100,
|
|
|
- "time_limit":60,
|
|
|
- "mark":90,
|
|
|
- "status":1,
|
|
|
- "questions":[
|
|
|
- {
|
|
|
- "id":1,
|
|
|
- "type":1,
|
|
|
- "title":u"欧姆定律是什么",
|
|
|
- "options":[u"A、电阻",u"B、电流"],
|
|
|
- "stand_answer":"A",
|
|
|
- "myanswer":"A"
|
|
|
- },
|
|
|
- {
|
|
|
- "id":2,
|
|
|
- "type":2,
|
|
|
- "title":u"欧姆定律是什么",
|
|
|
- "options":[u"A、电阻",u"B、电流"],
|
|
|
- "stand_answer":["A","B"],
|
|
|
- "myanswer":["A","B"]
|
|
|
- },
|
|
|
- {
|
|
|
- "id":3,
|
|
|
- "type":3,
|
|
|
- "title":u"电流等于电压除电阻",
|
|
|
- "options":[u"对",u"错"],
|
|
|
- "stand_answer":[u"对"],
|
|
|
- "myanswer":[u"对"]
|
|
|
- }
|
|
|
- ]
|
|
|
- }
|
|
|
- return data
|
|
|
+ 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):
|
|
|
"""
|
|
|
"""
|
|
|
+ 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"])
|
|
|
+ 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)
|
|
|
- vals["cid"] = 1
|
|
|
- vals["user_id"] = 2
|
|
|
+ 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
|
|
|
|
|
|
|
|
|
def update_signup(request):
|
|
|
"""
|
|
|
"""
|
|
|
+ uid = request.user.id
|
|
|
qdata = request.json
|
|
|
need_params = ["id"]
|
|
|
mse = ccf.check_params(*need_params,**qdata)
|
|
|
if mse:
|
|
|
raise ce.TipException(mse)
|
|
|
- id = qdata.pop("id")
|
|
|
- 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"])
|
|
|
+ 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)
|
|
|
- vals["cid"] = 1
|
|
|
+ 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
|
|
|
obj = cm.SignupOrders.objects.filter(id=id).update(**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
|
|
|
|
|
|
|
|
|
@@ -292,51 +307,25 @@ def get_yrxdetail(request):
|
|
|
def get_subject_tree(sub=None,data=None):
|
|
|
"""
|
|
|
"""
|
|
|
- roots = list(cm.Subject.objects.filter(pid=0).values())
|
|
|
- print roots,777777
|
|
|
+ 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:
|
|
|
- rn["children"] = list(cm.Subject.objects.filter(pid=rn["id"]).values())
|
|
|
+ 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"]:
|
|
|
- rnn["children"] = list(cm.Subject.objects.filter(pid=rnn["id"]).values())
|
|
|
+ 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):
|
|
|
"""
|
|
|
"""
|
|
|
- data = [{
|
|
|
- "id":1,
|
|
|
- "intro":u"说明",
|
|
|
- "name":u"特种作业",
|
|
|
- "price_new":1200,
|
|
|
- "price_re":120,
|
|
|
- "price_change":120,
|
|
|
- "children":[{
|
|
|
- "id":2,
|
|
|
- "price_new":1200,
|
|
|
- "price_re":120,
|
|
|
- "price_change":120,
|
|
|
- "name":u"电工作业",
|
|
|
- "intro":u"说明",
|
|
|
- "children":[{"id":3,"name":u"低压电工","children":[],"intro":u"说明"}]
|
|
|
- }]},
|
|
|
- {
|
|
|
- "id":4,
|
|
|
- "price_new":1200,
|
|
|
- "price_re":120,
|
|
|
- "price_change":120,
|
|
|
- "name":u"安全生产",
|
|
|
- "intro":u"说明",
|
|
|
- "children":[{
|
|
|
- "price_new":1200,
|
|
|
- "price_re":120,
|
|
|
- "price_change":120,
|
|
|
- "id":5,
|
|
|
- "name":u"子分类1",
|
|
|
- "intro":u"说明",
|
|
|
- "children":[{"id":6,"name":u"子分类2","children":[],"intro":u"说明"}]
|
|
|
- }]}
|
|
|
- ]
|
|
|
data = get_subject_tree()
|
|
|
return data
|
|
|
|
|
|
@@ -348,7 +337,25 @@ def post_paper(request):
|
|
|
if mse:
|
|
|
raise ce.TipException(mse)
|
|
|
paper_id = qdata.get("paper_id")
|
|
|
- return True
|
|
|
+ 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
|
|
|
|
|
|
|
|
|
def save_video_time(request):
|
|
|
@@ -366,6 +373,8 @@ def get_docs_list(request):
|
|
|
"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):
|
|
|
@@ -374,9 +383,116 @@ def do_signup_pay(request):
|
|
|
mse = ccf.check_params(*need_params,**qdata)
|
|
|
if mse:
|
|
|
raise ce.TipException(mse)
|
|
|
- signup_id = str(qdata.get("signup_id"))+str(int(time.time()))
|
|
|
- total_fee = str(qdata.get("total_fee"))
|
|
|
- openid = "ow7pX470Bl6IPeM188gNT8PjMBlw"
|
|
|
- prepayinfo = wxpay.get_wx_unifiedorder(signup_id,total_fee,openid)
|
|
|
+ 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")
|
|
|
+ cm.SignupOrders.objects.filter(out_trade_no=out_trade_no)\
|
|
|
+ .update(order_status=2,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
|
|
|
+ sorder = cm.SignupOrders.objects.filter(out_trade_no=out_trade_no).first()
|
|
|
+ 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):
|
|
|
+ """生成学时证明
|
|
|
+ """
|
|
|
+ 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
|
|
|
+ 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(170),"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
|
|
|
+
|
|
|
+def get_notice_list(request):
|
|
|
+ """
|
|
|
+ """
|
|
|
+ uid = request.user.id
|
|
|
+ #uid = 21
|
|
|
+ qset = cm.SysNotice.objects.filter(to=uid).order_by("-id")
|
|
|
+ data = list(qset.values())
|
|
|
+ return data
|
|
|
+
|
|
|
+
|