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');
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");
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 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