From 9154ada5a360396520b4230c58aa5215623e2c42 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 25 Nov 2019 17:43:07 +0800 Subject: [PATCH] operation notification --- safesite/static/safesite/mystatic/js/util.js | 2 +- safesite/tasks.py | 11 ++ safesite/templates/index.html | 4 +- safesite/views.py | 135 +++++++++---------- 4 files changed, 80 insertions(+), 72 deletions(-) diff --git a/safesite/static/safesite/mystatic/js/util.js b/safesite/static/safesite/mystatic/js/util.js index cae3dc06..c921e5ca 100644 --- a/safesite/static/safesite/mystatic/js/util.js +++ b/safesite/static/safesite/mystatic/js/util.js @@ -582,4 +582,4 @@ $.get('api/check_session',function(res){ }) } var t1 = window.setInterval(update, 1000 * 60) -var t2 = window.setInterval(checksession,1000*60*31) \ No newline at end of file +var t2 = window.setInterval(checksession,1000*60*41) \ No newline at end of file diff --git a/safesite/tasks.py b/safesite/tasks.py index 95f4ecb0..58811e89 100644 --- a/safesite/tasks.py +++ b/safesite/tasks.py @@ -35,6 +35,17 @@ def send_wechatmsgs(postdict,tolist): except: pass +@shared_task +def send_wechatmsgsu(postdict,tousers): + with open(dirname + 'token.txt','r',encoding= 'utf-8') as f: + token=f.read() + try: + for i in tousers: + postdict['touser']= User.object.get(userid=i).openid + requests.post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='+token,data=json.dumps(postdict)) + except: + pass + @shared_task def send_wechatmsg(postdict): with open(dirname + 'token.txt','r',encoding= 'utf-8') as f: diff --git a/safesite/templates/index.html b/safesite/templates/index.html index e90f8a2c..6c8a3b70 100644 --- a/safesite/templates/index.html +++ b/safesite/templates/index.html @@ -174,7 +174,7 @@ var headimgurl = $('#userindex').attr('headimgurl'); var issuper = {{ issuper }}; if (issuper == 1) { $('#setupb').show() } - if (openid == 0 && issuper != 1) { $('#wxdg').dialog(); } else { $('#bindwx').text('解绑微信'); }; + if ((openid == 0 ||openid == 'None') && issuper != 1) { $('#wxdg').dialog(); } else { $('#bindwx').text('解绑微信'); }; if (headimgurl != 0 && headimgurl != 'None') { $('#headimg').attr('src', headimgurl); } function logout() { $.messager.confirm('系统提示', '您确定要退出本次登录吗?', function (r) { @@ -184,7 +184,7 @@ }); } function bindwx() { - if (openid == 0) { + if (openid == 0 ||openid == 'None') { $('#wxdg').dialog('open'); } else { var str = '你已绑定昵称为' + nickname + '的微信号,确定解绑吗?' diff --git a/safesite/views.py b/safesite/views.py index a2b0c454..c92fbcf9 100644 --- a/safesite/views.py +++ b/safesite/views.py @@ -13,7 +13,7 @@ import time from datetime import datetime,date,timedelta from django.db.models import F,Count,Sum import requests -from .tasks import send_wechatmsgs,send_wechatmsg,yjjs,gettime,yjjs_px,yjjs_yl,updateTzzs,updateAqzs,yjjs_gc,yjjs_ws +from .tasks import send_wechatmsgs,send_wechatmsg,yjjs,gettime,yjjs_px,yjjs_yl,updateTzzs,updateAqzs,yjjs_gc,yjjs_ws,send_wechatmsgsu from .export import exportdoc,exportxlsx,exportyjdoc,exportsimplexlsx,exportdoc2 from .daoru import drusers,drequipments,drrisks,drquestions,cal_riskact_level,cal_area_risk_level,makeqr,makeqr_train,makeqr_riskact,makeqr_examtest,makeqr_area from django.forms.models import model_to_dict @@ -4499,30 +4499,29 @@ def apioperation(req): sprs = [obj.zyzt['splc'][index]['spr']] obj.todousers = sprs obj.save() - for i in sprs: - postdict={ - 'touser':'', - 'template_id':User.objects.get(userid=i).openid, - "miniprogram":{"appid":"wx5c39b569f01c27db"}, - 'data':{ - 'first':{ - 'value':obj.zylx.dickeyname + '作业审批:' - }, - 'keyword1':{ - 'value':obj.zynr - }, - 'keyword2':{ - 'value':obj.kssj - }, - 'keyword3':{ - 'value':obj.zydd - }, - 'remark':{ - 'value':'请您及时完成审批!' - } + postdict={ + 'touser':'', + 'template_id':'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', + "miniprogram":{"appid":"wx5c39b569f01c27db"}, + 'data':{ + 'first':{ + 'value':obj.zylx.dickeyname + '作业审批:' + }, + 'keyword1':{ + 'value':obj.zynr + }, + 'keyword2':{ + 'value':obj.kssj + }, + 'keyword3':{ + 'value':obj.zydd + }, + 'remark':{ + 'value':'请您及时完成审批!' } } - send_wechatmsg.delay(postdict) + } + send_wechatmsgsu.delay(postdict,sprs) return JsonResponse({"code":1}) elif a == 'spzy': userid = req.session['userid'] @@ -4541,7 +4540,7 @@ def apioperation(req): Operspxq.objects.create(oper=Operation.objects.get(zyid=zyid),jdmc=oldjdmc,spr=spruser,checked=1,spbm=spruser.ubelongpart) postdict={ 'touser':'', - 'template_id':obj.zyfzr.openid, + 'template_id':'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', "miniprogram":{"appid":"wx5c39b569f01c27db"}, 'data':{ 'first':{ @@ -4567,30 +4566,29 @@ def apioperation(req): newsprs = data['newsprs']#新审批人 obj.todousers = newsprs obj.save() - for i in newsprs: - postdict={ - 'touser':'', - 'template_id':User.objects.get(userid=i).openid, - "miniprogram":{"appid":"wx5c39b569f01c27db"}, - 'data':{ - 'first':{ - 'value':obj.zylx.dickeyname + '作业审批:' - }, - 'keyword1':{ - 'value':obj.zynr - }, - 'keyword2':{ - 'value':obj.kssj - }, - 'keyword3':{ - 'value':obj.zydd - }, - 'remark':{ - 'value':'请您及时完成审批!' - } + postdict={ + 'touser':'', + 'template_id':'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', + "miniprogram":{"appid":"wx5c39b569f01c27db"}, + 'data':{ + 'first':{ + 'value':obj.zylx.dickeyname + '作业审批:' + }, + 'keyword1':{ + 'value':obj.zynr + }, + 'keyword2':{ + 'value':obj.kssj + }, + 'keyword3':{ + 'value':obj.zydd + }, + 'remark':{ + 'value':'请您及时完成审批!' } } - send_wechatmsg.delay(postdict) + } + send_wechatmsgsu.delay(postdict,newsprs) Operspxq.objects.create(oper=Operation.objects.get(zyid=zyid),jdmc=oldjdmc,spr=spruser,checked=2,spbm=spruser.ubelongpart) return JsonResponse({"code":1}) try: @@ -4600,30 +4598,29 @@ def apioperation(req): obj.zyzt['jdmc'] = nextsplc['jdmc'] obj.todousers = nextsplc['sprs'] obj.save() - for i in nextsplc['sprs']: - postdict={ - 'touser':'', - 'template_id':User.objects.get(userid=i).openid, - "miniprogram":{"appid":"wx5c39b569f01c27db"}, - 'data':{ - 'first':{ - 'value':obj.zylx.dickeyname + '作业审批:' - }, - 'keyword1':{ - 'value':obj.zynr - }, - 'keyword2':{ - 'value':obj.kssj - }, - 'keyword3':{ - 'value':obj.zydd - }, - 'remark':{ - 'value':'请您及时完成审批!' - } + postdict={ + 'touser':'', + 'template_id':'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', + "miniprogram":{"appid":"wx5c39b569f01c27db"}, + 'data':{ + 'first':{ + 'value':obj.zylx.dickeyname + '作业审批:' + }, + 'keyword1':{ + 'value':obj.zynr + }, + 'keyword2':{ + 'value':obj.kssj + }, + 'keyword3':{ + 'value':obj.zydd + }, + 'remark':{ + 'value':'请您及时完成审批!' } } - send_wechatmsg.delay(postdict) + } + send_wechatmsgsu.delay(postdict,nextsplc['sprs']) Operspxq.objects.create(oper=Operation.objects.get(zyid=zyid),jdmc=oldjdmc,spr=spruser,checked=1,spbm=spruser.ubelongpart) except : @@ -4634,7 +4631,7 @@ def apioperation(req): Operspxq.objects.create(oper=Operation.objects.get(zyid=zyid),jdmc=oldjdmc,spr=spruser,checked=1,spbm=spruser.ubelongpart) postdict={ 'touser':'', - 'template_id':obj.zyfzr.openid, + 'template_id':'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', "miniprogram":{"appid":"wx5c39b569f01c27db"}, 'data':{ 'first':{