Commit a0f35f12 by 王勇飞

Merge branch 'tx-fi-tax' of gitlab.gongsibao.com:jiangyong/zhichan into tx-fi-tax

parents ada9e984 f0480d90
...@@ -59,10 +59,10 @@ class CtlBase { ...@@ -59,10 +59,10 @@ class CtlBase {
//添加组织结构路径,如果是上级,取上级 //添加组织结构路径,如果是上级,取上级
if (req.xctx.ptags && req.xctx.ptags != "") { if (req.xctx.ptags && req.xctx.ptags != "") {
pobj.opath = req.xctx.ptags pobj.opath = req.xctx.ptags
pob.isPrincipal = true pobj.isPrincipal = true
} else { } else {
pobj.opath = req.xctx.opath pobj.opath = req.xctx.opath
pob.isPrincipal = false pobj.isPrincipal = false
} }
if (!req.xctx.appkey) { if (!req.xctx.appkey) {
return [-200, "请求头缺少应用x-app-key"] return [-200, "请求头缺少应用x-app-key"]
......
...@@ -75,30 +75,30 @@ class BizOptCtl extends CtlBase { ...@@ -75,30 +75,30 @@ class BizOptCtl extends CtlBase {
* @param {*} mobj * @param {*} mobj
* @param {*} qobj * @param {*} qobj
* @param {*} req * @param {*} req
*/ * {
async distribution(mobj, qobj, req) {
let pobj = mobj.d;
let params = {
demand_code_list: ["1", "2", "3"],//至少一个需求编号 demand_code_list: ["1", "2", "3"],//至少一个需求编号
salesman_opcode: "",//唯一标识 salesman_opcode: "",//唯一标识
salesman_id: "jdlfaj",//销售员id salesman_id: "jdlfaj",//销售员id
salesman_name: "",//销售员姓名 salesman_name: "",//销售员姓名
salesman_phone: "",//销售员手机号 salesman_phone: "",//销售员手机号
} }
*/
async distribution(mobj, qobj, req) {
let pobj = mobj.d;
} }
/** /**
* 关闭需求 * 关闭需求
* @param {*} mobj * @param {*} mobj
*/ * {
async closeBizopt(mobj, qobj, req) {
let pobj = mobj.d;
pobj.business_status = "isClosed";
let params = {
demand_code: "",//需求编号 demand_code: "",//需求编号
close_reason: "",//关闭原因 close_reason: "",//关闭原因
remarks: ""//备注 remarks: ""//备注
} }
*/
async closeBizopt(mobj, qobj, req) {
let pobj = mobj.d;
pobj.business_status = "isClosed";
//根据需求编号去更新该条需求的状态为已关闭 //根据需求编号去更新该条需求的状态为已关闭
try { try {
let res = await this.service.updateStatusByDemandCode(pobj); let res = await this.service.updateStatusByDemandCode(pobj);
......
...@@ -112,5 +112,32 @@ class DeliverybillCtl extends CtlBase { ...@@ -112,5 +112,32 @@ class DeliverybillCtl extends CtlBase {
return system.getResult(null, err.message) return system.getResult(null, err.message)
} }
} }
/**
* 分配人
*/
async distributionPerson(pobj, qobj, req) {
try {
if (!Array.isArray(pobj.numbers) && pobj.numbers.length > 0) {
throw new Error("numbers 为数组 且 不能为空");
}
if (!pobj.nickName) {
throw new Error("nickName 不能为空");
}
if (!pobj.userId) {
throw new Error("userId 不能为空");
}
if (!pobj.opCode) {
throw new Error("opCode 不能为空");
}
if (![system.FLOWCODE.BIZ, system.FLOWCODE.DELIVERY].includes(pobj.type)) {
throw new Error("type 不合规");
}
const rs = await this.service.distributionPerson(pobj);
return system.getResult(rs);
} catch (err) {
return system.getResult(null, err.message)
}
}
} }
module.exports = DeliverybillCtl; module.exports = DeliverybillCtl;
\ No newline at end of file
...@@ -10,46 +10,46 @@ class OperationrecordCtl extends CtlBase { ...@@ -10,46 +10,46 @@ class OperationrecordCtl extends CtlBase {
/** /**
* 查询记录信息 * 查询记录信息
* @param {*} mobj * @param {*} mobj
* {
demand_code: "",//需求编号
operation_type: ""//操作类型
}
*/ */
async findOne(mobj, qobj, req) { async findAllInfo(mobj, qobj, req) {
let pobj = mobj.d; let pobj = mobj.d;
let params = {
demand_code: "",//需求编号
close_reason: "",//关闭原因
remarks: ""//备注
}
try { try {
if (!pobj.demand_code) { if (!pobj.demand_code) {
return system.getResultError("fitaxschemeCtl/findOne 缺少需求编号!"); return system.getResultError("operationrecordCtl/findAllInfo 缺少需求编号!");
} }
let res = await this.service.findInfo(pobj); let res = await this.service.findAllInfo(pobj);
return system.getResult(res); return system.getResult(res);
} catch (error) { } catch (error) {
console.log("fitaxschemeCtl/findOne " + error); console.log("operationrecordCtl/findAllInfo " + error);
return system.getResultError("fitaxschemeCtl/findOne 查询企业失败!"); return system.getResultError("operationrecordCtl/findAllInfo 查询企业失败!");
} }
} }
/** /**
* 新建记录信息 * 新建记录信息
* @param {*} mobj * @param {*} mobj
* {
demand_code: "",//需求编号
operator: { id: "", name: "" },//操作人
operation_type: "",//操作类型
operation_details: {}//操作详细记录
}
*/ */
async insertInfo(mobj, qobj, req) { async insertInfo(mobj, qobj, req) {
let pobj = mobj.d; let pobj = mobj.d;
let params = {
demand_code: "",//需求编号
close_reason: "",//关闭原因
remarks: ""//备注
}
try { try {
if (!pobj.demand_code) { if (!pobj.demand_code) {
return system.getResultError("fitaxschemeCtl/insertInfo 缺少需求编号!"); return system.getResultError("fitaxschemeCtl/insertInfo 缺少需求编号!");
} }
let insertRes = await this.service.insertInfo(pobj); let insertRes = await this.service.insertInfo(pobj);
return system.getResult("添加企业成功!"); return system.getResult("添加记录信息成功!");
} catch (error) { } catch (error) {
console.log("operationrecordCtl/insertInfo " + error); console.log("operationrecordCtl/insertInfo " + error);
return system.getResultError("operationrecordCtl/insertInfo 添加&修改企业信息失败!"); return system.getResultError("operationrecordCtl/insertInfo 添加记录信息失败!");
} }
} }
} }
......
...@@ -30,7 +30,7 @@ class Dao { ...@@ -30,7 +30,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 +38,8 @@ class Dao { ...@@ -38,8 +38,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 +64,13 @@ class Dao { ...@@ -64,13 +64,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 +202,16 @@ class Dao { ...@@ -202,16 +202,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);
} }
...@@ -224,16 +224,16 @@ class Dao { ...@@ -224,16 +224,16 @@ class Dao {
* p.group.aliasField=' as xxx' * p.group.aliasField=' as xxx'
* @param {*} p * @param {*} p
*/ */
async statGroupBy(p,paras,t){ async statGroupBy(p, paras, t) {
let groupFields=p.group.byFields.join(",") let groupFields = p.group.byFields.join(",")
let aggField=p.group.aggField?p.group.aggField:'' let aggField = p.group.aggField ? p.group.aggField : ''
let tblName=p.group.tblName?p.group.tblName:'' let tblName = p.group.tblName ? p.group.tblName : ''
let where=p.group.where?p.group.where:'' let where = p.group.where ? p.group.where : ''
let having=p.group.having?p.group.having:'' let having = p.group.having ? p.group.having : ''
let aliasField=p.group.aliasField?p.group.aliasField:'' let aliasField = p.group.aliasField ? p.group.aliasField : ''
let actionType=p.group.actionType?p.group.actionType:'count' let actionType = p.group.actionType ? p.group.actionType : 'count'
let sql=`select ${groupFields},${actionType}(${aggField}) ${aliasField} from ${tblName} ${where} group by ${groupFields} ${having} WITH ROLLUP` let sql = `select ${groupFields},${actionType}(${aggField}) ${aliasField} from ${tblName} ${where} group by ${groupFields} ${having} WITH ROLLUP`
return this.customQuery(sql,paras,t) return this.customQuery(sql, paras, t)
} }
async customQuery(sql, paras, t) { async customQuery(sql, paras, t) {
...@@ -275,7 +275,7 @@ class Dao { ...@@ -275,7 +275,7 @@ 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);
...@@ -286,5 +286,8 @@ class Dao { ...@@ -286,5 +286,8 @@ class Dao {
async findById(oid) { async findById(oid) {
return this.model.findById(oid); return this.model.findById(oid);
} }
async findAll(obj, include = []) {
return this.model.findAll({ "where": obj, include, row: true });
}
} }
module.exports = Dao; module.exports = Dao;
...@@ -10,7 +10,8 @@ class OperationrecordDao extends Dao { ...@@ -10,7 +10,8 @@ class OperationrecordDao extends Dao {
*@param {*} qobj *@param {*} qobj
*/ */
async findAllInfo(qobj) { async findAllInfo(qobj) {
qobj.raw = true; qobj.order_type = "BIZ",//数据类型需求|订单
qobj.raw = true;
return await this.model.findAll(qobj); return await this.model.findAll(qobj);
} }
...@@ -22,6 +23,7 @@ class OperationrecordDao extends Dao { ...@@ -22,6 +23,7 @@ class OperationrecordDao extends Dao {
async insertInfo(qobj, t) { async insertInfo(qobj, t) {
let obj = { let obj = {
"demand_code": qobj.demand_code,// 需求编码 "demand_code": qobj.demand_code,// 需求编码
"order_type": "BIZ",
} }
if (qobj.operator) {// 操作人 if (qobj.operator) {// 操作人
obj.operator = qobj.operator; obj.operator = qobj.operator;
......
const system = require("../../../system"); const system = require("../../../system");
const ServiceBase = require("../../sve.base"); const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings"); const settings = require("../../../../config/settings");
const System = require("../../../system");
const appconfig = system.getSysConfig(); const appconfig = system.getSysConfig();
class DeliverybillService extends ServiceBase { class DeliverybillService extends ServiceBase {
constructor() { constructor() {
super("bizchance", ServiceBase.getDaoName(DeliverybillService)); super("bizchance", ServiceBase.getDaoName(DeliverybillService));
this.logService = system.getObject("service.bizchance.statuslogSve"); this.logService = system.getObject("service.bizchance.statuslogSve");
this.fitaxschemeDao = system.getObject("service.bizchance.fitaxschemeDao"); this.fitaxschemeDao = system.getObject("service.bizchance.fitaxschemeDao");
this.bizoptDao = system.getObject("service.bizchance.bizoptDao");
this.operationrecordDao = system.getObject("service.bizchance.operationrecordDao");
} }
async updateOrderStatus(pobj) { async updateOrderStatus(pobj) {
...@@ -124,5 +126,113 @@ class DeliverybillService extends ServiceBase { ...@@ -124,5 +126,113 @@ class DeliverybillService extends ServiceBase {
} }
return result return result
} }
async distributionPerson(pobj) {
let { numbers, nickName, userId, opCode, phone, type } = pobj;
switch (type) {
case System.FLOWCODE.DELIVERY:
let datas = await this.dao.findAll({
delivery_code: {
$in: numbers
}
});
if (datas.length !== numbers.length) {
throw new Error("请检查单号是否正确");
}
await this.dao.updateByWhere({
salesman_id: userId,
salesman_opcode: opCode,
salesman_phone: phone,
salesman_name: nickName
}, {
delivery_code: {
$in: numbers
}
});
// 插入 流转 记录
let logs = [];
for (let val of datas) {
logs.push({
demand_code: val.delivery_code,
operator: {
id: pobj.userid,
username: pobj.username
},
operation_type: "distribution",
operation_details: {
isFirst: val.salesman_id ? true : false,
fromUserId: val.salesman_id,
fromUserName: val.salesman_name,
toUserId: userId,
toUserName: nickName
},
order_type: System.FLOWCODE.DELIVERY
})
}
this.operationrecordDao.bulkCreate(logs);
break
case System.FLOWCODE.BIZ:
let datas = await this.bizoptDao.findAll({
demand_code: {
$in: numbers
}
});
if (datas.length !== datas.length) {
throw new Error("请检查单号是否正确");
}
return this.db.transaction(async (t) => {
// 更新 操作人
await this.bizoptDao.updateByWhere({
salesman_id: userId,
salesman_opcode: opCode,
salesman_phone: phone,
salesman_name: nickName
}, {
demand_code: {
$in: numbers
}
}, t);
// 更新 状态
await this.bizoptDao.updateByWhere({
business_status: "beforeFollowUp"
}, {
$and: [
{
demand_code: {
$in: numbers
}
}, {
business_status: "received"
}
]
}, t);
// 插入 流转 记录
let logs = [];
for (let val of datas) {
logs.push({
demand_code: val.demand_code,
operator: {
id: pobj.userid,
username: pobj.username
},
operation_type: "distribution",
operation_details: {
isFirst: val.salesman_id ? true : false,
fromUserId: val.salesman_id,
fromUserName: val.salesman_name,
toUserId: userId,
toUserName: nickName
},
order_type: System.FLOWCODE.BIZ
})
}
this.operationrecordDao.bulkCreate(logs);
return "success"
});
break
}
return "SUCCESS"
}
} }
module.exports = DeliverybillService; module.exports = DeliverybillService;
\ 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