Commit 306a674e by 宋毅

tj

parent b4311bbf
......@@ -13,44 +13,23 @@ class OpProductAPI extends APIBase {
* action_body 执行的参数
*/
async springBoard(pobj, qobj, req) {
if (!pobj.actionProcess) {
return system.getResult(null, "actionProcess参数不能为空");
}
if (!pobj.actionType) {
return system.getResult(null, "actionType参数不能为空");
}
var result = null;
switch (pobj.actionProcess) {
case "jd"://京东
result = await this.opActionProcess(pobj.actionProcess, pobj.actionType, pobj.actionBody, pobj, req);
break;
case "1688"://1688
result = await this.opActionProcess(pobj.actionProcess, pobj.actionType, pobj.actionBody, pobj, req);
break;
case "gsbhome"://gsb_homepage
result = await this.opActionProcess(pobj.actionProcess, pobj.actionType, pobj.actionBody, pobj, req);
break;
default:
result = system.getResult(null, "actionProcess参数错误");
break;
}
var result = await this.opActionProcess(pobj, pobj.actionType, req);
return result;
}
async opActionProcess(action_process, action_type, action_body, pobj, req) {
// action_body.app = req.app;
// action_body.user = req.user;
async opActionProcess(pobj, action_type, req) {
var opResult = null;
switch (action_type) {
case "findByTypeCode"://通过产品类别编码获取产品列表
action_body["app"]=pobj.app;
opResult = await this.productSve.findByTypeCode(action_body);
case "getCAProductListByTypeCode"://通过产品类别编码获取产品列表
opResult = await this.productSve.findByTypeCode(pobj.actionBody, pobj.appInfo);
break;
case "findByTypeOneCode"://通过产品大类编码获取产品列表
action_body["app"]=pobj.app;
opResult = await this.productSve.findByTypeOneCode(action_body);
case "getCAProductListByTypeOneCode"://通过产品大类编码获取产品列表
opResult = await this.productSve.findByTypeOneCode(pobj.actionBody, pobj.appInfo);
break;
case "getProductDetailByCode"://获取产品详情
opResult = await this.productSve.getProductDetailByCode(action_body.channelItemCode,pobj.uapp_id);
case "getCAProductDetail"://获取产品详情
opResult = await this.productSve.getProductDetailByCode(pobj.actionBody.channelItemCode, pobj.appInfo.uapp_id);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
......
......@@ -16,38 +16,38 @@ class AccessAuthAPI extends APIBase {
}
async getVerifyCodeByMoblie(pobj, qobj, req) {
if (!pobj.mobile) {
return system.getResult(null, "pobj.mobile can not be empty !");
if (!pobj.actionBody.mobile) {
return system.getResult(null, "actionBody.mobile can not be empty !");
}
var result = await this.opPlatformUtils.fetchVCode(pobj.mobile, pobj.appInfo.uapp_key, pobj.appInfo.uapp_secret);
var result = await this.opPlatformUtils.fetchVCode(pobj.actionBody.mobile, pobj.appInfo.uapp_key, pobj.appInfo.uapp_secret);
return result;
}
async loginUserByChannelUserId(pobj, qobj, req) {
if (!pobj.channelUserId) {
return system.getResult(null, "pobj.channelUserId can not be empty !");
if (!pobj.actionBody.channelUserId) {
return system.getResult(null, "actionBody.channelUserId can not be empty !");
}
var result = await this.opPlatformUtils.getReqUserPinByChannelUserId(pobj);
return result;
}
async login(pobj, qobj, req) {
if (!pobj.userName) {
return system.getResult(null, "pobj.userName can not be empty !");
if (!pobj.actionBody.userName) {
return system.getResult(null, "actionBody.userName can not be empty !");
}
if (!pobj.password) {
return system.getResult(null, "pobj.password can not be empty !");
if (!pobj.actionBody.password) {
return system.getResult(null, "actionBody.password can not be empty !");
}
var result = await this.opPlatformUtils.getReqUserPinByLgoin(pobj);
return result;
}
async loginByVerifyCode(pobj, qobj, req) {
if (!pobj.mobile) {
return system.getResult(null, "pobj.mobile can not be empty !");
if (!pobj.actionBody.mobile) {
return system.getResult(null, "actionBody.mobile can not be empty !");
}
if (!pobj.vcode) {
return system.getResult(null, "pobj.vcode can not be empty !");
if (!pobj.actionBody.vcode) {
return system.getResult(null, "actionBody.vcode can not be empty !");
}
var result = await this.opPlatformUtils.getReqUserPinByLgoinVcode(pobj);
return result;
......
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
//缓存首次登录的赠送的宝币数量
class ApiAccessKeyCheckCache extends CacheBase {
constructor() {
super();
this.restS = system.getObject("util.restClient");
}
desc() {
return "应用中来访访问token缓存";
}
prefix() {
return settings.cacheprefix + "_verify_reqaccesskey:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var cacheManager = system.getObject("db.common.cacheManager");
//当来访key缓存不存在时,需要去开放平台检查是否存在来访key缓存
var acckapp = await cacheManager["ApiAccessKeyCache"].cache(settings.appKey, null, ex);//先获取本应用accessKey
if (acckapp.status != 0) {
return system.getResult(null, "获取本应用accessKey错误");
}
var checkresult = await this.restS.execPostWithAK({ checkAccessKey: inputkey }, settings.paasUrl() + "api/auth/accessAuth/authAccessKey", acckapp.data.accessKey);
if (checkresult.status == 0) {
return checkresult;
// var s = checkresult.data;
// return JSON.stringify(s);
} else {
await cacheManager["ApiAccessKeyCache"].invalidate(settings.appKey);
var acckapp = await cacheManager["ApiAccessKeyCache"].cache(settings.appKey, null, ex);//先获取本应用accessKey
var checkresult = await this.restS.execPostWithAK({ checkAccessKey: inputkey }, settings.paasUrl() + "api/auth/accessAuth/authAccessKey", acckapp.data.accessKey);
return checkresult;
// var s = checkresult.data;
// return JSON.stringify(s);
}
}
}
module.exports = ApiAccessKeyCheckCache;
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
class ApiAppKeyCheckCache extends CacheBase {
constructor() {
super();
this.appDao = system.getObject("db.dbapp.appDao");
}
desc() {
return "应用中来访访问appid缓存";
}
prefix() {
return settings.cacheprefix + "_verify_appKey:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var item = await this.appDao.getItemByAppKey(inputkey);
if (!item) {
return system.getResult(null, "返回数据为空!");
}
if (item.status != 1) {
return system.getResultFail(system.waitAuditSelfApp, "渠道应用处于待审核等待启用状态");
}
return system.getResultSuccess(item);
}
}
module.exports = ApiAppKeyCheckCache;
const CacheBase = require("../cache.base");
const system = require("../../system");
const settings = require("../../../config/settings");
//缓存首次登录的赠送的宝币数量
class ApiUserCache extends CacheBase {
constructor() {
super();
this.opPlatformUtils = system.getObject("util.businessManager.opPlatformUtils");
this.appDao = system.getObject("db.dbapp.appDao");
this.appuserDao = system.getObject("db.dbapp.appuserDao");
this.restClient = system.getObject("util.restClient");
}
desc() {
return "应用中来访访问token缓存";
}
prefix() {
return settings.cacheprefix + "_userdata:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var actionBody = items[0];
var selfAppInfo = items[1];
var uAppId = items[2];
var channelUserId = val || "";
var uUserName = channelUserId + "$" + selfAppInfo.data.uappKey;//uUserName
var createUserPwd = inputkey;//(格式:selfAppInfo.data.uappKey+”_“+channelUserId)
var userInfo = await this.appuserDao.getItemByUUserId(uUserName, selfAppInfo.data.id);
if (userInfo) {
var loginNum = Number(userInfo.loginNum || 0) + 1;
this.appuserDao.updateByWhere({ lastLoginTime: new Date(), loginNum: loginNum }, { where: { id: userInfo.id } });
return system.getResultSuccess(userInfo);
}
var uUserInfo = await this.opPlatformUtils.createUserInfo(uUserName, actionBody.channelUserMoblie || "15010888888",
createUserPwd, selfAppInfo.data.uappKey, selfAppInfo.data.appSecret);
if (uUserInfo.status != 2000 && uUserInfo.status != 0) {
return uUserInfo;
}//已经存在此用户 或 注册失败
if (uUserInfo.status == 0) {
var params = {
app_id: selfAppInfo.data.id,
channelUserId: channelUserId,
channelUserName: actionBody.channelUserName || channelUserId,
userMoblie: actionBody.channelUserMoblie || "88888888888",
nickname: actionBody.nickname || "",
orgName: actionBody.orgName || "",
orgPath: actionBody.orgPath || "",
uUserName: uUserName,
uAppId: uAppId,
isEnabled: 1,
lastLoginTime: new Date()
};
userInfo = await this.appuserDao.create(params);
}
else {
return uUserInfo;
}
return system.getResultSuccess(userInfo);
}
}
module.exports = ApiUserCache;
......@@ -15,10 +15,11 @@ class AppUserPinByChannelUserIdCache extends CacheBase {
return settings.cacheprefix + "_userPin:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var actionBody = val;
var createUserPwd = inputkey;//(格式:actionBody.appInfo.uapp_key+”_“+actionBody.channelUserId)
var actionBody = val.actionBody;
var appInfo = val.appInfo;
var createUserPwd = inputkey;//(格式:appInfo.uapp_key+”_“+actionBody.channelUserId)
var channelUserMoblie = actionBody.channelUserMoblie || "15010888888";
var userInfo = await this.appuserDao.getItemByChannelUserId(actionBody.channelUserId, actionBody.appInfo.uapp_id);
var userInfo = await this.appuserDao.getItemByChannelUserId(actionBody.channelUserId, appInfo.uapp_id);
if (userInfo) {
if (userInfo.is_enabled != 1) {
return system.getResult(null, "user to item is Disable !");
......@@ -26,13 +27,13 @@ class AppUserPinByChannelUserIdCache extends CacheBase {
return system.getResultSuccess(userInfo);
}
var uUserInfo = await this.opPlatformUtils.createUserInfo(actionBody.channelUserId, channelUserMoblie,
createUserPwd, actionBody.appInfo.uapp_key, actionBody.appInfo.uapp_secret);
createUserPwd, appInfo.uapp_key, appInfo.uapp_secret);
if (uUserInfo.status != 2000 && uUserInfo.status != 0) {
return uUserInfo;
}//2000已经存在此用户 或 注册失败
if (uUserInfo.status == 0) {
var params = {
uapp_id: actionBody.appInfo.uapp_id,
uapp_id: appInfo.uapp_id,
channel_userid: actionBody.channelUserId,
channel_username: actionBody.channelUserName || actionBody.channelUserId,
channel_nickname: actionBody.nickName || "",
......
......@@ -14,15 +14,16 @@ class AppUserPinByLoginPwdCache extends CacheBase {
return settings.cacheprefix + "_userPin:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var actionBody = val;
var actionBody = val.actionBody;
var appInfo = val.appInfo;
var uUserName = actionBody.userName;//uUserName
var uPassword = actionBody.password;//uPassword
var uUserInfo = await this.opPlatformUtils.login(uUserName, uPassword,
actionBody.appInfo.uapp_key, actionBody.appInfo.uapp_secret);
appInfo.uapp_key, appInfo.uapp_secret);
if (uUserInfo.status != 0) {
return uUserInfo;
}//值为2010为用户名或密码错误
var userInfo = await this.appuserDao.getItemByChannelUserId(actionBody.userName, actionBody.appInfo.uapp_id);
var userInfo = await this.appuserDao.getItemByChannelUserId(actionBody.userName, appInfo.uapp_id);
if (!userInfo) {
return system.getResult(null, "user to item is empty !");
}
......
......@@ -14,14 +14,15 @@ class AppUserPinByLoginVcodeCache extends CacheBase {
return settings.cacheprefix + "_userPin:";
}
async buildCacheVal(cachekey, inputkey, val, ex, ...items) {
var actionBody = val;
var actionBody = val.actionBody;
var appInfo = val.appInfo;
var uUserInfo = await this.opPlatformUtils.loginByVCode(actionBody.mobile, actionBody.vcode, actionBody.password,
actionBody.appInfo.uapp_key, actionBody.appInfo.uapp_secret);
appInfo.uapp_key, appInfo.uapp_secret);
if (uUserInfo.status != 0) {
return uUserInfo;
}//2030验证码校验不成功 或 注册失败
var userInfo = await this.appuserDao.getItemByChannelUserId(actionBody.mobile, actionBody.appInfo.uapp_id);
var userInfo = await this.appuserDao.getItemByChannelUserId(actionBody.mobile, appInfo.uapp_id);
if (userInfo) {
if (userInfo.is_enabled != 1) {
return system.getResult(null, "user to item is Disable !");
......@@ -29,7 +30,7 @@ class AppUserPinByLoginVcodeCache extends CacheBase {
return system.getResultSuccess(userInfo);
}
var params = {
uapp_id: actionBody.appInfo.uapp_id,
uapp_id: appInfo.uapp_id,
channel_userid: actionBody.mobile || "",
channel_username: actionBody.mobile || "",
channel_nickname: actionBody.nickName || "",
......
......@@ -9,102 +9,48 @@ class ProductService extends ServiceBase {
}
/**
* 获取产品详情
* @param {*} pid 产品id
*/
async getProductDetailById(pid){
if(!pid){
return system.getResult(null, "产品id有误");
}
var sql = "select * from v_product where id="+pid;
var tmpResult = await this.customQuery(sql);
if(tmpResult && tmpResult.length>0){
for(var i=0;i<tmpResult.length;i++){
var pro = tmpResult[i];
if(pro.id){
var ppList = await this.productpriceDao.model.findAll({
where:{product_id:pro.id},
attributes: ["price","supply_price","service_charge","public_expense","is_default","price_type","price_type_name",
"sort","price_desc","min_qty","max_qty"
],
raw:true
});
pro.productPriceList=ppList;
}
}
}
return system.getResultSuccess(tmpResult);
}
/**
* 获取产品详情2
* @param {*} channelItemCode 渠道产品码
* @param {*} uappid 渠道id
*/
async getProductDetailByCode(channelItemCode,uappid){
if(!channelItemCode){
return system.getResult(null, "产品编码有误");
}
if(!uappid){
return system.getResult(null, "渠道编码有误");
}
var sql = "select * from v_product where uapp_id="+uappid+" and channel_item_code='"+channelItemCode+"'";
async getProductDetailByCode(channelItemCode, uappid) {
var sql = "select * from v_product where uapp_id=" + uappid + " and channel_item_code='" + channelItemCode + "'";
var tmpResult = await this.customQuery(sql);
if(tmpResult && tmpResult.length>0){
for(var i=0;i<tmpResult.length;i++){
if (tmpResult && tmpResult.length > 0) {
for (var i = 0; i < tmpResult.length; i++) {
var pro = tmpResult[i];
if(pro.id){
if (pro.id) {
var ppList = await this.productpriceDao.model.findAll({
where:{product_id:pro.id},
attributes: ["price","supply_price","service_charge","public_expense","is_default","price_type","price_type_name",
"sort","price_desc","min_qty","max_qty"
where: { product_id: pro.id },
attributes: ["price", "supply_price", "service_charge", "public_expense", "is_default", "price_type", "price_type_name",
"sort", "price_desc", "min_qty", "max_qty"
],
raw:true
raw: true
});
pro.productPriceList=ppList;
pro.productPriceList = ppList;
}
}
}
return system.getResultSuccess(tmpResult);
}
/**
* 通过产品类别编码获取产品列表
* @param {*} obj
* 通过产品类别编码获取产品列表
* @param {*} actionBody
*/
async findByTypeCode(obj){
var app=obj.app;
if(!app || !app.uapp_id){
return system.getResult(null, "渠道参数有误");
}
var typeCode = obj.typeCode;
if(!typeCode){
return system.getResult(null, "产品类别编码有误");
}
var sql = "select * from v_product where uapp_id="+app.uapp_id+" and type_code='"+typeCode+"'";
async findByTypeCode(actionBody, appInfo) {
var sql = "select * from v_product where uapp_id=" + appInfo.uapp_id + " and type_code='" + actionBody.typeCode + "'";
var tmpResult = await this.customQuery(sql);
return system.getResultSuccess(tmpResult);
}
/**
* 通过产品大类编码获取产品列表
* @param {*} obj
* @param {*} actionBody
*/
async findByTypeOneCode(obj){
var app=obj.app;
if(!app || !app.id){
return system.getResult(null, "渠道参数有误");
}
var typeOneCode = obj.typeOneCode;
if(!typeOneCode){
return system.getResult(null, "产品类别编码有误");
}
var sql = "select * from v_product where uapp_id="+app.uapp_id+" and p_type_code='"+typeOneCode+"'";
async findByTypeOneCode(actionBody, appInfo) {
var sql = "select * from v_product where uapp_id=" + appInfo.uapp_id + " and p_type_code='" + actionBody.typeOneCode + "'";
var tmpResult = await this.customQuery(sql);
return system.getResultSuccess(tmpResult);
}
}
module.exports = ProductService;
// var task = new ProductService();
// task.getProductDetailByCode("test002",7).then(d=>{
// console.log(d,"ddddddddddddddddddddddddddddddddddddddddddddddd");
// console.log(d.data[0],"eeeee");
// });
......@@ -102,38 +102,6 @@ class ServiceBase {
}
return tResult;
}
async apiCallWithAk(url, params) {
var acckapp = await this.cacheManager["ApiAccessKeyCache"].cache(settings.appKey);
var acck = acckapp.accessKey;
//按照访问token
var restResult = await this.restS.execPostWithAK(params, url, acck);
if (restResult) {
if (restResult.status == 0) {
var resultRtn = restResult.data;
return resultRtn;
} else {
await this.cacheManager["ApiAccessKeyCache"].invalidate(settings.appKey);
return null;
}
}
return null;
}
// async apiCallWithAkNoWait(url,params){
// var acckapp=await this.cacheManager["ApiAccessKeyCache"].cache(settings.appKey);
// var acck=acckapp.accessKey;
// //按照访问token
// var restResult=await this.restS.execPostWithAK(params,url,acck);
// if(restResult){
// if(restResult.status==0){
// var resultRtn=restResult.data;
// return resultRtn;
// }else{
// await this.cacheManager["ApiAccessKeyCache"].invalidate(settings.appKey);
// return null;
// }
// }
// return null;
// }
static getDaoName(ClassObj) {
return ClassObj["name"].substring(0, ClassObj["name"].lastIndexOf("Service")).toLowerCase() + "Dao";
}
......
......@@ -199,34 +199,34 @@ class OpPlatformUtils {
var result = await cacheManager["AppTokenByHostsCache"].cache(app_hosts, null, system.exTime);
return result;
}
async getReqUserPinByChannelUserId(actionBody) {
var inputkey = actionBody.appInfo.uapp_key + "_" + actionBody.channelUserId;
async getReqUserPinByChannelUserId(pobj) {
var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.channelUserId;
var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppUserPinByChannelUserIdCache"].getCache(inputkey, actionBody, system.shortExTime);
var result = await cacheManager["AppUserPinByChannelUserIdCache"].getCache(inputkey, pobj, system.shortExTime);
if (result && result.status == 0) {
return system.getResultFail(system.reDoLoginFail, "请勿重复登录");
}
result = await cacheManager["AppUserPinByChannelUserIdCache"].cache(inputkey, actionBody, system.shortExTime);
result = await cacheManager["AppUserPinByChannelUserIdCache"].cache(inputkey, pobj, system.shortExTime);
return result;
}
async getReqUserPinByLgoin(actionBody) {
var inputkey = actionBody.appInfo.uapp_key + "_" + actionBody.userName;
async getReqUserPinByLgoin(pobj) {
var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.userName;
var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppUserPinByLoginPwdCache"].getCache(inputkey, actionBody, system.shortExTime);
var result = await cacheManager["AppUserPinByLoginPwdCache"].getCache(inputkey, pobj, system.shortExTime);
if (result && result.status == 0) {
return system.getResultFail(system.reDoLoginFail, "请勿重复登录");
}
result = await cacheManager["AppUserPinByLoginPwdCache"].cache(inputkey, actionBody, system.shortExTime);
result = await cacheManager["AppUserPinByLoginPwdCache"].cache(inputkey, pobj, system.shortExTime);
return result;
}
async getReqUserPinByLgoinVcode(actionBody) {
var inputkey = actionBody.appInfo.uapp_key + "_" + actionBody.mobile;
async getReqUserPinByLgoinVcode(pobj) {
var inputkey = pobj.appInfo.uapp_key + "_" + pobj.actionBody.mobile;
var cacheManager = system.getObject("db.common.cacheManager");
var result = await cacheManager["AppUserPinByLoginVcodeCache"].getCache(inputkey, actionBody, system.shortExTime);
var result = await cacheManager["AppUserPinByLoginVcodeCache"].getCache(inputkey, pobj, system.shortExTime);
if (result && result.status == 0) {
return system.getResultFail(system.reDoLoginFail, "请勿重复登录");
}
result = await cacheManager["AppUserPinByLoginVcodeCache"].cache(inputkey, actionBody, system.shortExTime);
result = await cacheManager["AppUserPinByLoginVcodeCache"].cache(inputkey, pobj, system.shortExTime);
return result;
}
}
......
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