Commit 1e0da477 by 王昆

gsb

parent d9326bec
const system=require("../system");
const axios = require("axios");
class SmsClient{
constructor(){
this.smsTeml="http://123.57.156.109:4103/api/Send";
......@@ -10,7 +11,17 @@ class SmsClient{
"mobilePhone":to,
"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;
......@@ -18,6 +18,13 @@ class Validation {
};
}
isMobile(mobile) {
if (!mobile) {
return false;
}
return !this.PATTERN.PHONE_PATTERN.test(mobile);
}
/**
* 验证字段合法
* @param data 验证的对象
......@@ -51,7 +58,7 @@ class Validation {
this.error(data, `${rule.name}:需要填写数字类型`);
}
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) {
this.error(data, `${rule.name}${v} 错误`);
......
......@@ -5,10 +5,13 @@ var settings = require("../../../config/settings");
const AppletBase = require("../applet.base");
const fs = require("fs");
const moment = require("moment");
const validation = system.getObject("util.validation");
class MerchantApplet extends AppletBase {
constructor() {
super();
this.SMS_BANKMOBILE_KEY = "gtb_appl_mobile_";
this.uploadCtl = system.getObject("web.common.uploadCtl");
this.idcardClient = system.getObject("util.idcardClient");
this.merchantappletuserSve = system.getObject("service.uc.merchantappletuserSve");
......@@ -18,6 +21,9 @@ class MerchantApplet extends AppletBase {
this.tradeSve = system.getObject("service.trade.tradeSve");
this.saasInvoiceSve = system.getObject("service.saas.invoiceSve");
this.redisClient = system.getObject("util.redisClient");
this.smsClient = system.getObject("util.smsClient");
}
async test(o, obj, req) {
......@@ -79,8 +85,8 @@ class MerchantApplet extends AppletBase {
// 保存订单信息
async saveOrder(gobj, pobj, req, loginUser) {
try {
let verificationCodeRes = await this.verificationCode(pobj.bank_mobile,pobj.msgCode)
if(!verificationCodeRes){
let verificationCodeRes = await this.verificationCode(pobj.bank_mobile, pobj.msgCode)
if (!verificationCodeRes) {
return this.returnFail("短信验证码错误");
}
//TODO: 银行卡四要数验证
......@@ -234,26 +240,24 @@ class MerchantApplet extends AppletBase {
}
}
async idNoValid(gobj, pobj, req, loginUser) {
try {
let idno = (pobj.idno || "").trim();
if (!idno) {
return {code: 0, msg: "请填写身份证号码"};
}
async idNoValid(gobj, pobj, req, loginUser){
try {
let idno = (pobj.idno || "").trim();
if(!idno) {
return {code: 0, msg: "请填写身份证号码"};
}
let success = await this.idcardClient.checkIDCard(idno);
if(success) {
return this.returnSuccess(1);
}
return this.returnFail("身份证号码格式错误");
} catch (error) {
console.log(error);
return {code: 500, msg: "服务忙,请稍后重试"};
let success = await this.idcardClient.checkIDCard(idno);
if (success) {
return this.returnSuccess(1);
}
return this.returnFail("身份证号码格式错误");
} catch (error) {
console.log(error);
return {code: 500, msg: "服务忙,请稍后重试"};
}
}
/**
* 个体户列表/个体户列表
* @param params
......@@ -261,13 +265,13 @@ class MerchantApplet extends AppletBase {
* @param req
* @returns {Promise<void>}
*/
async saasorderbusinessmenPage (params, pobj2, req){
async saasorderbusinessmenPage(params, pobj2, req) {
let loginUser = await this.getLoginUser(pobj2.merchant_id, pobj2.openid);
pobj2.merchant_app_user_id = loginUser.id;
let res = await this.businessmenSve.saasorderbusinessmenPage(pobj2);
if(res.status==0){
let res = await this.businessmenSve.saasorderbusinessmenPage(pobj2);
if (res.status == 0) {
return this.returnSuccess(res.data);
}else{
} else {
this.returnFail("请求超时 请稍后在试");
}
}
......@@ -279,33 +283,33 @@ class MerchantApplet extends AppletBase {
* @param req
* @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);
pobj2.merchant_app_user_id = loginUser.id;
pobj2.attrs=["credit_code"];
if(!pobj2.merchant_app_user_id){
pobj2.attrs = ["credit_code"];
if (!pobj2.merchant_app_user_id) {
return system.getResult(null, `登录失效,请重新登录`);
}
try{
let creditCodeArray =await this.businessmenSve.assorderBusinessmenInfo(pobj2);
if(creditCodeArray.status != 0){
return this.returnSuccess({count:0,rows:[]});
try {
let creditCodeArray = await this.businessmenSve.assorderBusinessmenInfo(pobj2);
if (creditCodeArray.status != 0) {
return this.returnSuccess({count: 0, rows: []});
}
let creditCodes = [];
for (let val of creditCodeArray.data) {
creditCodes.push(val.credit_code);
}
if(!creditCodes || creditCodes.length ==0){
return this.returnSuccess({count:0,rows:[]});
if (!creditCodes || creditCodes.length == 0) {
return this.returnSuccess({count: 0, rows: []});
}
pobj2.credit_code_array = creditCodes;
let res = await this.tradeSve.tradeItemBycreditCode(pobj2);
if(res.status==0){
if (res.status == 0) {
return this.returnSuccess(res.data);
}else{
} else {
return this.returnFail("请求超时 请稍后在试");
}
}catch (e) {
} catch (e) {
console.log(e);
return this.returnFail("请求超时 请稍后在试");
}
......@@ -318,52 +322,83 @@ class MerchantApplet extends AppletBase {
* @param req
* @returns {Promise<void>}
*/
async invoiceBycreditCode(pobj1, pobj2, req){
async invoiceBycreditCode(pobj1, pobj2, req) {
let loginUser = await this.getLoginUser(pobj2.merchant_id, pobj2.openid);
pobj2.merchant_app_user_id = loginUser.id;
pobj2.attrs=["credit_code"];
if(!pobj2.merchant_app_user_id){
pobj2.attrs = ["credit_code"];
if (!pobj2.merchant_app_user_id) {
return system.getResult(null, `登录失效,请重新登录`);
}
try{
let creditCodeArray =await this.businessmenSve.assorderBusinessmenInfo(pobj2);
if(creditCodeArray.status != 0){
return this.returnSuccess({count:0,rows:[]});
try {
let creditCodeArray = await this.businessmenSve.assorderBusinessmenInfo(pobj2);
if (creditCodeArray.status != 0) {
return this.returnSuccess({count: 0, rows: []});
}
let creditCodes = [];
for (let val of creditCodeArray.data) {
creditCodes.push(val.credit_code);
}
if(!creditCodes || creditCodes.length ==0){
return this.returnSuccess({count:0,rows:[]});
if (!creditCodes || creditCodes.length == 0) {
return this.returnSuccess({count: 0, rows: []});
}
pobj2.credit_code_array = creditCodes;
let res = await this.saasInvoiceSve.invoiceBycreditCode(pobj2);
if(res.status==0){
if (res.status == 0) {
return this.returnSuccess(res.data);
}else{
} else {
return this.returnFail("请求超时 请稍后在试");
}
}catch (e) {
} catch (e) {
console.log(e);
return system.getResult(null,`系统错误`);
return system.getResult(null, `系统错误`);
}
}
/**
* 获取验证码
* 银行卡预留手机号短信验证码
* @param pobj1
* @param pobj2
* @param pobj
* @param req
* @returns {Promise<void>}
*/
async getVerificationCode(pobj1, pobj2, req){
let code = await this.redisClient.setWithEx(`merchantAppletMsg:${pobj1.mobile}`,"123456", 60 * 1);
return this.returnSuccess("123456");
async sendBankMobileCode(pobj1, pobj, req) {
let loginUser = await this.getLoginUser(pobj.merchant_id, pobj.openid);
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;
}
/**
* 驗證验证码
* @param pobj1
......@@ -371,10 +406,10 @@ class MerchantApplet extends AppletBase {
* @param req
* @returns {Promise<void>}
*/
async verificationCode(mobile,code){
async verificationCode(mobile, code) {
let value = await this.redisClient.get(`merchantAppletMsg:${mobile}`);
console.log("小程序验证码"+value);
return value == code ? true:false;
console.log("小程序验证码" + value);
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