Commit 9ba7d6aa by 孙亚楠

d

parent 634b524f
......@@ -4,9 +4,7 @@ var settings = require("../../../../config/settings");
class ActionAPI extends APIBase {
constructor() {
super();
this.storderSve = system.getObject("service.trade.storderSve");
this.storderitemSve = system.getObject("service.trade.storderitemSve");
this.stpaySve = system.getObject("service.trade.stpaySve");
// this.storderSve = system.getObject("service.trade.storderSve");
}
/**
* 接口跳转
......
const system=require("../../../system");
const Dao=require("../../dao.base");
class UserDao extends Dao{
constructor(){
super(Dao.getModelName(UserDao));
}
async getAuths(userid){
var self=this;
return this.model.findOne({
where:{id:userid},
include:[{model:self.db.models.account,attributes:["id","isSuper","referrerOnlyCode"]},
{model:self.db.models.role,as:"Roles",attributes:["id","code"],include:[
{model:self.db.models.product,as:"Products",attributes:["id","code"]}
]},
],
});
}
extraModelFilter(){
//return {"key":"include","value":[{model:this.db.models.app,},{model:this.db.models.role,as:"Roles",attributes:["id","name"],joinTableAttributes:['created_at']}]};
return {"key":"include","value":[{model:this.db.models.app,},{model:this.db.models.role,as:"Roles",attributes:["id","name"]}]};
}
extraWhere(obj,w,qc,linkAttrs){
if(obj.codepath && obj.codepath!=""){
// if(obj.codepath.indexOf("userarch")>0){//说明是应用管理员的查询
// console.log(obj);
// w["app_id"]=obj.appid;
// }
}
if(linkAttrs.length>0){
var search=obj.search;
var lnkKey=linkAttrs[0];
var strq="$"+lnkKey.replace("~",".")+"$";
w[strq]= {[this.db.Op.like]:"%"+search[lnkKey]+"%"};
}
return w;
}
async preUpdate(u){
if(u.roles && u.roles.length>0){
var roles=await this.db.models.role.findAll({where:{id:{[this.db.Op.in]:u.roles}}});
console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
console.log(roles);
u.roles=roles
}
return u;
}
async update(obj){
var obj2=await this.preUpdate(obj);
console.log("update....................");
console.log(obj2);
await this.model.update(obj2,{where:{id:obj2.id}});
var user=await this.model.findOne({where:{id:obj2.id}});
user.setRoles(obj2.roles);
return user;
}
async findAndCountAll(qobj,t){
var users=await super.findAndCountAll(qobj,t);
return users;
}
async preCreate(u){
// var roles=await this.db.models.role.findAll({where:{id:{[this.db.Op.like]:u.roles}}});
// console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// console.log(roles);
// console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
// u.roles=roles
return u;
}
async create(u,t){
var self=this;
var u2=await this.preCreate(u);
if(t){
return this.model.create(u2,{transaction: t}).then(user=>{
return user;
});
}else{
return this.model.create(u2).then(user=>{
return user;
});
}
}
//修改用户(user表)公司的唯一码
async putUserCompanyOnlyCode(userId,company_only_code,result){
var customerObj={companyOnlyCode:company_only_code};
var putSqlWhere={where:{id:userId}};
this.updateByWhere(customerObj,putSqlWhere);
return result;
}
}
module.exports=UserDao;
// 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);
// }
//
// })();
const system=require("../../../system");
const fs=require("fs");
const settings=require("../../../../config/settings");
var glob = require("glob");
class APIDocManager{
constructor(){
this.doc={};
this.buildAPIDocMap();
}
async buildAPIDocMap(){
var self=this;
//订阅任务频道
var apiPath=settings.basepath+"/app/base/api/impl";
var rs = glob.sync(apiPath + "/**/*.js");
if(rs){
for(let r of rs){
// var ps=r.split("/");
// var nl=ps.length;
// var pkname=ps[nl-2];
// var fname=ps[nl-1].split(".")[0];
// var obj=system.getObject("api."+pkname+"."+fname);
var ClassObj=require(r);
var obj=new ClassObj();
var gk=obj.apiDoc.group+"|"+obj.apiDoc.groupDesc
if(!this.doc[gk]){
this.doc[gk]=[];
this.doc[gk].push(obj.apiDoc);
}else{
this.doc[gk].push(obj.apiDoc);
}
}
}
}
}
module.exports=APIDocManager;
const fs = require("fs");
const settings = require("../../../../config/settings");
class CacheManager {
constructor() {
//await this.buildCacheMap();
this.buildCacheMap();
}
buildCacheMap() {
var self = this;
self.doc = {};
var cachePath = settings.basepath + "/app/base/db/cache/";
const files = fs.readdirSync(cachePath);
if (files) {
files.forEach(function (r) {
var classObj = require(cachePath + "/" + r);
if (classObj.name) {
self[classObj.name] = new classObj();
var refTmp = self[classObj.name];
if (refTmp.prefix) {
self.doc[refTmp.prefix] = refTmp.desc;
} else {
console.log("请在" + classObj.name + "缓存中定义prefix");
}
}
});
}
}
}
module.exports = CacheManager;
// var cm= new CacheManager();
// cm["InitGiftCache"].cacheGlobalVal("hello").then(function(){
// cm["InitGiftCache"].cacheGlobalVal().then(x=>{
// console.log(x);
// });
// });
\ No newline at end of file
const Sequelize = require('sequelize');
const settings = require("../../../../config/settings")
const fs = require("fs")
const path = require("path");
var glob = require("glob");
class DbFactory {
constructor() {
const dbConfig = settings.database();
this.db = new Sequelize(dbConfig.dbname,
dbConfig.user,
dbConfig.password,
dbConfig.config);
this.db.Sequelize = Sequelize;
this.db.Op = Sequelize.Op;
this.initModels();
this.initRelations();
}
async initModels() {
var self = this;
var modelpath = path.normalize(path.join(__dirname, '../..')) + "/models/";
console.log("modelpath=====================================================");
console.log(modelpath);
var models = glob.sync(modelpath + "/**/*.js");
console.log(models.length);
models.forEach(function (m) {
console.log(m);
self.db.import(m);
});
console.log("init models....");
}
async initRelations() {
/**
一个账户对应多个登陆用户
一个账户对应一个commany
一个APP对应多个登陆用户
一个APP有多个角色
登陆用户和角色多对多
**/
/*建立账户和用户之间的关系*/
//account--不属于任何一个app,是统一用户
//用户登录时首先按照用户名和密码检查account是否存在,如果不存在则提示账号或密码不对,如果
//存在则按照按照accountid和应用key,查看user,后台实现对应user登录
}
//async getCon(){,用于使用替换table模型内字段数据使用
getCon() {
var that = this;
// await this.db.authenticate().then(()=>{
// console.log('Connection has been established successfully.');
// }).catch(err => {
// console.error('Unable to connect to the database:', err);
// throw err;
// });
//同步模型
if (settings.env == "dev") {
//console.log(pa);
// pconfigObjs.forEach(p=>{
// console.log(p.get({plain:true}));
// });
// await this.db.models.user.create({nickName:"dev","description":"test user",openId:"testopenid",unionId:"testunionid"})
// .then(function(user){
// var acc=that.db.models.account.build({unionId:"testunionid",nickName:"dev"});
// acc.save().then(a=>{
// user.setAccount(a);
// });
// });
}
return this.db;
}
getConhb() {
var that = this;
if (settings.env == "dev") {
}
return this.dbhb;
}
}
module.exports = DbFactory;
// const dbf=new DbFactory();
// dbf.getCon().then((db)=>{
// //console.log(db);
// // db.models.user.create({nickName:"jy","description":"cccc",openId:"xxyy",unionId:"zz"})
// // .then(function(user){
// // var acc=db.models.account.build({unionId:"zz",nickName:"jy"});
// // acc.save().then(a=>{
// // user.setAccount(a);
// // });
// // console.log(user);
// // });
// // db.models.user.findAll().then(function(rs){
// // console.log("xxxxyyyyyyyyyyyyyyyyy");
// // console.log(rs);
// // })
// });
// const User = db.define('user', {
// firstName: {
// type: Sequelize.STRING
// },
// lastName: {
// type: Sequelize.STRING
// }
// });
// db
// .authenticate()
// .then(() => {
// console.log('Co+nnection has been established successfully.');
//
// User.sync(/*{force: true}*/).then(() => {
// // Table created
// return User.create({
// firstName: 'John',
// lastName: 'Hancock'
// });
// });
//
// })
// .catch(err => {
// console.error('Unable to connect to the database:', err);
// });
//
// User.findAll().then((rows)=>{
// console.log(rows[0].firstName);
// });
const system=require("../../../system");
const Dao=require("../../dao.base");
class MetaDao{
constructor(){
//super(Dao.getModelName(AppDao));
}
}
module.exports=MetaDao;
const system=require("../../../system");
const Dao=require("../../dao.base");
class OplogDao extends Dao{
constructor(){
super(Dao.getModelName(OplogDao));
}
}
module.exports=OplogDao;
const system=require("../../../system");
const Dao=require("../../dao.base");
class TaskDao extends Dao{
constructor(){
super(Dao.getModelName(TaskDao));
}
extraWhere(qobj,qw,qc){
qc.raw=true;
return qw;
}
async delete(task,qobj,t){
return task.destroy({where:qobj,transaction:t});
}
}
module.exports=TaskDao;
const system=require("../../../system");
const fs=require("fs");
const settings=require("../../../../config/settings");
var cron = require('node-cron');
class TaskManager{
constructor(){
this.taskDic={};
this.redisClient=system.getObject("util.redisClient");
this.buildTaskMap();
}
async buildTaskMap(){
var self=this;
//订阅任务频道
await this.redisClient.subscribeTask("task",this);
var taskPath=settings.basepath+"/app/base/db/task/";
const files=fs.readdirSync(taskPath);
if(files){
files.forEach(function(r){
var classObj=require(taskPath+"/"+r);
self[classObj.name]=new classObj();
});
}
}
async addTask(taskClassName,exp){
(async (tn,ep)=>{
if(!this.taskDic[tn]){
this.taskDic[tn]=cron.schedule(ep,()=>{
this[tn].doTask();
});
}
})(taskClassName,exp);
}
async deleteTask(taskClassName){
if(this.taskDic[taskClassName]){
this.taskDic[taskClassName].destroy();
delete this.taskDic[taskClassName];
}
}
async clearlist(){
var x=await this.redisClient.clearlist("tasklist");
return x;
}
async publish(channel,msg){
var x=await this.redisClient.publish(channel,msg);
return x;
}
async newTask(taskstr){
return this.redisClient.rpush("tasklist",taskstr);
}
}
module.exports=TaskManager;
// var cm= new CacheManager();
// cm["InitGiftCache"].cacheGlobalVal("hello").then(function(){
// cm["InitGiftCache"].cacheGlobalVal().then(x=>{
// console.log(x);
// });
// });
const system = require("../../../system");
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)',
product_name: DataTypes.STRING, comment:'线索类型名称(商品名称)',
contact_mobile: DataTypes.STRING, comment:'联系电话',
contacts: DataTypes.STRING ,comment:'联系人',
status: DataTypes.STRING(3) ,defaultValue:'10', comment:'线索状态 10 待跟进 20 跟进中 30 已完成 40 已关闭',
operator_id: DataTypes.BIGINT ,defaultValue:'', comment:'业务员id',
operator_path: DataTypes.BIGINT ,defaultValue:'', comment:'业务员权限路径',
close_reason: DataTypes.STRING ,defaultValue:'', comment:'关闭原因 10 客户无意向 20 客户联系不上 30 客户暂时不需要 40 客户已购买其他家 50 其他',
close_remarks: DataTypes.INTEGER ,defaultValue:'', comment:'关闭备注',
callback_url: DataTypes.STRING ,defaultValue:'', comment:'阿里回调地址'
}, {
paranoid: true,
underscored: true,
version: true,
freezeTableName: true,
tableName: 'c_clue',
validate: {},
indexes: [],
});
}
\ 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("cfollowlog", {
clue_id: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '线索ID' },
record: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '沟通记录' },
operator: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '操作人' },
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
tableName: 'c_follow_log',
validate: {},
indexes: [],
});
}
\ 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("cscheme", {
product_type: { 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: '经营者' },
legal_mobile: { type: DataTypes.STRING, allowNull: true, defaultValue: "1", COMMENT: '联系电话' },
service_ids: { type: DataTypes.STRING, allowNull: true, defaultValue: "0", COMMENT: '服务IDs' },
business_type: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '经营范围' },
businessscope: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '经营范围详情' },
remarks: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '备注' },
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
tableName: 'c_scheme',
validate: {},
indexes: [],
});
}
\ 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("storder", {
saas_merchant_id: DataTypes.STRING, // saas商户id
out_trade_no: DataTypes.STRING, // 商户订单号
service_rate: DataTypes.INTEGER, // 商户订单号
amt: DataTypes.BIGINT, // 请求打款金额
actual_amt: DataTypes.BIGINT, // 实发金额
deduct_amt: DataTypes.BIGINT, // 扣款金额
service_tax: DataTypes.BIGINT, // 服务费
project_name: DataTypes.STRING, // 项目名称
item_count: DataTypes.INTEGER, // 打款笔数
order_type: DataTypes.STRING, // 订单类型 00未设置 10平台交易 20商户交易
acc_type: DataTypes.STRING, // 打款通道 00 银行 01 支付宝 02 微信
trade_mode: DataTypes.STRING, // 打款模式 00 未选择 01 系统打款 02 手工打款
trade_status: DataTypes.STRING, // 交易状态 00 成功 01 待处理 02 失败 03 部分成功
check_status: DataTypes.STRING, // 审核状态 00 一审 01 一审失败 02 二审 03 二审失败 04 二审通过
check1_remark: DataTypes.STRING, // 一审备注
check2_remark: DataTypes.STRING, // 二审备注
pay_voucher: DataTypes.STRING, // 付款凭证 暂用此字段,以后创建交易付款
pay_bank_account: DataTypes.STRING, // 订单付款账户名称
pay_bank_name: DataTypes.STRING, // 订单付款开户银行名称
pay_bank_no: DataTypes.STRING, // 订单付款银行账户
order_file: DataTypes.STRING, // 打款文件地址
saas_id: DataTypes.STRING, // saas_id
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'st_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("storderitem", {
trade_no: DataTypes.STRING, // 打款编号
saas_merchant_id: DataTypes.STRING, // saas商户id
order_id: DataTypes.STRING, // 订单id
order_type: DataTypes.STRING, // 订单类型 00未设置 10平台交易 20商户交易
out_trade_no: DataTypes.STRING, // 商户订单号
acc_name: DataTypes.STRING, // 收款户名
acc_no: DataTypes.STRING, // 收款账号
credit_code: DataTypes.STRING, // 统一社会信用代码
open_bank: DataTypes.STRING, // 开户银行全称
amt: DataTypes.BIGINT, // 请求打款金额
actual_amt: DataTypes.BIGINT, // 实发金额
deduct_amt: DataTypes.BIGINT, // 扣款金额
service_tax: DataTypes.BIGINT, // 服务费
trade_status: DataTypes.STRING, // 交易状态 00 成功 01 待处理 02 失败
trade_time: DataTypes.DATE, // 交易时间
trade_desc: DataTypes.STRING, // 交易描述
trade_receipt: DataTypes.STRING, // 回执
remark: DataTypes.STRING, // 上传备注
saas_id: DataTypes.STRING, // saas id
saas_invoice_id: DataTypes.STRING, // 发票id
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'st_order_item',
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("stpay", {
saas_id: { type: DataTypes.STRING(32), allowNull: true, defaultValue: "", COMMENT: '订单id' },
saas_merchant_id: { type: DataTypes.STRING(32), allowNull: true, defaultValue: "", COMMENT: '商户id, 可为空' },
busi_name: { type: DataTypes.STRING(32), allowNull: true, defaultValue: "", COMMENT: '业务名称' },
busi_id: { type: DataTypes.STRING(32), allowNull: true, defaultValue: "", COMMENT: '业务id' },
pay_type: { type: DataTypes.INTEGER, allowNull: true, defaultValue: "1", COMMENT: '支付类型 1线下支付 2...' },
amount: { type: DataTypes.BIGINT, allowNull: true, defaultValue: "0", COMMENT: '支付金额' },
pay_status: { type: DataTypes.STRING(4), allowNull: true, defaultValue: "", COMMENT: '支付状态 10待支付 20已支付' },
pay_voucher_img: { type: DataTypes.STRING(300), allowNull: true, defaultValue: "", COMMENT: '支付凭证' },
trade_no: { type: DataTypes.STRING(64), allowNull: true, defaultValue: "", COMMENT: '交易流水号' },
account_info: { type: DataTypes.STRING, allowNull: true, defaultValue: "", COMMENT: '收款账户快照' }
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'st_pay',
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
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