Commit 35b4bdf5 by 任晓松

常用联系人、申请人

parent 11977b6a
......@@ -5,6 +5,7 @@ class OrderAPI extends APIBase {
constructor() {
super();
this.orderinfoSve = system.getObject("service.dbcorder.orderinfoSve");
this.usuallycontactsSve = system.getObject("service.dbcorder.usuallycontactsSve");
}
/**
* 接口跳转-POST请求
......@@ -33,6 +34,18 @@ class OrderAPI extends APIBase {
case "getAllNcl":
opResult = await this.orderinfoSve.getAllNcl(pobj);
break;
case "addUsuallyContacts"://增加常用联系人,申请人
opResult = await this.usuallycontactsSve.addContacts(pobj,pobj.actionBody);
break;
case "delUsuallyContacts"://删除常用联系人,申请人
opResult = await this.usuallycontactsSve.delContacts(pobj,pobj.actionBody);
break;
case "updateUsuallyContacts"://修改常用联系人,申请人
opResult = await this.usuallycontactsSve.updateContacts(pobj,pobj.actionBody);
break;
case "getUsuallyContacts"://查询常用联系人,申请人
opResult = await this.usuallycontactsSve.getContacts(pobj,pobj.actionBody);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......
const system = require("../../../system");
const Dao = require("../../dao.base");
class UsuallyContactsDao extends Dao {
constructor() {
super(Dao.getModelName(UsuallyContactsDao));
}
async getItemByOrderNo(orderNo, uapp_id) {
return await this.model.findOne({
where: {
sourceOrderNo: orderNo
},
attributes: [
"id",
"contactName",
"mobile",
"tel",
"email",
"fax"],
raw: true
});
}
}
module.exports = UsuallyContactsDao;
module.exports = (db, DataTypes) => {
return db.define("usuallycontacts", {
uapp_id :DataTypes.INTEGER, //
channel_user_id :DataTypes.STRING,
contact_name :DataTypes.STRING,
contacts_content :DataTypes.JSON,
type :DataTypes.STRING
}, {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
timestamps: true,
updatedAt: false,
//freezeTableName: true,
// define the table's name
tableName: 'c_usually_contacts',
validate: {
},
indexes: [
]
});
}
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
class UsuallyContactsService extends ServiceBase {
constructor() {
super("dbcorder", ServiceBase.getDaoName(UsuallyContactsService));
}
//添加常用联系人、申请人
async addContacts(pobj,actionBody){
if (!actionBody.channel_user_id) {
return system.getResultFail(-1, "渠道用户id不能为空");
}
if(!actionBody.contacts){
return system.getResultFail(-1,'用户信息不能为空');
}
if(!actionBody.type){
return system.getResultFail(-1,'类型不能为空');
}
let params = {
channel_user_id:actionBody.channel_user_id,
uapp_id:pobj.appInfo.uapp_id,
type:actionBody.type,
contact_name:actionBody.contacts.contacts || actionBody.name
}
let item = await this.findOne(params);
if(item){
return system.getResultFail(-1,'联系人已存在,请勿重复添加')
}
let contactsInfo = {
uapp_id: pobj.appInfo.uapp_id,
channel_user_id:actionBody.channel_user_id,
contact_name:actionBody.contacts.name || actionBody.contacts.contacts,
contacts_content:actionBody.contacts,
type:actionBody.type
}
let result = await this.create(contactsInfo);
return system.getResultSuccess();
}
//删除常用联系人、申请人
async delContacts(pobj,actionBody){
let params = {
id:actionBody.id,
uapp_id:pobj.appInfo.uapp_id
}
await this.delete(params);
return system.getResultSuccess();
}
//修改常用联系人、申请人
async updateContacts(pobj,actionBody){
if(!actionBody.id){
return system.getResultFail(-1,'id 不能为空');
}
if(!actionBody.channel_user_id){
return system.getResultFail(-1,'id 不能为空');
}
if(Object.keys(actionBody.contacts).length<0){
return system.getResultFail(-1,'信息不能为空');
}
let obj = {
id:actionBody.id,
uapp_id:pobj.appInfo.uapp_id,
channel_user_id:actionBody.channel_user_id
}
let setParams = {
contact_name :actionBody.contacts.contacts || actionBody.contacts.name,
contacts:actionBody.contacts
}
let result = await this.updateByWhere(setParams, {where:obj});
return system.getResultSuccess();
}
//查询常用联系人、申请人
async getContacts(pobj,actionBody){
let sql = `select id,channel_user_id,contact_name,contacts_content,type from c_usually_contacts where uapp_id = :uapp_id and channel_user_id = :channel_user_id and type = :type and deleted_at is null`;
if(!actionBody.type){
return system.getResultFail(-1,'type 不能为空')
}
if(!actionBody.channel_user_id){
return system.getResultFail(-1,'type 不能为空')
}
let paramsWhere = {
uapp_id : pobj.appInfo.uapp_id,
channel_user_id: actionBody.channel_user_id,
type:actionBody.type
}
let result = await this.customQuery(sql,paramsWhere);
return system.getResult(result);
}
}
module.exports = UsuallyContactsService;
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