Commit 15abb784 by 孙亚楠

d

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