Commit 7c134b32 by 王昆

gsb

parent 6261af9b
node_modules/ node_modules/
.idea/ .idea/
bpo-auth/node_modules/ bpo-fee/node_modules/
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"type": "node", "type": "node",
"request": "launch", "request": "launch",
"name": "Launch Program", "name": "Launch Program",
"program": "${workspaceFolder}/bpo-auth/main.js" "program": "${workspaceFolder}/bpo-fee/main.js"
} }
] ]
} }
\ No newline at end of file
#!/bin/bash #!/bin/bash
FROM registry.cn-beijing.aliyuncs.com/hantang2/node105:v2 FROM registry.cn-beijing.aliyuncs.com/hantang2/node105:v2
MAINTAINER jy "jiangyong@gongsibao.com" MAINTAINER jy "jiangyong@gongsibao.com"
ADD bpo-auth /apps/bpo-auth/ ADD bpo-fee /apps/bpo-fee/
WORKDIR /apps/bpo-auth/ WORKDIR /apps/bpo-fee/
RUN cnpm install -S RUN cnpm install -S
CMD ["node","/apps/bpo-auth/main.js"] CMD ["node","/apps/bpo-fee/main.js"]
......
...@@ -4,7 +4,7 @@ var settings = require("../../../../config/settings"); ...@@ -4,7 +4,7 @@ var settings = require("../../../../config/settings");
class ActionAPI extends APIBase { class ActionAPI extends APIBase {
constructor() { constructor() {
super(); super();
this.storderSve = system.getObject("service.trade.storderSve"); this.accountSve = system.getObject("service.account.accountSve");
} }
/** /**
* 接口跳转 * 接口跳转
...@@ -34,7 +34,33 @@ class ActionAPI extends APIBase { ...@@ -34,7 +34,33 @@ class ActionAPI extends APIBase {
switch (action_type) { switch (action_type) {
// 测试 // 测试
case "test": case "test":
opResult = await this.storderSve.test(action_body); opResult = await this.accountSve.test(action_body);
break;
// 创建账户
case "accountCreate":
opResult = await this.accountSve.createAccount(action_body);
break;
// 账户余额查询
case "accountInfo":
opResult = await this.accountSve.accountInfo(action_body);
break;
// 账户充值
case "accountRecharge":
opResult = await this.accountSve.accountRecharge(action_body);
break;
// 账户充值
case "accountRefund":
opResult = await this.accountSve.accountRefund(action_body);
break;
case "accountTrade":
opResult = await this.accountSve.accountTrade(action_body);
break;
case "accountTradePage":
opResult = await this.accountSve.accountTradePage(action_body);
break;
// 账户交易
case "test4":
opResult = await this.accountSve.test(action_body);
break; break;
default: default:
opResult = system.getResult(null, "action_type参数错误"); opResult = system.getResult(null, "action_type参数错误");
......
const system = require("../../../system");
const Dao = require("../../dao.base");
class AccountDao extends Dao {
constructor() {
super(Dao.getModelName(AccountDao));
}
async incrementBalance(id, balance, t) {
let sql = [];
sql.push("UPDATE");
sql.push(this.model.tableName);
sql.push("SET");
sql.push("balance = balance + :balance");
sql.push("WHERE id = :id AND balance + :balance >= 0");
let res = await this.customUpdate(sql.join(" "), {id: id, balance: balance}, t);
console.log(res);
if (res.length < 2) {
return 0;
}
return res[1] || 0;
}
async listByIds(ids, attrs) {
if (!ids || ids.length == 0) {
return [];
}
var sql = [];
sql.push("SELECT");
sql.push(attrs || "*");
sql.push("FROM");
sql.push(this.model.tableName);
sql.push("WHERE id IN (:ids)");
return await this.customQuery(sql.join(" "), {
ids: ids
}) || [];
}
async mapByIds(ids, attrs) {
var result = {};
if (!ids || ids.length == 0) {
return result;
}
var list = await this.findListByIds(ids, attrs);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.id] = item;
}
return result;
}
}
module.exports = AccountDao;
const system = require("../../../system"); const system = require("../../../system");
const Dao = require("../../dao.base"); const Dao = require("../../dao.base");
class StOrderDao extends Dao { class AccountTradeDao extends Dao {
constructor() { constructor() {
super(Dao.getModelName(StOrderDao)); super(Dao.getModelName(AccountTradeDao));
} }
async listByIds(ids, attrs) { async listByIds(ids, attrs) {
...@@ -74,35 +74,23 @@ class StOrderDao extends Dao { ...@@ -74,35 +74,23 @@ class StOrderDao extends Dao {
if (!params || !sql) { if (!params || !sql) {
return; return;
} }
if (params.saas_id) { if (params.account_id) {
sql.push("AND saas_id = :saas_id"); sql.push("AND account_id = :account_id");
} }
if (params.saas_merchant_id) { if (params.trade_no) {
sql.push("AND saas_merchant_id = :saas_merchant_id"); sql.push("AND trade_no = :trade_no");
} }
if (params.saas_merchant_ids) { if (params.trade_type) {
sql.push("AND saas_merchant_id IN (:saas_merchant_ids)"); sql.push("AND trade_type = :trade_type");
} }
if (params.out_trade_no) { if (params.tradeTimeBegin) {
sql.push("AND out_trade_no = :out_trade_no"); sql.push("AND created_at >= :tradeTimeBegin");
} }
if (params.trade_status) { if (params.tradeTimeEnd) {
sql.push("AND trade_status = :trade_status"); sql.push("AND created_at <= :tradeTimeEnd");
}
if (params.check_status) {
sql.push("AND check_status = :check_status");
}
if (params.acc_type) {
sql.push("AND acc_type = :acc_type");
}
if (params.createBegin) {
sql.push("AND created_at >= :createBegin");
}
if (params.createEnd) {
sql.push("AND created_at <= :createEnd");
} }
} }
} }
module.exports = StOrderDao; module.exports = AccountTradeDao;
...@@ -2,30 +2,10 @@ const system = require("../../../system"); ...@@ -2,30 +2,10 @@ const system = require("../../../system");
const settings = require("../../../../config/settings"); const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey); const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => { module.exports = (db, DataTypes) => {
return db.define("storder", { return db.define("account", {
saas_merchant_id: DataTypes.STRING, // saas商户id app_id: DataTypes.STRING, // 应用id
out_trade_no: DataTypes.STRING, // 商户订单号 app_data_id: DataTypes.STRING, // 应用数据id
service_rate: DataTypes.INTEGER, // 商户订单号 balance: DataTypes.BIGINT, // 账户余额
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, //假的删除 paranoid: true, //假的删除
underscored: true, underscored: true,
...@@ -33,7 +13,7 @@ module.exports = (db, DataTypes) => { ...@@ -33,7 +13,7 @@ module.exports = (db, DataTypes) => {
freezeTableName: true, freezeTableName: true,
//freezeTableName: true, //freezeTableName: true,
// define the table's name // define the table's name
tableName: 'st_order', tableName: 'be_account',
validate: {}, validate: {},
indexes: [ indexes: [
// Create a unique index on email // Create a unique index on email
......
const system = require("../../../system");
const settings = require("../../../../config/settings");
const uiconfig = system.getUiConfig2(settings.appKey);
module.exports = (db, DataTypes) => {
return db.define("accounttrade", {
account_id: DataTypes.BIGINT, // 应用id
trade_type: DataTypes.INTEGER, // 交易类型 1账户交易 2消费交易
trade_no: DataTypes.STRING, // 交易流水号
trade_amt: DataTypes.BIGINT, // 交易金额
trade_desc: DataTypes.STRING, // 交易描述
}, {
paranoid: true, //假的删除
underscored: true,
version: true,
freezeTableName: true,
//freezeTableName: true,
// define the table's name
tableName: 'be_account_trade',
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("../../sve.base")
class AccountService extends ServiceBase {
constructor() {
super("account", ServiceBase.getDaoName(AccountService));
this.accounttradeDao = system.getObject("db.account.accounttradeDao");
this.dictionary = system.getObject("util.dictionary");
}
async createAccount(params) {
let app_id = this.trim(params.app_id);
let app_data_id = this.trim(params.app_data_id);
let apps = this.dictionary.getDict("APP", "app_id") || {};
if (!apps[app_id]) {
return system.getResult(null, `非法的app_id[${app_id}]`);
}
if (!app_data_id) {
return system.getResult(null, `请输入app_data_id[${app_data_id}]`);
}
let account = await this.dao.findOne({app_id: app_id, app_data_id: app_data_id});
if (account) {
return system.getResult(null, `app_id[${app_id}],app_data_id[${app_data_id}]账户已创建,请不要重复创建`);
}
account = await this.dao.create({
autoIncrement: true,
app_id: app_id,
app_data_id: app_data_id,
balance: 0,
});
return system.getResultSuccess({account_id: account.id});
}
async accountInfo(params) {
let account = await this.dao.getById(params.account_id);
return system.getResultSuccess(account);
}
async accountRecharge(params) {
let p = {trade_type: 2};
p.account_id = params.account_id;
p.trade_amt = Number(params.trade_amt);
p.trade_no = this.trim(params.trade_no);
p.trade_desc = params.trade_desc || "充值";
try {
return await this.trade(p);
} catch (e) {
console.log(e);
return system.getResult(null, "交易错误");
}
}
async accountRefund(params) {
let p = {trade_type: 3};
p.account_id = params.account_id;
p.trade_amt = Number(params.trade_amt);
p.trade_no = this.trim(params.trade_no);
p.trade_desc = params.trade_desc || "退款";
try {
return await this.trade(p);
} catch (e) {
console.log(e);
return system.getResult(null, "交易错误");
}
}
async accountTrade(params) {
let p = {trade_type: 1};
p.account_id = params.account_id;
p.trade_amt = Number(params.trade_amt);
p.trade_no = this.trim(params.trade_no);
p.trade_desc = params.trade_desc || "消费";
try {
return await this.trade(p);
} catch (e) {
console.log(e);
return system.getResult(null, "交易错误");
}
}
async trade(params) {
let accountId = params.account_id;
let trade_no = this.trim(params.trade_no);
let trade_type = params.trade_type;
let trade_amt = Number(params.trade_amt || 0);
if (trade_amt < 0) {
return system.getResult(null, "金额不能为负数");
}
let balance_amt = trade_type == 2 ? trade_amt : -1 * trade_amt;
let trade_desc = params.trade_desc;
if(!accountId) {
return system.getResult(null, "account_id不存在");
}
if(!trade_no) {
return system.getResult(null, "交易流水号不存在");
}
if(!trade_desc) {
return system.getResult(null, "请填写交易描述信息");
}
let _trade = await this.accounttradeDao.findOne({
account_id: accountId,
trade_type: trade_type,
trade_no: trade_no,
});
if (_trade) {
return system.getResult(null, `账户[${accountId}]已存在交易流水号[${trade_no}]`);
}
let res = await this.db.transaction(async t => {
//更新oorder订单记录
let bres = await this.dao.incrementBalance(accountId, balance_amt, t);
console.log(bres);
if (bres === 0) {
return system.getResult(null, "余额不足");
}
//创建orderdeliver记录
await this.accounttradeDao.create({
account_id: accountId,
trade_type: trade_type,
trade_no: trade_no,
trade_amt: trade_amt,
trade_desc: trade_desc,
}, t);
return system.getResultSuccess();
});
return res;
}
async accountTradePage(params) {
if (!params.account_id) {
return {count: 0, rows: []};
}
return await this.tradePageByCondition(params);
}
async tradePageByCondition(params) {
let page = {
count: 0,
rows: []
}
params.currentPage = Number(params.currentPage || 1);
params.pageSize = Number(params.pageSize || 10);
params.startRow = (params.currentPage - 1) * params.pageSize;
page.count = await this.accounttradeDao.countByCondition(params);
if (page.count == 0) {
return system.getResultSuccess(page);
}
page.rows = await this.accounttradeDao.listByCondition(params);
this.dictionary.setRowsName("ACCOUNT_TRADE", page.rows, ["trade_type"]);
this.handleRowsDate(page.rows, ["created_at", "updated_at"]);
return system.getResultSuccess(page);
}
async test(params) {
return system.getResultSuccess("test");
}
}
module.exports = AccountService;
// 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("../../sve.base")
class AccountTradeService extends ServiceBase {
constructor() {
super("account", ServiceBase.getDaoName(AccountTradeService));
this.dictionary = system.getObject("util.dictionary");
}
async test(params) {
return system.getResultSuccess("test");
}
}
module.exports = AccountTradeService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
\ No newline at end of file
...@@ -240,6 +240,15 @@ class ServiceBase { ...@@ -240,6 +240,15 @@ class ServiceBase {
} }
} }
} }
handleRowsDate(rows, fields, pattern, addHours) {
pattern = pattern || "YYYY-MM-DD HH:mm:ss";
if (!rows) {
return;
}
for (let row of rows) {
this.handleDate(row, fields, pattern, addHours)
}
}
addWhereTime(where, field, begin, end) { addWhereTime(where, field, begin, end) {
if(!begin && !end) { if(!begin && !end) {
......
...@@ -3,16 +3,12 @@ const system = require("../system"); ...@@ -3,16 +3,12 @@ const system = require("../system");
class Dictionary { class Dictionary {
constructor() { constructor() {
// 交易字典 // 交易字典
this.ORDER = { this.APP = {
order_type: {"00": "未设置", "10": "平台交易", "20": "商户交易"}, app_id: {"100001": "电子平台", "10000x": "xxxxxxxxxx"},
acc_type: {"00": "银行", "01": "支付宝", "02": "微信"}, };
trade_mode: {"00": "未设置", "01": "系统打款", "02": "手工打款"}, this.ACCOUNT_TRADE = {
trade_status: {"00": "成功", "01": "待处理", "02": "失败", "03": "部分成功"}, trade_type: {1: "交易", 2: "充值", 3: "退款"}
check_status: {"00": "待处理", "01": "一审", "02": "一审失败", "03": "二审", "04": "二审失败", "05": "审核通过"},
}; };
this.ORDER_ITEM = {
trade_status: {"00": "成功", "01": "待处理", "02": "失败"}
}
} }
getDict(module, field) { getDict(module, field) {
......
...@@ -29,6 +29,7 @@ module.exports = function (app) { ...@@ -29,6 +29,7 @@ module.exports = function (app) {
res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild, xggadminsid'); res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild, xggadminsid');
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS'); res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
res.header('content-type', 'text/html;charset=UTF-8');
// res.header('Access-Control-Allow-Credentials', 'true'); // res.header('Access-Control-Allow-Credentials', 'true');
if (req.method == 'OPTIONS') { if (req.method == 'OPTIONS') {
res.send(200); //让options请求快速返回/ res.send(200); //让options请求快速返回/
......
...@@ -6,7 +6,7 @@ var settings={ ...@@ -6,7 +6,7 @@ var settings={
db:10, db:10,
}, },
database:{ database:{
dbname : "xgg-trade", dbname : "bpo_fee",
user: "write", user: "write",
password: "write", password: "write",
config: { config: {
......
...@@ -4,11 +4,11 @@ var ENVINPUT = { ...@@ -4,11 +4,11 @@ var ENVINPUT = {
DB_PORT: process.env.DB_PORT, DB_PORT: process.env.DB_PORT,
DB_USER: process.env.DB_USER, DB_USER: process.env.DB_USER,
DB_PWD: process.env.DB_PWD, DB_PWD: process.env.DB_PWD,
DB_NAME: process.env.BPOAUTH_DB_NAME, DB_NAME: process.env.BPOFEE_DB_NAME,
REDIS_HOST: process.env.REDIS_HOST, REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT, REDIS_PORT: process.env.REDIS_PORT,
REDIS_PWD: process.env.REDIS_PWD, REDIS_PWD: process.env.REDIS_PWD,
REDIS_DB: process.env.BPOAUTH_REDIS_DB, REDIS_DB: process.env.BPOFEE_REDIS_DB,
APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev" APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev"
}; };
...@@ -21,7 +21,7 @@ var settings = { ...@@ -21,7 +21,7 @@ var settings = {
cacheprefix: "sjb", cacheprefix: "sjb",
usertimeout: 3600, //单位秒 usertimeout: 3600, //单位秒
basepath: path.normalize(path.join(__dirname, '../..')), basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 3110, port: process.env.NODE_PORT || 3300,
defaultPassWord: "987456", defaultPassWord: "987456",
paasUrl: function () { paasUrl: function () {
if (this.env == "dev") { if (this.env == "dev") {
......
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