Pārlūkot izejas kodu

Merge branch 'master' of http://192.168.1.41:3000/maixinrong/Calculation

MaiXinRong 5 gadi atpakaļ
vecāks
revīzija
e61960806d

+ 15 - 0
app/controller/material_controller.js

@@ -596,6 +596,20 @@ module.exports = app => {
             }
         }
 
+        _checkMaterialFileCanModify(ctx) {
+            // 检查登录用户,是否可操作
+            const accountId = ctx.session.sessionUser.accountId;
+            if (!ctx.material.curAuditor) {
+                if (ctx.material.status === auditConst.status.uncheck || ctx.material.status === auditConst.status.checkNo && accountId === ctx.material.user_id) {
+                    return;
+                }
+                throw '该调差期当前您无权操作';
+            } else {
+                if (ctx.material.curAuditor.aid === accountId) return;
+                throw '该调差期当前您无权操作';
+            }
+
+        }
         /**
          * 上传附件
          * @param {*} ctx 上下文
@@ -603,6 +617,7 @@ module.exports = app => {
         async upload(ctx) {
             let stream;
             try {
+                this._checkMaterialFileCanModify(ctx);
                 const parts = this.ctx.multipart({
                     autoFields: true,
                 });

+ 49 - 5
app/controller/wechat_controller.js

@@ -49,7 +49,8 @@ module.exports = app => {
          * @return {void}
          */
         async oauth(ctx) {
-            const url = await app.wechat.oauth.getAuthorizeURL('http://jluat.smartcost.com.cn/wx/bind', '', 'snsapi_userinfo');
+            const redirect_uri = ctx.query.redirect_uri;
+            const url = await app.wechat.oauth.getAuthorizeURL(redirect_uri, '', 'snsapi_userinfo');
             ctx.redirect(url);
         }
 
@@ -61,10 +62,6 @@ module.exports = app => {
          */
         async bind(ctx) {
             try {
-                if (!ctx.session.wechatToken) {
-                    const token = await app.wechat.oauth.getAccessToken(ctx.query.code);
-                    ctx.session.wechatToken = token.data;
-                }
                 const user = await app.wechat.oauth.getUser(ctx.session.wechatToken.openid);
                 const errorMessage = ctx.session.loginError;
                 // 获取系统维护信息
@@ -108,6 +105,25 @@ module.exports = app => {
                 if (!result2) {
                     throw '绑定失败';
                 }
+                const projectData = await ctx.service.project.getDataById(accountData.project_id);
+                // 绑定成功通知
+                const templateId = 'ElT988uf7EV8ROPKSAX7z7tN9ZxZCDMaXK5ouc9N49E';
+                const url = '';
+                const msgData = {
+                    first: {
+                        value: '微信绑定成功',
+                    },
+                    keyword1: {
+                        value: accountData.account,
+                    },
+                    keyword2: {
+                        value: '项目编号' + projectData.code + ' 账号' + accountData.account + ' 绑定成功',
+                    },
+                    remark: {
+                        value: '欢迎使用纵横云计量,我们竭诚为您服务。',
+                    },
+                };
+                await app.wechat.api.sendTemplate(ctx.session.wechatToken.openid, templateId, url, '', msgData);
                 ctx.body = '绑定成功';
             } catch (error) {
                 this.log(error);
@@ -119,6 +135,34 @@ module.exports = app => {
         async oauthTxt(ctx) {
             ctx.body = 't3MkWAMqplVxPjmr';
         }
+
+        async testwx(ctx) {
+            try {
+                // 绑定成功通知
+                const templateId = 'ElT988uf7EV8ROPKSAX7z7tN9ZxZCDMaXK5ouc9N49E';
+                const url = '';
+                const topColor = '#FFFFFF';
+                const msgData = {
+                    first: {
+                        value: '微信绑定成功',
+                    },
+                    keyword1: {
+                        value: 'hello world',
+                    },
+                    keyword2: {
+                        value: 'hello world 绑定成功',
+                    },
+                    remark: {
+                        value: '欢迎使用纵横云计量,我们竭诚为您服务。',
+                    },
+                };
+                await app.wechat.api.sendTemplate(ctx.session.wechatToken.openid, templateId, url, topColor, msgData);
+                ctx.body = 'success';
+            } catch (error) {
+                console.log(error);
+                ctx.body = error;
+            }
+        }
     }
 
     return WechatController;

+ 17 - 17
app/middleware/wechat_auth.js

@@ -1,33 +1,33 @@
 'use strict';
 
-// 加密类
-const crypto = require('crypto');
-const messageType = require('../const/message_type');
-
-module.exports = options => {
+module.exports = (options, app) => {
     /**
      * session判断中间件
      *
      * @param {function} next - 中间件继续执行的方法
      * @return {void}
      */
-    return function* wechatAuth(next) {
+    return async function wechatAuth(ctx, next) {
         try {
             // 判断session
-            // const wechatToken = this.session.wechatToken;
-            // if (wechatToken === undefined) {
-            //     throw '不存在session';
-            // }
-            // // 同步系统维护信息
-            // yield this.service.maintain.syncMaintainData();
-            // if (this.session === null) {
-            //     throw '系统维护中~';
-            // }
+            if (!ctx.session.wechatToken && ctx.query.code) {
+                const token = await app.wechat.oauth.getAccessToken(ctx.query.code);
+                ctx.session.wechatToken = token.data;
+            }
+            const wechatToken = ctx.session.wechatToken;
+            if (!wechatToken) {
+                ctx.redirect('/wx/oauth?redirect_uri=' + encodeURIComponent(ctx.request.headers.referer));
+            }
+            // 同步系统维护信息
+            await ctx.service.maintain.syncMaintainData();
+            if (ctx.session === null) {
+                throw '系统维护中~';
+            }
         } catch (error) {
             console.log(error);
-            this.body = error;
+            ctx.body = error;
             return;
         }
-        yield next;
+        await next();
     };
 };

+ 1 - 0
app/router.js

@@ -353,5 +353,6 @@ module.exports = app => {
     app.get('/wx/oauth', 'wechatController.oauth');
     app.get('/wx/bind', wechatAuth, 'wechatController.bind');
     app.post('/wx/bindwx', wechatAuth, 'wechatController.bindwx');
+    app.get('/wx/test', wechatAuth, 'wechatController.testwx');
     app.get('/MP_verify_t3MkWAMqplVxPjmr.txt', 'wechatController.oauthTxt');
 };

+ 1 - 1
config/config.default.js

@@ -176,7 +176,7 @@ module.exports = appInfo => {
             pfx: '',
         },
         modules: {
-            message: false, // enable or disable co-wechat
+            message: true, // enable or disable co-wechat
             api: true, // enable or disable co-wechat-api
             oauth: true, // enable or disable co-wechat-oauth
             payment: false, // enable or disable co-wechat-payment