Commit b569d9a8 by 蒋勇

Merge branch 'scratch-web' of gitlab.gongsibao.com:jiangyong/zhichan into scratch-web

parents 0537dd77 d65e6070
var childproc = require('child_process');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
const uuidv4 = require('uuid/v4');
class ExecClient {
constructor() {
this.cmdPostPattern = "curl --user admines:adminGSBes. -k -H 'Content-type: application/json' -d '{data}' {url}";
this.cmdGetPattern = "curl -G -X GET '{url}'";
this.cmdPushDataPostPattern = "curl -k -H 'Content-type: application/json' -H 'token:{tk}' -H 'request-id:{requestId}' -d '{data}' {url}";
}
async exec(cmd) {
......@@ -69,6 +71,26 @@ class ExecClient {
const {stdout, stderr} = await exec(cmd, options);
return {stdout, stderr};
}
getUUID() {
var uuid = uuidv4();
var u = uuid.replace(/\-/g, "");
return u;
}
FetchPushDataPostCmd(subData, url, token, requestId) {
var requestId = requestId || this.getUUID();
var data = JSON.stringify(subData);
var cmd = this.cmdPushDataPostPattern.replace(/\{data\}/g,
data).replace(/\{url\}/g, url).replace(/\{tk\}/g, token).replace(/\{requestId\}/g, requestId);
console.log(cmd);
return cmd;
}
async execPushDataPost(subData, url, token, requestId) {
let cmd = this.FetchPushDataPostCmd(subData, url, token, requestId);
var result = await this.exec(cmd);
return result;
}
}
module.exports = ExecClient;
......
var system=require("../../system")
const http=require("http")
var system = require("../../system")
const http = require("http")
const querystring = require('querystring');
var settings=require("../../../config/settings");
const AppletBase =require("../applet.base");
const logCtl=system.getObject("web.oplogCtl");
class businesschanceApplet extends AppletBase{
constructor(){
super();
this.businesschanceService=system.getObject("service.businesschanceSve");
this.orderService=system.getObject("service.orderSve");
this.businesschanceSve=system.getObject("service.businesschanceSve");
this.channelSve=system.getObject("service.channelSve");
this.servicesitemSve=system.getObject("service.servicesitemSve");
this.shopSve=system.getObject("service.shopSve");
}
async getBusinessChancesByHhrId(obj,req){
try {
var openid = obj.openid;
console.log(openid);
var userInfo =await this.cacheManager["AppletUserinfoCache"].get(openid);
if(userInfo==null||userInfo=="undefined"){
return system.getResult2(null,null);
}
userInfo=JSON.parse(userInfo);
console.log(userInfo);
var userId=userInfo.id;
var onlyCode=userInfo.onlyCode;
var payUserIds= await this.orderService.getPayUserIdByOnlyCode(userInfo.onlyCode);
var data={};
if(obj.searchName==null|| obj.searchName==""||obj.searchName=="undefined"){
if(payUserIds[0]==null){
data[this.db.Op.or]=[
{shopOnlyCode:onlyCode}
];
}else {
data[this.db.Op.or]=[
{publisherId:{[this.db.Op.in]:payUserIds}},
{shopOnlyCode:onlyCode}
];
}
}else{
if(payUserIds[0]==null){
data[this.db.Op.or]=[
{[this.db.Op.or]:[{shopOnlyCode:onlyCode},
{publisherName:{[this.db.Op.like]:"%"+obj.searchName+"%" }},
{publisherMobile:{[this.db.Op.like]:"%"+obj.searchName+"%" }},
{chanceTypeName:{[this.db.Op.like]: "%"+obj.searchName+"%" }},
{chanceStatusName:{[this.db.Op.like]: "%"+obj.searchName+"%" }}]}
];
var settings = require("../../../config/settings");
const AppletBase = require("../applet.base");
const logCtl = system.getObject("web.oplogCtl");
class businesschanceApplet extends AppletBase {
constructor() {
super();
this.businesschanceService = system.getObject("service.businesschanceSve");
this.orderService = system.getObject("service.orderSve");
this.businesschanceSve = system.getObject("service.businesschanceSve");
this.channelSve = system.getObject("service.channelSve");
this.servicesitemSve = system.getObject("service.servicesitemSve");
this.shopSve = system.getObject("service.shopSve");
this.execClient = system.getObject("util.execClient");
this.restClient = system.getObject("util.restClient");
}
async getBusinessChancesByHhrId(obj, req) {
try {
var openid = obj.openid;
console.log(openid);
var userInfo = await this.cacheManager["AppletUserinfoCache"].get(openid);
if (userInfo == null || userInfo == "undefined") {
return system.getResult2(null, null);
}
userInfo = JSON.parse(userInfo);
console.log(userInfo);
var userId = userInfo.id;
var onlyCode = userInfo.onlyCode;
var payUserIds = await this.orderService.getPayUserIdByOnlyCode(userInfo.onlyCode);
var data = {};
if (obj.searchName == null || obj.searchName == "" || obj.searchName == "undefined") {
if (payUserIds[0] == null) {
data[this.db.Op.or] = [
{ shopOnlyCode: onlyCode }
];
} else {
data[this.db.Op.or] = [
{ publisherId: { [this.db.Op.in]: payUserIds } },
{ shopOnlyCode: onlyCode }
];
}
} else {
if (payUserIds[0] == null) {
data[this.db.Op.or] = [
{
[this.db.Op.or]: [{ shopOnlyCode: onlyCode },
{ publisherName: { [this.db.Op.like]: "%" + obj.searchName + "%" } },
{ publisherMobile: { [this.db.Op.like]: "%" + obj.searchName + "%" } },
{ chanceTypeName: { [this.db.Op.like]: "%" + obj.searchName + "%" } },
{ chanceStatusName: { [this.db.Op.like]: "%" + obj.searchName + "%" } }]
}
];
}
else {
data[this.db.Op.or] = [
{ publisherId: { [this.db.Op.in]: payUserIds } },
{
[this.db.Op.or]: [{ shopOnlyCode: onlyCode },
{ publisherName: { [this.db.Op.like]: "%" + obj.searchName + "%" } },
{ publisherMobile: { [this.db.Op.like]: "%" + obj.searchName + "%" } },
{ chanceTypeName: { [this.db.Op.like]: "%" + obj.searchName + "%" } },
{ chanceStatusName: { [this.db.Op.like]: "%" + obj.searchName + "%" } }]
}
];
}
}
var chances = await this.businesschanceService.findAllChances(data);
if (chances == null || chances.length == 0) {
return system.getResult2(null, null);
}
console.log("chances.....................................01");
console.log(chances);
//获取渠道名称
var self = this;
for (var i = 0; i < chances.length; i++) {
if (chances[i] != null) {
chances[i].channelName = "";
}
if (chances[i].channelCode != null && chances[i].channelCode != "" && chances[i].channelCode != "undefined") {
var channel = await self.channelSve.getChannelItem(chances[i].channelCode);
if (channel != null) {
chances[i].channelName = channel.channelName;
}
else {
data[this.db.Op.or]=[
{publisherId:{[this.db.Op.in]:payUserIds}},
{[this.db.Op.or]:[{shopOnlyCode:onlyCode},
{publisherName:{[this.db.Op.like]:"%"+obj.searchName+"%" }},
{publisherMobile:{[this.db.Op.like]:"%"+obj.searchName+"%" }},
{chanceTypeName:{[this.db.Op.like]: "%"+obj.searchName+"%" }},
{chanceStatusName:{[this.db.Op.like]: "%"+obj.searchName+"%" }}]}
];
}
}
var chances = await this.businesschanceService.findAllChances(data);
if(chances==null||chances.length==0){
return system.getResult2(null,null);
}
console.log("chances.....................................01");
console.log(chances);
//获取渠道名称
var self=this;
for (var i = 0; i < chances.length; i++) {
if(chances[i]!=null){
chances[i].channelName="";
}
if(chances[i].channelCode!=null&&chances[i].channelCode!=""&&chances[i].channelCode!="undefined"){
var channel=await self.channelSve.getChannelItem(chances[i].channelCode);
if(channel!=null){
chances[i].channelName=channel.channelName;
}
}
}
console.log("chances--------------------------------------------------02");
console.log(chances);
return system.getResult2(chances,null);
} catch (e) {
console.log(e.stack);
//日志记录
logCtl.error({
optitle:"获取我的商机异常,openid="+obj.openid,
op:"wxapplet/impl/businesschanceApplet/getBusinessChancesByHhrId",
content:e.stack,
clientIp:req.clientIp
});
} finally {
}
}
console.log("chances--------------------------------------------------02");
console.log(chances);
return system.getResult2(chances, null);
} catch (e) {
console.log(e.stack);
//日志记录
logCtl.error({
optitle: "获取我的商机异常,openid=" + obj.openid,
op: "wxapplet/impl/businesschanceApplet/getBusinessChancesByHhrId",
content: e.stack,
clientIp: req.clientIp
});
} finally {
}
}
}
}
async findCustomers(obj,req){
var openid = obj.openid;
var nickName = obj.nickName;
var userinfo = await this.getUserInfo(openid);
userinfo=JSON.parse(userinfo);
console.log(userinfo.unionId);
console.log("findCustomers-----------------------getUserInfo------");
console.log(userinfo);
console.log(nickName);
if(!nickName){
return this.businesschanceService.findCustomersByOnlyCode(userinfo.unionId);
}else{
return this.businesschanceService.findCustomers(userinfo.unionId,nickName);
}
async findCustomers(obj, req) {
var openid = obj.openid;
var nickName = obj.nickName;
var userinfo = await this.getUserInfo(openid);
userinfo = JSON.parse(userinfo);
console.log(userinfo.unionId);
console.log("findCustomers-----------------------getUserInfo------");
console.log(userinfo);
console.log(nickName);
if (!nickName) {
return this.businesschanceService.findCustomersByOnlyCode(userinfo.unionId);
} else {
return this.businesschanceService.findCustomers(userinfo.unionId, nickName);
}
}
//发布需求
async submitneed(pobj,obj){
var serviceItem_name="";
var chanceType="yzc";
if(obj.publisherName==""||obj.publisherName==null){
return {code:-100,msg:"请填写您的姓名"};
}
if(obj.publisherMobile==""||obj.publisherMobile==null){
return {code:-100,msg:"请填写您的电话"};
}
if(obj.notes!=""&&obj.notes.length>255){
return {code:-100,msg:"备注字数超出限制,请重新填写"};
}
}
//发布需求
async submitneed(pobj, obj) {
var serviceItem_name = "";
var chanceType = "yzc";
if (obj.publisherName == "" || obj.publisherName == null) {
return { code: -100, msg: "请填写您的姓名" };
}
if (obj.publisherMobile == "" || obj.publisherMobile == null) {
return { code: -100, msg: "请填写您的电话" };
}
if (obj.notes != "" && obj.notes.length > 255) {
return { code: -100, msg: "备注字数超出限制,请重新填写" };
}
if(obj.channelCode==""){
return {code:-110,msg:"channelCode参数传递错误"};
}
var channelItem=await this.channelSve.getChannelItem(obj.channelCode);
if(channelItem==""||channelItem==null){
return {code:-110,msg:"channelCode参数传递错误"};
}
if (obj.channelCode == "") {
return { code: -110, msg: "channelCode参数传递错误" };
}
var channelItem = await this.channelSve.getChannelItem(obj.channelCode);
if (channelItem == "" || channelItem == null) {
return { code: -110, msg: "channelCode参数传递错误" };
}
if(obj.serviceItem_code==""){
return {code:-110,msg:"serviceItem_code参数传递错误"};
}
var serviceItem=await this.servicesitemSve.findOneByCode(obj.serviceItem_code);
if(serviceItem==""||serviceItem==null){
return {code:-110,msg:"serviceItem_code参数传递错误"};
}else{
serviceItem_name=serviceItem.name;
chanceType=serviceItem.itemType;
}
if (obj.serviceItem_code == "") {
return { code: -110, msg: "serviceItem_code参数传递错误" };
}
var serviceItem = await this.servicesitemSve.findOneByCode(obj.serviceItem_code);
if (serviceItem == "" || serviceItem == null) {
return { code: -110, msg: "serviceItem_code参数传递错误" };
} else {
serviceItem_name = serviceItem.name;
chanceType = serviceItem.itemType;
}
if(obj.publisherOnlyCode!=""&&obj.shopOnlyCode!=""){
var pobj={
publisherOnlyCode:obj.publisherOnlyCode,
shopOnlyCode:obj.shopOnlyCode,
serviceItem_code:obj.serviceItem_code,
channelCode:obj.channelCode,
chanceStatus:"1"
}
var result=await this.businesschanceService.findchance(pobj);
if(result!=""&&result!=null){
return {code:"0",msg:"您已经发布需求,请不要重复提交"};
}
}
try{
var reqParams={
notes:obj.notes,
publisherName:obj.publisherName,
publisherMobile:obj.publisherMobile,
channelCode:obj.channelCode,
serviceItem_code:obj.serviceItem_code,
serviceItem_name:serviceItem_name,
publisherOnlyCode:obj.publisherOnlyCode,
shopOnlyCode:obj.shopOnlyCode,
chanceStatus:"1",
chanceType:chanceType,
channelProfitRatio:channelItem.profitType==1?(channelItem.everySingleProfit||0):0,//渠道分成比率(如:总额100,字段值30,则渠道的利润为30/100,剩下的则为平台利润)
channelProfit:channelItem.profitType==2?(channelItem.everySingleProfit||0):0,//渠道利润
profitType:channelItem.profitType//渠道利润类型:1: "比例分成", 2: "每单分成"
}
//新增的省份和城市
var tCity=obj.city||"";
var tProvince=obj.province||"";
if(tCity && tProvince){
reqParams.city=tCity;
reqParams.province=tProvince;
}
// console.log(reqParams);
var chance = await this.businesschanceService.create(reqParams);
if(obj.shopOnlyCode!=null&&obj.shopOnlyCode!=""&&obj.shopOnlyCode!="undefined"&&chance){
var shopItem=await this.shopSve.getShopItem(obj.shopOnlyCode);
if(shopItem!=null&&shopItem.userMobile!=null&&shopItem.userMobile!=""&&shopItem.userMobile!="undefined"){
if (obj.publisherOnlyCode != "" && obj.shopOnlyCode != "") {
var pobj = {
publisherOnlyCode: obj.publisherOnlyCode,
shopOnlyCode: obj.shopOnlyCode,
serviceItem_code: obj.serviceItem_code,
channelCode: obj.channelCode,
chanceStatus: "1"
}
var result = await this.businesschanceService.findchance(pobj);
if (result != "" && result != null) {
return { code: "0", msg: "您已经发布需求,请不要重复提交" };
}
}
try {
var reqParams = {
notes: obj.notes,
publisherName: obj.publisherName,
publisherMobile: obj.publisherMobile,
channelCode: obj.channelCode,
serviceItem_code: obj.serviceItem_code,
serviceItem_name: serviceItem_name,
publisherOnlyCode: obj.publisherOnlyCode,
shopOnlyCode: obj.shopOnlyCode,
chanceStatus: "1",
chanceType: chanceType,
channelProfitRatio: channelItem.profitType == 1 ? (channelItem.everySingleProfit || 0) : 0,//渠道分成比率(如:总额100,字段值30,则渠道的利润为30/100,剩下的则为平台利润)
channelProfit: channelItem.profitType == 2 ? (channelItem.everySingleProfit || 0) : 0,//渠道利润
profitType: channelItem.profitType//渠道利润类型:1: "比例分成", 2: "每单分成"
}
//新增的省份和城市
var tCity = obj.city || "";
var tProvince = obj.province || "";
if (tCity && tProvince) {
reqParams.city = tCity;
reqParams.province = tProvince;
}
// console.log(reqParams);
var chance = await this.businesschanceService.create(reqParams);
if (obj.shopOnlyCode != null && obj.shopOnlyCode != "" && obj.shopOnlyCode != "undefined" && chance) {
var shopItem = await this.shopSve.getShopItem(obj.shopOnlyCode);
if (shopItem != null && shopItem.userMobile != null && shopItem.userMobile != "" && shopItem.userMobile != "undefined") {
//发送短信
var smsClient=system.getObject("util.smsClient");
smsClient.sendMsg(shopItem.userMobile,"亲,您的客户【"+obj.publisherName+"】于"+(new Date()).Format("yyyy-MM-dd")+"发布了关于【"+
serviceItem_name+"】求购需求,赶紧到知产合伙人小程序中【我的商机】进行查看!");
var smsClient = system.getObject("util.smsClient");
smsClient.sendMsg(shopItem.userMobile, "亲,您的客户【" + obj.publisherName + "】于" + (new Date()).Format("yyyy-MM-dd") + "发布了关于【" +
serviceItem_name + "】求购需求,赶紧到知产合伙人小程序中【我的商机】进行查看!");
}
}
// console.log("-----------------chance-----------");
// console.log(chance);
// this.smsClient=System.getObject("util.smsClient");
// this.smsClient.sendMsg("13381139519","亲爱的知产合伙人,你的客户于"+(new Date()).Format("yyyy-MM-dd")+"发布了新的需求,亲,赶紧去自己店铺去查看“我的商机”吧!");
return {code:"1",msg:"发布成功"};
}catch(e){
console.log(e);
logCtl.error({
optitle:"submitneed 发布需求异常,publisherName="+obj.publisherName+"publisherMobile:"+obj.publisherMobile+"serviceItem_code="+obj.serviceItem_code+",shopOnlyCode="+obj.shopOnlyCode+"publisherOnlyCode="+obj.publisherOnlyCode,
op:"wxapplet/impl/businesschanceApplet/submitneed",
content:e.stack,
clientIp:""
});
return {code:"-1",msg:"操作失败,请稍后重试"};
}
}
//获取需求信息----=get
async getNeedList(obj){
try {
return this.businesschanceSve.getTmTradeNeedList(obj);
} catch (e) {
//日志记录
logCtl.error({
optitle:"获取需求信息异常,openid="+obj.openid,
op:"wxapplet/impl/businesschanceApplet/getNeedList",
content:e.stack,
clientIp:""
});
return {
code: -200,
message: "error",
data: []
};
}
}
async getTmTradeChanceDetail(obj){
try {
return this.businesschanceSve.getTmTradeDetails(obj);
} catch (e) {
//日志记录
logCtl.error({
optitle:"获取需求详情信息异常,openid="+obj.openid,
op:"wxapplet/impl/businesschanceApplet/getTmTradeChanceDetail",
content:e.stack,
clientIp:""
});
return {
code: -200,
message: "error",
data: []
};
}
}
}
var token = "";
var app = {
"uappKey": "",
"appSecret": ""
}
switch (obj.channelCode) {
case "wssyh5":
app.uappKey = "202001201103";
app.appSecret = "d4770f7e2bea4e45861292ab4ffnhjkm";
break;
case "yjs":
app.uappKey = "202001201106";
app.appSecret = "d4770f7e2bea4e45861292ab4ffedfgn";
break;
case "gsb":
app.uappKey = "202001201108";
app.appSecret = "d4770f7e2bea4e45861292ab4ffed753";
break;
default:
break;
}
var tokenRes = await this.getCenterChannelToken(app);
if (tokenRes && tokenRes.status == 0 && tokenRes.data) {
token = tokenRes.data.token;
}
if (!token) {
return system.getResultFail(-99, "获取token失败");
}
var url = settings.centerChannelUrl() + "web/action/zcbusinesschanceApi/springBoard";
var npobj = {
"actionType": "needinfo2fq",
"actionBody": {
notes: obj.notes,
publishContent:obj.notes,
publishName: obj.publishName,
publishMobile: obj.publishMobile,
// chanceType_code: "ip_wssyh5",
// chanceTypeName:"商标"
chanceTypeName:chance.chanceTypeName,
chanceType_code: chance.chanceType + "_" + obj.channelCode
}
};
var rtn = await this.execClient.execPushDataPost(npobj, url, token);
console.log(rtn);
// console.log("-----------------chance-----------");
// console.log(chance);
// this.smsClient=System.getObject("util.smsClient");
// this.smsClient.sendMsg("13381139519","亲爱的知产合伙人,你的客户于"+(new Date()).Format("yyyy-MM-dd")+"发布了新的需求,亲,赶紧去自己店铺去查看“我的商机”吧!");
return { code: "1", msg: "发布成功" };
} catch (e) {
console.log(e);
logCtl.error({
optitle: "submitneed 发布需求异常,publisherName=" + obj.publisherName + "publisherMobile:" + obj.publisherMobile + "serviceItem_code=" + obj.serviceItem_code + ",shopOnlyCode=" + obj.shopOnlyCode + "publisherOnlyCode=" + obj.publisherOnlyCode,
op: "wxapplet/impl/businesschanceApplet/submitneed",
content: e.stack,
clientIp: ""
});
return { code: "-1", msg: "操作失败,请稍后重试" };
}
}
//获取center-channel token
async getCenterChannelToken(app) {
var pobj = {
"actionType": "getAppTokenByAppKey",
"actionBody": {
"appkey": app.uappKey,
"secret": app.appSecret
}
};
var url = settings.centerChannelUrl() + "web/auth/accessAuth/getAppTokenByAppKey";
var rtn = await this.restClient.execPost(pobj, url);
if (!rtn || !rtn.stdout) {
return system.getResult(null, "execPost is empty");
}
var result = JSON.parse(rtn.stdout);
console.log(result)
return result;
}
//获取需求信息----=get
async getNeedList(obj) {
try {
return this.businesschanceSve.getTmTradeNeedList(obj);
} catch (e) {
//日志记录
logCtl.error({
optitle: "获取需求信息异常,openid=" + obj.openid,
op: "wxapplet/impl/businesschanceApplet/getNeedList",
content: e.stack,
clientIp: ""
});
return {
code: -200,
message: "error",
data: []
};
}
}
async getTmTradeChanceDetail(obj) {
try {
return this.businesschanceSve.getTmTradeDetails(obj);
} catch (e) {
//日志记录
logCtl.error({
optitle: "获取需求详情信息异常,openid=" + obj.openid,
op: "wxapplet/impl/businesschanceApplet/getTmTradeChanceDetail",
content: e.stack,
clientIp: ""
});
return {
code: -200,
message: "error",
data: []
};
}
}
}
module.exports=businesschanceApplet;
// var task=new businesschanceApplet();
// var obj ={openid:"ovPx35GktY-8pn3GmpIYfcbmqZQk",chanceId:"53"};
// task.getTmTradeChanceDetail(obj).then(function(result){
module.exports = businesschanceApplet;
// var task = new businesschanceApplet();
// var obj = {
// notes: "obj.notes",
// publishName: "obj.publisherName",
// publishMobile: "obj.publisherMobile",
// channelCode: "wssyh5"
// }
// task.submitneed(null, obj);
// task.getTmTradeChanceDetail(obj).then(function (result) {
// console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
// console.log((result));
// }).catch(function(e){
// }).catch(function (e) {
// console.log(e);
// });
......@@ -7,11 +7,11 @@ var settings={
},
database:{
dbname : "zc",
user: "root",
password: "123456",
user: "write",
password: "write",
config: {
host: '192.168.4.119',
port: 3306,
host: '43.247.184.35',
port: 8899,
dialect: 'mysql',
operatorsAliases: false,
pool: {
......
......@@ -38,6 +38,13 @@ var settings = {
return "http://43.247.184.94:7200/";
}
},
centerChannelUrl: function () {
if (this.env == "dev") {
return "http://gsb.qifu.gongsibao.com:4012/";
} else {
return "http://center-channel-service/";
}
},
reqEsAddrIc:function(){
if(this.env=="dev"){
var localsettings=require("./localsettings");
......
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