Commit 7855e6d6 by zhaoxiqing

gsb

parent 92d492d8
......@@ -9,6 +9,17 @@ class APIBase extends DocBase {
this.cacheManager = system.getObject("db.common.cacheManager");
this.logCtl = system.getObject("web.common.oplogCtl");
this.oplogSve = system.getObject("service.common.oplogSve");
this.merchantappletuserSve = system.getObject("service.uc.merchantappletuserSve");
}
async getLoginUser(merchant_id, openid, forceUpdate) {
return await this.merchantappletuserSve.getLoginUser({merchant_id: merchant_id, openid: openid, forceUpdate: forceUpdate});
}
async getMerchant(merchant_id) {
return await this.merchantSve.getMerchantWithCache({id: merchant_id, forceUpdate: true});
}
getUUID() {
var uuid = uuidv4();
......@@ -17,7 +28,7 @@ class APIBase extends DocBase {
}
/**
* 验证签名
* @param {*} params 要验证的参数
* @param {*} params 要验证的参数
* @param {*} app_key 应用的校验key
*/
async verifySign(params, app_key) {
......
var APIBase = require("../../api.base");
var system = require("../../../system");
const axios = require("axios");
const validation = system.getObject("util.validation");
const md5 = require("MD5");
class TestAPI extends APIBase {
constructor() {
super();
......@@ -22,27 +26,68 @@ class TestAPI extends APIBase {
this.smsClient = system.getObject("util.smsClient");
}
//
async loginUser(gobj, pobj, req, loginUser) {
// TODO pobj.merchant_id 前端传过来,解密
let user = await this.getLoginUser(pobj.merchant_id, pobj.openid);
return this.returnSuccess(user);
}
async uploadConfig(gobj, pobj, req, loginUser) {
//H5登录获取验证码
async sendMobileCode(obj, obj1, req) {
let mobile = obj.mobile;
if (!mobile) {
return this.returnFail("请先填写手机号");
}
if (validation.isMobile(mobile)) {
return this.returnFail("手机号格式错误");
}
try {
let data = await this.uploadCtl.getOssConfig();
return this.returnSuccess(data);
let key = this.SMS_LOGINMOBILE_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);
//this.addLog(obj, "sms");
console.log(rs);
}
return this.returnSuccess(1);
} catch (error) {
console.log(error);
return {code: 500};
return system.getResultFail(500, "接口异常:" + error.message);
}
}
// 登录接口 post
async login(o, obj, req) {
async login(obj, obj1, req) {
try {
if (!obj.mobile) {
return this.returnFail("请填写手机号");
}
let noteCode = (obj.noteCode || "").trim();
if (!noteCode) {
return this.returnFail("请填写短信验证码");
}
// TODO 手机号验证码登录
let key = this.SMS_LOGINMOBILE_KEY + obj.mobile;
let vcode = await this.redisClient.get(key + "t");
if (!vcode) {
return this.returnFail("短信验证码已过期,请重新发送");
}
if (vcode != noteCode) {
return this.returnFail("短信验证码错误,请重新填写");
}
let openID = "gtbh5_" + obj.mobile;
let merchant_id = decodeURIComponent(obj.merchant_id);
let params = {
saas_merchant_id: merchant_id,
saas_id: null,
openid: openID,
nickName: obj.mobile,
avatarUrl: "",
ucname: obj.mobile,
mobile :obj.mobile,
};
let res = await this.merchantappletuserSve.login(params);
if (res.status === 0) {
return this.returnSuccess(res.data);
......@@ -54,19 +99,34 @@ class TestAPI extends APIBase {
}
}
async addLog(pobj, consume_type) {
let user = await this.getLoginUser(pobj.merchant_id, pobj.openid);
let log = {saas_id: user.saas_id, saas_merchant_id: user.saas_merchant_id, consume_type: consume_type, consume_id: user.id};
let rs = await this.merchantSve.addConsumeLog({log: log});
console.log("log rs : ", rs);
//验证登录
async loginUser(obj) {
let merchant_id = decodeURIComponent(obj.merchant_id);
let user = await this.getLoginUser(merchant_id, obj.openid);
return this.returnSuccess(user);
}
async uploadConfig(obj, obj1, req) {
try {
let data = await this.uploadCtl.getOssConfig();
return this.returnSuccess(data);
} catch (error) {
console.log(error);
return {code: 500};
}
}
// 保存订单信息
async saveOrder(gobj, pobj, req, loginUser) {
async saveOrder(obj, obj1, req) {
try {
// TODO this.loginUser();
let rs = await this.buildOrder(pobj);
let loginUser = await this.loginUser(obj);
if (!loginUser) {
return this.returnFail("订单保存失败");
}
let rs = await this.buildOrder(obj);
if (rs.code === 0) {
return rs;
}
......@@ -78,18 +138,18 @@ class TestAPI extends APIBase {
userBankNo: bminfo.bank_no,
userMobile: bminfo.bank_mobile,
});
this.addLog(pobj, "bankfour");
// this.addLog(obj, "bankfour");
if (bf.code !== 0) {
return this.returnFail("银行卡四要素验证失败,请检查法人姓名,身份证,银行卡号,银行卡预留手机号正确");
}
let merchant = await this.getMerchant(pobj.merchant_id);
let loginUser = await this.getLoginUser(pobj.merchant_id, pobj.openid);
let merchant = await this.getMerchant(obj.merchant_id);
//let loginUser = await this.getLoginUser(pobj.merchant_id, pobj.openid);
let order = {
saas_id: merchant.saas_id,
merchant_id: merchant.id,
product_id: "10020000",
merchant_app_user_id: loginUser.id,
merchant_app_user_id: loginUser.data.id,
price: system.y2f(merchant.sign.bm_reg_price) || 0,
bminfo: rs.data
};
......@@ -157,13 +217,13 @@ class TestAPI extends APIBase {
return this.returnFail("请填写短信验证码");
}
let vcode = await this.redisClient.get(this.SMS_BANKMOBILE_KEY + obj.bank_mobile);
if (!vcode) {
return this.returnFail("短信验证码已过期,请重新发送");
}
if (vcode != noteCode) {
return this.returnFail("短信验证码错误,请重新填写");
}
// let vcode = await this.redisClient.get(this.SMS_LOGINMOBILE_KEY + obj.bank_mobile);
// if (!vcode) {
// return this.returnFail("短信验证码已过期,请重新发送");
// }
// if (vcode != noteCode) {
// return this.returnFail("短信验证码错误,请重新填写");
// }
let bminfo = {
idcard_front: obj.idcard_front,
idcard_back: obj.idcard_back,
......@@ -181,19 +241,18 @@ class TestAPI extends APIBase {
return this.returnSuccess(bminfo);
}
async myOrders(gobj, pobj, req) {
async myOrders(obj, obj1, req) {
// TODO this.loginUser();
let loginUser = await this.getLoginUser(pobj.merchant_id, pobj.openid);
let loginUser = await this.loginUser(obj);
if (!loginUser) {
return this.returnSuccess({count: 0, rows: []});
}
try {
let params = {
pageSize: Number(pobj.pageSize || 10),
currentPage: Number(pobj.currentPage || 1),
merchant_app_user_id: loginUser.id,
merchant_id: loginUser.merchant_id,
pageSize: Number(obj.pageSize || 10),
currentPage: Number(obj.currentPage || 1),
merchant_app_user_id: loginUser.data.id,
merchant_id: loginUser.data.saas_merchant_id,
}
let page = await this.orderSve.page(params);
......@@ -223,19 +282,19 @@ class TestAPI extends APIBase {
* @param {*} req
* @param {*} loginUser
*/
async orderInfo(gobj, pobj, req) {
async orderInfo(obj, obj1, req) {
// TODO this.loginUser();
let loginUser = await this.getLoginUser(pobj.merchant_id, pobj.openid);
let loginUser = await this.loginUser(obj);
if (!loginUser) {
return this.returnSuccess({});
}
try {
let rs = await this.orderSve.orderInfo(pobj);
let rs = await this.orderSve.orderInfo(obj);
if (rs.status === 0) {
return this.returnSuccess(rs.data);
} else {
return this.returnFail(page.msg);
return this.returnFail(rs.msg);
}
} catch (error) {
console.log(error);
......@@ -243,9 +302,9 @@ class TestAPI extends APIBase {
}
}
async idNoValid(gobj, pobj, req, loginUser) {
async idNoValid(obj, obj1, req) {
try {
let idno = (pobj.idno || "").trim();
let idno = (obj.idno || "").trim();
if (!idno) {
return {code: 0, msg: "请填写身份证号码"};
}
......@@ -271,9 +330,9 @@ class TestAPI extends APIBase {
async saasorderbusinessmenPage(params, pobj2, req) {
// TODO this.loginUser();
let loginUser = await this.getLoginUser(pobj2.merchant_id, pobj2.openid);
pobj2.merchant_app_user_id = loginUser.id;
let res = await this.businessmenSve.saasorderbusinessmenPage(pobj2);
let loginUser = await this.loginUser(params);
params.merchant_app_user_id = loginUser.data.id;
let res = await this.businessmenSve.saasorderbusinessmenPage(params);
if (res.status == 0) {
return this.returnSuccess(res.data);
} else {
......@@ -288,16 +347,16 @@ class TestAPI extends APIBase {
* @param req
* @returns {Promise<{msg: string, data: (*|null), bizmsg: string, status: number}>}
*/
async saasTradeBusinessmenPage(pobj1, pobj2, req) {
async saasTradeBusinessmenPage(obj, obj1, req) {
// TODO this.loginUser();
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) {
let loginUser = await this.loginUser(obj);
obj.merchant_app_user_id = loginUser.data.id;
obj.attrs = ["credit_code"];
if (!obj.merchant_app_user_id) {
return system.getResult(null, `登录失效,请重新登录`);
}
try {
let creditCodeArray = await this.businessmenSve.assorderBusinessmenInfo(pobj2);
let creditCodeArray = await this.businessmenSve.assorderBusinessmenInfo(obj);
if (creditCodeArray.status != 0) {
return this.returnSuccess({count: 0, rows: []});
}
......@@ -308,8 +367,8 @@ class TestAPI extends APIBase {
if (!creditCodes || creditCodes.length == 0) {
return this.returnSuccess({count: 0, rows: []});
}
pobj2.credit_code_array = creditCodes;
let res = await this.tradeSve.tradeItemBycreditCode(pobj2);
obj.credit_code_array = creditCodes;
let res = await this.tradeSve.tradeItemBycreditCode(obj);
if (res.status == 0) {
return this.returnSuccess(res.data);
} else {
......@@ -328,16 +387,16 @@ class TestAPI extends APIBase {
* @param req
* @returns {Promise<void>}
*/
async invoiceBycreditCode(pobj1, pobj2, req) {
async invoiceBycreditCode(obj, obj1, req) {
// TODO this.loginUser();
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) {
let loginUser = await this.loginUser(obj);
obj.merchant_app_user_id = loginUser.data.id;
obj.attrs = ["credit_code"];
if (!obj.merchant_app_user_id) {
return system.getResult(null, `登录失效,请重新登录`);
}
try {
let creditCodeArray = await this.businessmenSve.assorderBusinessmenInfo(pobj2);
let creditCodeArray = await this.businessmenSve.assorderBusinessmenInfo(obj);
if (creditCodeArray.status != 0) {
return this.returnSuccess({count: 0, rows: []});
......@@ -349,9 +408,9 @@ class TestAPI extends APIBase {
if (!creditCodes || creditCodes.length == 0) {
return this.returnSuccess({count: 0, rows: []});
}
pobj2.credit_code_array = creditCodes;
obj.credit_code_array = creditCodes;
let res = await this.saasInvoiceSve.invoiceBycreditCode(pobj2);
let res = await this.saasInvoiceSve.invoiceBycreditCode(obj);
if (res.status == 0) {
return this.returnSuccess(res.data);
} else {
......@@ -370,10 +429,10 @@ class TestAPI extends APIBase {
* @param req
* @returns {Promise<void>}
*/
async sendBankMobileCode(pobj1, pobj, req) {
async sendBankMobileCode(obj, obj1, req) {
// TODO this.loginUser();
let loginUser = await this.getLoginUser(pobj.merchant_id, pobj.openid);
let mobile = pobj.mobile;
let loginUser = await this.loginUser(obj);
let mobile = obj.mobile;
if (!mobile) {
return this.returnFail("请先填写银行卡预留手机号");
}
......@@ -390,7 +449,7 @@ class TestAPI extends APIBase {
await this.redisClient.setWithEx(key + "t", vcode, 60);
let msg = "您的个体户注册手机验证码为" + vcode + ", (切勿将验证码告知别人, 请在5分钟内输入完成验证, 如有问题请联系客服。)";
let rs = await this.smsClient.sendMsg(mobile, msg);
this.addLog(pobj, "sms");
//this.addLog(pobj, "sms");
console.log(rs);
}
return this.returnSuccess(1);
......@@ -399,6 +458,7 @@ class TestAPI extends APIBase {
}
}
getVCode() {
var randomNum = "" + Math.round(Math.random() * 1000000);
while (randomNum.length < 6) {
......@@ -447,9 +507,69 @@ class TestAPI extends APIBase {
return rs.data || {};
}
//日志
async addLog(obj, consume_type) {
let user = await this.getLoginUser(obj.merchant_id, obj.openid);
let log = {
// saas_id: user.saas_id,
saas_merchant_id: user.saas_merchant_id,
consume_type: consume_type,
consume_id: user.id
};
let rs = await this.merchantSve.addConsumeLog({log: log});
console.log("log rs : ", rs);
}
returnResult(code, msg, data) {
return {
code: code || 0,
msg: msg || "",
data: data
}
}
returnSuccess(data) {
return this.returnResult(1, "success", data)
}
returnFail(msg, data) {
return this.returnResult(0, msg, data);
}
trim(o) {
if (!o) {
return "";
}
return o.toString().trim();
}
getUidStr(len, radix) {
var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
var uuid = [],
i;
radix = radix || chars.length;
if (len) {
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
} else {
var r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random() * 16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
}
exam() {
return "";
}
classDesc() {
return {
groupName: "",
......@@ -459,6 +579,7 @@ class TestAPI extends APIBase {
exam: "",
};
}
methodDescs() {
return [
{
......@@ -478,4 +599,5 @@ class TestAPI extends APIBase {
];
}
}
module.exports = TestAPI;
\ No newline at end of file
module.exports = TestAPI;
......@@ -22,7 +22,7 @@ class ServiceBase {
/**
* 验证签名
* @param {*} params 要验证的参数
* @param {*} params 要验证的参数
* @param {*} app_key 应用的校验key
*/
async verifySign(params, app_key) {
......@@ -55,7 +55,7 @@ class ServiceBase {
}
/**
* 创建签名
* @param {*} params 要验证的参数
* @param {*} params 要验证的参数
* @param {*} app_key 应用的校验key
*/
async createSign(params, app_key) {
......@@ -220,7 +220,7 @@ class ServiceBase {
}
try {
var params = {
"action_process": "xgg-saas-platform",
"action_process": "sijibao",
"action_type": apiName,
"action_body": params || {},
}
......@@ -231,7 +231,7 @@ class ServiceBase {
url: reqUrl,
data: params
});
console.log(rs);
return rs.data;
}
......@@ -293,4 +293,4 @@ class ServiceBase {
return o.toString().trim();
}
}
module.exports = ServiceBase;
\ No newline at end of file
module.exports = ServiceBase;
......@@ -188,22 +188,22 @@ class System {
let dev = "http://39.107.234.14";
return {
// 公共服务
common: local + ":3102" + path,
common: dev + ":3102" + path,
// 商户服务
merchant: local + ":3101" + path,
merchant: dev + ":3101" + path,
// 订单服务
order: local + ":3103" + path,
order: dev + ":3103" + path,
// 发票服务
invoice: dev + ":3105" + path,
// 用户服务
uc: local + ":3106" + path,
uc: dev + ":3106" + path,
// 交易
trade: local + ":3107" + path,
trade: dev + ":3107" + path,
}
} else {
return {
......
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