Commit 1e0da477 by 王昆

gsb

parent d9326bec
const system=require("../system"); const system=require("../system");
const axios = require("axios");
class SmsClient{ class SmsClient{
constructor(){ constructor(){
this.smsTeml="http://123.57.156.109:4103/api/Send"; this.smsTeml="http://123.57.156.109:4103/api/Send";
...@@ -10,7 +11,17 @@ class SmsClient{ ...@@ -10,7 +11,17 @@ class SmsClient{
"mobilePhone":to, "mobilePhone":to,
"content":content "content":content
} }
return this.restClient.execPost(txtObj,this.smsTeml); let res = await axios({
method: 'post',
url: this.smsTeml,
data: txtObj
});
// if (!res || !res.data || res.data.status != 0 || res.data.data.length == 0) {
// return system.getResult(null, `试算错误`);
// }
return res.data;
// return this.restClient.execPost(txtObj,this.smsTeml);
} }
} }
module.exports=SmsClient; module.exports=SmsClient;
...@@ -18,6 +18,13 @@ class Validation { ...@@ -18,6 +18,13 @@ class Validation {
}; };
} }
isMobile(mobile) {
if (!mobile) {
return false;
}
return !this.PATTERN.PHONE_PATTERN.test(mobile);
}
/** /**
* 验证字段合法 * 验证字段合法
* @param data 验证的对象 * @param data 验证的对象
...@@ -51,7 +58,7 @@ class Validation { ...@@ -51,7 +58,7 @@ class Validation {
this.error(data, `${rule.name}:需要填写数字类型`); this.error(data, `${rule.name}:需要填写数字类型`);
} }
if (rule.is_mobile && this.PATTERN.PHONE_PATTERN.test(v)) { if (rule.is_mobile && this.PATTERN.PHONE_PATTERN.test(v)) {
this.error(data, `${rule.name}需要填写数字类型`); this.error(data, `${rule.name}格式错误`);
} }
if (rule.dics && rule.dics.indexOf(v) == -1) { if (rule.dics && rule.dics.indexOf(v) == -1) {
this.error(data, `${rule.name}${v} 错误`); this.error(data, `${rule.name}${v} 错误`);
......
...@@ -5,10 +5,13 @@ var settings = require("../../../config/settings"); ...@@ -5,10 +5,13 @@ var settings = require("../../../config/settings");
const AppletBase = require("../applet.base"); const AppletBase = require("../applet.base");
const fs = require("fs"); const fs = require("fs");
const moment = require("moment"); const moment = require("moment");
const validation = system.getObject("util.validation");
class MerchantApplet extends AppletBase { class MerchantApplet extends AppletBase {
constructor() { constructor() {
super(); super();
this.SMS_BANKMOBILE_KEY = "gtb_appl_mobile_";
this.uploadCtl = system.getObject("web.common.uploadCtl"); this.uploadCtl = system.getObject("web.common.uploadCtl");
this.idcardClient = system.getObject("util.idcardClient"); this.idcardClient = system.getObject("util.idcardClient");
this.merchantappletuserSve = system.getObject("service.uc.merchantappletuserSve"); this.merchantappletuserSve = system.getObject("service.uc.merchantappletuserSve");
...@@ -18,6 +21,9 @@ class MerchantApplet extends AppletBase { ...@@ -18,6 +21,9 @@ class MerchantApplet extends AppletBase {
this.tradeSve = system.getObject("service.trade.tradeSve"); this.tradeSve = system.getObject("service.trade.tradeSve");
this.saasInvoiceSve = system.getObject("service.saas.invoiceSve"); this.saasInvoiceSve = system.getObject("service.saas.invoiceSve");
this.redisClient = system.getObject("util.redisClient"); this.redisClient = system.getObject("util.redisClient");
this.smsClient = system.getObject("util.smsClient");
} }
async test(o, obj, req) { async test(o, obj, req) {
...@@ -79,8 +85,8 @@ class MerchantApplet extends AppletBase { ...@@ -79,8 +85,8 @@ class MerchantApplet extends AppletBase {
// 保存订单信息 // 保存订单信息
async saveOrder(gobj, pobj, req, loginUser) { async saveOrder(gobj, pobj, req, loginUser) {
try { try {
let verificationCodeRes = await this.verificationCode(pobj.bank_mobile,pobj.msgCode) let verificationCodeRes = await this.verificationCode(pobj.bank_mobile, pobj.msgCode)
if(!verificationCodeRes){ if (!verificationCodeRes) {
return this.returnFail("短信验证码错误"); return this.returnFail("短信验证码错误");
} }
//TODO: 银行卡四要数验证 //TODO: 银行卡四要数验证
...@@ -234,16 +240,15 @@ class MerchantApplet extends AppletBase { ...@@ -234,16 +240,15 @@ class MerchantApplet extends AppletBase {
} }
} }
async idNoValid(gobj, pobj, req, loginUser) {
async idNoValid(gobj, pobj, req, loginUser){
try { try {
let idno = (pobj.idno || "").trim(); let idno = (pobj.idno || "").trim();
if(!idno) { if (!idno) {
return {code: 0, msg: "请填写身份证号码"}; return {code: 0, msg: "请填写身份证号码"};
} }
let success = await this.idcardClient.checkIDCard(idno); let success = await this.idcardClient.checkIDCard(idno);
if(success) { if (success) {
return this.returnSuccess(1); return this.returnSuccess(1);
} }
return this.returnFail("身份证号码格式错误"); return this.returnFail("身份证号码格式错误");
...@@ -253,7 +258,6 @@ class MerchantApplet extends AppletBase { ...@@ -253,7 +258,6 @@ class MerchantApplet extends AppletBase {
} }
} }
/** /**
* 个体户列表/个体户列表 * 个体户列表/个体户列表
* @param params * @param params
...@@ -261,13 +265,13 @@ class MerchantApplet extends AppletBase { ...@@ -261,13 +265,13 @@ class MerchantApplet extends AppletBase {
* @param req * @param req
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async saasorderbusinessmenPage (params, pobj2, req){ async saasorderbusinessmenPage(params, pobj2, req) {
let loginUser = await this.getLoginUser(pobj2.merchant_id, pobj2.openid); let loginUser = await this.getLoginUser(pobj2.merchant_id, pobj2.openid);
pobj2.merchant_app_user_id = loginUser.id; pobj2.merchant_app_user_id = loginUser.id;
let res = await this.businessmenSve.saasorderbusinessmenPage(pobj2); let res = await this.businessmenSve.saasorderbusinessmenPage(pobj2);
if(res.status==0){ if (res.status == 0) {
return this.returnSuccess(res.data); return this.returnSuccess(res.data);
}else{ } else {
this.returnFail("请求超时 请稍后在试"); this.returnFail("请求超时 请稍后在试");
} }
} }
...@@ -279,33 +283,33 @@ class MerchantApplet extends AppletBase { ...@@ -279,33 +283,33 @@ class MerchantApplet extends AppletBase {
* @param req * @param req
* @returns {Promise<{msg: string, data: (*|null), bizmsg: string, status: number}>} * @returns {Promise<{msg: string, data: (*|null), bizmsg: string, status: number}>}
*/ */
async saasTradeBusinessmenPage(pobj1, pobj2, req){ async saasTradeBusinessmenPage(pobj1, pobj2, req) {
let loginUser = await this.getLoginUser(pobj2.merchant_id, pobj2.openid); let loginUser = await this.getLoginUser(pobj2.merchant_id, pobj2.openid);
pobj2.merchant_app_user_id = loginUser.id; pobj2.merchant_app_user_id = loginUser.id;
pobj2.attrs=["credit_code"]; pobj2.attrs = ["credit_code"];
if(!pobj2.merchant_app_user_id){ if (!pobj2.merchant_app_user_id) {
return system.getResult(null, `登录失效,请重新登录`); return system.getResult(null, `登录失效,请重新登录`);
} }
try{ try {
let creditCodeArray =await this.businessmenSve.assorderBusinessmenInfo(pobj2); let creditCodeArray = await this.businessmenSve.assorderBusinessmenInfo(pobj2);
if(creditCodeArray.status != 0){ if (creditCodeArray.status != 0) {
return this.returnSuccess({count:0,rows:[]}); return this.returnSuccess({count: 0, rows: []});
} }
let creditCodes = []; let creditCodes = [];
for (let val of creditCodeArray.data) { for (let val of creditCodeArray.data) {
creditCodes.push(val.credit_code); creditCodes.push(val.credit_code);
} }
if(!creditCodes || creditCodes.length ==0){ if (!creditCodes || creditCodes.length == 0) {
return this.returnSuccess({count:0,rows:[]}); return this.returnSuccess({count: 0, rows: []});
} }
pobj2.credit_code_array = creditCodes; pobj2.credit_code_array = creditCodes;
let res = await this.tradeSve.tradeItemBycreditCode(pobj2); let res = await this.tradeSve.tradeItemBycreditCode(pobj2);
if(res.status==0){ if (res.status == 0) {
return this.returnSuccess(res.data); return this.returnSuccess(res.data);
}else{ } else {
return this.returnFail("请求超时 请稍后在试"); return this.returnFail("请求超时 请稍后在试");
} }
}catch (e) { } catch (e) {
console.log(e); console.log(e);
return this.returnFail("请求超时 请稍后在试"); return this.returnFail("请求超时 请稍后在试");
} }
...@@ -318,51 +322,82 @@ class MerchantApplet extends AppletBase { ...@@ -318,51 +322,82 @@ class MerchantApplet extends AppletBase {
* @param req * @param req
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async invoiceBycreditCode(pobj1, pobj2, req){ async invoiceBycreditCode(pobj1, pobj2, req) {
let loginUser = await this.getLoginUser(pobj2.merchant_id, pobj2.openid); let loginUser = await this.getLoginUser(pobj2.merchant_id, pobj2.openid);
pobj2.merchant_app_user_id = loginUser.id; pobj2.merchant_app_user_id = loginUser.id;
pobj2.attrs=["credit_code"]; pobj2.attrs = ["credit_code"];
if(!pobj2.merchant_app_user_id){ if (!pobj2.merchant_app_user_id) {
return system.getResult(null, `登录失效,请重新登录`); return system.getResult(null, `登录失效,请重新登录`);
} }
try{ try {
let creditCodeArray =await this.businessmenSve.assorderBusinessmenInfo(pobj2); let creditCodeArray = await this.businessmenSve.assorderBusinessmenInfo(pobj2);
if(creditCodeArray.status != 0){ if (creditCodeArray.status != 0) {
return this.returnSuccess({count:0,rows:[]}); return this.returnSuccess({count: 0, rows: []});
} }
let creditCodes = []; let creditCodes = [];
for (let val of creditCodeArray.data) { for (let val of creditCodeArray.data) {
creditCodes.push(val.credit_code); creditCodes.push(val.credit_code);
} }
if(!creditCodes || creditCodes.length ==0){ if (!creditCodes || creditCodes.length == 0) {
return this.returnSuccess({count:0,rows:[]}); return this.returnSuccess({count: 0, rows: []});
} }
pobj2.credit_code_array = creditCodes; pobj2.credit_code_array = creditCodes;
let res = await this.saasInvoiceSve.invoiceBycreditCode(pobj2); let res = await this.saasInvoiceSve.invoiceBycreditCode(pobj2);
if(res.status==0){ if (res.status == 0) {
return this.returnSuccess(res.data); return this.returnSuccess(res.data);
}else{ } else {
return this.returnFail("请求超时 请稍后在试"); return this.returnFail("请求超时 请稍后在试");
} }
}catch (e) { } catch (e) {
console.log(e); console.log(e);
return system.getResult(null,`系统错误`); return system.getResult(null, `系统错误`);
} }
} }
/** /**
* 获取验证码 * 银行卡预留手机号短信验证码
* @param pobj1 * @param pobj1
* @param pobj2 * @param pobj
* @param req * @param req
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async getVerificationCode(pobj1, pobj2, req){ async sendBankMobileCode(pobj1, pobj, req) {
let code = await this.redisClient.setWithEx(`merchantAppletMsg:${pobj1.mobile}`,"123456", 60 * 1); let loginUser = await this.getLoginUser(pobj.merchant_id, pobj.openid);
return this.returnSuccess("123456"); let mobile = pobj.mobile;
if (!mobile) {
return this.returnFail("请先填写银行卡预留手机号");
}
if (validation.isMobile(mobile)) {
return this.returnFail("银行卡预留手机号格式错误");
}
try {
let key = this.SMS_BANKMOBILE_KEY + mobile;
let vcode = await this.redisClient.get(key + "t");
// let vcode;
if (!vcode) {
vcode = await this.getVCode();
await this.redisClient.setWithEx(key, vcode, 5 * 60);
await this.redisClient.setWithEx(key + "t", vcode, 60);
let msg = "您的个体户注册手机验证码为" + vcode + ", (切勿将验证码告知别人, 请在5分钟内输入完成验证, 如有问题请联系客服。)";
let rs = await this.smsClient.sendMsg(mobile, msg);
console.log(rs);
}
return this.returnSuccess(1);
} catch (error) {
return system.getResultFail(500, "接口异常:" + error.message);
} }
}
getVCode() {
var randomNum = "" + Math.round(Math.random() * 1000000);
while (randomNum.length < 6) {
randomNum = "0" + randomNum;
}
return randomNum;
}
/** /**
* 驗證验证码 * 驗證验证码
...@@ -371,10 +406,10 @@ class MerchantApplet extends AppletBase { ...@@ -371,10 +406,10 @@ class MerchantApplet extends AppletBase {
* @param req * @param req
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async verificationCode(mobile,code){ async verificationCode(mobile, code) {
let value = await this.redisClient.get(`merchantAppletMsg:${mobile}`); let value = await this.redisClient.get(`merchantAppletMsg:${mobile}`);
console.log("小程序验证码"+value); console.log("小程序验证码" + value);
return value == code ? true:false; return value == code ? true : false;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment