Commit 15abb784 by 孙亚楠

d

parent 2e679cf1
...@@ -55,7 +55,7 @@ class ActionAPI extends APIBase { ...@@ -55,7 +55,7 @@ class ActionAPI extends APIBase {
case "saveCfollowLog": //保存跟进进度 case "saveCfollowLog": //保存跟进进度
opResult = await this.cfollowlogSve.saveCfollowLog(action_body); opResult = await this.cfollowlogSve.saveCfollowLog(action_body);
break; break;
case "saveCscheme": //保存跟进进度 case "saveCscheme": //保存方案
opResult = await this.cschemeSve.saveCscheme(action_body); opResult = await this.cschemeSve.saveCscheme(action_body);
break; break;
default: default:
......
...@@ -11,11 +11,15 @@ class CclueDao extends Dao { ...@@ -11,11 +11,15 @@ class CclueDao extends Dao {
* @param params * @param params
* @returns {Promise<*>} * @returns {Promise<*>}
*/ */
async ordersCount(params){ async countClue(params){
let sql = []; let sql = [];
sql.push('SELECT COUNT(1) AS count FROM c_clue WHERE 1 = 1 '); sql.push('SELECT COUNT(1) AS count FROM c_clue WHERE 1 = 1 ');
this.setClueCount(sql,params); this.setClueCount(sql,params);
return await this.customQuery(sql.join(" "), params); let res = await this.customQuery(sql.join(" "), params);
if(!res || res.length==0){
return {count:0};
}
return res[0];
} }
setClueCount(sql,params){ setClueCount(sql,params){
...@@ -54,11 +58,11 @@ class CclueDao extends Dao { ...@@ -54,11 +58,11 @@ class CclueDao extends Dao {
var sql = []; var sql = [];
sql.push("SELECT * FROM `c_clue` WHERE 1 = 1"); sql.push("SELECT * FROM `c_clue` WHERE 1 = 1");
this.setClueCount(sql,params); this.setClueCount(sql,params);
sql.push("ORDER BY t1.created_at DESC"); sql.push("ORDER BY created_at DESC");
sql.push("LIMIT :startRow, :pageSize"); sql.push("LIMIT :startRow, :pageSize");
let list = await this.customQuery(sql.join(" "), params); let list = await this.customQuery(sql.join(" "), params);
if(!list || list.length==0){ if(!list || list.length==0){
return {count:0}; return [];
} }
return list; return list;
} }
...@@ -72,7 +76,11 @@ class CclueDao extends Dao { ...@@ -72,7 +76,11 @@ class CclueDao extends Dao {
var sql = []; var sql = [];
sql.push("SELECT * FROM `c_clue` WHERE 1 = 1"); sql.push("SELECT * FROM `c_clue` WHERE 1 = 1");
this.setClueCount(sql,params); this.setClueCount(sql,params);
return await this.customQuery(sql.join(" "), params) || {}; let list= await this.customQuery(sql.join(" "), params);
if(list && list.length==0){
return null;
}
return list[0];
} }
} }
......
...@@ -9,7 +9,7 @@ class CfollowlogDao extends Dao { ...@@ -9,7 +9,7 @@ class CfollowlogDao extends Dao {
/** /**
* fn:根据线索ID查询记录 * fn:根据线索ID查询记录
* @param params * @param params
* @returns {Promise<void>} * @returns {Promise<void>} HashMap
*/ */
async followlogsByClueIds(params){ async followlogsByClueIds(params){
var sql = []; var sql = [];
...@@ -27,6 +27,19 @@ class CfollowlogDao extends Dao { ...@@ -27,6 +27,19 @@ class CfollowlogDao extends Dao {
return map; return map;
} }
/**
* fn:根据线索ID查询记录
* @param params
* @returns {Promise<void>} ArrayList
*/
async listFollowlogsByClueIds(params){
var sql = [];
sql.push("SELECT * FROM `c_follow_log` WHERE 1=1");
this.setcfollowlogCount(sql,params);
sql.push("ORDER BY created_at DESC");
return await this.customQuery(sql.join(" "), params);
}
setcfollowlogCount(sql,params){ setcfollowlogCount(sql,params){
if(params.clueIds && params.clueIds.length>0){ if(params.clueIds && params.clueIds.length>0){
sql.push(`and clue_id in (:clueIds)`); sql.push(`and clue_id in (:clueIds)`);
......
...@@ -3,9 +3,9 @@ const settings = require("../../../../config/settings"); ...@@ -3,9 +3,9 @@ const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey); const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("cclue", { return db.define("cclue", {
product_id: DataTypes.STRING, comment:'线索类型ID(商品ID)', clue_type_id: DataTypes.STRING, comment:'线索类型ID(商品ID)',
deliver_id: DataTypes.STRING ,defaultValue:'', comment:'交付商ID', deliver_id: DataTypes.STRING ,defaultValue:'', comment:'交付商ID',
product_name: DataTypes.STRING, comment:'线索类型名称(商品名称)', clue_type_name: DataTypes.STRING, comment:'线索类型名称(商品名称)',
contact_mobile: DataTypes.STRING, comment:'联系电话', contact_mobile: DataTypes.STRING, comment:'联系电话',
contacts: DataTypes.STRING ,comment:'联系人', contacts: DataTypes.STRING ,comment:'联系人',
status: DataTypes.STRING(3) ,defaultValue:'10', comment:'线索状态 10 待跟进 20 跟进中 30 已完成 40 已关闭', status: DataTypes.STRING(3) ,defaultValue:'10', comment:'线索状态 10 待跟进 20 跟进中 30 已完成 40 已关闭',
......
...@@ -4,7 +4,7 @@ const uiconfig = system.getUiConfig2(settings.appKey); ...@@ -4,7 +4,7 @@ const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("cscheme", { return db.define("cscheme", {
deliver_id: DataTypes.STRING ,defaultValue:'', comment:'交付商ID', deliver_id: DataTypes.STRING ,defaultValue:'', comment:'交付商ID',
product_type: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '商品类型' }, clue_type_name: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '商品类型' },
name: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '个体户名称' }, name: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '个体户名称' },
business_place: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '注册场所' }, business_place: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '注册场所' },
legal_name: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '经营者' }, legal_name: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '经营者' },
......
const system = require("../../../system"); const system = require("../../../system");
const ServiceBase = require("../../sve.base") const ServiceBase = require("../../sve.base")
const moment = require("moment");
/** /**
* 订单产品表 * 订单产品表
*/ */
class CclueService extends ServiceBase { class CclueService extends ServiceBase {
constructor() { constructor() {
super("order", ServiceBase.getDaoName(CclueService)); super("chance", ServiceBase.getDaoName(CclueService));
this.cschemeDao = system.getObject("db.chance.cschemeDao"); this.cschemeDao = system.getObject("db.chance.cschemeDao");
this.cfollowlogDao = system.getObject("db.chance.cfollowlogDao"); this.cfollowlogDao = system.getObject("db.chance.cfollowlogDao");
} }
...@@ -17,37 +16,37 @@ class CclueService extends ServiceBase { ...@@ -17,37 +16,37 @@ class CclueService extends ServiceBase {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async saveClue(params){ async saveClue(params){
if(!params.product_id){ if(!params.clue_type_id){
return system.getResult(null, `参数错误 产品ID不能为空`); return system.getResult(null, `参数错误 产品ID不能为空`);
} }
if(!params.product_name){ if(!params.clue_type_name){
return system.getResult(null, `参数错误 产品名称不能为空`); return system.getResult(null, `参数错误 产品名称不能为空`);
} }
if(!params.deliver_id){ if(!params.deliver_id){
return system.getResult(null, `参数错误 交付商ID不能为空`); return system.getResult(null, `参数错误 交付商ID不能为空`);
} }
let clue_properties = { let clue_properties = {
product_id : this.trim(params.product_id), clue_type_id : this.trim(params.clue_type_id),
product_name : this.trim(params.product_name), clue_type_name : this.trim(params.clue_type_name),
contacts : this.trim(params.contacts), contacts : this.trim(params.contacts),
contact_mobile : this.trim(params.contact_mobile), contact_mobile:this.trim(params.contact_mobile),
operator_id : this.trim(params.operator_id), operator_id:this.trim(params.operator_id),
operator_path : this.trim(params.operator_path), operator_path : this.trim(params.operator_path),
callback_url : this.trim(params.callback_url), callback_url : this.trim(params.callback_url),
status:"10", status:"10",
deliver_id: this.trim(params.deliver_id) deliver_id:this.trim(params.deliver_id)
}; };
try{ try{
let res = await this.db.transaction(async t =>{ await this.db.transaction(async t =>{
let cclueBean =await this.dao.create(clue_properties, t); let cclueBean =await this.dao.create(clue_properties, t);
let scheme_properties = { let scheme_properties = {
id:cclueBean.id, id:cclueBean.id,
product_name:clue_properties.product_name, clue_type_name:clue_properties.clue_type_name,
deliver_id:clue_properties.deliver_id, deliver_id:clue_properties.deliver_id,
}; };
await this.cschemeDao.create(scheme_properties,t); await this.cschemeDao.create(scheme_properties,t);
}); });
return system.getResult(res); return system.getResultSuccess();
}catch (e) { }catch (e) {
console.log(e); console.log(e);
return system.getResult(null, `系统错误`); return system.getResult(null, `系统错误`);
...@@ -63,24 +62,40 @@ class CclueService extends ServiceBase { ...@@ -63,24 +62,40 @@ class CclueService extends ServiceBase {
if(!params.id){ if(!params.id){
return system.getResult(null, `参数错误 ID不能为空`); return system.getResult(null, `参数错误 ID不能为空`);
} }
if(!params.deliver_id){
return system.getResult(null, `参数错误 交付商ID不能为空`);
}
if(!params.close_reason){ if(!params.close_reason){
return system.getResult(null, `参数错误 关闭原因不能为空`); return system.getResult(null, `参数错误 关闭原因不能为空`);
} }
if(params.close_reason=="50" && !params.close_remarks){ if(params.close_reason=="50" && !params.close_remarks){
return system.getResult(null, `参数错误 关闭原因不能为空`); return system.getResult(null, `参数错误 关闭原因不能为空`);
} }
let _cclue = await this.dao.getById(this.trim(params.id)); let _cclue = await this.dao.model.findOne({
where:{
id: this.trim(params.id),
deliver_id: this.trim(params.deliver_id)
},
attributes:['id','status','callback_url']
});
if(!_cclue){ if(!_cclue){
return system.getResult(null, `线索不存在`); return system.getResult(null, `线索不存在`);
} }
if(_cclue.status=='30'){
return system.getResult(null, `线索已完成`);
}
if(_cclue.status=='40'){
return system.getResult(null, `线索已关闭`);
}
let upd = { let upd = {
id: this.trim(params.id), id: this.trim(params.id),
close_reason: this.trim(params.close_reason), close_reason: this.trim(params.close_reason),
close_remarks: this.trim(params.close_remarks) || "" close_remarks: this.trim(params.close_remarks) || "",
status:"40"
}; };
try{ try{
let res = await this.update(upd); let res = await this.update(upd);
return system.getResult(res); return system.getResult({id:_cclue.id,callback_url:_cclue.callback_url});
}catch (e) { }catch (e) {
console.log(e); console.log(e);
system.getResult(null, `系统错误`); system.getResult(null, `系统错误`);
...@@ -93,8 +108,8 @@ class CclueService extends ServiceBase { ...@@ -93,8 +108,8 @@ class CclueService extends ServiceBase {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async listClue(params){ async listClue(params){
if(!params.product_id){ if(!params.deliver_id){
return system.getResult(null, `参数错误 产品ID不能为空`); return system.getResult(null, `参数错误 交付商不存在`);
} }
params.currentPage = Number(params.currentPage || 1); params.currentPage = Number(params.currentPage || 1);
params.pageSize = Number(params.pageSize || 10); params.pageSize = Number(params.pageSize || 10);
...@@ -124,9 +139,9 @@ class CclueService extends ServiceBase { ...@@ -124,9 +139,9 @@ class CclueService extends ServiceBase {
} }
await this.formatCscheme(list, clueIds); await this.formatCscheme(list, clueIds);
await this.formatCfollowLog(list, clueIds); await this.formatCfollowLog(list, clueIds);
return system.getResult(list); return system.getResult({count:countRes.count,rows:list});
}catch (e) { }catch (e) {
cosnole.log(e); console.log(e);
return system.getResult(null, `系统错误`); return system.getResult(null, `系统错误`);
} }
} }
...@@ -140,11 +155,15 @@ class CclueService extends ServiceBase { ...@@ -140,11 +155,15 @@ class CclueService extends ServiceBase {
if(!list || list.length<=0){ if(!list || list.length<=0){
return ; return ;
} }
let cschemeMap={}; let cschemeMap={},cschemeArrayList=[];
if(clueIds && clueIds.length>0){ if(clueIds && clueIds.length>0){
cschemeMap = await this.cfollowlogDao.followlogsByClueIds({clueIds:clueIds}); cschemeArrayList = await this.cfollowlogDao.listFollowlogsByClueIds({clueIds:clueIds});
for (let key in cschemeMap) { for (let item of cschemeArrayList) {
this.handleDate(cschemeMap[key], ["created_at"], null, null); this.handleDate(item, ["created_at"], null, null);
if(!cschemeMap[item.clue_id]){
cschemeMap[item.clue_id]=[];
}
cschemeMap[item.clue_id].push(item);
} }
} }
for (let ele of list) { for (let ele of list) {
...@@ -172,7 +191,11 @@ class CclueService extends ServiceBase { ...@@ -172,7 +191,11 @@ class CclueService extends ServiceBase {
} }
for (let ele of list) { for (let ele of list) {
ele.cscheme = map[ele.id]; ele.cscheme = map[ele.id];
ele.cschemeIsShow =cscheme.name?true:false; if(ele.cscheme.name && ele.status=='40'){
ele.cschemeIsShow =false;
}else{
ele.cschemeIsShow=true;
}
} }
} }
...@@ -213,12 +236,14 @@ class CclueService extends ServiceBase { ...@@ -213,12 +236,14 @@ class CclueService extends ServiceBase {
if(!params.id){ if(!params.id){
return system.getResult(null, `参数错误 ID不能为空`); return system.getResult(null, `参数错误 ID不能为空`);
} }
let where={ if(!params.deliver_id){
deliver_id:this.trim(params.deliver_id), return system.getResult(null, `参数错误 交付商ID不能为空`);
id:this.trim(params.id) }
};
try{ try{
let cclueBean = await this.dao.getCclueInfo(where); let cclueBean = await this.dao.getCclueInfo({
deliver_id:this.trim(params.deliver_id),
id:this.trim(params.id)
});
if(!cclueBean){ if(!cclueBean){
return system.getResult(null, `线索不存在`); return system.getResult(null, `线索不存在`);
} }
...@@ -226,22 +251,24 @@ class CclueService extends ServiceBase { ...@@ -226,22 +251,24 @@ class CclueService extends ServiceBase {
//查询方案 //查询方案
let cschemeBean = await this.cschemeDao.getById(cclueBean.id) || {}; let cschemeBean = await this.cschemeDao.getById(cclueBean.id) || {};
this.handleDate(cschemeBean, ["created_at"], null, null); this.handleDate(cschemeBean, ["created_at"], null, null);
cschemeBean.cschemeIsShow=cschemeBean.name?true:false; cclueBean.cschemeBean = cschemeBean;
cclueBean.cschemeIsShow=cschemeBean.name?true:false;
//查询跟踪记录 //查询跟踪记录
let cfollowlog = await this.cfollowlogDao.followlogsByClueIds({clue_id:cschemeBean.id}); let cfollowlog = await this.cfollowlogDao.followlogsByClueIds({clue_id:cschemeBean.id});
for(let item of cfollowlog){ for(let item in cfollowlog){
this.handleDate(item, ["created_at"], null, null); for (let key in cschemeMap) {
this.handleDate(cschemeMap[key], ["created_at"], null, null);
}
} }
cclueBean.cfollowlog=cfollowlog; cclueBean.cfollowlog=cfollowlog[cclueBean.id]||[];
cschemeBean.cfollowlogIsShow =cfollowlog.length>0?true:false; cclueBean.cfollowlogIsShow =cclueBean.cfollowlog.length>0?true:false;
return system.getResult(cclueBean); return system.getResult(cclueBean);
}catch (e) { }catch (e) {
console.log(e); console.log(e);
return system.getResult(null, `系统错误`); return system.getResult(null, `系统错误`);
} }
} }
} }
module.exports = CclueService; module.exports = CclueService;
\ No newline at end of file
...@@ -5,7 +5,7 @@ const ServiceBase = require("../../sve.base") ...@@ -5,7 +5,7 @@ const ServiceBase = require("../../sve.base")
*/ */
class CfollowlogService extends ServiceBase { class CfollowlogService extends ServiceBase {
constructor() { constructor() {
super("order", ServiceBase.getDaoName(CfollowlogService)); super("chance", ServiceBase.getDaoName(CfollowlogService));
this.cclueDao = system.getObject("db.chance.cclueDao"); this.cclueDao = system.getObject("db.chance.cclueDao");
} }
...@@ -31,6 +31,9 @@ class CfollowlogService extends ServiceBase { ...@@ -31,6 +31,9 @@ class CfollowlogService extends ServiceBase {
if(!cclueBean){ if(!cclueBean){
return system.getResult(null,`线索不存在`); return system.getResult(null,`线索不存在`);
} }
if(cclueBean.status=="40"){
return system.getResult(null, `线索已关闭`);
}
try{ try{
let cfollowlogProperties = { let cfollowlogProperties = {
clue_id: this.trim(params.clue_id), clue_id: this.trim(params.clue_id),
...@@ -38,8 +41,15 @@ class CfollowlogService extends ServiceBase { ...@@ -38,8 +41,15 @@ class CfollowlogService extends ServiceBase {
record: this.trim(params.record), record: this.trim(params.record),
operator: this.trim(params.operator) operator: this.trim(params.operator)
}; };
let res = await this.dao.create(cfollowlogProperties); await this.db.transaction(async t=>{
return system.getResult(res); await this.dao.create(cfollowlogProperties, t);
let cclueProperties = {
id: this.trim(params.clue_id),
status: "20"
};
await this.cclueDao.update(cclueProperties, t);
})
return system.getResultSuccess();
}catch (e) { }catch (e) {
console.log(e); console.log(e);
return system.getResult(null, `系统错误`); return system.getResult(null, `系统错误`);
......
...@@ -2,8 +2,9 @@ const system = require("../../../system"); ...@@ -2,8 +2,9 @@ const system = require("../../../system");
const ServiceBase = require("../../sve.base") const ServiceBase = require("../../sve.base")
class CschemeService extends ServiceBase { class CschemeService extends ServiceBase {
constructor() { constructor() {
super("order", ServiceBase.getDaoName(CschemeService)); super("chance", ServiceBase.getDaoName(CschemeService));
this.redisClient =system.getObject("util.redisClient"); this.redisClient =system.getObject("util.redisClient");
this.cclueDao = system.getObject("db.chance.cclueDao");
} }
/** /**
...@@ -18,7 +19,7 @@ class CschemeService extends ServiceBase { ...@@ -18,7 +19,7 @@ class CschemeService extends ServiceBase {
if(!params.id){ if(!params.id){
return system.getResult(null, `参数错误 线索ID不能为空`); return system.getResult(null, `参数错误 线索ID不能为空`);
} }
if(!params.product_name){ if(!params.clue_type_name){
return system.getResult(null, `参数错误 产品名称不能为空`); return system.getResult(null, `参数错误 产品名称不能为空`);
} }
if(!params.name){ if(!params.name){
...@@ -42,20 +43,30 @@ class CschemeService extends ServiceBase { ...@@ -42,20 +43,30 @@ class CschemeService extends ServiceBase {
if(!params.businessscope){ if(!params.businessscope){
return system.getResult(null, `参数错误 经营范围不能为空`); return system.getResult(null, `参数错误 经营范围不能为空`);
} }
//查询线索是否存在或者是已经关闭
let cclueBean = await this.cclueDao.getCclueInfo({id:this.trim(params.id),deliver_id:this.trim(params.deliver_id)});
if(!cclueBean){
return system.getResult(null,`线索不存在`);
}
if(cclueBean.status=="40"){
return system.getResult(null, `线索已关闭`);
}
let cschemeBean = await this.dao.model.findOne({ let cschemeBean = await this.dao.model.findOne({
where:{ where:{
id: this.trim(params.id), id: this.trim(params.id),
deliver_id: this.trim(params.deliver_id) deliver_id: this.trim(params.deliver_id)
} },
attributes: ['id']
}); });
if(cschemeBean){ if(!cschemeBean){
return system.getResult(null, `线索已存在`); return system.getResult(null, `线索数据存在异常`);
} }
try{ try{
let cschemeProperties ={ let cschemeProperties ={
id: this.trim(params.id), id: this.trim(params.id),
deliver_id: this.trim(params.deliver_id), deliver_id: this.trim(params.deliver_id),
product_name: this.trim(params.product_name), clue_type_name: this.trim(params.product_name),
name: this.trim(params.name), name: this.trim(params.name),
business_place: this.trim(params.business_place), business_place: this.trim(params.business_place),
legal_name: this.trim(params.legal_name), legal_name: this.trim(params.legal_name),
...@@ -65,8 +76,15 @@ class CschemeService extends ServiceBase { ...@@ -65,8 +76,15 @@ class CschemeService extends ServiceBase {
businessscope: this.trim(params.businessscope), businessscope: this.trim(params.businessscope),
remarks: this.trim(params.remarks) || "" remarks: this.trim(params.remarks) || ""
}; };
let res = await this.dao.update(cschemeProperties); await this.db.transaction(async t=>{
return system.getResult(res); await this.dao.update(cschemeProperties, t);
let cclueProperties = {
id: this.trim(params.id),
status: "30"
};
await this.cclueDao.update(cclueProperties, t);
})
return system.getResultSuccess();
}catch (e) { }catch (e) {
console.log(e); console.log(e);
return system.getResult(null,`系统错误`) return system.getResult(null,`系统错误`)
......
...@@ -6,7 +6,7 @@ var settings={ ...@@ -6,7 +6,7 @@ var settings={
db:10, db:10,
}, },
database:{ database:{
dbname : "xgg-trade", dbname : "xgg-chance",
user: "write", user: "write",
password: "write", password: "write",
config: { config: {
......
...@@ -21,7 +21,7 @@ var settings = { ...@@ -21,7 +21,7 @@ var settings = {
cacheprefix: "sjb", cacheprefix: "sjb",
usertimeout: 3600, //单位秒 usertimeout: 3600, //单位秒
basepath: path.normalize(path.join(__dirname, '../..')), basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 3107, port: process.env.NODE_PORT || 3108,
defaultPassWord: "987456", defaultPassWord: "987456",
paasUrl: function () { paasUrl: function () {
if (this.env == "dev") { if (this.env == "dev") {
......
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