Commit 4be6526d by zhaoxiqing

gsb

parent 60392743
......@@ -101,7 +101,9 @@ class ActionAPI extends APIBase {
break;
//资金流水
case "merchanttradesOfListAll":
opResult = await this.merchanttradeSve.merchanttradesOfListAll(action_body);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......
const Dao=require("../../dao.base");
class MerchantaccountDao extends Dao{
constructor(){
const Dao = require("../../dao.base");
class MerchantaccountDao extends Dao {
constructor() {
super(Dao.getModelName(MerchantaccountDao));
}
async addtomerchantrmb(params){
var sql = [];
sql.push("UPDATE");
sql.push(this.model.tableName);
sql.push("SET balance_amount = balance_amount+ : amount");
sql.push("AND available_amount = available_amount + :available_amount");
sql.push("WHERE merchant_id = :merchant_id")
return await this.customQuery(sql.join(" "), params);
}
}
module.exports=MerchantaccountDao;
module.exports = MerchantaccountDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class MerchantapiDao extends Dao {
constructor() {
super(Dao.getModelName(MerchantapiDao));
}
}
module.exports = MerchantapiDao;
const Dao=require("../../dao.base");
class merchanttradeDao extends Dao{
constructor(){
const Dao = require("../../dao.base");
class merchanttradeDao extends Dao {
constructor() {
super(Dao.getModelName(merchanttradeDao));
}
}
module.exports=merchanttradeDao;
module.exports = merchanttradeDao;
......@@ -20,15 +20,45 @@ module.exports = (db, DataTypes) => {
audit_remark: DataTypes.STRING,
audit_user_id: DataTypes.STRING,
}, {
paranoid: false,//假的删除
},{
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
timestamps: true,
updatedAt: false,
//freezeTableName: true,
// define the table's name
tableName: 'e_merchant',
validate: {},
indexes: []
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}]
// }
],
});
}
......@@ -3,15 +3,45 @@ module.exports = (db, DataTypes) => {
merchant_id: DataTypes.STRING,
balance_amount: DataTypes.BIGINT,
available_amount: DataTypes.BIGINT,
}, {
paranoid: false,//假的删除
},{
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
timestamps: true,
updatedAt: false,
//freezeTableName: true,
// define the table's name
tableName: 'e_merchant_account',
validate: {},
indexes: []
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}]
// }
],
});
}
module.exports = (db, DataTypes) => {
return db.define("merchantapi", {
secret: DataTypes.STRING,
ip: DataTypes.TINYINT,
},{
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'e_merchant_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}]
// }
],
});
}
......@@ -13,15 +13,45 @@ module.exports = (db, DataTypes) => {
audit_user_id: DataTypes.STRING,
balance_amount: DataTypes.BIGINT,
available_amount: DataTypes.BIGINT,
}, {
paranoid: false,//假的删除
},{
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
timestamps: true,
updatedAt: false,
//freezeTableName: true,
// define the table's name
tableName: 'e_merchant_trade',
validate: {},
indexes: []
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 ServiceBase = require("../../sve.base");
const system = require("../../../system");
class MerchantService extends ServiceBase {
constructor() {
super("merchant", ServiceBase.getDaoName(MerchantService));
this.redisClient = system.getObject("util.redisClient");
this.merchantapiSve = system.getObject("service.merchant.merchantapiSve");
}
async addModifyMerchants(params) {
try {
if (!params.name) {
......@@ -53,16 +56,19 @@ class MerchantService extends ServiceBase {
if (!params.bd_email) {
return system.getResultFail(-1, "请提供客户经理Email");
}
var id = await this.redisClient.genrateId("e_merchant");
var merchant = null;
if (params.id) {
merchant = await this.service.findById(params.id);
merchant = await this.dao.findById(params.id);
}
var rtn = null;
if (merchant) {
rtn = await this.service.update(params)
rtn = await this.dao.update(params)
} else {
rtn = await this.service.create(params);
params.id = id;
rtn = await this.dao.create(params);
var secret = await this.getUidInfo(32);
this.merchantapiSve.create({id: id, secret: secret});
}
return system.getResultSuccess(rtn);
} catch (e) {
......@@ -80,10 +86,10 @@ class MerchantService extends ServiceBase {
var where = {};
if (params.name) {
where.name = {
[this.db.Op.like]: params.name
[this.db.Op.like]: "%" + params.name + "%"
};
}
this.addWhereTime(where, 'completed_at', params.beginTime, params.entTime, true);
this.addWhereTime(where, 'created_at', params.beginTime, params.entTime, true);
var orderby = [["id", 'desc']];
var attributes = [`id`, `name`, `credit_code`, `contact_man`, `contact_mobile`, `contact_email`, `account_name`, `audit_status`];
var page = await this.getPageList(currentPage, pageSize, where, orderby, attributes);
......@@ -111,7 +117,7 @@ class MerchantService extends ServiceBase {
return system.getResultFail(-1, "请输入失败原因");
}
var rtn = await this.service.update(params);
var rtn = await this.dao.update(params);
return system.getResultSuccess(rtn);
} catch (e) {
......@@ -122,7 +128,7 @@ class MerchantService extends ServiceBase {
async merchantSuggest(params) {
try {
return await this.dao.suggest(name);
return await this.dao.suggest(params.name);
} catch (e) {
console.log(e);
return system.getResultFail();
......
......@@ -5,6 +5,14 @@ class MerchantaccountService extends ServiceBase {
super("merchant", ServiceBase.getDaoName(MerchantaccountService));
}
async addtomerchantrmb(merchant_id,amount){
var params = {
merchant_id :merchant_id,
amount :amount
}
return this.dao.addtomerchantrmb(params)
}
}
module.exports = MerchantaccountService;
const ServiceBase = require("../../sve.base");
class merchantapiService extends ServiceBase {
constructor() {
super("merchant", ServiceBase.getDaoName(merchantapiService));
}
}
module.exports = merchantapiService;
const ServiceBase = require("../../sve.base");
const system = require("../../../system");
const moment = require('moment');
class MerchanttradeService extends ServiceBase {
constructor() {
super("merchant", ServiceBase.getDaoName(MerchanttradeService));
this.merchantaccountSve = system.getObject("service.merchant.merchantaccountSve");
}
async addMerchanttrades(params) {
try {
if (!params.merchant_id) {
return system.getResultFail(-1, "请选择商户");
}
if (!params.trade_time) {
return system.getResultFail(-1, "请选择交易时间");
}
if (!params.amount) {
return system.getResultFail(-1, "请提供交易金额");
} else if (0 > params.amount) {
return system.getResultFail(-1, "交易金额错误");
}
if (!params.trade_voucher) {
return system.getResultFail(-1, "请上传交易凭证");
}
params.trade_type = 1; //线下充值
params.pay_type = 2; //线下支付
params.amount_type = 1;//后入
params.trade_data_id = moment().format("YYYYMMDDHHmmss");
params.amount = params.amount * 100;
var accountamount = await this.merchantaccountSve.findOne({merchant_id: params.merchant_id})
params.available_amount = params.amount;
params.balance_amount = params.amount;
if (accountamount) {
params.available_amount = params.amount + accountamount.available_amount;
params.balance_amount = params.available_amount;
}
var rtn = await this.dao.create(params);
return system.getResultSuccess(rtn);
} catch (e) {
console.log(e);
return system.getResultFail();
......@@ -16,7 +47,27 @@ class MerchanttradeService extends ServiceBase {
async merchanttradesOfList(params) {
try {
var currentPage = Number(params.currentPage || 0);
var pageSize = Number(params.pageSize || 10);
var where = {};
if (params.merchant_id) {
where.merchant_id = {
[this.db.Op.eq]: params.merchant_id
};
}
where.trade_type = {
[this.db.Op.eq]: 1
};
this.addWhereTime(where, 'created_at', params.beginTime, params.entTime, true);
var orderby = [["id", 'desc']];
var attributes = [`id`, `trade_time`, `amount`, `audit_status`, `audit_remark`];
var page = await this.getPageList(currentPage, pageSize, where, orderby, attributes);
if (page && page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["trade_time"], null);
}
}
return system.getResultSuccess(page);
} catch (e) {
console.log(e);
return system.getResultFail();
......@@ -25,7 +76,64 @@ class MerchanttradeService extends ServiceBase {
async auditMerchanttrade(params) {
try {
if (!params.id) {
return system.getResultFail(-1, "请提供ID");
}
if (params.audit_status == 0) {
return system.getResultFail(-1, "请选择审核状态");
}
if (params.audit_status == 2 && !params.audit_remark) {
return system.getResultFail(-1, "请输入失败原因");
}
var rtn = await this.dao.update(params);
var trades = await this.dao.findById(params.id);
var account = await this.merchantaccountSve.findOne({merchant_id: trades.merchant_id});
if (account && params.audit_status == 1) {
this.merchantaccountSve.addtomerchantrmb(trades.merchant_id, trades.amount);
} else {
await this.merchantaccountSve.create({
merchant_id: trades.merchant_id,
balance_amount: trades.amount,
available_amount: trades.amount
});
}
return system.getResultSuccess(rtn);
} catch (e) {
console.log(e);
return system.getResultFail();
}
}
async merchanttradesOfListAll(params) {
try {
var currentPage = Number(params.currentPage || 0);
var pageSize = Number(params.pageSize || 10);
var where = {};
if (params.merchant_id) {
where.merchant_id = {
[this.db.Op.eq]: params.merchant_id
};
}
if (params.amount_type) {
where.amount_type = {
[this.db.Op.eq]: params.amount_type
};
}
this.addWhereTime(where, 'created_at', params.beginTime, params.entTime, true);
var orderby = [["id", 'desc']];
var attributes = [];
var page = await this.getPageList(currentPage, pageSize, where, orderby, attributes);
if (page && page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["trade_time"], null);
}
}
return system.getResultSuccess(page);
} catch (e) {
console.log(e);
return system.getResultFail();
......
......@@ -14,11 +14,11 @@ var settings={
// port: 3306,
host: '43.247.184.35',
port: 8899,
timezone: '+08:00',
dialect: 'mysql',
operatorsAliases: false,
pool: {
max: 5,
max: 100,
min: 0,
acquire: 90000000,
idle: 1000000
......
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