Commit f4a70192 by wkliang

init

parent 33a7ae94
var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class BizChanceAPI extends APIBase {
constructor() {
super();
this.bizChanceS = system.getObject("service.bizchance.bizoptSve");
this.dateUtil = system.getObject("util.dateClient");
}
/**
* 按照服务商进行分组统计
* @param {*} p
* @param {*} q
* @param {*} req
*/
async statBizChanceCountBySp(p, q, req) {
let bizStatus = p.bizStatus
let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizChanceS.statBizChanceCountBySp(bizStatus, betweenTime)
return system.getResult(rtn)
}
/**
* 待处理商机beforeSubmission
* 处理中商机 beforeConfirmation
*累计处理商机 包括成单和关闭
* @param {*} p
* @param {*} q
* @param {*} req
*/
async statBizChance(p, q, req) {
let companyId = p.company_id
let userid = p.userid
let username = p.username
let opath = p.opath
let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizChanceS.statBizChance(companyId, opath, username, userid, betweenTime);
return system.getResult(rtn)
}
classDesc() {
return {
groupName: "auth",
groupDesc: "认证相关的包",
name: "AccessAuthAPI",
desc: "关于认证的类",
exam: `
post http://p.apps.com/api/auth/accessAuth/getAccessKey
{
appKey:xxxxx,
secret:yyyyyy
}
`,
};
}
methodDescs() {
return [
{
methodDesc: "生成访问token,访问地址:http://......../api/auth/accessAuth/getAccessKey,访问token需要放置到后续API方法调用的请求头中",
methodName: "getAccessKey",
paramdescs: [
{
paramDesc: "访问appkey",
paramName: "appkey",
paramType: "string",
defaultValue: "",
},
{
paramDesc: "访问secret",
paramName: "secret",
paramType: "string",
defaultValue: "",
}
],
rtnTypeDesc: "返回JSON对象字符串",
rtnType: "json object {accessKey: xxxxxx, app: {xxx:xxx}},注意app,是当前app信息,详细见后面示例"
},
];
}
exam() {
return ``
}
}
module.exports = BizChanceAPI;
var APIBase = require("../../api.base");
var system = require("../../../system");
var settings = require("../../../../config/settings");
class BizDeliverAPI extends APIBase {
constructor() {
super();
this.bizDeliveryS = system.getObject("service.bizchance.deliverybillSve")
this.dateUtil = system.getObject("util.dateClient");
}
async statBizDeliveryCountBySp(p, q, req) {
let bizStatus = p.bizStatus;
let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizDeliveryS.statBizDeliveryCountBySp(bizStatus, betweenTime)
return system.getResult(rtn)
}
async statBizDeliverySettleAmountBySp(p, q, req) {
let bizStatus = p.bizStatus
let rtn = await this.bizDeliveryS.statBizDeliverySettleAmountBySp(bizStatus)
return system.getResult(rtn)
}
/**
* 待处理商机beforeSubmission
* 处理中商机 beforeConfirmation
*累计处理商机 包括成单和关闭
* @param {*} p
* @param {*} q
* @param {*} req
*/
async statBizDelivery(p, q, req) {
let companyId = p.company_id
let userid = p.userid
let username = p.username
let opath = p.opath
let betweenTime = this.dateUtil.betweenTime(p.dateType);
let rtn = await this.bizDeliveryS.statBizDelivery(companyId, opath, username, userid, betweenTime)
return system.getResult(rtn)
}
classDesc() {
return {
groupName: "auth",
groupDesc: "认证相关的包",
name: "AccessAuthAPI",
desc: "关于认证的类",
exam: `
post http://p.apps.com/api/auth/accessAuth/getAccessKey
{
appKey:xxxxx,
secret:yyyyyy
}
`,
};
}
methodDescs() {
return [
{
methodDesc: "生成访问token,访问地址:http://......../api/auth/accessAuth/getAccessKey,访问token需要放置到后续API方法调用的请求头中",
methodName: "getAccessKey",
paramdescs: [
{
paramDesc: "访问appkey",
paramName: "appkey",
paramType: "string",
defaultValue: "",
},
{
paramDesc: "访问secret",
paramName: "secret",
paramType: "string",
defaultValue: "",
}
],
rtnTypeDesc: "返回JSON对象字符串",
rtnType: "json object {accessKey: xxxxxx, app: {xxx:xxx}},注意app,是当前app信息,详细见后面示例"
},
];
}
exam() {
return ``
}
}
module.exports = BizDeliverAPI;
var system = require("../../../system");
const http = require("http");
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const moment = require('moment');
const appconfig = system.getSysConfig();
class BizOptCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(BizOptCtl));
this.schemeService = system.getObject("service.bizchance.schemeSve");
this.logService = system.getObject("service.bizchance.statuslogSve");
this.receiveUrl = settings.receiveUrl();
this.queueUrl = settings.queueUrl();
//this.wdyUrl = settings.wdyUrl();
this.dateUtil = system.getObject("util.dateClient");
}
/*根据用户id获取商机信息,分页获取*/
async findAndCountAll(pobj, qobj, req) {
try {
//TODO 根据业务员id获取该业务员所有列表
//设置查询条件
console.log("pobj--", pobj)
if (pobj.search && pobj.search.dateType) {
if (pobj.search.dateType !== '全部') {
pobj.search.created_at = this.dateUtil.betweenTime(pobj.search.dateType);
}
delete pobj.search.dateType
}
const rs = await this.service.findAndCountAll(pobj);
let rarr = [];
let results = rs.results.rows;
results.forEach(element => {
let robj = {};
robj.id = element.id;//数据的id
robj.demand_code = element.demand_code;//商机编号
robj.source = element.source_name;//商机来源
robj.business_type = element.business_type;//商机类型
robj.business_info_person = element.business_info.contactsName;//联系人
robj.business_info_phone = element.business_info.contactsPhone;//联系电话
robj.business_status = element.business_status;//商机当前状态
robj.updated_at = this.timeFormat(element.updated_at);//商机当前状态日期
robj.servicerName = element.facilitator_name;
robj.facilitator_name = element.facilitator_name;
robj.sourceName = element.source_name;//渠道来源
robj.salesman_name=element.salesman_name
robj.salesman_phone=element.salesman_phone
rarr.push(robj);
});
rs.results.rows = rarr;
return system.getResult(rs);
} catch (error) {
return system.getResultError(error);
}
}
/*根据商机编号获取商机详情*/
async findInfoByDemandCode(mobj, qobj, req) {
var pobj = mobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined') {
try {
var rs = await this.service.findInfoByDemandCode(pobj);
var ms = await this.schemeService.findInfoByDemandCode(pobj);
var rarr = {}
if (rs) {
var statusInfo = { "currentStatus": rs.business_status };//商机状态
var businessInfo = {};
businessInfo.businessMode = rs.demand_code;//商机编号
businessInfo.channelSource = appconfig.pdict.source[rs.source_name];///渠道来源
// businessInfo.businessType = rs.business_type;//商机类型代码
businessInfo.businessType = appconfig.pdict.businessType[rs.business_type];//商机类型名称
// businessInfo.serviceArea = rs.service_address;//服务地区
if (businessInfo.businessName == "云上园区注册") {
businessInfo.serviceArea = appconfig.pdict.registeredParkDict[rs.service_address];//服务地区名称
}
else {
businessInfo.serviceArea = appconfig.pdict.registeredAreaDict[rs.service_address];//服务地区名称
}
if (businessInfo.businessName == "注册地址") {
businessInfo.registeredAddress = appconfig.pdict.registeredAreaDict[rs.service_address];//注册地址名称
}
businessInfo.statusReason = rs.close_reason;//商机关闭原因
businessInfo.memoInfo = rs.business_info.memoInfo;//备注信息
businessInfo.contactsName = rs.business_info.contactsName;//联系人名称
businessInfo.contactsPhone = rs.business_info.contactsPhone;//联系人联系方式
businessInfo.createdTime = this.timeFormat(rs.created_at);//商机创建时间
rarr.statusInfo = statusInfo;
rarr.businessInfo = businessInfo;
}
if (ms) {
var planInfo = ms.scheme_info;
planInfo.schemeNumber = ms.scheme_number;
planInfo.currentStatus = ms.scheme_status;
if (ms.scheme_status && ms.scheme_status == "isReject") {
planInfo.currentStatus = "已退回";
}
else {
planInfo.currentStatus = ms.scheme_status;
}
planInfo.statusReason = ms.reject_reason;
rarr.planInfo = planInfo;
}
return system.getResult(rarr);
}
catch (error) {
console.log("eeeeeeeeeeeeeeeeeeeeee");
console.log(error);
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
/*根据商机编号更新商机状态*/
async updateStatusByDemandCode(mobj, qobj, req) {
var pobj = mobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.currentStatus && pobj.currentStatus != 'undefined') {
try {
await this.service.updateStatusByDemandCode(pobj);
await this.schemeService.updateStatusByDemandCode(pobj);//同时更新方案的状态
var res = this.service.findInfoByDemandCode(pobj);
if (res && res != 'undefined') {
var logInfo = {
"flowType": "BIZ",
"flowId": res.id,
"statusCode": pobj.currentStatus,
"statusReason": res.close_reason,
"clerkName": res.salesman_name,
"clerkId": res.salesman_id
}
await this.logService.insertInfo(logInfo);//插入状态日至表
}
if (pobj.currentStatus == "isClosed") { //关闭需求时调用
var rc = system.getObject("util.execClient");
var requrl = this.queueUrl;
var params = {
"actionType": "produceData",
"actionBody": {
"pushUrl": this.receiveUrl,
"actionType": "closeNeed",
"identifyCode": "ic-manage",
"messageBody": {
"needNum": pobj.businessMode,
"note": pobj.statusReason
}
}
}
var rtn = await rc.execPost(params, requrl);
var j = JSON.parse(rtn.stdout);
if (j.status == 1) {
return system.getResult("操作成功!");
}
else {
return system.getResultError("更新方案状态出错!");
}
}
else {
return system.getResult("操作成功!");
}
}
catch (error) {
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
/*插入数据信息 */
async insertInfo(nobj, qobj, req) {
var pobj = nobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.businessType && pobj.businessType != 'undefined') {
try {
pobj.currentStatus = "beforeSubmission";//加上当前状态为待提交方案
pobj.channelSource = "tencentCloud";//目前渠道只有腾讯
pobj.sourceNumber = "1111111";
pobj.businessType = appconfig.pdict.dyDict[pobj.businessType];
var buInfo = await this.service.insertInfo(pobj);
var logInfo = {
"flowType": "BIZ",
"flowId": buInfo.id,
"statusCode": pobj.currentStatus,
"clerkName": pobj.clerkName,
"clerkId": pobj.salesmanId
}
await this.logService.insertInfo(logInfo);//插入状态日至表
return {
"status": 1, //1代表成功,否则失败
"message": "操作成功",
"data": "",
"requestId": ""
};
}
catch (error) {
console.log("TTTTTTTTTTTTTTTTTTTTTTT");
console.log(error);
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
timeFormat(date) {
let localTime = moment.utc(date).toDate();
localTime = moment(localTime).format("YYYY-MM-DD");
return localTime;
}
}
module.exports = BizOptCtl;
// var task = new BizOptCtl();
// var obj={"businessMode":"202006100001","currentStatus":"isClosed","statusReason":"未付款"};
// task.updateStatusByDemandCode(obj,{},{}).then(d=>{
// console.log(d);
// })
var system = require("../../../system");
const http = require("http");
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const moment = require('moment');
class CacheInfoCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(CacheInfoCtl));
this.deliverService = system.getObject("service.bizchance.deliverybillSve");
}
/*根据交付单id获取缓存详情*/
async findInfoByDeliverId(mobj,qobj,req){
var pobj = mobj.d;
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined')
{
try{
var rs = await this.service.findInfoByDeliverId(pobj);
var divInfo = await this.deliverService.findInfoByDeliverCode(pobj);
var rarr = {};
if (rs && rs != 'undefined'){
rarr.deliverNumber = rs.deliver_id;
rarr.cacheInfo = rs.cache_info;
rarr.statusInfo = {};
if (divInfo && divInfo != 'undefined'){
rarr.statusInfo.deliverStatus = divInfo.delivery_status;//状态
rarr.statusInfo.statusReason = divInfo.close_reason;//状态原因
rarr.statusInfo.createdTime = this.timeFormat(divInfo.created_at);
rarr.statusInfo.updateTime = this.timeFormat(divInfo.updated_at)
}
}
return system.getResult(rarr);
}
catch(error){
return system.getResultError(error);
}
}
else{
return system.getResultError("参数错误!");
}
}
/*根据交付单id更新缓存信息*/
async updateInfoByDeliverId(mobj,qobj,req){
var pobj = mobj.d;
console.log("cache---------------------------------------" + JSON.stringify(pobj));
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined' && pobj.cacheInfo && pobj.cacheInfo != 'undefined'){
try{
var res = await this.service.updateInfoByDeliverId(pobj);
return system.getResult("更新成功!");
}
catch (error){
console.log("error----------------------------" + error);
return system.getResultError(error);
}
}
else{
console.log("-----------------------------------------参数错误");
return system.getResultError("参数错误!");
}
}
/*插入或更新缓存信息 */
async createInfo(mobj,qobj,req){
var pobj = mobj.d;
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined' && pobj.cacheInfo && pobj.cacheInfo != 'undefined'){
try{
var rs = await this.service.findInfoByDeliverId(pobj);
if (rs){
await this.service.updateInfoByDeliverId(pobj);
}
else{
await this.service.insertInfo(pobj);
}
return system.getResult("操作成功!");
}
catch (error){
return system.getResultError(error);
}
}
else{
return system.getResultError("参数错误!");
}
}
timeFormat(date) {
let localTime = moment.utc(date).toDate();
localTime = moment(localTime).format("YYYY-MM-DD");
return localTime;
}
}
module.exports = CacheInfoCtl;
// var task = new CacheInfoCtl();
// var obj={"demand_code":"30030302992","business_status":"isFinished"};
// task.updateStatusByDemandCode(obj,{},{}).then(d=>{
// console.log(d);
// //console.log(d[0].analyse);
// })
var system = require("../../../system");
const http = require("http");
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const moment = require('moment');
const appconfig = system.getSysConfig();
class DeliverybillCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(DeliverybillCtl));
this.materialService = system.getObject("service.bizchance.materialSve");
this.schemeService = system.getObject("service.bizchance.schemeSve");
this.bizoptService = system.getObject("service.bizchance.bizoptSve");
this.logService = system.getObject("service.bizchance.statuslogSve");
this.cacheService = system.getObject("service.bizchance.cacheinfoSve");
this.receiveUrl = settings.receiveUrl();
this.queueUrl = settings.queueUrl();
this.wdyUrl = settings.wdyUrl();
this.dateUtil = system.getObject("util.dateClient");
}
/*根据用户id获取商机信息,分页获取*/
async findAndCountAll(pobj, qobj, req) {
try {
//TODO 根据业务员id获取该业务员所有交付单列表
if (pobj.search && pobj.search.dateType) {
if (pobj.search.dateType !== '全部') {
pobj.search.created_at = this.dateUtil.betweenTime(pobj.search.dateType);
}
delete pobj.search.dateType
}
const rs = await this.service.findAndCountAll(pobj);
let rarr = [];
let results = rs.results.rows;
results.forEach(element => {
let robj = {};
robj.id = element.id;//数据的id
robj.deliverNumber = element.delivery_code;//交付单编号
robj.businessName = element.product_name;//产品名称
robj.businessType = element.product_code;//产品编码
robj.product_code = element.product_code;//产品编码
robj.sourceName = element.source_name;//渠道来源
robj.source_name = element.source_name;//渠道来源--前端服务
robj.channelNumber = element.source_number;//渠道编码
robj.facilitator_name = element.facilitator_name;//服务商--前端服务
robj.facilitator_id = element.facilitator_id;//服务商--id
robj.serviceName = element.facilitator_name;
robj.baseInfo = element.delivery_info;//交付单详情
robj.payStatus = element.delivery_info.payStatus;//交付状态
robj.costPrice = this.FenToYuan(element.cost_price);//成本
robj.settle_status = element.settle_status;
robj.settlebill = element.settlebill;
if (robj.businessName == '公司注册') {
if (robj.baseInfo.isWhether == "yes" || robj.baseInfo.isVirtual == "yes") {//如果有刻章需求或者是虚拟地址
robj.relatedProducts = '有';
}
else {
robj.relatedProducts = '无';
}
}
else if (robj.businessName == '云上园区注册') {
robj.registeredType = element.delivery_info.registeredType;//园区注册时,根据该值跳界面
if (robj.baseInfo.isWhether == "yes" || robj.baseInfo.financial == "yes") {//如果有刻章需求或者是财税服务
robj.relatedProducts = '有';
}
else {
robj.relatedProducts = '无';
}
}
else {
robj.relatedProducts = '无';
};
robj.payAmount = this.FenToYuan(element.selling_price);//交付单金额
robj.deliverStatus = element.delivery_status;//交付单状态
robj.delivery_status = element.delivery_status;//交付单状态
robj.contactsName = robj.baseInfo.contactsName;//联系人
robj.contactsPhone = robj.baseInfo.contactsPhone;//联系电话
robj.clerkName = element.salesman_name;//业务员名称
robj.clerkPhone = element.salesman_phone;//业务员电话
robj.createdTime = this.timeFormat(element.created_at);//交付单创建时间
rarr.push(robj);
});
rs.results.rows = rarr;
return system.getResult(rs);
} catch (error) {
console.log("error-------------------" +error);
return system.getResultError(error);
}
}
/*根据交付单编号获取交付单xinxi*/
async findInfoByDeliverCode(mobj, qobj, req) {
var pobj = mobj.d;
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined') {
try {
var rs = await this.service.findInfoByDeliverCode(pobj);
if (rs) {
return system.getResult(rs);
}
else {
return system.getResultError("数据不存在");
}
}
catch (error) {
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
/*根据交付单编号获取交付单详情和材料详情*/
async dealInfo(mobj, qobj, req) {
var pobj = mobj.d;
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined') {
try {
var rs = await this.service.findInfoByDeliverCode(pobj);
var ms = await this.materialService.findInfoByDeliverNumber(pobj);
var rarr = {
"baseInfo": {},
"contactsInfo": {},
"statusInfo": {},
"companyInfo": {},
"registeredInfo": {},
"contributionInfo": {},
"positionInfo": {},
"managerInfo": {},
"regInfo": {},
"expressInfo": {}
}
if (rs) {
console.log("D___________________________" + JSON.stringify(rs));
rarr.id = rs.id;//数据的id
rarr.baseInfo.deliverNumber = rs.delivery_code;//交付单编号
rarr.baseInfo.businessName = rs.product_name;//产品名称
rarr.baseInfo.businessMode = rs.demand_code;//shangjibianhao
rarr.baseInfo.businessType = rs.product_code;//产品编码
rarr.baseInfo.channelSource = rs.source_name;//渠道名称
rarr.baseInfo.channelNumber = rs.source_number;//渠道编码
rarr.baseInfo.serviceCode = rs.service_address;//服务地区编码
rarr.baseInfo.servicerCode = rs.facilitator_id;//服务商编码
rarr.baseInfo.servicerName = rs.facilitator_name;//服务商名称
rarr.baseInfo.clerkName = rs.salesman_name;//业务员名称
rarr.baseInfo.clerkPhone = rs.salesman_phone;//业务员电话
rarr.baseInfo.sellingPrice = this.FenToYuan(rs.selling_price);//价格
rarr.baseInfo.costPrice = this.FenToYuan(rs.cost_price);//成本价
rarr.baseInfo.deliverStatus = rs.delivery_status;//状态
rarr.baseInfo.statusReason = rs.close_reason;//状态原因
if (rarr.businessName == "云上园区注册") {
rarr.baseInfo.serviceArea = appconfig.pdict.registeredParkDict[rarr.serviceCode];//服务地区名称
}
else {
rarr.baseInfo.serviceArea = appconfig.pdict.registeredAreaDict[rarr.serviceCode];//服务地区名称
}
if (rs.delivery_info.contactsName && rs.delivery_info.contactsName != 'undefined') {
rarr.contactsInfo.contactsName = rs.delivery_info.contactsName;//联系人信息
rarr.baseInfo.contactsName = rs.delivery_info.contactsName;//联系人信息
}
if (rs.delivery_info.contactsPhone && rs.delivery_info.contactsPhone != 'undefined') {
rarr.contactsInfo.contactsPhone = rs.delivery_info.contactsPhone;//联系电话信息
rarr.baseInfo.contactsPhone = rs.delivery_info.contactsPhone;//联系电话信息
}
if (rs.delivery_info.isWhether && rs.delivery_info.isWhether != 'undefined') {
rarr.baseInfo.isWhether = rs.delivery_info.isWhether;//是否刻章
}
//财税服务
if (rs.delivery_info.financial && rs.delivery_info.financial != 'undefined') {
rarr.baseInfo.financial = rs.delivery_info.financial;
}
if (rs.delivery_info.payStatus && rs.delivery_info.payStatus != 'undefined') {
rarr.baseInfo.payStatus = rs.delivery_info.payStatus;//支付状态
}
if (rs.delivery_info.officialSeal && rs.delivery_info.officialSeal != 'undefined') {
rarr.baseInfo.officialSeal = rs.delivery_info.officialSeal;//公章扫描件
}
if (rs.delivery_info.isAdviser && rs.delivery_info.isAdviser != 'undefined') {
rarr.baseInfo.isAdviser = rs.delivery_info.isAdviser;//是否分配顾问
}
if (rs.delivery_info.businessLicense && rs.delivery_info.businessLicense != 'undefined') {
rarr.baseInfo.businessLicense = rs.delivery_info.businessLicense;//营业执照扫描件
}
if (rs.delivery_info.taxpayerType && rs.delivery_info.taxpayerType != 'undefined') {
rarr.baseInfo.taxpayerType = rs.delivery_info.taxpayerType;//纳税人类型
}
if (rs.delivery_info.buyDuration && rs.delivery_info.buyDuration != 'undefined') {
rarr.baseInfo.buyDuration = rs.delivery_info.buyDuration;//购买时长
}
if (rs.delivery_info.buyTime && rs.delivery_info.buyTime != 'undefined') {
rarr.baseInfo.buyTime = rs.delivery_info.buyTime;//购买时间
}
if (rs.delivery_info.startTime && rs.delivery_info.startTime != 'undefined') {
rarr.baseInfo.startTime = rs.delivery_info.startTime;//开始计费时间
}
if (rs.delivery_info.buyDuration && rs.delivery_info.buyDuration != 'undefined' && rarr.baseInfo.startTime && rarr.baseInfo.startTime != 'undefined') {
console.log("ddddddddddd____________________________" + rarr.baseInfo.startTime);
var d = new Date(rarr.baseInfo.startTime);
console.log("ddddddddddd____________________________" + d);
rarr.baseInfo.endTime = this.oneYearPast(d, 1);//到期时间
var ss = moment();
rarr.baseInfo.surplusDuration = this.diffDays(ss, rarr.baseInfo.endTime);//剩余时长
}
if (rs.delivery_info.isRenew && rs.delivery_info.isRenew != 'undefined') {
rarr.baseInfo.isRenew = rs.delivery_info.isRenew;//是否自动续费
}
if (rs.delivery_info.whetherType && rs.delivery_info.whetherType != 'undefined') {
rarr.baseInfo.whetherType = rs.delivery_info.whetherType;//刻章类型
}
if (rs.delivery_info.subjectType && rs.delivery_info.subjectType != 'undefined') {
rarr.baseInfo.subjectType = rs.delivery_info.subjectType;//代理记账主体类型
}
rarr.baseInfo.createdTime = this.timeFormat(rs.created_at);
rarr.baseInfo.updateTime = this.timeFormat(rs.updated_at)
rarr.statusInfo.deliverStatus = rs.delivery_status;//状态
rarr.statusInfo.statusReason = rs.close_reason;//状态原因
rarr.companyInfo = ms.company_info;//公司详情
rarr.registeredInfo = ms.registered_info;//注册信息
rarr.contributionInfo = ms.contribution_info;//出资比例信息
rarr.positionInfo = ms.position_info;//任职信息;公司注册和个人独资时取该值
rarr.managerInfo = ms.position_info;//经营者信息,个体工商户的经营者信息取该值
rarr.regInfo = ms.file_info;//注册文件信息
rarr.expressInfo = ms.express_info;//邮寄信息
}
return system.getResult(rarr);
}
catch (error) {
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
async updatestartTimeByDeliverCode(mobj, qobj, red) {//根据交付单编号更新开始计费时间
var pobj = mobj.d;
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined' && pobj.baseInfo.startTime && pobj.baseInfo.startTime != 'undefined') {
try {
var rs = await this.service.findInfoByDeliverCode(pobj)//先得到交付单详情
if (rs && rs != 'undefined') {
rs.delivery_info.startTime = pobj.baseInfo.startTime;
var d = new Date(rs.delivery_info.startTime);
rs.delivery_info.endTime = this.oneYearPast(d, 1);//到期时间
//回传信息给庄冰,放队列
var rc = system.getObject("util.execClient");
var requrl = this.queueUrl;
var params = {
"actionType": "produceData",
"actionBody": {
"pushUrl": this.receiveUrl,
"actionType": "updateOrderStatus",
"identifyCode": "ic-manage",
"messageBody": {
"orderNum": pobj.deliverNumber,//订单编码
"status": appconfig.pdict.ddyDict[rs.delivery_status],
"deliverContent": { "baseInfo": rs.delivery_info }
}
}
}
var rtn = await rc.execPost(params, requrl);
var j = JSON.parse(rtn.stdout);
console.log("RRRRRRRRRRRRRR");
console.log(JSON.stringify(j));
params = {
"actionType": "produceData",
"actionBody": {
"pushUrl": this.wdyUrl,
"actionType": "jftime",
"identifyCode": "ic-manage",
"messageBody": {
"orderNum": pobj.deliverNumber,//订单编码
"startTime": rs.delivery_info.startTime,
"endTime": rs.delivery_info.endTime
}
}
}
rtn = await rc.execPost(params, requrl);
var j1 = JSON.parse(rtn.stdout);
console.log("R1RRRRR1RR1RRRR1RR1");
console.log(JSON.stringify(j1));
if (j.status == 1 && j1.status == 1) {
//更新详情
var uarr = {
"deliverNumber": pobj.deliverNumber,
"baseInfo": rs.delivery_info
};
await this.service.updateInfoByDeliverCode(uarr);
return system.getResult("更新成功");
}
else {
return system.getResultError("更新失败!");
}
}
else {
return system.getResultError("数据不存在!");
}
}
catch (error) {
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
/*根据交付单编号更新交付单状态*/
async updateStatusByDeliverCode(mobj, qobj, req) {
var pobj = mobj.d;
console.log("--------------------" + JSON.stringify(pobj));
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined' && pobj.deliverStatus && pobj.deliverStatus != 'undefined') {
try {
//调商城接口,回传状态信息,放队列
var rc = system.getObject("util.execClient");
var requrl = this.queueUrl;
var params = {
"actionType": "produceData",
"actionBody": {
"pushUrl": this.receiveUrl,
"actionType": "updateOrderStatus",
"identifyCode": "ic-manage",
"messageBody": {
"orderNum": pobj.deliverNumber,//订单编码
"status": appconfig.pdict.ddyDict[pobj.deliverStatus]
//"deliverContent":pobj
}
}
}
var rtn = await rc.execPost(params, requrl);
console.log("_____________________________" + rtn.stdout);
var j = JSON.parse(rtn.stdout);
var j1status = 1;
if (pobj.deliverStatus == "closed") {//退款
params = {
"actionType": "produceData",
"actionBody": {
"pushUrl": this.wdyUrl,
"actionType": "refundOrder",
"identifyCode": "ic-manage",
"messageBody": {
"orderNum": pobj.deliverNumber//订单编码
}
}
}
rtn = await rc.execPost(params, requrl);
console.log("_____________________________tuifei" + rtn.stdout);
var j1 = JSON.parse(rtn.stdout);
j1status = j1.status;
}
if (j.status == 1 && j1status == 1) {
await this.service.updateStatusByDeliverCode(pobj);
var pInfo = this.service.findInfoByDeliverCode(pobj);
if (pInfo) {
var logInfo = {
"flowType": "DELIVERY",
"flowId": pInfo.id,
"statusCode": pobj.deliverStatus,
"clerkName": pInfo.salesman_name,
"clerkId": pInfo.salesman_id
}
if (pInfo.statusReason && pInfo.statusReason != 'undefined') {
logInfo.statusReason = pInfo.statusReason;
}
await this.logService.insertInfo(logInfo);//插入状态日至表
}
return system.getResult("更新成功!");
}
else {
return system.getResultError("更新状态失败!");
}
}
catch (error) {
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
async UpdateofficialSealByDeliverCode(mobj, qobj, req) {//更新营业执照扫描件和公章扫描件
var pobj = mobj.d;
if ((pobj.deliverNumber && pobj.deliverNumber != 'undefined' && ((pobj.baseInfo.officialSeal && pobj.baseInfo.officialSeal != 'undefined') || (pobj.baseInfo.businessLicense && pobj.baseInfo.businessLicense != 'undefined')))) {
try {
var rs = await this.service.findInfoByDeliverCode(pobj)//先得到交付单详情
if (rs && rs != 'undefined') {
if (pobj.baseInfo.officialSeal && pobj.baseInfo.officialSeal != 'undefined') {
rs.delivery_info.officialSeal = pobj.baseInfo.officialSeal;
}
if (pobj.baseInfo.businessLicense && pobj.baseInfo.businessLicense != 'undefined') {
rs.delivery_info.businessLicense = pobj.baseInfo.businessLicense;
}
//回传信息给庄冰,放队列
var rc = system.getObject("util.execClient");
var requrl = this.queueUrl;
var params = {
"actionType": "produceData",
"actionBody": {
"pushUrl": this.receiveUrl,
"actionType": "updateOrderStatus",
"identifyCode": "ic-manage",
"messageBody": {
"orderNum": pobj.deliverNumber,//订单编码
"status": appconfig.pdict.ddyDict[rs.delivery_status],
"deliverContent": { "baseInfo": rs.delivery_info }
}
}
}
var rtn = await rc.execPost(params, requrl);
var j = JSON.parse(rtn.stdout);
console.log("RRRRRRRRRRRRRR");
console.log(JSON.stringify(j));
if (j.status == 1) {
//更新详情
var uarr = {
"deliverNumber": pobj.deliverNumber,
"baseInfo": rs.delivery_info
};
await this.service.updateInfoByDeliverCode(uarr);
return system.getResult("更新成功");
}
else {
return system.getResultError("更新失败!");
}
}
else {
return system.getResultError("数据不存在!");
}
}
catch (error) {
console.log("##########");
console.log(error);
return system.getResultError(error);
}
}
else {
console.log("参数错误" + pobj);
return system.getResultError("参数错误!");
}
}
async updateExpressInfoByDeliverCode(mobj, qobj, req) {//更新邮寄信息
var pobj = mobj.d;
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined' && pobj.expressInfo && pobj.expressInfo != 'undefined') {
try {
var deliverInfo = await this.service.findInfoByDeliverCode(pobj)//先得到交付单详情
if (deliverInfo && deliverInfo != 'undefined') {
//回传信息给庄冰,放队列
var rc = system.getObject("util.execClient");
var requrl = this.queueUrl;
console.log("deliverNumber---------------------------" + pobj.deliverNumber);
var params = {
"actionType": "produceData",
"actionBody": {
"pushUrl": this.receiveUrl,
"actionType": "updateOrderStatus",
"identifyCode": "ic-manage",
"messageBody": {
"orderNum": pobj.deliverNumber,//订单编码
"status": appconfig.pdict.ddyDict[deliverInfo.delivery_status],
"deliverContent": { "expressInfo": pobj.expressInfo }
}
}
}
var rtn = await rc.execPost(params, requrl);
var j = JSON.parse(rtn.stdout);
console.log("EXEXEXEXEXEEEEEEEEEEEEEEEEEEE" + rtn.stdout);
if (j.status == 1) {
await this.materialService.updateInfoByDeliverNumber(pobj);
return system.getResult("更新成功");
}
else {
return system.getResultError("更新失败!");
}
}
else {
return system.getResultError("数据不存在!");
}
}
catch (error) {
console.log("Error-----------------------------------------------" + error);
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
/*根据交付单编号更新交付单详情*/
async updateInfoByDeliverCode(mobj, qobj, req) {//
var pobj = mobj.d;
console.log("根据交付单编号更新交付单详情-------------------------" + JSON.stringify(pobj));
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined') {
try {
var rs = await this.service.findInfoByDeliverCode(pobj)//先得到交付单详情
var baseInfo = rs.delivery_info;
if (pobj.contactsInfo.contactsName && pobj.contactsInfo.contactsName != 'undefined') {
baseInfo.contactsName = pobj.contactsInfo.contactsName;
}
if (pobj.contactsInfo.contactsPhone && pobj.contactsInfo.contactsPhone != 'undefined') {
baseInfo.contactsPhone = pobj.contactsInfo.contactsPhone;
}
var parms = {
"deliverNumber": pobj.deliverNumber
}
if (rs.product_code == "psCase") {
parms.deliverStatus = "checking";//状态为园区入驻审核
baseInfo.payStatus = "已交付";
}
else if (rs.product_code == "companyCase") {
parms.deliverStatus = "auditing";//状态为工商审核环节
baseInfo.payStatus = "已交付";
}
parms.baseInfo = baseInfo;
await this.service.updateInfoByDeliverCode(parms);
//更新材料信息
await this.materialService.updateInfoByDeliverNumber(pobj);
//return system.getResult("操作成功!");
//传给庄冰,tongbu
baseInfo.clerkName = rs.salesman_name;//业务员名称
baseInfo.clerkPhone = rs.salesman_phone;
pobj.baseInfo = baseInfo;
var rc = system.getObject("util.execClient");
var requrl = this.receiveUrl;
var params = {
"actionType": "updateOrderStatus",
"actionBody": {
"orderNum": pobj.deliverNumber,//订单编码
//"status":appconfig.pdict.ddyDict["collecting"],
"deliverContent": pobj
}
}
if (rs.product_code == "psCase") {
params.actionBody.status = appconfig.pdict.ddyDict["checking"];
}
else if (rs.product_code == "companyCase") {
params.actionBody.status = appconfig.pdict.ddyDict["auditing"];
}
else {
params.actionBody.status = appconfig.pdict.ddyDict[rs.delivery_status];
}
var rtn = await rc.execPost(params, requrl);
console.log("rtn-------------------------------------------" + rtn.stdout);
var j = JSON.parse(rtn.stdout);
if (j.status == 1) {
return system.getResult("操作成功!");
}
else {
return system.getResultError("更新交付单状态出错!");
}
}
catch (error) {
console.log("error-------------------------------------------" + error);
return system.getResultError(error);
}
}
else {
console.log("参数错误-------------------------------------------参数错误!");
return system.getResultError("参数错误!");
}
}
async settleApplyForTacent(p, q, req) {
let ids = p.ids
let spname = p.spname
let spid = p.spid
let rtn = await this.service.settleApplyForTacent(ids, p.userid, p.username, spname, spid)
return system.getResult({})
}
async settleApply(p, q, req) {
let ids = p.ids
let spname = p.spname
let spid = p.spid
let rtn = await this.service.settleApply(ids, p.userid, p.username, spname, spid)
return system.getResult({})
}
/*根据商机编号插入交付单信息*/
async insertInfo(nobj, qobj, req) {//队列的时候用
var pobj = nobj.d;
console.log("根据交付单编号更新交付单详情-------------------------" + JSON.stringify(pobj));
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined') {
try {
pobj.deliverStatus = "received";
pobj.businessType = appconfig.pdict.dyDict[pobj.businessType];
if (pobj.companyInfo.companyPropertiesName && pobj.companyInfo.companyPropertiesName != 'undefined') {
if (pobj.businessName == "公司注册") {
pobj.companyInfo.companyProperties = appconfig.pdict.companyNatureDictT[pobj.companyInfo.companyPropertiesName];
pobj.baseInfo.companyProperties = pobj.companyInfo.companyProperties;
pobj.baseInfo.companyType = pobj.companyInfo.companyProperties;
}
else if (pobj.businessName == "云上园区注册") {
pobj.companyInfo.companyProperties = appconfig.pdict.registeredTypeDictT[pobj.companyInfo.companyPropertiesName];
pobj.baseInfo.companyProperties = pobj.companyInfo.companyProperties;
pobj.baseInfo.companyType = pobj.companyInfo.companyProperties;
}
else {
pobj.companyInfo.companyType = pobj.companyInfo.companyPropertiesName;
pobj.baseInfo.companyProperties = pobj.companyInfo.companyPropertiesName;
pobj.baseInfo.companyType = pobj.companyInfo.companyPropertiesName;
}
}
if (pobj.companyInfo.engagedIndName && pobj.companyInfo.engagedIndName != 'undefined') {
pobj.companyInfo.engagedIndustry = appconfig.pdict.engagedIndustryDictT[pobj.companyInfo.engagedIndName];
}
if (pobj.baseInfo.taxpayerName && pobj.baseInfo.taxpayerName != 'undefined') {
pobj.baseInfo.taxpayerType = appconfig.pdict.TaxpayerTypeDictT[pobj.baseInfo.taxpayerName];
if (pobj.businessName == "公司注册" || pobj.businessName == "云上园区注册") {
pobj.companyInfo.taxpayerType = pobj.baseInfo.taxpayerType;
}
}
pobj.schemeNumber = "";
pobj.channelSource = "tencentCloud";//目前渠道只有腾讯
pobj.channelNumber = "1111111";
pobj.cacheInfo = {
"cmpDeliverInfo": {},
"cmpContactInfo": {}
};
if (pobj.businessMode && pobj.businessMode != 'undefined') {//如果有商机编号,需要取方案编号
var schemeInfo = await this.schemeService.findInfoByDemandCode(pobj);
if (schemeInfo && schemeInfo != 'undefined') {
pobj.schemeNumber = schemeInfo.scheme_number;
pobj.cacheInfo.cmpDeliverInfo = schemeInfo.scheme_info;//获取方案中的缓存信息
}
}
//缓存信息和交付单保持一致
console.log("---------------------------------------------------------------------------------------------------------------------------------------");
if (pobj.companyInfo.companyProperties && pobj.companyInfo.companyProperties != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.companyProperties = pobj.companyInfo.companyProperties;
}
else {
if (pobj.cacheInfo.cmpDeliverInfo.companyType && pobj.cacheInfo.cmpDeliverInfo.companyType) {
pobj.cacheInfo.cmpDeliverInfo.companyProperties = pobj.cacheInfo.cmpDeliverInfo.companyType;
}
}
console.log("---------------------------------------------------------------------------------------------------------------------------------------");
if (pobj.baseInfo.memoInfo && pobj.baseInfo.memoInfo != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.memoInfo = pobj.baseInfo.memoInfo;
}
if (pobj.baseInfo.isWhether && pobj.baseInfo.isWhether != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.isWhether = pobj.baseInfo.isWhether;
}
if (pobj.baseInfo.financial && pobj.baseInfo.financial != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.financial = pobj.baseInfo.financial;
}
if (pobj.baseInfo.addressType && pobj.baseInfo.addressType != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.addressType = pobj.baseInfo.addressType;
}
if (pobj.baseInfo.companyName && pobj.baseInfo.companyName != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.companyName = pobj.baseInfo.companyName;
}
if (pobj.serviceCode && pobj.serviceCode != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.serviceArea = pobj.serviceCode;
}
if (pobj.serviceName && pobj.serviceName != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.serviceAreaName = pobj.serviceName;
pobj.baseInfo.serviceName = pobj.serviceName;
}
if (pobj.companyInfo.businessScope && pobj.companyInfo.businessScope != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.businessScope = pobj.companyInfo.businessScope;
}
if (pobj.baseInfo.taxpayerType && pobj.baseInfo.taxpayerType != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.taxpayerType = pobj.baseInfo.taxpayerType;
}
if (pobj.baseInfo.taxpayerName && pobj.baseInfo.taxpayerName != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.taxpayerName = pobj.baseInfo.taxpayerName;
}
if (pobj.companyInfo.engagedIndustry && pobj.companyInfo.engagedIndustry != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.engagedIndustry = pobj.companyInfo.engagedIndustry;
}
if (pobj.companyInfo.engagedIndName && pobj.companyInfo.engagedIndName) {
pobj.cacheInfo.cmpDeliverInfo.engagedIndName = pobj.companyInfo.engagedIndName
}
if (pobj.companyInfo.fullAddress && pobj.companyInfo.fullAddress != 'undefined') {
pobj.cacheInfo.cmpDeliverInfo.fullAddress = pobj.companyInfo.fullAddress;
pobj.cacheInfo.cmpDeliverInfo.residenceAddress = pobj.companyInfo.fullAddress;
}
if (pobj.baseInfo.contactsName && pobj.baseInfo.contactsName != 'undefined') {
pobj.cacheInfo.cmpContactInfo.contactsName = pobj.baseInfo.contactsName;
}
if (pobj.baseInfo.contactsPhone && pobj.baseInfo.contactsPhone != 'undefined') {
pobj.cacheInfo.cmpContactInfo.contactsPhone = pobj.baseInfo.contactsPhone;
}
if (pobj.baseInfo.virtualPrice && pobj.baseInfo.virtualPrice != 'undefined') {//虚拟地址价格
pobj.cacheInfo.virtualPrice = pobj.baseInfo.virtualPrice;
}
if ((pobj.deliverNumber != pobj.txOrderNum) && (pobj.businessType == "sealSevCase" || pobj.businessType == "agentCase")) {
pobj.companyInfo = {};
}
//更新状态给庄冰
var rc = system.getObject("util.execClient");
var requrl = this.queueUrl;
var params = {
"actionType": "produceData",
"actionBody": {
"pushUrl": this.receiveUrl,
"actionType": "updateOrderStatus",
"identifyCode": "ic-manage",
"messageBody": {
"orderNum": pobj.deliverNumber,//订单编码
"status": 20,//已接单
"deliverContent": pobj
}
}
}
var rtn = await rc.execPost(params, requrl);
console.log("rtn---------------------------" + rtn.stdout);
var j = JSON.parse(rtn.stdout);
if (j.status == 1) {
// var res = await this.service.insertInfo(pobj);//插入交付单列表
// pobj.deliverId = res.id;
// //插入暂存
// if (pobj.cacheInfo && (pobj.businessType == "companyCase" || pobj.businessType == "psCase")) {
// await this.cacheService.insertInfo(pobj);
// }
// var logInfo = {
// "flowType": "DELIVERY",
// "flowId": res.id,
// "statusCode": res.delivery_status,
// "statusReason": res.close_reason,
// "clerkName": res.salesman_name,
// "clerkId": res.salesman_id
// }
// await this.logService.insertInfo(logInfo);//插入状态日至表
// await this.materialService.insertInfo(pobj);//插入材料信息
// return system.getResult("插入成功!");
return await this.service.insertInfoall(pobj);
}
else {
return system.getResultError("插入数据失败!");
}
}
catch (error) {
console.log("ERROR---------------------------" + error);
return system.getResultError(error);
}
} else {
return system.getResultError("参数错误!");
}
}
/*获取压缩文件的信息 */
async findZipUrlByDeliverCode(mobj, qobj, req) {//
var pobj = mobj.d;
if (pobj.deliverNumber && pobj.deliverNumber != 'undefined') {
try {
var ms = await this.materialService.findInfoByDeliverNumber(pobj);
if (ms && ms != 'undefined') {
if (ms.download_url && ms.download_url != undefined) {
var comInfo = ms.company_info;
var rtndata = {
"zipUrl":ms.download_url,
"companyName":comInfo.companyName
}
if (comInfo.companyProperties == "limitedLiabilityCompany"){
rtndata.companyProperties = "有限责任公司"
}
else if (comInfo.companyProperties == "incorporatedCompany"){
rtndata.companyProperties = "股份有限公司"
}
else if (comInfo.companyProperties == "groupLimitedCompany"){
rtndata.companyProperties = "集团有限公司"
}
else if (comInfo.companyProperties == "selfEmployed"){
rtndata.companyProperties = "个体工商户"
}
else if (comInfo.companyProperties == "soleProprietorship"){
rtndata.companyProperties = "个人独资企业"
}
else if (comInfo.companyProperties == "company"){
rtndata.companyProperties = "有限公司"
}
return system.getResult(rtndata);
}
else {
return system.getResultError("暂没有url信息!");
}
}
else {
return system.getResultError("没有相关信息!");
}
}
catch (error) {
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
timeFormat(date) {
let localTime = moment.utc(date).toDate();
localTime = moment(localTime).format("YYYY-MM-DD");
return localTime;
}
//元转分 - 解决精度问题 yuan:要转换的钱,单位元; digit:转换倍数
YuanToFen(yuan, digit) {
var m = 0,
s1 = yuan.toString(),
s2 = digit.toString();
try { m += s1.split(".")[1].length } catch (e) { }
try { m += s2.split(".")[1].length } catch (e) { }
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
FenToYuan(fen) {
var num = fen;
num = fen * 0.01;
num += '';
var reg = num.indexOf('.') > -1 ? /(\d{1,3})(?=(?:\d{3})+\.)/g : /(\d{1,3})(?=(?:\d{3})+$)/g;
num = num.replace(reg, '$1');
num = this.toDecimal2(num);
return num;
}
toDecimal2(x) {
var f = parseFloat(x);
if (isNaN(f)) {
return false;
}
var f = Math.round(x * 100) / 100;
var s = f.toString();
var rs = s.indexOf('.');
if (rs < 0) {
rs = s.length;
s += '.';
}
while (s.length <= rs + 2) {
s += '0';
}
return s;
}
//time时间n年后的的前一天
oneYearPast(time, n) {
//var time=new Date();
try {
var year = time.getFullYear() + n;
var d = time.setFullYear(year);
var date = time.getDate(d) - 1;
var xx = time.setDate(date);
return moment(new Date(xx)).format('yyyy-MM-DD');
}
catch{
return "";
}
}
//计算俩日期相差多少天
diffDays(time1, time2) {
try {
var m1 = moment(time1);
var m2 = moment(time2);
return m2.diff(m1, 'day');
}
catch{
return "";
}
}
}
module.exports = DeliverybillCtl;
//var task = new DeliverybillCtl();
// var d = new Date("2020-06-05");
// console.log("dddddddddddd:" + d);
// var oneYear = task.oneYearPast(d,1);
// var ss = moment();
// var diff = task.diffDays(ss,oneYear);
// console.log(oneYear);
// console.log(diff);
// var obj={"d":{"deliverNumber":"1111111"}};
// task.findZipUrlByDeliverCode(obj,{},{}).then(d=>{
// console.log(d);
// //console.log(d[0].analyse);
// })
var system = require("../../../system");
const http = require("http");
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const moment = require('moment');
class MaterialCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(MaterialCtl));
}
/*根据交付单id获取材料信息*/
async findInfoByDeliverId(mobj, qobj, req) {
var pobj = mobj.d;
if (pobj.deliverId && pobj.deliverId != 'undefined') {
try {
var rs = await this.service.findInfoByDeliverId(pobj);
var rarr = {};
if (rs) {
rarr.deliverId = rs.delivery_id;
rarr.deliverNumber = rs.delivery_code;
rarr.companyInfo = rs.company_info;
rarr.registeredInfo = rs.registered_info;
rarr.contributionInfo = rs.contribution_info;
rarr.positionInfo = rs.position_info;
rarr.regInfo = rs.file_info;
rarr.expressInfo = rs.express_info;
}
return system.getResult(rarr);
}
catch (error) {
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
/*根据交付单id更新交付单编号信息*/
async updateInfoByDeliverId(mobj, qobj, req) {
var pobj = mobj.d;
if (pobj.deliverId && pobj.deliverId != 'undefined' && pobj.deliverNumber && pobj.deliverNumber != 'undefined') {
try {
var res = await this.service.updateInfoByDeliverId(pobj);
return system.getResult("更新成功!");
}
catch (error) {
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
/*插入缓存信息 */
async insertInfo(mobj, qobj, req) {
var pobj = mobj.d;
if (pobj.deliverId && pobj.deliverId != 'undefined') {
try {
var res = await this.service.insertInfo(pobj);
return system.getResult("插入成功!");
}
catch (error) {
return system.getResultError(error);
}
}
else {
return system.getResultError("参数错误!");
}
}
/* 获取待压缩文件的信息*/
async waitGenerate() {
try {
var res = await this.service.findnoUrlInfo();
if (res && res != 'undefined') {
return system.getResult(res);
}
else {
return system.getResultError("没有待压缩的数据");
}
}
catch (error) {
return system.getResultError(error);
}
}
/* 根据id更新zip信息 */
async updateZipById(pobj, qobj, req) {
console.log("zip------------------" + JSON.stringify(pobj));
if (pobj.id && pobj.id != 'undefined' && pobj.url && pobj.url != 'undefined'){
try{
await this.service.updateZipById(pobj);
return system.getResult("更新压缩信息成功");
}
catch(error){
return system.getResultError(error);
}
}
else{
return system.getResultError("参数错误!");
}
}
timeFormat(date) {
let localTime = moment.utc(date).toDate();
localTime = moment(localTime).format("YYYY-MM-DD");
return localTime;
}
}
module.exports = MaterialCtl;
// var task = new MaterialCtl();
// var obj={"id":2,"url":"http://test-1258715722.cos.ap-beijing.myqcloud.com/materials/90c263e0-b9d6-11ea-9e11-29abb292cf5f.png"};
// task.updateZipById(obj).then(d=>{
// console.log(JSON.stringify(d));
// //console.log(d[0].analyse);
// })
var system = require("../../../system");
const http = require("http");
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const moment = require('moment');
const appconfig = system.getSysConfig();
class SchemeCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(SchemeCtl));
this.bizoptService = system.getObject("service.bizchance.bizoptSve");
this.logService = system.getObject("service.bizchance.statuslogSve");
this.receiveUrl = settings.receiveUrl();
//this.queueUrl = settings.queueUrl();
//this.wdyUrl = settings.wdyUrl();
}
/*根据id获取方案信息详情*/
async findById(mobj, qobj, req) {
var pobj = mobj.d;
if (pobj.id && pobj.id != 'undefined'){
try{
var rs = await this.service.findById(pobj);
var rarr = {}
if (rs){
rarr.businessMode = rs.demand_code;//商机编号
rarr.schemeNumber = rs.scheme_number;//方案编号
rarr.businessType = "";//商机类型
rarr.businessName = "";//商机名称
var bizoptInfo = await this.bizoptService.findInfoByDemandCode({"businessMode":rarr.businessMode});
if (bizoptInfo){
rarr.businessType = bizoptInfo.business_type;
rarr.businessName = appconfig.pdict.businessType[rarr.businessType];//商机类型名称
}
// rarr.planInfo = rs.scheme_info;//方案详情
rarr.memoInfo = rs.remark_info;//备注信息
rarr.currentStatus = rs.scheme_status;//当前状态
rarr.statusReason = rs.reject_reason;//状态原因
rarr.businessId = rs.bizopt_id;//商机id
rarr.servicerCode = rs.facilitator_id;//服务商id
rarr.servicerName = rs.facilitator_name;//服务商名称
rarr.clerkName = rs.salesman_name;//业务员名称
rarr.clerkPhone = rs.salesman_phone;//业务员联系方式
rarr.createdTime = this.timeFormat(rs.created_at);//创建方案的日期
rarr.statusTime = this.timeFormat(rs.updated_at);//当前状态的日期
var baseInfo = {};
if (rs.scheme_info.companyName && rs.scheme_info.companyName != 'undefined'){//公司名称
rarr.companyName = rs.scheme_info.companyName;
}
if (rarr.businessName == "公司注册" || rarr.businessName == "园区注册"
|| rarr.businessName == "税控申请" || rarr.businessName == "代理记账"){
baseInfo.taxpayerType = rs.scheme_info.taxpayerType;
}
if (rarr.businessName == "园区注册"){
baseInfo.registeredType = rs.scheme_info.registeredType;
}
if (rarr.businessName == "公司注册" || rarr.businessName == "园区注册"){
baseInfo.companyProperties = rs.scheme_info.companyProperties;
baseInfo.engagedIndustry = rs.scheme_info.engagedIndustry;
baseInfo.addressType = rs.scheme_info.addressType;
baseInfo.fullAddress = rs.scheme_info.fullAddress;
baseInfo.businessScope = rs.scheme_info.businessScope;
baseInfo.isWhether = rs.scheme_info.isWhether;
}
if (rarr.businessName == "刻章服务"){
baseInfo.whetherType = rs.scheme_info.whetherType;
}
if (rarr.businessName == "代理记账"){
baseInfo.subjectType = rs.scheme_info.subjectType;
}
if (rarr.businessName == "注册地址" || rarr.businessName == "代理记账"){
baseInfo.buyTime = rs.scheme_info.buyTime;
baseInfo.buyDuration = rs.scheme_info.buyDuration;
baseInfo.isRenew = rs.scheme_info.isRenew;
}
rarr.baseInfo = baseInfo;
if (rarr.businessName != "公司注册" && rarr.businessName != "园区注册"){
var companyInfo = {};
companyInfo.creditCode = rs.scheme_info.creditCode;
companyInfo.companyType = rs.scheme_info.companyType;
companyInfo.establishedTime = rs.scheme_info.establishedTime;
companyInfo.registeredCapital =rs.scheme_info.registeredCapital;
companyInfo.shareholderName = rs.scheme_info.shareholderName;
companyInfo.businessTerm = rs.scheme_info.businessTerm;
companyInfo.businessScope = rs.scheme_info.businessScope;
companyInfo.residenceAddress = rs.scheme_info.residenceAddress;
rarr.companyInfo = companyInfo;
}
}
return system.getResult(rarr);
}
catch(error){
return system.getResultError(error);
}
}
else{
return system.getResultError("参数错误!");
}
}
/*根据商机编号获取方案详情*/
async findInfoByDemandCode(mobj, qobj, req){
var pobj = mobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined'){
try{
var rs = await this.service.findInfoByDemandCode(pobj);
var rarr = {}
if (rs){
rarr.businessMode = rs.demand_code;//商机编号
rarr.schemeNumber = rs.scheme_number;//方案编号
rarr.businessType = "";//商机类型
rarr.businessName = "";//商机名称
var bizoptInfo = await this.bizoptService.findInfoByDemandCode({"businessMode":rarr.businessMode});
if (bizoptInfo){
rarr.businessType = bizoptInfo.business_type;
rarr.businessName = appconfig.pdict.businessType[rarr.businessType];//商机类型名称
}
//rarr.planInfo = rs.scheme_info;//方案详情
rarr.memoInfo = rs.remark_info;//备注信息
rarr.currentStatus = rs.scheme_status;//当前状态
rarr.statusReason = rs.reject_reason;//状态原因
rarr.businessId = rs.bizopt_id;//商机id
rarr.servicerCode = rs.facilitator_id;//服务商id
rarr.servicerName = rs.facilitator_name;//服务商名称
rarr.clerkId = rs.salesman_id;//业务员id;
rarr.clerkName = rs.salesman_name;//业务员名称
rarr.clerkPhone = rs.salesman_phone;//业务员联系方式
rarr.createdTime = this.timeFormat(rs.created_at);//创建方案的日期
rarr.statusTime = this.timeFormat(rs.updated_at);//当前状态的日期
rarr.baseInfo = rs.scheme_info;
}
return system.getResult(rarr);
}
catch(error){
return system.getResultError(error);
}
}
else{
return system.getResultError("参数错误!");
}
}
/* 根据商机编号更新方案状态及原因 */
async updateStatusByDemandCode(mobj, qobj, req){
var pobj = mobj.d;
if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.currentStatus && pobj.currentStatus != 'undefined'){
try{
await this.service.updateStatusByDemandCode(pobj);
var res= await this.service.findInfoByDemandCode(pobj);
if (res){
var logInfo = {
"flowType":"SCHEME",
"flowId":res.id,
"statusCode":res.scheme_status,
"statusReason":res.reject_reason,
"clerkName":res.salesman_name,
"clerkId":res.salesman_id
}
await this.logService.insertInfo(logInfo);//插入状态日至表
}
if (pobj.currentStatus == "isReject"){
var parms ={
"businessMode": pobj.businessMode,
"currentStatus": "beforeSubmission"
}
await this.bizoptService.updateStatusByDemandCode(parms);//把商机状态修改为待提交方案
}
return system.getResult("更新成功!");
}
catch(error){
return system.getResultError(error);
}
}
else{
return system.getResultError("参数错误!");
}
}
/*根据商机编号更新方案详情*/
async updateInfoByDemandCode(mobj, qobj, req){
var pobj = mobj.d;
console.log("------------------------------修改方案------------------------------------");
console.log(JSON.stringify(pobj));
console.log("------------------------------修改方案------------------------------------");
if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.schemeNumber && pobj.schemeNumber != 'undefined' && pobj.baseInfo && pobj.baseInfo != 'undefined'){
try{
pobj.currentStatus = "beforeConfirmation";//同时把方案的状态也更新为待确认
pobj.statusReason = " ";
var businessInfo = await this.bizoptService.findInfoByDemandCode(pobj);//得到商机的信息,插入方案表时要用到
if (businessInfo){
pobj.businessId = businessInfo.id;//商机id
pobj.businessType = businessInfo.business_type;//商机类型
pobj.servicerCode = businessInfo.facilitator_id;//服务商id
pobj.servicerName = businessInfo.facilitator_name;//服务商的名称
pobj.clerkOpcode = businessInfo.salesman_opcode;//这个信息需要确认
pobj.clerkId = businessInfo.salesman_id;//业务员id
pobj.clerkName = businessInfo.salesman_name;//业务员名称
pobj.clerkPhone = businessInfo.salesman_phone;//业务员联系电话
//pobj.currentStatus = appconfig.pdict.businessStatus[businessInfo.business_status];//商机状态即为方案状态
//pobj.statusReason = businessInfo.close_reason;//状态原因
}
if (pobj.baseInfo.caseRemarks && pobj.baseInfo.caseRemarks != 'undefined'){
pobj.baseInfo.memoInfo = pobj.baseInfo.caseRemarks;//备注信息
}
if (pobj.baseInfo.cmpName && pobj.baseInfo.cmpName != 'undefined'){
pobj.baseInfo.companyName = pobj.baseInfo.cmpName;//公司名称
}
//是否刻章
if (pobj.baseInfo.cmpSealSevCase && pobj.baseInfo.cmpSealSevCase != 'undefined'){
pobj.baseInfo.isWhether = pobj.baseInfo.cmpSealSevCase;
}
if (pobj.baseInfo.psSealSevCase && pobj.baseInfo.psSealSevCase != 'undefined'){
pobj.baseInfo.isWhether = pobj.baseInfo.psSealSevCase
}
//纳税人类型
if (pobj.baseInfo.psTaxpayerType && pobj.baseInfo.psTaxpayerType != 'undefined'){
pobj.baseInfo.taxpayerType = pobj.baseInfo.psTaxpayerType;
}
if (pobj.baseInfo.cmpTaxPayerType && pobj.baseInfo.cmpTaxPayerType != 'undefined'){
pobj.baseInfo.taxpayerType = pobj.baseInfo.cmpTaxPayerType;
}
if (pobj.baseInfo.agentTaxpayerType && pobj.baseInfo.agentTaxpayerType != 'undefined'){
pobj.baseInfo.taxpayerType = pobj.baseInfo.agentTaxpayerType;
}
//详细地址
if (pobj.baseInfo.addressTypeInput && pobj.baseInfo.addressTypeInput != 'undefined'){
pobj.baseInfo.residenceAddress = pobj.baseInfo.addressTypeInput;
}
if (pobj.baseInfo.addressType && pobj.baseInfo.addressType != 'undefined'){//地址类型
pobj.baseInfo.addressTypeName = appconfig.pdict.addressTypeDict[pobj.baseInfo.addressType];//地址类型名称
}
if (pobj.baseInfo.taxpayerType && pobj.baseInfo.taxpayerType != 'undefined'){
pobj.baseInfo.taxpayerName = appconfig.pdict.TaxpayerTypeDict[pobj.baseInfo.taxpayerType];//纳税人名称
}
if (pobj.baseInfo.registeredType && pobj.baseInfo.registeredType != 'undefined'){
pobj.baseInfo.registeredName = appconfig.pdict.registeredTypeDict[pobj.baseInfo.registeredType];//云上园区名称
}
if (pobj.baseInfo.agentType && pobj.baseInfo.agentType != 'undefined'){
pobj.baseInfo.agentName = appconfig.pdict.agentTypeDict[pobj.baseInfo.agentType];//代理记账主体名称
if (pobj.baseInfo.serviceArea && pobj.baseInfo.serviceArea != 'undefined'){
if (pobj.baseInfo.agentType == "company"){
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredAreaDict[pobj.baseInfo.serviceArea];//注册地区
}
else{
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredParkDict[pobj.baseInfo.serviceArea];//注册地区
}
}
}
if (pobj.businessType == "companyCase"){
if (pobj.baseInfo.companynature && pobj.baseInfo.companynature != 'undefined'){
pobj.baseInfo.companyType = appconfig.pdict.companyNatureDict[pobj.baseInfo.companynature];//公司类型的名称
}
//注册地区
if (pobj.baseInfo.serviceArea && pobj.baseInfo.serviceArea != 'undefined'){
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredAreaDict[pobj.baseInfo.serviceArea];//注册地区
}
}
else if (pobj.businessType == "psCase"){
//注册地区
if (pobj.baseInfo.serviceArea && pobj.baseInfo.serviceArea != 'undefined'){
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredParkDict[pobj.baseInfo.serviceArea];//注册地区
}
}
else{
//注册地区
if (pobj.baseInfo.serviceArea && pobj.baseInfo.serviceArea != 'undefined'){
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredAreaDict[pobj.baseInfo.serviceArea];//注册地区
}
}
//goumaisichang
// if (pobj.baseInfo.buyDuration && pobj.baseInfo.buyDuration != 'undefined'){
// pobj.baseInfo.buyDuration = appconfig.pdict.buyDurationDict[pobj.baseInfo.buyDuration];
// }
if (pobj.baseInfo.hasOwnProperty("isRenew")){
pobj.baseInfo.isRenew = appconfig.pdict.isRenewDict[pobj.baseInfo.isRenew];
}
else{
pobj.baseInfo.isRenew = "不开启"
}
if (pobj.baseInfo.engagedIndustry && pobj.baseInfo.engagedIndustry != 'undefined'){
pobj.baseInfo.engagedIndName = appconfig.pdict.engagedIndustryDict[pobj.baseInfo.engagedIndustry];//从事行业名称
}
if (pobj.baseInfo.sealSevType && pobj.baseInfo.sealSevType != 'undefined'){
pobj.baseInfo.sealSevName = appconfig.pdict.sealSevTypeDict[pobj.baseInfo.sealSevType];//刻章类型名称名称
if (pobj.baseInfo.serviceArea && pobj.baseInfo.serviceArea != 'undefined'){
if (pobj.baseInfo.sealSevType == "company"){
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredAreaDict[pobj.baseInfo.serviceArea];//注册地区
}
else{
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredParkDict[pobj.baseInfo.serviceArea];//注册地区
}
}
}
//修改方案的时候,需要把修改的方案传给商城
var ttype = pobj.businessType;
console.log("ttype:" + ttype);
pobj.businessType = appconfig.pdict.fdyDict[pobj.businessType];
console.log("businessType:" + pobj.businessType);
var rc = system.getObject("util.execClient");
var requrl = this.receiveUrl;
var params = {
"actionType":"submitSolution",
"actionBody":{
"needNum": pobj.businessMode,
"solutionNum":pobj.schemeNumber,
"solutionContent": pobj
}
}
console.log(JSON.stringify(params) + "HHHHHHHHHHHHHHHHHHHHHH");
var rtn = await rc.execPost(params, requrl);
var j = JSON.parse(rtn.stdout);
console.log(JSON.stringify(j) + "IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII");
if (j.status == 1){
pobj.businessType = ttype;
//pobj.schemeNumber = j.data;
await this.service.updateInfoByDemandCode(pobj);//更新方案详情,同时更新新的方案编号
var bobj = {"businessMode":pobj.businessMode,"currentStatus":"beforeConfirmation"};//同时把商机状态更新回待确认
await this.bizoptService.updateStatusByDemandCode(bobj);
return system.getResult("更新成功!");
}
else{
return system.getResultError("更新方案出错!");
}
}
catch(error){
console.log("EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE" + error);
return system.getResultError(error);
}
}
else{
console.log("CCCCCCCCCCCCCCCCCCCCCCC参数错误!");
return system.getResultError("参数错误!");
}
}
/*根据商机编号更新方案编号*/
async updateSchemeNumberByDemandCode(mobj, qobj, req){
var pobj = mobj.d;
if (pobj.schemeNumber && pobj.schemeNumber != 'undefined' && pobj.businessMode && pobj.businessMode != 'undefined'){
try{
await this.service.updateSchemeNumberByDemandCode(pobj);
return system.getResult("更新成功!");
}
catch(error){
return system.getResultError(error);
}
}
else{
return system.getResultError("参数错误!");
}
}
/*插入方案信息*/
async insertInfo(mobj, qobj, req){
var pobj = mobj.d;
console.log("22222222222222222" + JSON.stringify(pobj));
if (pobj.businessMode && pobj.businessMode != 'undefined' && pobj.baseInfo && pobj.baseInfo != 'undefined'){//商机编号必须存在
try{
pobj.currentStatus = "beforeConfirmation";//商机状态为待用户确认
var businessInfo = await this.bizoptService.findInfoByDemandCode(pobj);//得到商机的信息,插入方案表时要用到
if (businessInfo){
pobj.businessId = businessInfo.id;//商机id
pobj.businessType = businessInfo.business_type;//商机类型
pobj.servicerCode = businessInfo.facilitator_id;//服务商id
pobj.servicerName = businessInfo.facilitator_name;//服务商的名称
pobj.clerkOpcode = businessInfo.salesman_opcode;//这个信息需要确认
pobj.clerkId = businessInfo.salesman_id;//业务员id
pobj.clerkName = businessInfo.salesman_name;//业务员名称
pobj.clerkPhone = businessInfo.salesman_phone;//业务员联系电话
//pobj.baseInfo.userName = businessInfo.business_info.userName;//
//pobj.currentStatus = appconfig.pdict.businessStatus[businessInfo.business_status];//商机状态即为方案状态
//pobj.statusReason = businessInfo.close_reason;//状态原因
}
if (pobj.baseInfo.caseRemarks && pobj.baseInfo.caseRemarks != 'undefined'){
pobj.baseInfo.memoInfo = pobj.baseInfo.caseRemarks;//备注信息
}
if (pobj.baseInfo.cmpName && pobj.baseInfo.cmpName != 'undefined'){
pobj.baseInfo.companyName = pobj.baseInfo.cmpName;//公司名称
}
//是否刻章
if (pobj.baseInfo.cmpSealSevCase && pobj.baseInfo.cmpSealSevCase != 'undefined'){
pobj.baseInfo.isWhether = pobj.baseInfo.cmpSealSevCase;
}
if (pobj.baseInfo.psSealSevCase && pobj.baseInfo.psSealSevCase != 'undefined'){
pobj.baseInfo.isWhether = pobj.baseInfo.psSealSevCase
}
//纳税人类型
if (pobj.baseInfo.psTaxpayerType && pobj.baseInfo.psTaxpayerType != 'undefined'){
pobj.baseInfo.taxpayerType = pobj.baseInfo.psTaxpayerType;
}
if (pobj.baseInfo.cmpTaxPayerType && pobj.baseInfo.cmpTaxPayerType != 'undefined'){
pobj.baseInfo.taxpayerType = pobj.baseInfo.cmpTaxPayerType;
}
if (pobj.baseInfo.agentTaxpayerType && pobj.baseInfo.agentTaxpayerType != 'undefined'){
pobj.baseInfo.taxpayerType = pobj.baseInfo.agentTaxpayerType;
}
//详细地址
if (pobj.baseInfo.addressTypeInput && pobj.baseInfo.addressTypeInput != 'undefined'){
pobj.baseInfo.residenceAddress = pobj.baseInfo.addressTypeInput;
}
if (pobj.baseInfo.addressType && pobj.baseInfo.addressType != 'undefined'){//地址类型
pobj.baseInfo.addressTypeName = appconfig.pdict.addressTypeDict[pobj.baseInfo.addressType];//地址类型名称
}
if (pobj.baseInfo.taxpayerType && pobj.baseInfo.taxpayerType != 'undefined'){
pobj.baseInfo.taxpayerName = appconfig.pdict.TaxpayerTypeDict[pobj.baseInfo.taxpayerType];//纳税人名称
}
if (pobj.baseInfo.registeredType && pobj.baseInfo.registeredType != 'undefined'){
pobj.baseInfo.registeredName = appconfig.pdict.registeredTypeDict[pobj.baseInfo.registeredType];//云上园区名称
}
if (pobj.baseInfo.agentType && pobj.baseInfo.agentType != 'undefined'){
pobj.baseInfo.agentName = appconfig.pdict.agentTypeDict[pobj.baseInfo.agentType];//代理记账主体名称
if (pobj.baseInfo.serviceArea && pobj.baseInfo.serviceArea != 'undefined'){
if (pobj.baseInfo.agentType == "company"){
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredAreaDict[pobj.baseInfo.serviceArea];//注册地区
}
else{
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredParkDict[pobj.baseInfo.serviceArea];//注册地区
}
}
}
if (pobj.businessType == "companyCase"){
if (pobj.baseInfo.companynature && pobj.baseInfo.companynature != 'undefined'){
pobj.baseInfo.companyType = appconfig.pdict.companyNatureDict[pobj.baseInfo.companynature];//公司类型的名称
}
//注册地区
if (pobj.baseInfo.serviceArea && pobj.baseInfo.serviceArea != 'undefined'){
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredAreaDict[pobj.baseInfo.serviceArea];//注册地区
}
}
else if (pobj.businessType == "psCase"){
//注册地区
if (pobj.baseInfo.serviceArea && pobj.baseInfo.serviceArea != 'undefined'){
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredParkDict[pobj.baseInfo.serviceArea];//注册地区
}
}
else{
//注册地区
if (pobj.baseInfo.serviceArea && pobj.baseInfo.serviceArea != 'undefined'){
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredAreaDict[pobj.baseInfo.serviceArea];//注册地区
}
}
//goumaisichang
if (pobj.baseInfo.buyDuration && pobj.baseInfo.buyDuration != 'undefined'){
pobj.baseInfo.buyDuration = appconfig.pdict.buyDurationDict[pobj.baseInfo.buyDuration];
}
if (pobj.baseInfo.isRenew && pobj.baseInfo.isRenew != 'undefined' ){
pobj.baseInfo.isRenew = appconfig.pdict.isRenewDict[pobj.baseInfo.isRenew];
}
if (pobj.baseInfo.engagedIndustry && pobj.baseInfo.engagedIndustry != 'undefined'){
pobj.baseInfo.engagedIndName = appconfig.pdict.engagedIndustryDict[pobj.baseInfo.engagedIndustry];//从事行业名称
}
if (pobj.baseInfo.sealSevType && pobj.baseInfo.sealSevType != 'undefined'){
pobj.baseInfo.sealSevName = appconfig.pdict.sealSevTypeDict[pobj.baseInfo.sealSevType];//刻章类型名称名称
if (pobj.baseInfo.serviceArea && pobj.baseInfo.serviceArea != 'undefined'){
if (pobj.baseInfo.sealSevType == "company"){
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredAreaDict[pobj.baseInfo.serviceArea];//注册地区
}
else{
pobj.baseInfo.serviceAreaName = appconfig.pdict.registeredParkDict[pobj.baseInfo.serviceArea];//注册地区
}
}
}
//调商城的接口,把商机详情返回给商城
var btype = pobj.businessType;
pobj.businessType = appconfig.pdict.fdyDict[pobj.businessType];
var rc = system.getObject("util.execClient");
var requrl = this.receiveUrl;
var params = {
"actionType":"submitSolution",
"actionBody":{
"needNum": pobj.businessMode,
"solutionNum":"",
"solutionContent": pobj
}
}
var rtn = await rc.execPost(params, requrl);
var j = JSON.parse(rtn.stdout);
console.log("------------------------------------------" + rtn.stdout);
if (j.status == 1){
pobj.schemeNumber = j.data;
pobj.businessType = btype;
await this.service.insertInfo(pobj);
await this.bizoptService.updateStatusByDemandCode(pobj);//先修改商机状态
return system.getResult("操作成功!");
}
else{
return j;
}
}
catch(error){
return system.getResultError(error);
}
}
else{
return system.getResultError("参数错误!");
}
}
/*插入或更新方案*/
async createInfo(datajson,qobj, req){
console.log("datejson:" + JSON.stringify(datajson));
try{
var rs = await this.service.findInfoByDemandCode(datajson.d);
if (rs && rs != 'undefined'){
datajson.d.schemeNumber = rs.scheme_number;
return await this.updateInfoByDemandCode(datajson);
}
else{
return await this.insertInfo(datajson);
}
}
catch(error){
return system.getResultError(error);
}
}
timeFormat(date) {
let localTime = moment.utc(date).toDate();
localTime = moment(localTime).format("YYYY-MM-DD");
return localTime;
}
}
module.exports = SchemeCtl;
// var task = new SchemeCtl();
// var obj={"businessMode":"202006100002","baseInfo":{"memoInfo":"sfdsff","whetherType":"individual","creditCode":"1223345455","companyType":"有限公司","companyName":"三个五","establishedTime":"2010-5-6","registeredCapital":"5万元","shareholderName":"2B","businessTerm":"500","businessScope":"sgrgdrgghhh","residenceAddress":"北京市"}};
// task.insertInfo(obj,{},{}).then(d=>{
// console.log(d);
// //console.log(d[0].analyse)
// })
var system = require("../../../system");
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const appconfig = system.getSysConfig();
class SettleBillCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(SettleBillCtl));
}
async advice(p,q,req){
let sid= p.advice.settleId
let msg=p.advice.memo
let userid=p.userid
let userName=p.username
let rtn=await this.service.advice(sid,msg,userid,userName)
return system.getResult(rtn)
}
async auditPass(p,q,req){
let sid= p.pass.settleId
let rtn=await this.service.auditPass(sid,p.userid,p.username)
return system.getResult(rtn)
}
async pay(p,q,req){
let sid= p.pay.settleId
let rtn=await this.service.pay(sid,p.userid,p.username)
return system.getResult(rtn)
}
}
module.exports = SettleBillCtl;
var system = require("../../../system");
const http = require("http");
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base");
const moment = require('moment');
class StatusLogCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(StatusLogCtl));
}
/*插入缓存信息 */
async insertInfo(mobj,qobj,req){
var pobj = mobj.d;
if (pobj.flowType && pobj.flowType != 'undefined' && pobj.flowId && pobj.flowId != 'undefined'
&& pobj.statusCode && pobj.statusCode != 'undefined'){
try{
var res = await this.service.insertInfo(pobj);
return system.getResult("插入成功!");
}
catch (error){
return system.getResultError(error);
}
}
else{
return system.getResultError("参数错误!");
}
}
timeFormat(date) {
let localTime = moment.utc(date).toDate();
localTime = moment(localTime).format("YYYY-MM-DD");
return localTime;
}
}
module.exports = StatusLogCtl;
// var task = new CacheInfoCtl();
// var obj={"demand_code":"30030302992","business_status":"isFinished"};
// task.updateStatusByDemandCode(obj,{},{}).then(d=>{
// console.log(d);
// //console.log(d[0].analyse);
// })
const system = require("../../../system");
const Dao = require("../../dao.base");
class BizoptDao extends Dao {
constructor() {
super(Dao.getModelName(BizoptDao));
}
extraWhere(qobj, qw, qc) {//根据业务员id获取商机信息的组装条件
qc.raw = true;
//检查查询的用户所属公司是否是平台运营公司-1,如果是则不添加公司查询条件, 不添加路径条件,返回所有数据
if (qobj.company_id == 1) {
return qw
} else {
//需要添加公司查询条件
qw["facilitator_id"] = Number(qobj.company_id)
// 为空说明是管理员,不需设置组织结构过滤
if (qobj.opath && qobj.opath != "") {
qw["salesman_opcode"] = { [this.db.Op.like]: `%${qobj.opath}%` }
}
//不是来自平台前端查询
if (qobj.bizpath && qobj.bizpath.indexOf("pmx") < 0) {
qc.where.business_type = qc.where.business_type || {
[this.db.Op.notIn]: ["ICP", "EDI"]
}
if (qobj.bizpath && qobj.bizpath != "") {
if (qobj.bizpath.indexOf("myChance") > 0) {//说明是从商机列表过来的
qw["salesman_id"] = qobj.userid;
}
}
}
}
return qw;
}
/*根据商机编号获取商机详情*/
async findInfoByDemandCode(qobj) {
var qcwhere = { "demand_code": qobj.businessMode };
return await this.findOne(qcwhere);
}
/*更新商机状态*/
async updateStatusByDemandCode(qobj, t) {
var setobj = { "business_status": qobj.currentStatus };
if (qobj.statusReason && qobj.statusReason != 'undefined') {
setobj["close_reason"] = qobj.statusReason;
}
else {
setobj["close_reason"] = "";
}
var whereobj = { "demand_code": qobj.businessMode };
return await this.updateByWhere(setobj, whereobj, t);
}
/*插入商机信息*/
async insertInfo(qobj, t) {
var obj = {
"demand_code": qobj.businessMode,
"business_type": qobj.businessType,
"business_status": qobj.currentStatus,
"business_info": {}
};
if (qobj.channelSource && qobj.channelSource != 'undefined') {
obj.source_name = qobj.channelSource;
}
if (qobj.sourceNumber && qobj.sourceNumber != 'undefined') {
obj.source_number = qobj.sourceNumber;
}
if (qobj.serviceCode && qobj.serviceCode != 'undefined') {
obj.service_address = qobj.serviceCode;
}
if (qobj.memoInfo && qobj.memoInfo != 'undefined') {
obj.business_info.memoInfo = qobj.memoInfo;
}
if (qobj.statusReason && qobj.statusReason != 'undefined') {
obj.close_reason = qobj.statusReason;
}
if (qobj.contactsName && qobj.contactsName != 'undefined') {
obj.business_info.contactsName = qobj.contactsName;
}
if (qobj.contactsPhone && qobj.contactsPhone != 'undefined') {
obj.business_info.contactsPhone = qobj.contactsPhone;
}
if (qobj.serviceName && qobj.serviceName != 'undefined') {
obj.business_info.serviceName = qobj.serviceName;
}
if (qobj.businessName && qobj.businessName != 'undefined') {
obj.business_info.businessName = qobj.businessName;
}
if (qobj.UserName && qobj.UserName != 'undefined') {
obj.business_info.userName = qobj.UserNames;
}
if (qobj.companyName && qobj.companyName != 'undefined') {
obj.business_info.companyName = qobj.companyName;
}
if (qobj.servicerCode && qobj.servicerCode != 'undefined') {
obj.facilitator_id = qobj.servicerCode;
}
if (qobj.servicerName && qobj.servicerName != 'undefined') {
obj.facilitator_name = qobj.servicerName;
}
if (qobj.salesmanOpcode && qobj.salesmanOpcode != 'undefined') {
obj.salesman_opcode = qobj.salesmanOpcode;
}
if (qobj.salesmanId && qobj.salesmanId != 'undefined') {
obj.salesman_id = qobj.salesmanId;
}
if (qobj.clerkName && qobj.clerkName != 'undefined') {
obj.salesman_name = qobj.clerkName;
}
if (qobj.clerkPhone && qobj.clerkPhone != 'undefined') {
obj.salesman_phone = qobj.clerkPhone;
}
return await this.create(obj, t);
}
}
module.exports = BizoptDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class CacheinfoDao extends Dao {
constructor() {
super(Dao.getModelName(CacheinfoDao));
}
// extraWhere(qobj, qw, qc) {//根据业务员id获取商机信息的组装条件
// qc.raw = true;
// qc.where.business_type = qc.where.business_type || {
// [this.db.Op.notIn]: ["ICP", "EDI"]
// }
// if(qobj.bizpath && qobj.bizpath!=""){
// if(qobj.bizpath.indexOf("myChance")>0){//说明是从商机列表过来的
// qw["salesman_id"]=qobj.userid;
// }
// }
// return qw;
// }
/*根据订单id获取缓存信息详情*/
async findInfoByDeliverId(qobj){
var qcwhere = {"deliver_id":qobj.deliverNumber};
return await this.findOne(qcwhere);
}
/*更加订单id更新缓存信息*/
async updateInfoByDeliverId(qobj,t){
var setobj = {"cache_info":qobj.cacheInfo};
var whereobj = {"deliver_id":qobj.deliverNumber};
return await this.updateByWhere(setobj,whereobj,t);
}
/*插入缓存信息*/
async insertInfo(qobj,t){
var obj = {
"deliver_id":qobj.deliverNumber,
"cache_info":qobj.cacheInfo
};
return await this.create(obj,t);
}
}
module.exports = CacheinfoDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class DeliverybillDao extends Dao {
constructor() {
super(Dao.getModelName(DeliverybillDao));
}
extraModelFilter(pobj) {
return {"key":"include","value":{model:this.db.models.settlebill,raw:true,attributes:['memo']}};
}
extraWhere(qobj, qw, qc) {//根据业务员id获取交付单信息的组装条件
//qc.raw = true;
//检查查询的用户所属公司是否是平台运营公司-1,如果是则不添加公司查询条件, 不添加路径条件,返回所有数据
if(qw["delivery_status"]=="handling"){//解决首页多状态查询
qw["delivery_status"]= { [this.db.Op.notIn]:['received', 'success', 'closed']}
}
if (qobj.company_id == 1) {
if (qobj.bizpath && qobj.bizpath != "") {
if (qobj.bizpath.indexOf("pmxdeliverrequest") > 0) {//说明是从商机列表过来的
qw["delivery_status"] = "success";
qw["settle_status"] = "waittosettle";
}
}
return qw
} else {
//需要添加公司查询条件
qw["facilitator_id"] = Number(qobj.company_id)
// 为空说明是管理员,不需设置组织结构过滤
if (qobj.opath && qobj.opath != "") {
qw["salesman_opcode"] = { [this.db.Op.like]:`%${qobj.opath}%`}
}else{//说明是租户管理员,给租户自己核销结算的功能,
if (qobj.bizpath.indexOf("pmxdeliverrequest") > 0) {//说明是结算核销路由过来的
qw["delivery_status"] = "success";
qw["settle_status"] = "waittosettle";
}
}
//不是来自平台前端查询
if (qobj.bizpath && qobj.bizpath.indexOf("pmx") < 0) {
qc.where.product_code = qc.where.product_code || {
[this.db.Op.notIn]: ["ICP", "EDI","ICPANNUALREPORT","EDIANNUALREPORT"]
}
if (qobj.bizpath && qobj.bizpath != "") {
if (qobj.bizpath.indexOf("myDeliver") > 0) {//说明是从商机列表过来的
qw["salesman_id"] = qobj.userid;
}
}
}
}
return qw;
}
/*根据交付单编号获取订单详情*/
async findInfoByDeliverCode(qobj) {
var qcwhere = { "delivery_code": qobj.deliverNumber };
return await this.findOne(qcwhere);
}
/*根据交付单编号更新状态信息*/
async updateStatusByDeliverCode(qobj, t) {
var setobj = { "delivery_status": qobj.deliverStatus };
if (qobj.statusReason && qobj.statusReason != 'undefined') {
setobj.close_reason = qobj.statusReason;
}
else{
setobj.close_reason = "";
}
var whereobj = { "delivery_code": qobj.deliverNumber };
var rs = await this.findOne(whereobj);
if (rs && rs != 'undefined'){
if (qobj.deliverStatus == "collecting" || qobj.deliverStatus == "received" || qobj.deliverStatus == "paid"){
rs.delivery_info.payStatus = "待交付";
}
else if (qobj.deliverStatus == "closed"){
rs.delivery_info.payStatus = "已关闭";
}
else{
rs.delivery_info.payStatus = "已交付";
}
setobj.delivery_info = rs.delivery_info;
}
return await this.updateByWhere(setobj, whereobj, t);
}
/*根据交付单更新交付材料信息*/
async updateInfoByDeliverCode(qobj, t) {//公司注册、云上园区注册时填写交付材料
var whereobj = { "delivery_code": qobj.deliverNumber };
var setobj = { "delivery_info": qobj.baseInfo };
if (qobj.deliverStatus && qobj.deliverStatus != 'undefined'){
setobj.delivery_status = qobj.deliverStatus;
}
if (qobj.statusReason && qobj.statusReason != 'undefined') {
setobj.close_reason = qobj.statusReason;
}
else{
setobj.close_reason = "";
}
return await this.updateByWhere(setobj, whereobj, t);
}
/*插入交付单信息*/
async insertInfo(qobj, t) {//到时候看交付单信息后再确定
var obj = {
"delivery_code": qobj.deliverNumber,
"delivery_status": qobj.deliverStatus,
"delivery_info":qobj.baseInfo
};
if (qobj.businessMode && qobj.businessMode != 'undefined'){
obj.demand_code = qobj.businessMode;
}
if (qobj.schemeNumber && qobj.schemeNumber != 'undefined'){
obj.scheme_number = qobj.schemeNumber;
}
if (qobj.businessName && qobj.businessName != 'undefined') {
obj.product_name = qobj.businessName;
}
if (qobj.businessType && qobj.businessType != 'undefined') {
obj.product_code = qobj.businessType;
}
if (qobj.txOrderNum && qobj.txOrderNum != 'undefined'){
obj.master_source_number= qobj.txOrderNum;
}
if (qobj.channelSource && qobj.channelSource != 'undefined') {
obj.source_name = qobj.channelSource;
}
if (qobj.channelNumber && qobj.channelNumber != 'undefined') {
obj.source_number = qobj.channelNumber;
}
if (qobj.skuCode && qobj.skuCode != 'undefined') {
obj.sku_code = qobj.skuCode;
}
if (qobj.serviceCode && qobj.serviceCode != 'undefined') {
obj.service_address = qobj.serviceCode;
}
if (qobj.servicerCode && qobj.servicerCode != 'undefined') {
obj.facilitator_id = qobj.servicerCode;
}
if (qobj.servicerName && qobj.servicerName != 'undefined') {
obj.facilitator_name = qobj.servicerName;
}
if (qobj.clerkName && qobj.clerkName != 'undefined') {
obj.salesman_name = qobj.clerkName;
}
if (qobj.clerkPhone && qobj.clerkPhone != 'undefined') {
obj.salesman_phone = qobj.clerkPhone
}
if (qobj.clerkOpcode && qobj.clerkOpcode != 'undefined') {
obj.salesman_opcode = qobj.clerkOpcode;
}
if (qobj.clerkId && qobj.clerkId != 'undefined') {
obj.salesman_id = qobj.clerkId;
}
if (qobj.sellingPrice && qobj.sellingPrice != 'undefined') {
obj.selling_price = qobj.sellingPrice;
}
if (qobj.costPrice && qobj.costPrice != 'undefined') {
obj.cost_price = qobj.costPrice;
}
if (qobj.statusReason && qobj.statusReason != 'undefined') {
obj.close_reason = qobj.statusReason;
}
return await this.create(obj, t);
}
}
module.exports = DeliverybillDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class MaterialDao extends Dao {
constructor() {
super(Dao.getModelName(MaterialDao));
}
/*根据交付单编号获取注册材料信息详情*/
async findInfoByDeliverNumber(qobj) {
var qcwhere = { "delivery_code": qobj.deliverNumber };
return await this.findOne(qcwhere);
}
/* 根据id更新zip信息 */
async updateZipById(qobj, t) {
try{
var whereobj = { "id": qobj.id };
var setobj= {
"is_download":1,
"download_url":qobj.url
};
return await this.updateByWhere(setobj, whereobj, t);
}
catch(error){
console.log("error----------" + error);
return error;
}
}
/*根据交付单编号更新交材料详情*/
async updateInfoByDeliverNumber(qobj, t) {
var whereobj = { "delivery_code": qobj.deliverNumber };
var setobj = {};
if (qobj.companyInfo && qobj.companyInfo != 'undefined') {
setobj.company_info = qobj.companyInfo;
}
if (qobj.registeredInfo && qobj.registeredInfo != 'undefined') {
setobj.registered_info = qobj.registeredInfo;
}
if (qobj.contributionInfo && qobj.contributionInfo != 'undefined') {
setobj.contribution_info = qobj.contributionInfo;
}
if (qobj.positionInfo && qobj.positionInfo != 'undefined') {
setobj.position_info = qobj.positionInfo;
}
if (qobj.managerInfo && qobj.managerInfo != 'undefined') {
setobj.position_info = qobj.managerInfo;
}
if (qobj.regInfo && qobj.regInfo != 'undefined') {
setobj.file_info = qobj.regInfo;
}
if (qobj.expressInfo && qobj.expressInfo != 'undefined') {
setobj.express_info = qobj.expressInfo;
}
return await this.updateByWhere(setobj, whereobj, t);
}
/*插入注册材料信息*/
async insertInfo(pobj, t) {//公司注册,云上园区注册时的信息
var obj = {
"delivery_code": pobj.deliverNumber
};
if (pobj.deliverId && pobj.deliverId != 'undefined') {
obj["delivery_id"] = pobj.deliverId;
}
if (pobj.companyInfo && pobj.companyInfo != 'undefined') {
obj.company_info = pobj.companyInfo;
}
if (pobj.registeredInfo && pobj.registeredInfo != 'undefined') {
obj.registered_info = pobj.registeredInfo;
}
if (pobj.positionInfo && pobj.positionInfo != 'undefined') {
obj.position_info = pobj.positionInfo;
}
if (pobj.regInfo && pobj.regInfo != 'undefined') {
obj.file_info = pobj.regInfo;
}
if (pobj.expressInfo && pobj.expressInfo != 'undefined') {
obj.express_info = pobj.expressInfo;
}
return await this.create(obj, t);
}
}
module.exports = MaterialDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class SchemeDao extends Dao {
constructor() {
super(Dao.getModelName(SchemeDao));
}
/*根据商机编号获取方案信息详情*/
async findInfoByDemandCode(qobj){
var qcwhere = {"demand_code":qobj.businessMode};
return await this.findOne(qcwhere);
}
/*根据方案编号更新方案状态及原因*/
async updateStatusByDemandCode(qobj,t){
var setobj = {"scheme_status":qobj.currentStatus};
if (qobj.statusReason && qobj.statusReason != 'undefined'){
setobj["reject_reason"] = qobj.statusReason;
}
else{
setobj["reject_reason"] = "";
}
var whereobj = {"demand_code":qobj.businessMode};
return await this.updateByWhere(setobj,whereobj,t);
}
/*根据商机编号更新方案详情*/
async updateInfoByDemandCode(qobj,t){
var whereobj = {"demand_code":qobj.businessMode};
var setobj = {"scheme_info":qobj.baseInfo,"scheme_status":qobj.currentStatus};
if (qobj.schemeNumber && qobj.schemeNumber != 'undefined'){
setobj.scheme_number = qobj.schemeNumber;
}
if (qobj.statusReason && qobj.statusReason != 'undefined'){
setobj.reject_reason = qobj.statusReason;
}
else{
setobj.reject_reason = "";
}
return await this.updateByWhere(setobj,whereobj,t);
}
/*根据方案编号更新方案编号*/
async updateSchemeNumberByDemandCode(qobj,t){
var setobj = {"scheme_number":qobj.schemeNumber};
var whereobj = {"demand_code":qobj.businessMode};
return await this.updateByWhere(setobj,whereobj,t);
}
/*插入方案信息*/
async insertInfo(qobj,t){
var obj = {
"demand_code":qobj.businessMode,
"scheme_info":qobj.baseInfo
};
if (qobj.currentStatus && qobj.currentStatus != 'undefined'){
obj["scheme_status"] = qobj.currentStatus;
}
if (qobj.schemeNumber && qobj.schemeNumber != 'undefined'){
obj["scheme_number"] = qobj.schemeNumber;
}
if (qobj.statusReason && qobj.statusReason != 'undefined'){
obj["reject_reason"] = qobj.statusReason;
}
if (qobj.memoInfo && qobj.memoInfo != 'undefined'){
obj["remark_info"] = qobj.memoInfo;
}
if (qobj.businessId && qobj.businessId != 'undefined'){
obj["bizopt_id"] = qobj.businessId;
}
if (qobj.servicerCode && qobj.servicerCode != 'undefined'){
obj["facilitator_id"] = qobj.servicerCode;
}
if (qobj.servicerName && qobj.servicerName != 'undefined'){
obj["facilitator_name"] = qobj.servicerName;
}
if (qobj.clerkOpcode && qobj.clerkOpcode != 'undefined'){
obj["salesman_opcode"] = qobj.clerkOpcode;
}
if (qobj.clerkId && qobj.clerkId != 'undefined'){
obj["salesman_id"] = qobj.clerkId;
}
if (qobj.clerkName && qobj.clerkName != 'undefined'){
obj["salesman_name"] = qobj.clerkName;
}
if (qobj.clerkPhone && qobj.clerkPhone != 'undefined'){
obj["salesman_phone"] = qobj.clerkPhone;
}
return await this.create(obj,t);
}
}
module.exports = SchemeDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class SettlebillDao extends Dao {
constructor() {
super(Dao.getModelName(SettlebillDao));
}
extraWhere(qobj, qw, qc) {//根据业务员id获取交付单信息的组装条件
//qc.raw = true;
//检查查询的用户所属公司是否是平台运营公司-1,如果是则不添加公司查询条件, 不添加路径条件,返回所有数据
if (qobj.company_id == 1) {
return qw
} else {
//需要添加公司查询条件
qw["facilitator_id"] = Number(qobj.company_id)
}
return qw;
}
}
module.exports = SettlebillDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class StatuslogDao extends Dao {
constructor() {
super(Dao.getModelName(StatuslogDao));
}
/*插入状态信息信息*/
async insertInfo(qobj,t){
var obj = {
"flow_type":qobj.flowType,
"flow_id":qobj.flowId,
"status_code":qobj.statusCode
};
if (qobj.statusReason && qobj.statusReason != 'undefined'){
obj.status_reason = qobj.statusReason;
}
else{
obj.status_reason = "";
}
if (qobj.clerkName && qobj.clerkName != 'undefined'){
obj.salesman_name = qobj.clerkName;
}
if (qobj.clerkId && qobj.clerkId != 'undefined'){
obj.salesman_id = qobj.clerkId;
}
return await this.create(obj,t);
}
}
module.exports = StatuslogDao;
const system=require("../../../system");
const Dao=require("../../dao.base");
class MsgHistoryDao extends Dao{
constructor(){
super(Dao.getModelName(MsgHistoryDao));
}
extraWhere(obj,w){
if(obj.ukstr && obj.ukstr!=""){
// w={[this.db.Op.or]:[
// {[this.db.Op.and]:[{sender:obj.ukstr},{target:obj.extra}]},
// {[this.db.Op.and]:[{sender:obj.extra},{target:obj.ukstr}]},
// ]
// };
w[this.db.Op.or]=[
{[this.db.Op.and]:[{sender:obj.ukstr},{target:obj.extra}]},
{[this.db.Op.and]:[{sender:obj.extra},{target:obj.ukstr}]},
];
}
return w;
}
orderBy(){
//return {"key":"include","value":{model:this.db.models.app}};
return [["id","DESC"]];
}
}
module.exports=MsgHistoryDao;
const system=require("../../../system");
const Dao=require("../../dao.base");
class MsgNoticeDao extends Dao{
constructor(){
super(Dao.getModelName(MsgNoticeDao));
}
async saveNotice(msg, t) {
var noticeFrom = await super.findOne({fromId : msg.senderId, toId : msg.targetId});
if(noticeFrom) {
var set = {lastMsgId:msg.id};
if(msg.businessLicense_id) {
set.businessLicense_id = msg.businessLicense_id;
}
await super.updateByWhere(set, {where:{id:noticeFrom.id}}, t);
} else {
noticeFrom = {
fromuser: msg.sender,
fromId:msg.senderId,
touser: msg.target,
toId:msg.targetId,
isAccepted:true,
lastMsgId:msg.id,
businessLicense_id : msg.businessLicense_id || 0
};
await super.create(noticeFrom, t);
}
var noticeTo = await super.findOne({fromId : msg.targetId, toId : msg.senderId});
if(noticeTo) {
var set = {lastMsgId:msg.id};
if(msg.businessLicense_id) {
set.businessLicense_id = msg.businessLicense_id;
}
await super.updateByWhere(set, {where:{id:noticeTo.id}}, t);
} else {
noticeTo = {
fromuser: msg.target,
fromId:msg.targetId,
touser: msg.sender,
toId:msg.senderId,
isAccepted:true,
lastMsgId:msg.id,
businessLicense_id : msg.businessLicense_id || 0
};
await super.create(noticeTo, t);
}
}
orderBy(){
//return {"key":"include","value":{model:this.db.models.app}};
return [["id","DESC"]];
}
}
module.exports=MsgNoticeDao;
const system = require("../../../system");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
/**
* 商机表
*/
module.exports = (db, DataTypes) => {
return db.define("bizopt", {
demand_code: { // 需求编码
allowNull: false,
type: DataTypes.STRING
},
business_type: { // 商机类型
allowNull: false,
type: DataTypes.STRING
},
business_status: { // 商机状态
allowNull: false,
type: DataTypes.STRING
},
business_info: { // 商机详情
allowNull: false,
type: DataTypes.JSON
},
source_number: { // 来源单号 (下单时产生的编号)
allowNull: true,
type: DataTypes.STRING
},
source_name: { //渠道来源
allowNull: true,
type: DataTypes.STRING
},
service_address: { // 区域地址
allowNull: false,
type: DataTypes.STRING
},
close_reason: { // 关闭理由
allowNull: true,
type: DataTypes.STRING
},
facilitator_id: { // 服务商id
allowNull: true,
type: DataTypes.STRING
},
facilitator_name: { // 服务商名称
allowNull: true,
type: DataTypes.STRING
},
salesman_opcode: { // 组织架构路径
allowNull: true,
type: DataTypes.STRING
},
salesman_id: {// 业务员id
allowNull: true,
type: DataTypes.STRING
},
salesman_name: { // 业务员姓名
allowNull: true,
type: DataTypes.STRING
},
salesman_phone: { // 业务员联系方式
allowNull: true,
type: DataTypes.STRING
}
}, {
paranoid: false,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'bussiness_opportunity',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
/**
* 交付信息缓存表
*/
module.exports = (db, DataTypes) => {
return db.define("cacheinfo", {
deliver_id: { // 交付单id
allowNull: false,
type: DataTypes.STRING
},
cache_info: { // 缓存信息
allowNull: false,
type: DataTypes.JSON
}
}, {
paranoid: false,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'cache_information',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
/**
* 交付单表
*/
module.exports = (db, DataTypes) => {
return db.define("deliverybill", {
delivery_code: { //交付单编号
allowNull: true,
type: DataTypes.STRING
},
source_number: { // 来源单号
allowNull: true,
type: DataTypes.STRING
},
source_name: { // 渠道名称
allowNull: true,
type: DataTypes.STRING
},
demand_code: {// 商机编号
allowNull: true,
type: DataTypes.STRING
},
sku_code: {// sku编码
allowNull: true,
type: DataTypes.STRING
},
scheme_number: {// 方案编号
allowNull: true,
type: DataTypes.STRING
},
product_code: { // 产品编码
allowNull: false,
type: DataTypes.STRING
},
product_name: { // 产品名称
allowNull: false,
type: DataTypes.STRING
},
service_address: { // 区域地址
allowNull: false,
type: DataTypes.STRING
},
delivery_info: { //服务概况
allowNull: false,
type: DataTypes.JSON
},
delivery_status: {// 服务单流转状态
allowNull: false,
type: DataTypes.STRING
},
master_source_number:{//主订单号
allowNull: false,
type: DataTypes.STRING
},
settle_status: {// 服务单流转状态
allowNull: false,
type: DataTypes.STRING,
defaultValue:'waittosettle'
},
selling_price: {//售价
allowNull: false,
type: DataTypes.INTEGER
},
cost_price: {//成本价
allowNull: true,
type: DataTypes.INTEGER
},
close_reason: {//关闭理由
allowNull: true,
type: DataTypes.STRING
},
facilitator_id: { // 服务商id
allowNull: true,
type: DataTypes.STRING
},
facilitator_name: { // 服务商名称
allowNull: true,
type: DataTypes.STRING
},
salesman_opcode: { // 组织架构路径
allowNull: true,
type: DataTypes.STRING
},
salesman_id: {// 业务员id
allowNull: true,
type: DataTypes.STRING
},
salesman_name: { // 业务员姓名
allowNull: true,
type: DataTypes.STRING
},
salesman_phone: { // 业务员联系方式
allowNull: true,
type: DataTypes.STRING
}
}, {
paranoid: false,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'delivery_bill',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const moment = require('moment');
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
/**
* 材料信息表
*/
module.exports = (db, DataTypes) => {
return db.define("material", {
delivery_id: { // 交付单id
allowNull: true,
type: DataTypes.INTEGER
},
delivery_code: { // 交付单编号
allowNull: true,
type: DataTypes.STRING
},
company_info: { // 企业信息
allowNull: true,
type: DataTypes.JSON
},
registered_info: { // 注册资本信息
allowNull: true,
type: DataTypes.JSON
},
contribution_info: { // 出资比例信息
allowNull: true,
type: DataTypes.JSON
},
position_info: { // 任职信息
allowNull: true,
type: DataTypes.JSON
},
file_info: { // 注册文件信息
allowNull: true,
type: DataTypes.JSON
},
express_info: { // 邮寄信息
allowNull: true,
type: DataTypes.JSON
},
is_download: { // 是否已有压缩文件的路径
allowNull: true,
type: DataTypes.INTEGER
},
download_url: { // 压缩文件的路径
allowNull: true,
type: DataTypes.STRING
},
}, {
paranoid: false,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'material_information',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
\ No newline at end of file
const system = require("../../../system");
const moment = require('moment');
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
/**
* 方案表
*/
module.exports = (db, DataTypes) => {
return db.define("scheme", {
demand_code: { // 需求编码
allowNull: false,
type: DataTypes.STRING
},
scheme_number: { //方案编号
allowNull: true,
type: DataTypes.STRING
},
scheme_info: {//方案详情
allowNull: false,
type: DataTypes.JSON
},
scheme_status: { //方案状态
allowNull: false,
type: DataTypes.STRING
},
reject_reason: {//驳回理由
allowNull: true,
type: DataTypes.STRING
},
remark_info: { //备注
allowNull: true,
type: DataTypes.STRING
},
bizopt_id: { //商机id
allowNull: true,
type: DataTypes.STRING
},
facilitator_id: { //服务商id
allowNull: true,
type: DataTypes.STRING
},
facilitator_name: { //服务商名称
allowNull: true,
type: DataTypes.STRING
},
salesman_opcode: { //组织架构路径
allowNull: true,
type: DataTypes.STRING
},
salesman_id: { //业务员id
allowNull: true,
type: DataTypes.STRING
},
salesman_name: { //业务员名称
allowNull: true,
type: DataTypes.STRING
},
salesman_phone: { //业务员联系方式
allowNull: true,
type: DataTypes.STRING
}
}, {
paranoid: false,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'scheme_information',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
/**
* 交付单表
*/
module.exports = (db, DataTypes) => {
return db.define("settlebill", {
code: { //交付单编号
allowNull: true,
type: DataTypes.STRING
},
auditedStatus: {// 审核状态
type:DataTypes.BOOLEAN,
defaultValue: false
},
settle_amount: {//结算金额
allowNull: true,
type: DataTypes.INTEGER
},
isPayedStatus:{
type:DataTypes.BOOLEAN,
defaultValue: false
},
memo:{//结算建议
allowNull: true,
type:DataTypes.STRING,
},
creator_id:{//申请人
allowNull: true,
type: DataTypes.INTEGER
},
creator:{
allowNull: true,
type: DataTypes.STRING,
},
auditor_id:{//审核人
allowNull: true,
type: DataTypes.INTEGER
},
auditor:{//审核人
allowNull: true,
type: DataTypes.STRING,
},
payer_id:{//付款人
allowNull: true,
type: DataTypes.INTEGER
},
payer:{
allowNull: true,
type: DataTypes.STRING,
},
facilitator_id:{
allowNull: true,
type: DataTypes.INTEGER,
},
facilitator_name:{
allowNull: true,
type: DataTypes.STRING,
},
}, {
paranoid: true,//真的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'fi_settlebill',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
/**
* 状态流转记录表
*/
module.exports = (db, DataTypes) => {
return db.define("statuslog", {
flow_type: { // 流程类型 (商机、方案、交付单)
allowNull: false,
type: DataTypes.STRING
},
flow_id: { // 流程对应id
allowNull: false,
type: DataTypes.STRING
},
status_reason: { // 状态原因
allowNull: true,
type: DataTypes.STRING
},
status_code: { // 流转状态
allowNull: false,
type: DataTypes.STRING
},
salesman_id: {// 业务员id
allowNull: true,
type: DataTypes.STRING
},
salesman_name: { // 业务员姓名
allowNull: true,
type: DataTypes.STRING
}
}, {
paranoid: false,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'status_log',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const settings = require("../../../../config/settings");
const appconfig=system.getSysConfig();
module.exports = (db, DataTypes) => {
return db.define("msghistory", {
msgType:{
type:DataTypes.ENUM,
allowNull: false,
values: Object.keys(appconfig.pdict.msgType),
},
app_id:DataTypes.INTEGER,
company_id:DataTypes.INTEGER,
sender:DataTypes.STRING,
senderId:DataTypes.INTEGER,
target:DataTypes.STRING,
targetId:DataTypes.INTEGER,
content: {
type: DataTypes.TEXT('long'),
allowNull: false,
},//需要在后台补充
isRead:{
type:DataTypes.BOOLEAN,
defaultValue: false,
}
},{
paranoid: false,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'msghistory',
validate: {
},
indexes:[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
module.exports = (db, DataTypes) => {
return db.define("msgnotice", {
fromuser: DataTypes.STRING,//需要在后台补充
fromId:DataTypes.INTEGER,
touser: DataTypes.STRING,//需要在后台补充
toId:DataTypes.INTEGER,
isAccepted:DataTypes.BOOLEAN,
lastMsgId:DataTypes.INTEGER
},{
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'msgnotice',
validate: {
},
indexes:[
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
class BizOptService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(BizOptService));
}
async statBizChanceCountBySp(bizStatus, betweenTime) {
let params = {}
params.group = {
byFields: ['facilitator_name'],
actionType: 'count',
aggField: 'id',
aliasField: ' as chanceCount',
tblName: 'bussiness_opportunity',
where: bizStatus != "" ? `where business_status='${bizStatus}'` : '',
having: '',
}
if (betweenTime.length > 0) {
params.group.where = `${params.group.where} ${params.group.where ? 'AND' : "WHERE"} (created_at BETWEEN '${betweenTime[0]}' AND '${betweenTime[1]}')`
}
let s = await this.dao.statGroupBy(params, null)
return s
}
/**
* 公司id,平台公司ID为1
* @param {*} companyId
* @param {*} opath
* @param {*} username
* @param {*} userid
*/
async statBizChance(companyId, opath, username, userid, betweenTime) {
// 时间 筛选
let andWhere = [];
if (betweenTime.length > 0) {
andWhere.push({
"created_at": { [this.db.Op.between]: betweenTime }
})
}
//如果当前登录人是平台,返回所有商机
let waittoHandledCount = 0
let handlingCount = 0
let finishedCount = 0
let closedCount = 0
if (companyId == 1) {
waittoHandledCount = await this.dao.findCount({ where: { business_status: 'beforeSubmission', [this.db.Op.and]: andWhere } })
handlingCount = await this.dao.findCount({ where: { business_status: 'beforeConfirmation', [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { business_status: 'isFinished', [this.db.Op.and]: andWhere } })
closedCount = await this.dao.findCount({ where: { business_status: 'isClosed', [this.db.Op.and]: andWhere } })
} else {
let opathstr = ''
if (opath) {
opathstr = opath
waittoHandledCount = await this.dao.findCount({ where: { business_status: 'beforeSubmission', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
handlingCount = await this.dao.findCount({ where: { business_status: 'beforeConfirmation', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { business_status: 'isFinished', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
closedCount = await this.dao.findCount({ where: { business_status: 'isClosed', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
} else {
waittoHandledCount = await this.dao.findCount({ where: { business_status: 'beforeSubmission', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
handlingCount = await this.dao.findCount({ where: { business_status: 'beforeConfirmation', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { business_status: 'isFinished', 'facilitator_id': companyId }, [this.db.Op.and]: andWhere })
closedCount = await this.dao.findCount({ where: { business_status: 'isClosed', 'facilitator_id': companyId }, [this.db.Op.and]: andWhere })
}
}
//成单率
let allChance = waittoHandledCount + handlingCount + finishedCount + closedCount
let successRadio = Math.ceil((finishedCount / allChance) * 100)
//如果当前登录人不是平台,那么需要按照opath查询
return { waittoHandledCount: waittoHandledCount, handlingCount: handlingCount, finishedCount: finishedCount, closedCount: closedCount, successRadio: successRadio }
}
async findAndCountAll(obj) {
var self = this;
const apps = await this.dao.findAndCountAll(obj);
return apps;
}
/*根据商机编号获取商机详情*/
async findInfoByDemandCode(qobj) {
return await this.dao.findInfoByDemandCode(qobj);
}
/* 根据商机编号更新商机状态 */
async updateStatusByDemandCode(qobj) {
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.updateStatusByDemandCode(qobj, t);
});
}
/*插入商机信息*/
async insertInfo(qobj) {
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.insertInfo(qobj, t);
});
}
}
module.exports = BizOptService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
class CacheInfoService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(CacheInfoService));
}
// async findAndCountAll(obj) {
// var self = this;
// const apps = await this.dao.findAndCountAll(obj);
// return apps;
// }
/*根据交付单id获取缓存详情*/
async findInfoByDeliverId(qobj){
return await this.dao.findInfoByDeliverId(qobj);
}
/* 根据交付单id更新缓存信息 */
async updateInfoByDeliverId(qobj){
var self=this;
return self.db.transaction(async function (t) {
return await self.dao.updateInfoByDeliverId(qobj,t);
});
}
/*插入缓存信息*/
async insertInfo(qobj){
var self=this;
return self.db.transaction(async function (t) {
return await self.dao.insertInfo(qobj,t);
});
}
}
module.exports = CacheInfoService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
class DeliverybillService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(DeliverybillService));
this.materialDao = system.getObject("db.bizchance.materialDao");
this.logDao = system.getObject("db.bizchance.statuslogDao");
this.cacheDao = system.getObject("db.bizchance.cacheinfoDao");
}
async statBizDeliverySettleAmountBySp(settleStatus) {
let params = {}
let where = settleStatus != "" ? `where settle_status='${settleStatus}'` : ''
params.group = {
byFields: ['facilitator_name'],
actionType: 'sum',
aggField: 'cost_price',
aliasField: ' as chanceCount',
tblName: 'delivery_bill',
where: where,
having: '',
}
let s = await this.dao.statGroupBy(params, null)
return s
}
async statBizDeliveryCountBySp(deliverStatus, betweenTime) {
let params = {}
let where = deliverStatus != "" ? `where delivery_status='${deliverStatus}'` : ''
if (deliverStatus == "handling") {
where = `where delivery_status not in ('received', 'success', 'closed')`
}
params.group = {
byFields: ['facilitator_name'],
actionType: 'count',
aggField: 'id',
aliasField: ' as chanceCount',
tblName: 'delivery_bill',
where: where,
having: '',
}
if (betweenTime.length > 0) {
params.group.where = `${params.group.where} ${params.group.where ? 'AND' : "WHERE"} (created_at BETWEEN '${betweenTime[0]}' AND '${betweenTime[1]}')`
}
let s = await this.dao.statGroupBy(params, null)
return s
}
async statBizDelivery(companyId, opath, username, userid, betweenTime) {
// 时间 筛选
let andWhere = [];
if (betweenTime.length > 0) {
andWhere.push({
"created_at": { [this.db.Op.between]: betweenTime }
})
}
//如果当前登录人是平台,返回所有商机
let waittoHandledCount = 0//received
let handlingCount = 0
let finishedCount = 0//success
let closedCount = 0//closed
let toSettle = 0
let toSettleAmount = 0
let settling = 0
let settlingAmount = 0
let settled = 0
let settledAmount = 0
if (companyId == 1) {
waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received', [this.db.Op.and]: andWhere } })
handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] }, [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', [this.db.Op.and]: andWhere } })
closedCount = await this.dao.findCount({ where: { delivery_status: 'closed', [this.db.Op.and]: andWhere } })
toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle', [this.db.Op.and]: andWhere } })
toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle', [this.db.Op.and]: andWhere } })
settling = await this.dao.findCount({ where: { settle_status: 'settling', [this.db.Op.and]: andWhere } })
settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling', [this.db.Op.and]: andWhere } })
settled = await this.dao.findCount({ where: { settle_status: 'settled', [this.db.Op.and]: andWhere } })
settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled', [this.db.Op.and]: andWhere } })
} else {
let opathstr = ''
if (opath) {
opathstr = opath
waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] }, salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
closedCount = await this.dao.findCount({ where: { delivery_status: 'closed', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settling = await this.dao.findCount({ where: { settle_status: 'settling', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settled = await this.dao.findCount({ where: { settle_status: 'settled', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled', salesman_opcode: { [this.db.Op.like]: `%${opathstr}%` }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
} else {
waittoHandledCount = await this.dao.findCount({ where: { delivery_status: 'received', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
handlingCount = await this.dao.findCount({ where: { delivery_status: { [this.db.Op.notIn]: ['received', 'success', 'closed'] }, 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
finishedCount = await this.dao.findCount({ where: { delivery_status: 'success', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
closedCount = await this.dao.findCount({ where: { delivery_status: 'closed', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
toSettle = await this.dao.findCount({ where: { settle_status: 'waittosettle', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
toSettleAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'waittosettle', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settling = await this.dao.findCount({ where: { settle_status: 'settling', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settlingAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settling', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settled = await this.dao.findCount({ where: { settle_status: 'settled', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
settledAmount = await this.dao.findSum('cost_price', { where: { settle_status: 'settled', 'facilitator_id': companyId, [this.db.Op.and]: andWhere } })
}
}
//成单率
let allHandled = finishedCount + closedCount
//如果当前登录人不是平台,那么需要按照opath查询
return {
waittoHandledCount: waittoHandledCount,
handlingCount: handlingCount,
finishedCount: finishedCount,
closedCount: closedCount,
allHandled: allHandled,
toSettle: toSettle,
toSettleAmount: toSettleAmount ? toSettleAmount : 0,
settling: settling,
settlingAmount: settlingAmount ? settlingAmount : 0,
settled: settled,
settledAmount: settledAmount ? settledAmount : 0
}
}
//为租户自己给交付打标记,表示中台已经给予结算,自己记账用
//租户自己临时记录结算情况
async settleApplyForTacent(ids, uid, uname, spname, spid) {
var self = this
return this.db.transaction(async function (t) {
//先按照ids查询出交付单的合计服务成本
let d = await self.dao.customQuery("select sum(cost_price) as settleAmount from delivery_bill where id in (:idstr)", { idstr: ids });
// let settleAmount=await self.dao.model.sum("cost_price",{where:{id:{[self.db.Op.In]:['40','41','42']}},transaction:t})
let settleAmount = d[0].settleAmount
settleAmount = isNaN(settleAmount) ? 0 : settleAmount
let settlecode = await self.getBusUid("JSD")
let settleObj = {
code: settlecode,
settle_amount: settleAmount,
creator_id: uid,
creator: uname,
facilitator_name: spname,
facilitator_id: spid,
isPayedStatus: false,
auditedStatus: true,
payer_id: uid,
payer: uname,
auditor_id: uid,
auditor: uname
}
//生成结算单,结算单状态直接更改为已经付款
let newentity = await self.db.models.settlebill.create(settleObj, { transaction: t })
//然后按照ids更新交付单的状态为结算中,更新结算单的id到交付单表
for (let idstr of ids) {
let up = await self.dao.updateByWhere({
settle_status: 'settling',
settlebill_id: newentity.id
}, { id: idstr }, t);
}
return newentity
});
}
async settleApply(ids, uid, uname, spname, spid) {
var self = this
return this.db.transaction(async function (t) {
//先按照ids查询出交付单的合计服务成本
let d = await self.dao.customQuery("select sum(cost_price) as settleAmount from delivery_bill where id in (:idstr)", { idstr: ids });
// let settleAmount=await self.dao.model.sum("cost_price",{where:{id:{[self.db.Op.In]:['40','41','42']}},transaction:t})
let settleAmount = d[0].settleAmount
settleAmount = isNaN(settleAmount) ? 0 : settleAmount
let settlecode = await self.getBusUid("JSD")
let settleObj = {
code: settlecode,
settle_amount: settleAmount,
creator_id: uid,
creator: uname,
facilitator_name: spname,
facilitator_id: spid
}
//生成结算单,结算单状态为待审核
let newentity = await self.db.models.settlebill.create(settleObj, { transaction: t })
//然后按照ids更新交付单的状态为结算中,更新结算单的id到交付单表
for (let idstr of ids) {
let up = await self.dao.updateByWhere({
settle_status: 'settling',
settlebill_id: newentity.id
}, { id: idstr }, t);
}
return newentity
});
}
async findAndCountAll(obj) {
var self = this;
const apps = await self.dao.findAndCountAll(obj);
return apps;
}
async findInfoByDeliverCode(qobj) {//*根据交付单编号获取交付单详情*/
return await this.dao.findInfoByDeliverCode(qobj);
}
async updateStatusByDeliverCode(qobj) {//* 根据交付单编号更新交付单状态 */
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.updateStatusByDeliverCode(qobj, t);
});
}
async updateInfoByDeliverCode(qobj) {//*更新交付单信息 */
console.log("--------------------------------------------------------------------------------------------------------------------------------------");
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.updateInfoByDeliverCode(qobj, t);
});
}
async insertInfo(qobj) {//*插入交付单信息*/从队列取数据的时候用
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.insertInfo(qobj, t);
});
}
async insertInfoall(pobj) {//*插入交付单信息,大事务*/从队列取数据的时候用
var self = this;
return await self.db.transaction(async function (t) {
var res = await self.dao.insertInfo(pobj);//插入交付单列表
pobj.deliverId = res.id;
//插入暂存
if (pobj.cacheInfo && (pobj.businessType == "companyCase" || pobj.businessType == "psCase")) {
await self.cacheDao.insertInfo(pobj);
}
var logInfo = {
"flowType": "DELIVERY",
"flowId": res.id,
"statusCode": res.delivery_status,
"statusReason": res.close_reason,
"clerkName": res.salesman_name,
"clerkId": res.salesman_id
}
await self.logDao.insertInfo(logInfo);//插入状态日至表
await self.materialDao.insertInfo(pobj);//插入材料信息
return system.getResultSuccess();
});
}
}
module.exports = DeliverybillService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
class MaterialService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(MaterialService));
}
// async findAndCountAll(obj) {
// var self = this;
// const apps = await this.dao.findAndCountAll(obj);
// return apps;
// }
/*根据交付单编号获取注册材料信息详情*/
async findInfoByDeliverNumber(qobj) {
return await this.dao.findInfoByDeliverNumber(qobj);
}
/* 根据交付单编号更新交付单编号信息 */
async updateInfoByDeliverNumber(qobj) {
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.updateInfoByDeliverNumber(qobj, t);
});
}
/* 根据id更新zip信息 */
async updateZipById(qobj) {
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.updateZipById(qobj, t);
});
}
/*获取没有压缩文件的信息*/
async findnoUrlInfo() {
var sql = "select id,file_info from material_information where is_download = 0 and file_info is not null";
var d = await this.dao.customQuery(sql);
if (d && d.length > 0) {
var rtndata = [];
d.forEach(item => {
if (item.file_info.uploadList && item.file_info.uploadList != 'undefined') {
rtndata.push({ "id": item.id, "uploadList": item.file_info.uploadList });
}
});
return rtndata;
}
else {
return [];
}
}
/*插入信息*/
async insertInfo(qobj) {
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.insertInfo(qobj, t);
});
}
}
module.exports = MaterialService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
class SchemeService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(SchemeService));
}
async findById(qobj){//根据id获取方案信息
var oid = qobj.id;
return await this.dao.findById(oid);
}
async findInfoByDemandCode(qobj){//根据方案编号获取方案详情
return await this.dao.findInfoByDemandCode(qobj);
}
async updateStatusByDemandCode(qobj){//根据商机编号号更新方案状态及原因
var self=this;
return self.db.transaction(async function (t) {
return await self.dao.updateStatusByDemandCode(qobj,t);
});
}
async updateInfoByDemandCode(qobj){//根据商机编号更新方案详情
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.updateInfoByDemandCode(qobj,t);
});
}
async updateSchemeNumberByDemandCode(qobj){//根据商机编号更新方案编号
var self = this;
return self.db.transaction(async function (t) {
return await self.dao.updateSchemeNumberByDemandCode(qobj,t);
});
}
async insertInfo(qobj){//插入方案信息
var self = this;
return await self.db.transaction(async function (t) {
return await self.dao.insertInfo(qobj,t);
});
}
}
module.exports = SchemeService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
class SettleBillService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(SettleBillService));
this.deliverbillDao=system.getObject("db.bizchance.deliverybillDao")
}
async advice(id,msg,userId,userName){
var self=this
return this.db.transaction(async function (t){
//先按照ids查询出交付单的合计服务成本
let st=await self.dao.findById(id,{transaction:t})
st.auditor_id=userId
st.auditor=userName
st.memo=msg
await st.save({transaction:t})
return st
});
}
async auditPass(settleId,userId,userName){
var self=this
return this.db.transaction(async function (t){
//先按照ids查询出交付单的合计服务成本
let st=await self.dao.findById(settleId,{transaction:t})
st.auditedStatus=true
st.auditor_id=userId
st.auditor=userName
await st.save({transaction:t})
return st
});
}
async pay(settleId,userId,userName){
var self=this
return this.db.transaction(async function (t){
//先按照ids查询出交付单的合计服务成本
let st=await self.dao.findById(settleId,{transaction:t})
st.isPayedStatus=true
st.payer_id=userId
st.payer=userName
await st.save({transaction:t})
//改变所有交付单的结算settle_status settled ,
await self.deliverbillDao.updateByWhere({settle_status:'settled'}, { settlebill_id: st.id }, t);
return st
});
}
async delete(p){
var self=this
return this.db.transaction(async function(t){
let dobj=await self.dao.delete(p,t)
//更新交付单上结算状态为waittosettle--待结算,清空settlebill_id
//waittosettle
await self.deliverbillDao.updateByWhere({settle_status:'waittosettle',settlebill_id:null}, { settlebill_id: dobj.id }, t);
return dobj
})
}
}
module.exports = SettleBillService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const appconfig = system.getSysConfig();
class StatusLogService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(StatusLogService));
}
/*插入状态信息*/
async insertInfo(qobj){
var self=this;
return self.db.transaction(async function (t) {
return await self.dao.insertInfo(qobj,t);
});
}
}
module.exports = StatusLogService;
\ No newline at end of file
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
class ArticleService extends ServiceBase{
constructor(){
super(ServiceBase.getDaoName(ArticleService));
this.newschannelDao=system.getObject("db.newschannelDao");
}
//获取频道列表
async findChannel(obj){
// const apps=await super.findAndCountAll(obj);
var usageType = obj.usageType;
if(usageType==null||usageType==""||usageType=="undefined"){
return {code:-101,msg:"参数有误",data:null};
}
try {
var sqlwhere = {
where: {usageType:usageType},
attributes: ["id", "code", "title", "bgimg", "isPubed", "usageType", "app_id"],
order: [["orderNo", 'ASC']],
raw: true
};
var list = await this.newschannelDao.model.findAll(sqlwhere);
if (list == null || list.length == 0) {
return {code:0,msg:"没有信息",data:null};
}else {
return {code:1,msg:"操作成功",data:list};
}
}catch (e) {
return {code:-1,msg:"操作失败",data:null};
}
}
//获取该频道所有列表
async findAndCountAll2(obj){
// const apps=await super.findAndCountAll(obj);
var newschannel = obj.newschannel_id;
var pageSize=obj.page_size;
var currentPage=obj.current_page;
if(newschannel==null||newschannel==""||newschannel=="undefined"){
return {code:-101,msg:"参数有误",data:null};
}
if(pageSize==null||pageSize==""||pageSize=="undefined"){
pageSize="";
}
if(currentPage==null||currentPage==""||currentPage=="undefined"){
currentPage="";
}
try {
var sqlwhere = {
where: {newschannel_id:newschannel},
attributes: ["id","code", "title", "listimg", "videourl", "desc", "mediaType", "usageType",
"test","newschannel_id", "app_id"],
order: [["orderNo", 'ASC']],
raw: true
};
if(pageSize!=""&&currentPage!=""){
var tPageSize=Number(pageSize);
var tCurrentPage=Number(currentPage);
if(tCurrentPage<1){
tCurrentPage=1;
}
if(tPageSize>50){
tPageSize=50;
}
if(tPageSize<1){
tPageSize=1;
}
sqlwhere.limit=tPageSize;
sqlwhere.offset= (tCurrentPage - 1) * tPageSize;
}
var list = await this.dao.model.findAll(sqlwhere);
if (list == null || list.length == 0) {
return {code:0,msg:"没有信息",data:null};
}else {
return {code:1,msg:"操作成功",data:list};
}
}catch (e) {
return {code:-1,msg:"操作失败",data:null};
}
// apps.forEach(a=>{
// if(a.content && a.content!=""){
// a.content=decodeURIComponent(a.content);
// }
// });
// console.log("xxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyxxxxxxxxxxxxxxxxx");
// for(var arch of apps.rows){
// var c=arch.content.toString("utf-8") ;
// console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// console.log(c);
// if(c && c!=""){
// arch.content=c;
// }
// }
// return apps;
}
//获取详细信息
async findArticle(obj){
// const apps=await super.findAndCountAll(obj);
var id = obj.id;
if(id==null||id==""||id=="undefined"){
return {code:-101,msg:"参数有误",data:null};
}
try {
var sqlwhere = {
where: {id:id},
attributes: ["id","code", "title", "listimg", "videourl", "desc", "content", "mediaType", "usageType",
"test", "app_id"],
order: [["created_at", 'desc']],
raw: true
};
var list = await this.dao.model.findOne(sqlwhere);
if (list == null || list.length == 0) {
return {code:0,msg:"没有信息",data:null};
}else {
return {code:1,msg:"操作成功",data:list};
}
}catch (e) {
return {code:-1,msg:"操作失败",data:null};
}
}
}
module.exports=ArticleService;
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
class NewschannelService extends ServiceBase{
constructor(){
super(ServiceBase.getDaoName(NewschannelService));
//this.appDao=system.getObject("db.appDao");
}
async findAgreenment(queryobj,qobj,req){
return this.dao.findAgreenment();
}
async findPrev5(queryobj,qobj){
return this.dao.findPrev5();
}
}
module.exports=NewschannelService;
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
class SloganpictureService extends ServiceBase{
constructor(){
super(ServiceBase.getDaoName(SloganpictureService));
//this.appDao=system.getObject("db.appDao");
}
async findAndCountAll(obj){
const apps=await super.findAndCountAll(obj);
// apps.forEach(a=>{
// if(a.content && a.content!=""){
// a.content=decodeURIComponent(a.content);
// }
// });
// console.log("xxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyxxxxxxxxxxxxxxxxx");
// for(var arch of apps.rows){
// var c=arch.content.toString("utf-8") ;
// console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// console.log(c);
// if(c && c!=""){
// arch.content=c;
// }
// }
return apps;
}
}
module.exports=SloganpictureService;
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
class MsgHistoryService extends ServiceBase{
constructor(){
super(ServiceBase.getDaoName(MsgHistoryService));
this.msgnoticeDao = system.getObject("db.msg.msgnoticeDao");
this.userDao = system.getObject("db.auth.userDao");
this.redisClient = system.getObject("util.redisClient");
}
async saveMsg(msg) {
var self = this;
console.log("save msg ", msg);
// 事务
await this.db.transaction(async function (t){
// 1.保存聊天信息
msg = await self.dao.create(msg, t);
// 2.保存好友信息
await self.msgnoticeDao.saveNotice(msg, t);
});
return msg;
}
async pushBusinessLicenseMsg(senderId, targetId, businessLicense_id) {
if(!businessLicense_id) {
return 0;
}
var notice = await this.msgnoticeDao.findOne({fromId : senderId, toId : targetId});
if(notice && notice.businessLicense_id == businessLicense_id) {
return 0;
}
var senderUser = await this.userDao.findById(senderId);
var targetUser = await this.userDao.findById(targetId);
var senderChannel = senderUser.app_id + "¥" + senderUser.id;
var targetChannel = targetUser.app_id + "¥" + targetUser.id;
var sender = senderUser.app_id + "¥" + senderUser.id + "¥" + senderUser.headUrl;
var target = targetUser.app_id + "¥" + targetUser.id + "¥" + targetUser.headUrl;
var msg = {
msgType: "mryzLicense",
sender:sender,
senderId:senderId,
target:target,
targetId:targetId,
content:businessLicense_id,
isRead:false,
businessLicense_id:businessLicense_id
}
var obj = await this.saveMsg(msg);
var bl = await this.businesslicenseDao.findById(businessLicense_id);
msg.businessLicense = bl;
msg.id = obj.id;
msg.created_at = obj.created_at;
this.redisClient.publish(senderChannel, JSON.stringify(msg));
this.redisClient.publish(targetChannel, JSON.stringify(msg));
return 1;
}
async getChatList(senderId, targetId, maxId, pageSize) {
let sql = "SELECT * FROM `msghistory` WHERE id < :maxId AND ((senderId = :senderId AND targetId = :targetId) OR (targetId = :senderId AND senderId = :targetId)) ORDER BY id DESC LIMIT :pageSize "
let params = {senderId:senderId, targetId: targetId, maxId: maxId, pageSize: pageSize};
var list = await this.dao.customQuery(sql, params);
if(!list || list.length == 0) {
return [];
}
var licenseIds = [];
var msgIds = [];
list.forEach(item => {
if(item.msgType == 'mryzLicense') {
licenseIds.push(Number(item.businessLicense_id));
}
msgIds.push(item.id);
});
if(licenseIds.length > 0) {
let licenseSql = "SELECT * FROM yz_business_license WHERE id IN (" + licenseIds.join(",") + ") ";
var licenseList = await this.businesslicenseDao.customQuery(licenseSql);
var licenseMap = [];
licenseList.forEach(item => {
licenseMap["id" + item.id] = item;
});
list.forEach(item => {
if(item.msgType == 'mryzLicense') {
item.businessLicense = licenseMap['id' + item.businessLicense_id];
}
});
}
var self = this;
setTimeout(function(){
self.setRead(senderId, targetId, list);
}, 1000);
return list;
}
async setRead(senderId, targetId, list) {
if(!list || list.length == 0) {
return;
}
var target = await this.userDao.findById(targetId);
if(!target) {
return;
}
var pushIds = [];
for(var item of list) {
if(item.isRead || senderId != item.targetId) {
continue;
}
pushIds.push(item.id);
}
if(pushIds.length == 0) {
return;
}
this.dao.updateByWhere({isRead: true}, {where:{id:{[this.db.Op.in]:pushIds}}});
var channel = target.app_id + "¥" + target.id;
var rs = await this.redisClient.publish(channel, JSON.stringify({type:"readmsg", data : pushIds}));
console.log(rs, "------------------------------------------ publish result ");
}
async readMsg(userId, id) {
var msg = await this.dao.findById(id);
if(!msg || userId != msg.targetId) {
return 0;
}
msg.isRead = true;
await msg.save();
var user = await this.userDao.findById(msg.senderId);
if(!user) {
return 0;
}
var channel = user.app_id + "¥" + user.id;
return await this.redisClient.publish(channel, JSON.stringify({type:"readmsg", data : [msg.id]}));
}
}
module.exports=MsgHistoryService;
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
class MsgNoticeService extends ServiceBase {
constructor() {
super(ServiceBase.getDaoName(MsgNoticeService));
this.userDao = system.getObject("db.auth.userDao");
this.msghistoryDao = system.getObject("db.msg.msghistoryDao");
}
getApp(appkey) {
return this.cacheManager["AppCache"].cacheApp(appkey);
}
async getUserList(userId) {
var list = await this.dao.model.findAll({
where: {
fromId: userId
},
order: [
["updated_at", "DESC"]
],
raw: true
});
if (!list || list.length == 0) {
return [];
}
var msgIds = [];
var businessLicenseIds = [];
var userIds = [];
for (var item of list) {
msgIds.push(item.lastMsgId);
businessLicenseIds.push(item.businessLicense_id);
userIds.push(item.toId);
}
var msgMap = [];
var businessLicenseMap = [];
var userMap = [];
var unreadMap = [];
// 最后一条聊天记录
if (msgIds.length > 0) {
var msgList = await this.msghistoryDao.customQuery("SELECT * FROM msghistory WHERE id IN (" + msgIds.join(",") + ") ");
msgList.forEach(item => {
msgMap["id" + item.id] = item;
});
}
// 最后一次聊天关联执照
if (businessLicenseIds.length > 0) {
var licenseList = await this.businesslicenseDao.customQuery("SELECT * FROM yz_business_license WHERE id IN (" + businessLicenseIds.join(",") + ") ");
var serviceTypeIds = [];
for (var item of licenseList) {
serviceTypeIds.push(item.serviceTypeOneId);
serviceTypeIds.push(item.serviceTypeTwoId);
}
if (serviceTypeIds.length > 0) {
var sql = "SELECT id, name FROM `p_service_type` WHERE id IN (" + serviceTypeIds.join(",") + ") ";
var typeList = await this.dao.customQuery(sql);
var typeMap = [];
if (typeList && typeList.length > 0) {
for (var t of typeList) {
typeMap["type_id_" + t.id] = t.name;
if (t.id == item.serviceTypeOneId) {
item.serviceTypeOneName = t.name;
} else if (t.id == item.serviceTypeTwoId) {
item.serviceTypeTwoName = t.name;
} else {}
}
}
}
for (var item of licenseList) {
item.serviceTypeOneName = typeMap["type_id_" + item.serviceTypeOneId];
item.serviceTypeTwoName = typeMap["type_id_" + item.serviceTypeTwoId];
}
licenseList.forEach(item => {
businessLicenseMap["id" + item.id] = item;
});
}
// 聊天好友用户信息
if (userIds.length > 0) {
var userList = await this.userDao.customQuery("SELECT * FROM p_user WHERE id IN (" + userIds.join(",") + ") ");
userList.forEach(item => {
userMap["id" + item.id] = item;
});
}
// 未读消息数量
var unreadList = await this.userDao.customQuery("SELECT senderId, COUNT(1) AS num FROM `msghistory` WHERE isRead = 0 AND targetId = " + userId + " GROUP BY senderId ");
unreadList.forEach(item => {
unreadMap["id" + item.senderId] = item.num;
});
var rs = [];
for (var i in list) {
var item = list[i];
item.lastMsg = msgMap["id" + item.lastMsgId];
item.businessLicense = businessLicenseMap["id" + item.businessLicense_id];
item.friend = userMap["id" + item.toId];
item.unreadCount = unreadMap["id" + item.toId] || 0;
rs.push(item);
}
return rs;
}
async countUnread(userId) {
debugger;
var unreadList = await this.userDao.customQuery("SELECT COUNT(1) AS num FROM `msghistory` WHERE isRead = 0 AND targetId = " + userId);
var count = 0;
if (unreadList && unreadList.length > 0) {
count = unreadList[0].num || 0;
}
return count;
}
}
module.exports = MsgNoticeService;
\ No newline at end of file
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