Commit 19da3e78 by 王昆

gsb

parent 6eb81369
var system = require("../../../system")
const http = require("http")
const querystring = require('querystring');
var settings = require("../../../../config/settings");
const CtlBase = require("../../ctlms.base");
var cacheBaseComp = null;
class BusinessmenCtl extends CtlBase {
constructor() {
super();
this.businessmenSve = system.getObject("service.business.businessmenSve");
}
async allPage(pobj, pobj2, req) {
try {
let condition = {
currentPage: pobj.currentPage,
pageSize: pobj.pageSize,
order_id: this.trim(pobj.order_id),
deliver_id: this.trim(pobj.deliver_id),
name: this.trim(pobj.name),
legal_name: this.trim(pobj.legal_name),
legal_mobile: this.trim(pobj.legal_mobile),
legal_idcard: this.trim(pobj.legal_idcard),
credit_code: this.trim(pobj.credit_code)
};
if (!condition.deliver_id) {
return system.getResult(null, "请重新登录");
}
return await this.businessmenSve.allPage(condition);
} catch (error) {
console.log(error);
return system.getResultFail(500, "接口异常:" + error.message);
}
}
async myPage(pobj, pobj2, req) {
try {
let condition = {
currentPage: pobj.currentPage,
pageSize: pobj.pageSize,
order_id: this.trim(pobj.order_id),
name: this.trim(pobj.name),
operator_id: this.trim(req.loginUser.id),
legal_name: this.trim(pobj.legal_name),
legal_mobile: this.trim(pobj.legal_mobile),
legal_idcard: this.trim(pobj.legal_idcard),
credit_code: this.trim(pobj.credit_code)
};
if (!condition.operator_id) {
return system.getResult(null, "请重新登录");
}
return await this.businessmenSve.allPage(condition);
} catch (error) {
console.log(error);
return system.getResultFail(500, "接口异常:" + error.message);
}
}
}
module.exports = BusinessmenCtl;
\ No newline at end of file
var system = require("../../../system")
const CtlBase = require("../../ctlms.base");
class OrderCtl extends CtlBase {
constructor() {
super();
this.orderSve = system.getObject("service.order.orderSve");
}
}
module.exports = OrderCtl;
\ No newline at end of file
const system=require("../../../system");
const Dao=require("../../dao.base");
class OpuserrelationDao extends Dao{
constructor(){
super(Dao.getModelName(OpuserrelationDao));
}
}
module.exports=OpuserrelationDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class SynlogDao extends Dao {
constructor() {
super(Dao.getModelName(SynlogDao));
}
}
module.exports = SynlogDao;
\ No newline at end of file
const system = require("../../../system");
const Dao = require("../../dao.base");
class PushapiDao extends Dao {
constructor() {
super(Dao.getModelName(PushapiDao));
}
}
module.exports = PushapiDao;
\ No newline at end of file
const system = require("../../../system");
const Dao = require("../../dao.base");
class PushlogDao extends Dao {
constructor() {
super(Dao.getModelName(PushlogDao));
}
}
module.exports = PushlogDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
// var users=await u.model.findAll({where:{app_id:1}});
// var role=await roledao.model.findOne({where:{code:"guest"}});
// console.log(role);
// for(var i=0;i<users.length;i++){
// await users[i].setRoles([role]);
// console.log(i);
// }
//
// })();
\ No newline at end of file
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("opuserrelation", {
ucname: DataTypes.STRING,
ucid: DataTypes.STRING
}, {
paranoid: true,//假的删除
underscored: true,
version: true,
freezeTableName: true,
timestamps: true,
updatedAt: false,
//freezeTableName: true,
// define the table's name
tableName: 'op_user_relation',
validate: {
},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("synlog", {
apiUrl: DataTypes.STRING,
apiName: DataTypes.STRING,
apiReq: DataTypes.STRING,
apiRes: DataTypes.STRING,
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'xgg_syn_log',
validate: {},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
\ No newline at end of file
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("businessmen", {
order_id: DataTypes.BIGINT,
merchant_id: DataTypes.BIGINT,
orderNo: DataTypes.STRING(64),
channelOrderNo: DataTypes.STRING(64),
status: DataTypes.STRING(20),//状态 00待处理 10出执照 20已刻章 30银行开户 40税务报道 50已邮寄 60已签约
legalName: DataTypes.STRING(20),
legalMobile: DataTypes.STRING(20),
name: DataTypes.STRING(100),
creditCode: DataTypes.STRING(100),
businessPlace: DataTypes.STRING(100),
businessScope: DataTypes.STRING(500),
regDate: DataTypes.DATE,
businessImg: DataTypes.STRING(300),
gongzhang: DataTypes.STRING(300),
caiwuzhang: DataTypes.STRING(300),
fapiaozhang: DataTypes.STRING(300),
hetongzhang: DataTypes.STRING(300),
farenzhang: DataTypes.STRING(300),
isBank: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
bankName: DataTypes.STRING(50),
bankNo: DataTypes.STRING(30),
bank: DataTypes.STRING(100),
bankImg: DataTypes.STRING(300),
caImg: DataTypes.STRING(300),
taxRegDay: DataTypes.DATE,
taxOrg: DataTypes.STRING(100),
courierNo: DataTypes.STRING(100),
courierImg: DataTypes.STRING(100),
addedValueRate: DataTypes.DOUBLE(11, 2),
supertaxRate: DataTypes.DOUBLE(11, 2),
commonTaxLadder: DataTypes.STRING(1000),
commonOtherLadder: DataTypes.STRING(1000),
specialTaxLadder: DataTypes.STRING(1000),
specialOtherLadder: DataTypes.STRING(1000),
contractStartData: DataTypes.DATE,
contractEndData: DataTypes.DATE,
contract: DataTypes.STRING(300),//个体户合同
notes: DataTypes.STRING,//备注
opNotes: DataTypes.STRING,//操作备注
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'xgg_businessmen',
validate: {},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
\ No newline at end of file
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("order", {
merchant_id: DataTypes.BIGINT,
orderNo: DataTypes.STRING(64),
channelOrderNo: DataTypes.STRING(64),
legalName: DataTypes.STRING(20),
legalMobile: DataTypes.STRING(20),
legalImg: DataTypes.STRING(300),
idcard: DataTypes.STRING(20),
idcardFront: DataTypes.STRING(300),
idcardBack: DataTypes.STRING(300),
bankNo: DataTypes.STRING(30),
bank: DataTypes.STRING(200),
names: DataTypes.STRING(300),
businessScope: DataTypes.STRING(500),
capital: DataTypes.STRING(100),
status: DataTypes.STRING(20),//订单状态 00待处理 10出执照 20已刻章 30银行开户 40税务报道 50已邮寄
notes: DataTypes.STRING,//备注
opNotes: DataTypes.STRING,//操作备注
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'xgg_order',
validate: {},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
\ No newline at end of file
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("pushapi", {
merchant_id: DataTypes.BIGINT,
rechargeAudit: DataTypes.STRING(200),
orderStatus: DataTypes.STRING(200),
businessmenSign: DataTypes.STRING(200),
invoiceStatus: DataTypes.STRING(200),
invoiceTax: DataTypes.STRING(200),
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'xgg_push_api',
validate: {},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
\ No newline at end of file
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("pushlog", {
merchant_id: DataTypes.STRING,
dataType: DataTypes.INTEGER,
dataId: DataTypes.STRING,
api: DataTypes.STRING(200),
params: DataTypes.STRING(5000),
rs: DataTypes.STRING(200),
success: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'xgg_push_log',
validate: {},
indexes: [
// Create a unique index on email
// {
// unique: true,
// fields: ['email']
// },
//
// // Creates a gin index on data with the jsonb_path_ops operator
// {
// fields: ['data'],
// using: 'gin',
// operator: 'jsonb_path_ops'
// },
//
// // By default index name will be [table]_[fields]
// // Creates a multi column partial index
// {
// name: 'public_by_author',
// fields: ['author', 'status'],
// where: {
// status: 'public'
// }
// },
//
// // A BTREE index with a ordered field
// {
// name: 'title_index',
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
});
}
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../svems.base")
const settings = require("../../../../config/settings")
class InvoiceService extends ServiceBase {
constructor() {
super();
}
async processDics(params) {
var rs = await this.callms("invoice", "processDics", params);
return rs;
}
async invoiceApply(params) {
var rs = await this.callms("invoice", "invoiceApply", params);
return rs;
}
async invoicePage(params) {
params.currentPage = Number(params.currentPage || 1);
params.pageSize = Number(params.pageSize || 10);
var rs = await this.callms("invoice", "deliverInvoicePage", params);
if (rs.data && rs.data.rows) {
for (let item of rs.data.rows) {
item.invoice_amount = system.f2y(item.invoice_amount);
}
}
return rs;
}
async handleStatus(params) {
var rs = await this.callms("invoice", "handleStatus", params);
return rs;
}
async invoice(params) {
var rs = await this.callms("invoice", "invoice", params);
return rs;
}
}
module.exports = InvoiceService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../svems.base")
const settings = require("../../../../config/settings")
class MerchantService extends ServiceBase {
constructor() {
super();
}
//查询商户
async apiQueryMerchant(params) {
try {
return await this.queryMerchant(params);
} catch (error) {
return system.getResultFail(-1);
}
}
// ----------------------------------- 以上为api --------------------------------------
async queryMerchant(params) {
try {
var p = {
id : params.merchant_id || params.merchantId,
options: {
title: true,
address:true,
}
}
var rs = await this.callms("merchant", "getById", p);
if(rs.status != 0 || !rs.data) {
return system.getResult(null, "商户不存在");
}
let merchant ={};
merchant.name=rs.data.name;
merchant.taxType=rs.data.taxType;
merchant.contactName=rs.data.contactName;
merchant.contactMobile=rs.data.contactMobile;
merchant.contactEmail=rs.data.contactEmail;
merchant.invoiceValid=rs.data.invoiceValid;
merchant.mustPay=rs.data.mustPay;
merchant.status=rs.data.status;
merchant.ownerName=rs.data.ownerName;
merchant.ownerMobile=rs.data.ownerMobile;
merchant.created_at=rs.data.created_at;
merchant.titleList=[];
for (let item of rs.data.titleList) {
let temp={};
temp.titleNo=item.titleNo;
temp.taxNo=item.taxNo;
temp.invoiceAddr=item.invoiceAddr;
temp.invoiceMobile=item.invoiceMobile;
temp.accountName=item.accountName;
temp.accountPublic=item.accountName;
merchant.titleList.push(temp);
}
merchant.addressList=[];
for (let item of rs.data.addressList) {
let temp={};
temp.addressNo=item.addressNo;
temp.mailAddr=item.mailAddr;
temp.mailTo=item.mailTo;
temp.mailMobile=item.mailMobile;
merchant.addressList.push(temp);
}
return system.getResultSuccess(merchant);
} catch (error) {
return system.getResultFail(-1);
}
}
async nameList() {
var rs = await this.callms("merchant", "nameList", {});
return rs;
}
async infoPage(params) {
var rs = await this.callms("merchant", "infoList", params);
return rs;
}
async getById(id) {
var rs = await this.callms("merchant", "getById", {id: id});
return rs;
}
async add(params) {
var merchant = {};
var title = {};
var address = {};
if(["00", "10"].indexOf(params.taxType) == -1) {
return system.getResult(null, "纳税人类型类型错误");
}
// 商户信息
merchant.name = this.trim(params.name);
merchant.taxType = params.taxType;
merchant.contactName = this.trim(params.contactName);
merchant.contactMobile = this.trim(params.contactMobile);
merchant.contactEmail = this.trim(params.contactEmail);
merchant.invoiceValid = params.invoiceValid ? 1 : 0;
merchant.mustPay = params.mustPay ? 1 : 0;
merchant.status = "00";
merchant.ownerId = this.trim(params.ownerId);
if(merchant.ownerId) {
// TODO 去用户平台查询用户信息
merchant.ownerName = "测试用户名";
merchant.ownerMobile = "测试用户手机号";
merchant.ownerPath = "/aaa/bbbb/ccc/ddd/eee/fff/zzz/yyy";
}
title.taxNo = this.trim(params.taxNo);
title.invoiceAddr = this.trim(params.invoiceAddr);
title.invoiceMobile = this.trim(params.invoiceMobile);
title.accountName = this.trim(params.accountName);
title.accountPublic = this.trim(params.accountPublic);
address.mailAddr = this.trim(params.mailAddr);
address.mailTo = this.trim(params.mailTo);
address.mailMobile = this.trim(params.mailMobile);
merchant.title = title;
merchant.address = address;
return await this.callms("merchant", "addMerchant", merchant);
}
async upd(params) {
var merchant = {};
var title = {};
var address = {};
if(["00", "10"].indexOf(params.taxType) == -1) {
return system.getResult(null, "纳税人类型类型错误");
}
// 商户信息
merchant.id = params.id;
merchant.name = this.trim(params.name);
merchant.taxType = params.taxType;
merchant.contactName = this.trim(params.contactName);
merchant.contactMobile = this.trim(params.contactMobile);
merchant.contactEmail = this.trim(params.contactEmail);
merchant.invoiceValid = params.invoiceValid ? 1 : 0;
merchant.mustPay = params.mustPay ? 1 : 0;
merchant.status = "00";
merchant.ownerId = this.trim(params.ownerId);
if(merchant.ownerId) {
// TODO 去用户平台查询用户信息
merchant.ownerName = "测试用户名";
merchant.ownerMobile = "测试用户手机号";
merchant.ownerPath = "/aaa/bbbb/ccc/ddd/eee/fff/zzz/yyy";
}
return await this.callms("merchant", "updMerchant", merchant);
}
async audit(params) {
var mobile = this.trim(params.mobile);
var ucname = this.trim(params.mobile);
params.status = "10";
params.ucname = ucname;
params.ucid = ucid;
// TODO 调用平台,创建商户用户
var auditRs = await this.callms("merchant", "auditMerchant", params);
return auditRs;
}
}
module.exports = MerchantService;
const system=require("../../../system");
const ServiceBase=require("../../svems.base")
const settings=require("../../../../config/settings")
class MerchantaccountService extends ServiceBase{
constructor(){
super();
}
async page(params) {
var res = await this.callms("merchant", "merchantAccountPage", params);
await this.trans(res.data.rows);
return res;
}
async infoByMerchantId(params) {
var merchantId = params.merchantId || params.merchant_id;
var res = await this.callms("merchant", "merchantAccountInfoByMerchantId", {merchantId : merchantId});
if(res.status != 0 || !res.data) {
return res;
}
var info = res.data;
var dto = {
"merchant_id": info.merchant_id,
"banlance": info.banlance
};
return system.getResultSuccess(dto);
}
async trans(rows) {
if (!rows) {
return;
}
for (var item of rows) {
if (!item) {
continue;
}
item.banlance = system.f2y(item.banlance);
}
}
}
module.exports=MerchantaccountService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
const system = require("../../../system");
const ServiceBase = require("../../svems.base")
const settings = require("../../../../config/settings")
class MerchantaddressService extends ServiceBase {
constructor() {
super();
}
async page(params) {
var res = await this.callms("merchant", "merchantAddressList", params);
return res;
}
async info(params) {
return await this.callms("merchant", "merchantAddressInfo", params);
}
async save(params) {
return await this.callms("merchant", "merchantAddressSave", params);
}
async setDefault(params) {
var res = await this.callms("merchant", "merchantAddressDefault", params);
return res;
}
}
module.exports = MerchantaddressService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../svems.base")
const settings = require("../../../../config/settings")
class MerchantrechargeService extends ServiceBase {
constructor() {
super();
this.pushapiSve = system.getObject("service.push.pushapiSve");
}
async add(params) {
//
var recharge = {};
recharge.merchantId = params.merchant_id || params.merchantId;
recharge.amt = Number(params.amt);
recharge.outTradeNo = this.trim(params.outTradeNo);
recharge.voucher = this.trim(params.voucher);
if (recharge.amt <= 0) {
return system.getResult(null, "充值金额不能小于0");
}
return await this.callms("merchant", "merchantRechargeAdd", params);
// await this.transfield(res.data.rows);
// return res;
}
async info(params) {
var res = await this.callms("merchant", "merchantRechargeInfo", params);
await this.transfield([res.data]);
return res;
}
async audit(params) {
var res = await this.callms("merchant", "merchantRechargeAudit", params);
if (res.status == 0) {
this.pushAudit(params);
}
return res;
}
async page(params) {
var res = await this.callms("merchant", "merchantRechargePage", params);
await this.transfield(res.data.rows);
return res;
}
async pushAudit(params) {
try {
var recharge = await this.callms("merchant", "merchantRechargeInfo", params);
recharge = recharge.data;
// 查商户加密信息
var merchant = await this.callms("merchant", "secretById", {
id: recharge.merchant_id
});
merchant = merchant.data;
// 推送审核信息
await this.pushapiSve.push({
merchantId: merchant.id,
appKey: merchant.appSecret,
dataType: 0,
dataId: merchant.id,
field: "rechargeAudit",
params: {
merchantId: merchant.id,
outTradeNo: recharge.outTradeNo,
status: recharge.status,
remark: this.trim(recharge.remark)
},
});
} catch (error) {
console.log(error);
}
}
async transfield(rows) {
if (!rows) {
return;
}
for (var item of rows) {
if (!item) {
continue;
}
item.amt = system.f2y(item.amt);
}
}
}
module.exports = MerchantrechargeService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../svems.base")
const settings = require("../../../../config/settings")
class MerchantsignedService extends ServiceBase {
constructor() {
super();
}
async page(params) {
var res = await this.callms("merchant", "merchantSignList", params);
await this.doRate(res.data.rows);
return res;
}
async save(params) {
params.serviceRate = system.y2f(params.serviceRate);
return await this.callms("merchant", "saveMerchantSign", params);
}
async info(params) {
var res = await this.callms("merchant", "merchantSignInfo", params);
await this.doRate([res.data]);
return res;
}
async doRate(rows) {
if (!rows) {
return;
}
for (var item of rows) {
if (!item) {
continue;
}
item.serviceRate = system.f2y(item.serviceRate);
}
}
}
module.exports = MerchantsignedService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
\ No newline at end of file
const system=require("../../../system");
const ServiceBase=require("../../svems.base");
var settings=require("../../../../config/settings");
class MerchanttitleService extends ServiceBase{
constructor(){
super();
}
async merchantTitleList(params){
return await this.callms("merchant","merchantTitleList",params);
}
async merchantTitleInfo(params){
console.log(JSON.stringify(params));
return await this.callms("merchant","merchantTitleInfo", params);
}
async merchantTitleSave(params){
console.log(JSON.stringify(params));
return await this.callms("merchant","merchantTitleSave",params);
}
async merchantTitleDefault(params){
return await this.callms("merchant","merchantTitleDefault",params);
}
}
module.exports=MerchanttitleService;
const system=require("../../../system");
const ServiceBase=require("../../sve.base");
class MsgHistoryService extends ServiceBase{
constructor(){
super(ServiceBase.getDaoName(MsgHistoryService));
this.msgnoticeDao = system.getObject("db.msgnoticeDao");
this.userDao = system.getObject("db.userDao");
this.redisClient = system.getObject("util.redisClient");
this.businesslicenseDao = system.getObject("db.businesslicenseDao");
}
getApp(appkey){
return this.cacheManager["AppCache"].cacheApp(appkey);
}
async saveMsg(msg) {
var self = this;
console.log("save msg ", msg);
// 事务
await this.db.transaction(async function (t){
// 1.保存聊天信息
msg = await self.dao.create(msg, t);
// 2.保存好友信息
await self.msgnoticeDao.saveNotice(msg, t);
});
return msg;
}
async pushBusinessLicenseMsg(senderId, targetId, businessLicense_id) {
if(!businessLicense_id) {
return 0;
}
var notice = await this.msgnoticeDao.findOne({fromId : senderId, toId : targetId});
if(notice && notice.businessLicense_id == businessLicense_id) {
return 0;
}
var senderUser = await this.userDao.findById(senderId);
var targetUser = await this.userDao.findById(targetId);
var senderChannel = senderUser.app_id + "¥" + senderUser.id;
var targetChannel = targetUser.app_id + "¥" + targetUser.id;
var sender = senderUser.app_id + "¥" + senderUser.id + "¥" + senderUser.headUrl;
var target = targetUser.app_id + "¥" + targetUser.id + "¥" + targetUser.headUrl;
var msg = {
msgType: "mryzLicense",
sender:sender,
senderId:senderId,
target:target,
targetId:targetId,
content:businessLicense_id,
isRead:false,
businessLicense_id:businessLicense_id
}
var obj = await this.saveMsg(msg);
var bl = await this.businesslicenseDao.findById(businessLicense_id);
msg.businessLicense = bl;
msg.id = obj.id;
msg.created_at = obj.created_at;
this.redisClient.publish(senderChannel, JSON.stringify(msg));
this.redisClient.publish(targetChannel, JSON.stringify(msg));
return 1;
}
async getChatList(senderId, targetId, maxId, pageSize) {
let sql = "SELECT * FROM `msghistory` WHERE id < :maxId AND ((senderId = :senderId AND targetId = :targetId) OR (targetId = :senderId AND senderId = :targetId)) ORDER BY id DESC LIMIT :pageSize "
let params = {senderId:senderId, targetId: targetId, maxId: maxId, pageSize: pageSize};
var list = await this.dao.customQuery(sql, params);
if(!list || list.length == 0) {
return [];
}
var licenseIds = [];
var msgIds = [];
list.forEach(item => {
if(item.msgType == 'mryzLicense') {
licenseIds.push(Number(item.businessLicense_id));
}
msgIds.push(item.id);
});
if(licenseIds.length > 0) {
let licenseSql = "SELECT * FROM yz_business_license WHERE id IN (" + licenseIds.join(",") + ") ";
var licenseList = await this.businesslicenseDao.customQuery(licenseSql);
var licenseMap = [];
licenseList.forEach(item => {
licenseMap["id" + item.id] = item;
});
list.forEach(item => {
if(item.msgType == 'mryzLicense') {
item.businessLicense = licenseMap['id' + item.businessLicense_id];
}
});
}
var self = this;
setTimeout(function(){
self.setRead(senderId, targetId, list);
}, 1000);
return list;
}
async setRead(senderId, targetId, list) {
if(!list || list.length == 0) {
return;
}
var target = await this.userDao.findById(targetId);
if(!target) {
return;
}
var pushIds = [];
for(var item of list) {
if(item.isRead || senderId != item.targetId) {
continue;
}
pushIds.push(item.id);
}
if(pushIds.length == 0) {
return;
}
this.dao.updateByWhere({isRead: true}, {where:{id:{[this.db.Op.in]:pushIds}}});
var channel = target.app_id + "¥" + target.id;
var rs = await this.redisClient.publish(channel, JSON.stringify({type:"readmsg", data : pushIds}));
console.log(rs, "------------------------------------------ publish result ");
}
async readMsg(userId, id) {
var msg = await this.dao.findById(id);
if(!msg || userId != msg.targetId) {
return 0;
}
msg.isRead = true;
await msg.save();
var user = await this.userDao.findById(msg.senderId);
if(!user) {
return 0;
}
var channel = user.app_id + "¥" + user.id;
return await this.redisClient.publish(channel, JSON.stringify({type:"readmsg", data : [msg.id]}));
}
}
module.exports=MsgHistoryService;
const system = require("../../../system");
const ServiceBase = require("../../sve.base");
class MsgNoticeService extends ServiceBase {
constructor() {
super(ServiceBase.getDaoName(MsgNoticeService));
//this.appDao=system.getObject("db.appDao");
this.userDao = system.getObject("db.userDao");
this.businesslicenseDao = system.getObject("db.businesslicenseDao");
this.msghistoryDao = system.getObject("db.msghistoryDao");
}
getApp(appkey) {
return this.cacheManager["AppCache"].cacheApp(appkey);
}
async getUserList(userId) {
var list = await this.dao.model.findAll({
where: {
fromId: userId
},
order: [
["updated_at", "DESC"]
],
raw: true
});
if (!list || list.length == 0) {
return [];
}
var msgIds = [];
var businessLicenseIds = [];
var userIds = [];
for (var item of list) {
msgIds.push(item.lastMsgId);
businessLicenseIds.push(item.businessLicense_id);
userIds.push(item.toId);
}
var msgMap = [];
var businessLicenseMap = [];
var userMap = [];
var unreadMap = [];
// 最后一条聊天记录
if (msgIds.length > 0) {
var msgList = await this.msghistoryDao.customQuery("SELECT * FROM msghistory WHERE id IN (" + msgIds.join(",") + ") ");
msgList.forEach(item => {
msgMap["id" + item.id] = item;
});
}
// 最后一次聊天关联执照
if (businessLicenseIds.length > 0) {
var licenseList = await this.businesslicenseDao.customQuery("SELECT * FROM yz_business_license WHERE id IN (" + businessLicenseIds.join(",") + ") ");
var serviceTypeIds = [];
for (var item of licenseList) {
serviceTypeIds.push(item.serviceTypeOneId);
serviceTypeIds.push(item.serviceTypeTwoId);
}
if (serviceTypeIds.length > 0) {
var sql = "SELECT id, name FROM `p_service_type` WHERE id IN (" + serviceTypeIds.join(",") + ") ";
var typeList = await this.dao.customQuery(sql);
var typeMap = [];
if (typeList && typeList.length > 0) {
for (var t of typeList) {
typeMap["type_id_" + t.id] = t.name;
if (t.id == item.serviceTypeOneId) {
item.serviceTypeOneName = t.name;
} else if (t.id == item.serviceTypeTwoId) {
item.serviceTypeTwoName = t.name;
} else {}
}
}
}
for (var item of licenseList) {
item.serviceTypeOneName = typeMap["type_id_" + item.serviceTypeOneId];
item.serviceTypeTwoName = typeMap["type_id_" + item.serviceTypeTwoId];
}
licenseList.forEach(item => {
businessLicenseMap["id" + item.id] = item;
});
}
// 聊天好友用户信息
if (userIds.length > 0) {
var userList = await this.userDao.customQuery("SELECT * FROM p_user WHERE id IN (" + userIds.join(",") + ") ");
userList.forEach(item => {
userMap["id" + item.id] = item;
});
}
// 未读消息数量
var unreadList = await this.userDao.customQuery("SELECT senderId, COUNT(1) AS num FROM `msghistory` WHERE isRead = 0 AND targetId = " + userId + " GROUP BY senderId ");
unreadList.forEach(item => {
unreadMap["id" + item.senderId] = item.num;
});
var rs = [];
for (var i in list) {
var item = list[i];
item.lastMsg = msgMap["id" + item.lastMsgId];
item.businessLicense = businessLicenseMap["id" + item.businessLicense_id];
item.friend = userMap["id" + item.toId];
item.unreadCount = unreadMap["id" + item.toId] || 0;
rs.push(item);
}
return rs;
}
async countUnread(userId) {
debugger;
var unreadList = await this.userDao.customQuery("SELECT COUNT(1) AS num FROM `msghistory` WHERE isRead = 0 AND targetId = " + userId);
var count = 0;
if (unreadList && unreadList.length > 0) {
count = unreadList[0].num || 0;
}
return count;
}
}
module.exports = MsgNoticeService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../svems.base")
const settings = require("../../../../config/settings")
class OrderService extends ServiceBase {
constructor() {
super();
this.pushapiSve = system.getObject("service.push.pushapiSve");
this.deliverSve = system.getObject("service.common.deliverSve");
}
async allProcess(params) {
try {
return await this.callms("order", "allProcess", params);
} catch (error) {
return system.getResult(null, `系统错误 错误信息 ${error}`);
}
}
async orders(params) {
var rs = await this.callms("order", "orderDelivers", params);
if (rs.status === 0 && rs.data) {
await this.setUcUser(rs.data.rows);
await this.transfields(rs.data.rows);
}
return rs;
}
async handleStatus(params) {
return await this.callms("order", "handleStatus", params);
}
async orderInfo(params) {
var rs = await this.callms("order", "orderInfo", params);
return rs;
}
async orderInfoAll(params) {
let rs = await this.callms("order", "orderInfoAll", params);
// await this.setUcUser([rs.data.order]);
if (rs.status === 0 && rs.data) {
if (rs.data.orderDeliver) {
await this.setUcUser([rs.data.orderDeliver]);
}
}
return rs;
}
async productDics(params) {
var rs = await this.callms("order", "productDics", params);
return rs;
}
async transfields(rows) {
if (!rows || rows.length == 0) {
return;
}
for (let row of rows) {
if(row.deliver_divide) {
row.deliver_divide = system.f2y(row.deliver_divide);
}
}
}
async setUcUser(rows) {
if (!rows || rows.length == 0) {
return;
}
let ids = [];
for (let row of rows) {
if (row.operator_id) {
ids.push(row.operator_id);
}
}
let map = await this.deliverSve.mayByIds(ids);
for (let row of rows) {
let user = map[row.operator_id] || {};
row.operator_name = user.real_name || "";
}
}
// 交付商统计
async deliverStatTransData(params) {
if (!params.current_date) {
return system.getResult(null, `参数错误 当前时间不能为空`);
}
if (!params.deliver_id) {
return system.getResult(null, `参数错误 交付商不能为空`);
}
try {
return await this.callms("order", "deliverStatTransData", params);
} catch (error) {
console.log(error);
return system.getResult(null,`系统错误 错误信息 ${error}`);
}
}
// 业务办理
async businessManagement(params) {
if (!params.current_date) {
return system.getResult(null, `参数错误 当前时间不能为空`);
}
if (!params.deliver_id) {
return system.getResult(null, `参数错误 交付商不能为空`);
}
try {
return await this.callms("order", "businessManagement", params);
} catch (error) {
console.log(error);
return system.getResult(null,`系统错误 错误信息 ${error}`);
}
}
}
module.exports = OrderService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class PushapiService extends ServiceBase {
constructor() {
super("push", ServiceBase.getDaoName(PushapiService));
this.pushlogDao = system.getObject("db.push.pushlogDao");
}
/**
*
* @param {} options 参数如下
* @param merchantId 商户id
* @param appKey 商户加密key
* @param dataType 数据类型
* @param dataId 数据id
* @param field 推送字段,通过字段去查找推送地址
* @param params 推送参数
*/
async push(options) {
var api = await this.findById(options.merchantId);
if (!api) {
console.log("api不存在[" + JSON.stringify(options) + "]");
return;
}
var apiurl = api[options.field];
if (!apiurl) {
console.log("api地址不存在[" + JSON.stringify(options) + "]");
return;
}
var log;
try {
var params = options.params;
params.times_tamp = new Date().getTime();
var signData = await this.createSign(params, options.appKey);
params.sign = signData.data;
params.requestid = this.getUUID();
log = await this.pushlogDao.create({
dataType: Number(options.dataType),
dataId: options.dataId,
api: apiurl,
params: JSON.stringify(options.params),
rs: "",
success: 0,
});
try {
console.log(JSON.stringify(params));
var rtn = await this.restS.execPost(params, apiurl);
var returnValue = 0;
if (rtn.stdout) {
var result = JSON.parse(rtn.stdout);
if (result.code == "success") {
log.success = 1;
log.rs = trn.stdout;
await log.save();
}
}
} catch (error) {
log.success = 0;
log.rs = error.message;
await log.save();
}
} catch (error) {
if (log) {
log.success = 0;
log.rs = error.message;
await log.save();
}
console.log(error.stack, JSON.stringify(options), "--------------------------------- push exception ---------------------------------");
}
}
}
module.exports = PushapiService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class PushlogService extends ServiceBase {
constructor() {
super("push", ServiceBase.getDaoName(PushlogService));
}
}
module.exports = PushlogService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
\ 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