Commit ce4c87d3 by sxy

feat: 商机方方案功能

parent 820c29fd
var system = require("../../../system") var system = require("../../../system");
const http = require("http") const http = require("http");
const querystring = require('querystring'); const querystring = require('querystring');
var settings = require("../../../../config/settings"); var settings = require("../../../../config/settings");
const CtlBase = require("../../ctl.base"); const CtlBase = require("../../ctl.base");
const moment = require("moment");
class BizOptCtl extends CtlBase { class BizOptCtl extends CtlBase {
constructor() { constructor() {
super("bizchance", CtlBase.getServiceName(BizOptCtl)); super("bizchance", CtlBase.getServiceName(BizOptCtl));
} }
async findAndCountAll(pobj, qobj, req) {
//设置查询条件
const rs = await this.service.findAndCountAll(pobj);
if (rs.results && rs.results.rows) {
let result = [];
for (let val of rs.results.rows) {
val.company_name = val.business_info.company;
val.customer_number = val.business_info.phone;
val.customer_name = val.business_info.person;
val.updated_at = moment(val.updated_at).format('YYYY-MM-DD HH:mm:ss');
val.created_at = moment(val.created_at).format('YYYY-MM-DD HH:mm:ss');
result.push(val);
}
rs.results.rows = result;
}
return system.getResult(rs);
}
async findBizAndSheme(pobj, qobj, req) {
if (!pobj.id) {
return system.getResult(null, "id can not be empty,100290");
}
const rs = await this.service.findBizAndSheme({ id: pobj.id });
return system.getResult(rs);
}
async closeBiz(pobj, qobj, req) {
if (!pobj.bizId) {
return system.getResult(null, "bizId can not be empty,100290");
}
try {
await this.service.closeBiz({ bizId: pobj.bizId });
return system.getResultSuccess();
} catch (err) {
return system.getResult(null, err.message)
}
}
} }
module.exports = BizOptCtl; module.exports = BizOptCtl;
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 SchemeCtl extends CtlBase {
constructor() {
super("bizchance", CtlBase.getServiceName(SchemeCtl));
}
async create(pobj, qobj, req) {
if (!pobj.bizopt_id) {
return system.getResult(null, "bizopt_id can not be empty,100290");
}
try {
let data = await this.service.create(pobj);
return system.getResult(data);
} catch (err) {
return system.getResult(null, err.message)
}
}
async findOne(pobj, qobj, req) {
if (!pobj.bizopt_id) {
return system.getResult(null, "bizopt_id can not be empty,100290");
}
const rs = await this.service.findOne({ bizopt_id: pobj.bizopt_id });
return system.getResult(rs);
}
}
module.exports = SchemeCtl;
...@@ -15,8 +15,6 @@ class Dao { ...@@ -15,8 +15,6 @@ class Dao {
async create(u, t) { async create(u, t) {
var u2 = this.preCreate(u); var u2 = this.preCreate(u);
if (t) { if (t) {
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
console.log( this.model);
return this.model.create(u2, { transaction: t }).then(u => { return this.model.create(u2, { transaction: t }).then(u => {
return u; return u;
}); });
...@@ -30,7 +28,7 @@ class Dao { ...@@ -30,7 +28,7 @@ class Dao {
return ClassObj["name"].substring(0, ClassObj["name"].lastIndexOf("Dao")).toLowerCase() return ClassObj["name"].substring(0, ClassObj["name"].lastIndexOf("Dao")).toLowerCase()
} }
async refQuery(qobj) { async refQuery(qobj) {
var w =qobj.refwhere? qobj.refwhere:{}; var w = qobj.refwhere ? qobj.refwhere : {};
if (qobj.levelinfo) { if (qobj.levelinfo) {
w[qobj.levelinfo.levelfield] = qobj.levelinfo.level; w[qobj.levelinfo.levelfield] = qobj.levelinfo.level;
} }
...@@ -38,8 +36,8 @@ class Dao { ...@@ -38,8 +36,8 @@ class Dao {
w[qobj.parentinfo.parentfield] = qobj.parentinfo.parentcode; w[qobj.parentinfo.parentfield] = qobj.parentinfo.parentcode;
} }
//如果需要控制数据权限 //如果需要控制数据权限
if(qobj.datapriv){ if (qobj.datapriv) {
w["id"]={ [this.db.Op.in]: qobj.datapriv}; w["id"] = { [this.db.Op.in]: qobj.datapriv };
} }
if (qobj.likestr) { if (qobj.likestr) {
w[qobj.fields[0]] = { [this.db.Op.like]: "%" + qobj.likestr + "%" }; w[qobj.fields[0]] = { [this.db.Op.like]: "%" + qobj.likestr + "%" };
...@@ -64,13 +62,13 @@ class Dao { ...@@ -64,13 +62,13 @@ class Dao {
async delete(qobj, t) { async delete(qobj, t) {
var en = null var en = null
if (t != null && t != 'undefined') { if (t != null && t != 'undefined') {
en=await this.model.findOne({ where: {id:qobj.id},transaction:t}); en = await this.model.findOne({ where: { id: qobj.id }, transaction: t });
if (en != null) { if (en != null) {
await en.destroy({ transaction: t }); await en.destroy({ transaction: t });
return en return en
} }
} else { } else {
en=await this.model.findOne({ where: {id:qobj.id}}); en = await this.model.findOne({ where: { id: qobj.id } });
if (en != null) { if (en != null) {
return en.destroy(); return en.destroy();
} }
...@@ -202,16 +200,16 @@ class Dao { ...@@ -202,16 +200,16 @@ class Dao {
} }
async updateByWhere(setObj, whereObj, t) { async updateByWhere(setObj, whereObj, t) {
let inWhereObj={} let inWhereObj = {}
if (t && t != 'undefined') { if (t && t != 'undefined') {
if (whereObj && whereObj != 'undefined') { if (whereObj && whereObj != 'undefined') {
inWhereObj["where"]=whereObj; inWhereObj["where"] = whereObj;
inWhereObj["transaction"] = t; inWhereObj["transaction"] = t;
} else { } else {
inWhereObj["transaction"] = t; inWhereObj["transaction"] = t;
} }
}else{ } else {
inWhereObj["where"]=whereObj; inWhereObj["where"] = whereObj;
} }
return this.model.update(setObj, inWhereObj); return this.model.update(setObj, inWhereObj);
} }
...@@ -257,13 +255,13 @@ class Dao { ...@@ -257,13 +255,13 @@ class Dao {
if (includeObj != null && includeObj.length > 0) { if (includeObj != null && includeObj.length > 0) {
tmpWhere.include = includeObj; tmpWhere.include = includeObj;
tmpWhere.distinct = true; tmpWhere.distinct = true;
}else{ } else {
tmpWhere.raw = true; tmpWhere.raw = true;
} }
return await this.model.findAndCountAll(tmpWhere); return await this.model.findAndCountAll(tmpWhere);
} }
async findOne(obj) { async findOne(obj) {
return this.model.findOne({ "where": obj }); return this.model.findOne({ "where": obj, row: true });
} }
async findById(oid) { async findById(oid) {
return this.model.findById(oid); return this.model.findById(oid);
......
const system = require("../../../system");
const Dao = require("../../dao.base");
class BizoptDao extends Dao {
constructor() {
super(Dao.getModelName(BizoptDao));
}
extraWhere(qobj, qw, qc) {
qc.raw = true;
qc.where.business_type = qc.where.business_type || {
[this.db.Op.in]: [system.SERVICECODE.EDI, system.SERVICECODE.ICP]
}
return qw;
}
async findBizAndSheme(id) {
const result = await this.model.findOne({
where: {
id
},
include: [
{
model: this.db.models.scheme,
raw: false
}
],
raw: false
});
return result;
}
}
module.exports = BizoptDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class SchemeDao extends Dao {
constructor() {
super(Dao.getModelName(SchemeDao));
}
}
module.exports = SchemeDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class StatuslogDao extends Dao {
constructor() {
super(Dao.getModelName(StatuslogDao));
}
}
module.exports = StatuslogDao;
...@@ -22,10 +22,14 @@ module.exports = (db, DataTypes) => { ...@@ -22,10 +22,14 @@ module.exports = (db, DataTypes) => {
allowNull: false, allowNull: false,
type: DataTypes.JSON type: DataTypes.JSON
}, },
sourse_number: { // 来源单号 (下单时产生的编号) source_number: { // 来源单号 (下单时产生的编号)
allowNull: true, allowNull: true,
type: DataTypes.STRING type: DataTypes.STRING
}, },
source: { // 渠道来源
allowNull: false,
type: DataTypes.STRING
},
address: { // 区域地址 address: { // 区域地址
allowNull: false, allowNull: false,
type: DataTypes.STRING type: DataTypes.STRING
......
...@@ -10,7 +10,11 @@ module.exports = (db, DataTypes) => { ...@@ -10,7 +10,11 @@ module.exports = (db, DataTypes) => {
allowNull: false, allowNull: false,
type: DataTypes.STRING type: DataTypes.STRING
}, },
sourse_number: { // 来源单号 (订单编号) source_number: { // 来源单号 (订单编号)
allowNull: false,
type: DataTypes.STRING
},
source: { // 渠道来源
allowNull: false, allowNull: false,
type: DataTypes.STRING type: DataTypes.STRING
}, },
......
...@@ -28,7 +28,7 @@ module.exports = (db, DataTypes) => { ...@@ -28,7 +28,7 @@ module.exports = (db, DataTypes) => {
type: DataTypes.STRING type: DataTypes.STRING
}, },
remark: { //备注 remark: { //备注
allowNull: false, allowNull: true,
type: DataTypes.STRING type: DataTypes.STRING
} }
}, { }, {
......
...@@ -5,7 +5,7 @@ const appconfig = system.getSysConfig(); ...@@ -5,7 +5,7 @@ const appconfig = system.getSysConfig();
* 状态流转记录表 * 状态流转记录表
*/ */
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("status_log", { return db.define("statuslog", {
flow_type: { // 流程类型 (商机、方案、交付单) flow_type: { // 流程类型 (商机、方案、交付单)
allowNull: false, allowNull: false,
type: DataTypes.STRING type: DataTypes.STRING
......
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const moment = require("moment");
class BizoptService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(BizoptService));
this.schemeDao = system.getObject("db.bizchance.schemeDao");
this.statuslogDao = system.getObject("db.bizchance.statuslogDao");
}
async findBizAndSheme(pobj) {
let data = await this.dao.findBizAndSheme(pobj.id);
if (data) {
data = JSON.parse(JSON.stringify(data));
let bussinessData = {
id: data.id,
demand_code: data.demand_code,
business_type: data.business_type,
company_name: data.business_info.company,
customer_name: data.business_info.person,
customer_number: data.business_info.phone,
annual_report: data.business_info.annual_report || false,
content: data.business_info.content,
address: data.address,
source: data.source,
business_status: data.business_status,
source_number: data.source_number,
updated_at: moment(data.updated_at).format('YYYY-MM-DD HH:mm:ss'),
created_at: moment(data.created_at).format('YYYY-MM-DD HH:mm:ss'),
close_reason: data.close_reason
};
let schemeData = null;
if (data.scheme) {
schemeData = {
id: data.scheme.id,
scheme_number: data.scheme.scheme_number,
status: data.scheme.status,
address: data.address,
reject_reason: data.scheme.reject_reason || "无",
company_name: data.scheme.scheme_info.company,
address: data.scheme.scheme_info.address,
annual_report: data.scheme.scheme_info.annual_report || false,
remark: data.scheme.remark || "无",
updated_at: moment(data.scheme.updated_at).format('YYYY-MM-DD HH:mm:ss'),
created_at: moment(data.scheme.created_at).format('YYYY-MM-DD HH:mm:ss'),
}
}
return {
bussinessData,
schemeData
}
}
return data
}
async closeBiz(pobj) {
/**
* 1. 查询 是否有权限
* 2. 判断是否可以关闭
* 3. 更改 商机、方案状态
* 4. 插入更改记录
* 5. TODO:回传给腾讯
*/
const bizResult = await this.dao.findOne({
id: pobj.bizId
});
if (!bizResult) {
throw new Error("查不到该商机");
}
if ([system.BUSSTATUS.CLOSED, system.BUSSTATUS.SUCCESS].includes(bizResult.business_status)) {
throw new Error("此商机状态下不可操作");
}
const schemeResult = await this.schemeDao.findOne({
bizopt_id: pobj.bizId
});
return this.db.transaction(async (t) => {
await this.dao.updateByWhere({
business_status: system.BUSSTATUS.CLOSED
}, {
id: pobj.bizId
}, t);
this.statuslogDao.create({
flow_type: system.FLOWCODE.BIZ,
flow_id: pobj.bizId,
status: system.BUSSTATUS.CLOSED
});
if (schemeResult) {
await this.dao.updateByWhere({
status: system.SCHEMESTATUS.CLOSED
}, {
id: schemeResult.id
}, t);
this.statuslogDao.create({
flow_type: system.FLOWCODE.SCHEME,
flow_id: schemeResult.id,
status: system.SCHEMESTATUS.CLOSED
});
}
return "success"
})
}
}
module.exports = BizoptService;
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
const moment = require("moment");
class SchemeService extends ServiceBase {
constructor() {
super("bizchance", ServiceBase.getDaoName(SchemeService));
this.bizoptDao = system.getObject("db.bizchance.bizoptDao");
this.statuslogDao = system.getObject("db.bizchance.statuslogDao");
}
async create(data) {
// TODO: 权限判断
let bizData = await this.bizoptDao.findOne({
id: data.bizopt_id
});
if (!bizData) {
throw new Error("查不到该商机");
}
if ([system.BUSSTATUS.CLOSED, system.BUSSTATUS.SUCCESS, system.BUSSTATUS.WAITINGCONFIRM].includes(bizData.business_status)) {
throw new Error("此商机状态下不可操作");
}
let schemeData = await this.dao.findOne({
bizopt_id: data.bizopt_id
})
if (schemeData && [system.SCHEMESTATUS.WAITINGCONFIRM, system.SCHEMESTATUS.CLOSED].includes(schemeData.status)) {
throw new Error("此方案状态下不可操作");
}
if (!schemeData) {
// TODO: scheme_number 提交到腾讯获取 方案编号
data.scheme_number = "TX回传"
}
return this.db.transaction(async (t) => {
/**
* 1. 更改 商机状态
* 2. 查询 是否有方案及方案状态
* 3. 新增 或更改 方案
* 4. 添加 状态记录更改
* TODO:5. 传给腾讯状态
*/
try {
await this.bizoptDao.updateByWhere({
business_status: system.BUSSTATUS.WAITINGCONFIRM
}, {
id: data.bizopt_id
}, t);
this.statuslogDao.create({
flow_type: system.FLOWCODE.BIZ,
flow_id: data.bizopt_id,
status: system.BUSSTATUS.WAITINGCONFIRM
});
let scheme_id = null;
if (schemeData) {
await this.dao.updateByWhere({
...data,
demand_code: bizData.demand_code,
status: system.SCHEMESTATUS.WAITINGCONFIRM
}, {
id: schemeData.id
}, t);
scheme_id = schemeData.id
} else {
let schemeResult = await this.dao.create({
...data,
demand_code: bizData.demand_code,
status: system.SCHEMESTATUS.WAITINGCONFIRM,
bizopt_id: data.bizopt_id
}, t);
scheme_id = schemeResult.id;
}
this.statuslogDao.create({
flow_type: system.FLOWCODE.SCHEME,
flow_id: scheme_id,
status: system.SCHEMESTATUS.WAITINGCONFIRM
});
return { bizId: data.bizopt_id };
} catch (err) {
console.log(err)
}
});
}
}
module.exports = SchemeService;
const system=require("../../../system"); const system = require("../../../system");
const ServiceBase=require("../../sve.base"); const ServiceBase = require("../../sve.base");
class ArticleService extends ServiceBase{ class ArticleService extends ServiceBase {
constructor(){ constructor() {
super(ServiceBase.getDaoName(ArticleService)); super(ServiceBase.getDaoName(ArticleService));
this.newschannelDao=system.getObject("db.newschannelDao"); this.newschannelDao = system.getObject("db.newschannelDao");
} }
//获取频道列表 //获取频道列表
async findChannel(obj){ async findChannel(obj) {
// const apps=await super.findAndCountAll(obj); // const apps=await super.findAndCountAll(obj);
var usageType = obj.usageType; var usageType = obj.usageType;
if(usageType==null||usageType==""||usageType=="undefined"){ if (usageType == null || usageType == "" || usageType == "undefined") {
return {code:-101,msg:"参数有误",data:null}; return { code: -101, msg: "参数有误", data: null };
} }
try { try {
var sqlwhere = { var sqlwhere = {
where: {usageType:usageType}, where: { usageType: usageType },
attributes: ["id", "code", "title", "bgimg", "isPubed", "usageType", "app_id"], attributes: ["id", "code", "title", "bgimg", "isPubed", "usageType", "app_id"],
order: [["orderNo", 'ASC']], order: [["orderNo", 'ASC']],
raw: true raw: true
}; };
var list = await this.newschannelDao.model.findAll(sqlwhere); var list = await this.newschannelDao.model.findAll(sqlwhere);
if (list == null || list.length == 0) { if (list == null || list.length == 0) {
return {code:0,msg:"没有信息",data:null}; return { code: 0, msg: "没有信息", data: null };
}else { } else {
return {code:1,msg:"操作成功",data:list}; return { code: 1, msg: "操作成功", data: list };
} }
}catch (e) { } catch (e) {
return {code:-1,msg:"操作失败",data:null}; return { code: -1, msg: "操作失败", data: null };
} }
} }
//获取该频道所有列表 //获取该频道所有列表
async findAndCountAll2(obj){ async findAndCountAll2(obj) {
// const apps=await super.findAndCountAll(obj); // const apps=await super.findAndCountAll(obj);
var newschannel = obj.newschannel_id; var newschannel = obj.newschannel_id;
var pageSize=obj.page_size; var pageSize = obj.page_size;
var currentPage=obj.current_page; var currentPage = obj.current_page;
if(newschannel==null||newschannel==""||newschannel=="undefined"){ if (newschannel == null || newschannel == "" || newschannel == "undefined") {
return {code:-101,msg:"参数有误",data:null}; return { code: -101, msg: "参数有误", data: null };
} }
if(pageSize==null||pageSize==""||pageSize=="undefined"){ if (pageSize == null || pageSize == "" || pageSize == "undefined") {
pageSize=""; pageSize = "";
} }
if(currentPage==null||currentPage==""||currentPage=="undefined"){ if (currentPage == null || currentPage == "" || currentPage == "undefined") {
currentPage=""; currentPage = "";
} }
try { try {
var sqlwhere = { var sqlwhere = {
where: {newschannel_id:newschannel}, where: { newschannel_id: newschannel },
attributes: ["id","code", "title", "listimg", "videourl", "desc", "mediaType", "usageType", attributes: ["id", "code", "title", "listimg", "videourl", "desc", "mediaType", "usageType",
"test","newschannel_id", "app_id"], "test", "newschannel_id", "app_id"],
order: [["orderNo", 'ASC']], order: [["orderNo", 'ASC']],
raw: true raw: true
}; };
if(pageSize!=""&&currentPage!=""){ if (pageSize != "" && currentPage != "") {
var tPageSize=Number(pageSize); var tPageSize = Number(pageSize);
var tCurrentPage=Number(currentPage); var tCurrentPage = Number(currentPage);
if(tCurrentPage<1){ if (tCurrentPage < 1) {
tCurrentPage=1; tCurrentPage = 1;
} }
if(tPageSize>50){ if (tPageSize > 50) {
tPageSize=50; tPageSize = 50;
} }
if(tPageSize<1){ if (tPageSize < 1) {
tPageSize=1; tPageSize = 1;
} }
sqlwhere.limit=tPageSize; sqlwhere.limit = tPageSize;
sqlwhere.offset= (tCurrentPage - 1) * tPageSize; sqlwhere.offset = (tCurrentPage - 1) * tPageSize;
} }
var list = await this.dao.model.findAll(sqlwhere); var list = await this.dao.model.findAll(sqlwhere);
if (list == null || list.length == 0) { if (list == null || list.length == 0) {
return {code:0,msg:"没有信息",data:null}; return { code: 0, msg: "没有信息", data: null };
}else { } else {
return {code:1,msg:"操作成功",data:list}; return { code: 1, msg: "操作成功", data: list };
} }
}catch (e) { } catch (e) {
return {code:-1,msg:"操作失败",data:null}; return { code: -1, msg: "操作失败", data: null };
} }
// apps.forEach(a=>{ // apps.forEach(a=>{
// if(a.content && a.content!=""){ // if(a.content && a.content!=""){
...@@ -96,30 +96,30 @@ class ArticleService extends ServiceBase{ ...@@ -96,30 +96,30 @@ class ArticleService extends ServiceBase{
} }
//获取详细信息 //获取详细信息
async findArticle(obj){ async findArticle(obj) {
// const apps=await super.findAndCountAll(obj); // const apps=await super.findAndCountAll(obj);
var id = obj.id; var id = obj.id;
if(id==null||id==""||id=="undefined"){ if (id == null || id == "" || id == "undefined") {
return {code:-101,msg:"参数有误",data:null}; return { code: -101, msg: "参数有误", data: null };
} }
try { try {
var sqlwhere = { var sqlwhere = {
where: {id:id}, where: { id: id },
attributes: ["id","code", "title", "listimg", "videourl", "desc", "content", "mediaType", "usageType", attributes: ["id", "code", "title", "listimg", "videourl", "desc", "content", "mediaType", "usageType",
"test", "app_id"], "test", "app_id"],
order: [["created_at", 'desc']], order: [["created_at", 'desc']],
raw: true raw: true
}; };
var list = await this.dao.model.findOne(sqlwhere); var list = await this.dao.model.findOne(sqlwhere);
if (list == null || list.length == 0) { if (list == null || list.length == 0) {
return {code:0,msg:"没有信息",data:null}; return { code: 0, msg: "没有信息", data: null };
}else { } else {
return {code:1,msg:"操作成功",data:list}; return { code: 1, msg: "操作成功", data: list };
} }
}catch (e) { } catch (e) {
return {code:-1,msg:"操作失败",data:null}; return { code: -1, msg: "操作失败", data: null };
} }
} }
} }
module.exports=ArticleService; module.exports = ArticleService;
...@@ -275,6 +275,42 @@ Date.prototype.Format = function (fmt) { //author: meizz ...@@ -275,6 +275,42 @@ Date.prototype.Format = function (fmt) { //author: meizz
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt; return fmt;
} }
/**
* 常用 ENUM
*/
// 表分类
System.FLOWCODE = {
"BIZ": "BIZ",//商机表
"SCHEME": "SCHEME",//方案表
"DELIVERY": "DELIVERY"//服务单表
}
// 服务名称
System.SERVICECODE = {
ICP: "ICP",
EDI: 'EDI'
}
// 商机状态
System.BUSSTATUS = {
WAITINGSCHEME: "beforeSubmission",//待业务员响应
WAITINGCONFIRM: "beforeConfirmation",//待用户确认
SUCCESS: "isFinished",//已确认
CLOSED: "isClosed"//需求关闭
}
// 方案状态
System.SCHEMESTATUS = {
WAITINGCONFIRM: "beforeConfirmation",//待用户确认.
CLOSED: "isClosed",//方案关闭
REJECT: "isReject"//方案被拒绝
}
// 服务单状态
System.SERVERSESTATUS = {
}
/* /*
编码说明, 编码说明,
1000----1999 为请求参数验证和app权限验证 1000----1999 为请求参数验证和app权限验证
......
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