Commit 6261af9b by 王昆

gsb

parent c8a8a5d2
node_modules/
.idea/
xggsve-trade/node_modules/
bpo-auth/node_modules/
......@@ -8,7 +8,7 @@
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/xggsve-trade/main.js"
"program": "${workspaceFolder}/bpo-auth/main.js"
}
]
}
\ No newline at end of file
#!/bin/bash
FROM registry.cn-beijing.aliyuncs.com/hantang2/node105:v2
MAINTAINER jy "jiangyong@gongsibao.com"
ADD xggsve-trade /apps/xggsve-trade/
WORKDIR /apps/xggsve-trade/
ADD bpo-auth /apps/bpo-auth/
WORKDIR /apps/bpo-auth/
RUN cnpm install -S
CMD ["node","/apps/xggsve-trade/main.js"]
CMD ["node","/apps/bpo-auth/main.js"]
......
......@@ -5,8 +5,6 @@ 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");
}
/**
* 接口跳转
......@@ -34,70 +32,10 @@ class ActionAPI extends APIBase {
async handleRequest(action_process, action_type, action_body) {
var opResult = null;
switch (action_type) {
// 图片验证码
// 测试
case "test":
opResult = await this.storderSve.test(action_body);
break;
case "orderPage":
opResult = await this.storderSve.pageByCondition(action_body);
break;
case "orderAdd":
opResult = await this.storderSve.saveOrder(action_body);
break;
case "orderInfo":
opResult = await this.storderSve.info(action_body);
break;
case "orderPay":
opResult = await this.storderSve.pay(action_body);
break;
case "orderAudit1":
opResult = await this.storderSve.audit1(action_body);
break;
case "orderAudit2":
opResult = await this.storderSve.audit2(action_body);
break;
case "orderTrade":
opResult = await this.storderSve.trade(action_body);
break;
break;
case "itemPage":
opResult = await this.storderitemSve.pageByCondition(action_body);
break;
case "itemTradeOfflineCB":
opResult = await this.storderitemSve.tradeOfflineCB(action_body);
break;
case "itemByIds":
opResult = await this.storderitemSve.byIds(action_body);
break;
case "itemByInvoiceId":
opResult = await this.storderitemSve.bySaasInvoiceId(action_body);
break;
case "updateItemInvoice":
opResult = await this.storderitemSve.updateInvoice(action_body);
break;
case "cancelItemInvoice":
opResult = await this.storderitemSve.cancelInvoice(action_body);
break;
case "cancelInvoiceByDataIds":
opResult = await this.storderitemSve.cancelInvoiceByDataIds(action_body);
break;
case "invoiceTrade":
opResult = await this.storderitemSve.invoiceTrade(action_body);
break;
case "saveStPay":
opResult = await this.stpaySve.saveStPay(action_body);
break;
case "mapByBusiIds":
opResult = await this.stpaySve.mapByBusiIds(action_body);
break;
case "updateStatus":
opResult = await this.stpaySve.updateStatus(action_body);
break;
case "tradeItemBycreditCode":
opResult = await this.storderitemSve.tradeItemBycreditCode(action_body);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
class StOrderService extends ServiceBase {
constructor() {
super("trade", ServiceBase.getDaoName(StOrderService));
this.dictionary = system.getObject("util.dictionary");
}
async test(params) {
return system.getResultSuccess("test");
}
}
module.exports = StOrderService;
// var task=new UserService();
// task.getUserStatisticGroupByApp().then(function(result){
// console.log((result));
// }).catch(function(e){
// console.log(e);
// });
\ No newline at end of file
......@@ -4,11 +4,11 @@ var ENVINPUT = {
DB_PORT: process.env.DB_PORT,
DB_USER: process.env.DB_USER,
DB_PWD: process.env.DB_PWD,
DB_NAME: process.env.XGGSVETRADE_DB_NAME,
DB_NAME: process.env.BPOAUTH_DB_NAME,
REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT,
REDIS_PWD: process.env.REDIS_PWD,
REDIS_DB: process.env.XGGSVETRADE_REDIS_DB,
REDIS_DB: process.env.BPOAUTH_REDIS_DB,
APP_ENV: process.env.APP_ENV ? process.env.APP_ENV : "dev"
};
......@@ -21,7 +21,7 @@ var settings = {
cacheprefix: "sjb",
usertimeout: 3600, //单位秒
basepath: path.normalize(path.join(__dirname, '../..')),
port: process.env.NODE_PORT || 3107,
port: process.env.NODE_PORT || 3110,
defaultPassWord: "987456",
paasUrl: function () {
if (this.env == "dev") {
......
{
"name": "xggsve-trade",
"name": "bpo-auth",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
......
{
"name": "xggsve-trade",
"name": "bpo-auth",
"version": "1.0.0",
"description": "h5framework",
"main": "main.js",
......
const system = require("../../../system");
const Dao = require("../../dao.base");
class StOrderItemDao extends Dao {
constructor() {
super(Dao.getModelName(StOrderItemDao));
}
async byIds(params) {
let attrs = params.attrs || "*";
let ids = params.ids;
if (!ids || ids.length == 0) {
return [];
}
let sql = [];
sql.push("SELECT");
sql.push(attrs);
sql.push("FROM");
sql.push(this.model.tableName);
sql.push("WHERE id IN (:ids) ");
if (params.trade_statuses && params.trade_statuses.length > 0) {
sql.push("AND trade_status IN (:trade_statuses)");
}
if (params.saas_merchant_id) {
sql.push("AND saas_merchant_id IN (:saas_merchant_id)");
}
if (params.unInvoice) {
sql.push("AND saas_invoice_id = ''");
}
if (params.order_type) {
sql.push("AND order_type = :order_type");
}
return await this.customQuery(sql.join(" "), params);
}
async bySaasInvoiceId(params) {
let attrs = params.attrs || "*";
let sql = [];
sql.push("SELECT");
sql.push(attrs);
sql.push("FROM");
sql.push(this.model.tableName);
sql.push("WHERE saas_invoice_id = :saas_invoice_id ");
return await this.customQuery(sql.join(" "), params);
}
async updateTrade(params, t) {
let sql = "UPDATE st_order_item SET trade_time = :trade_time, trade_status = '00', trade_desc = :trade_desc WHERE id IN (:ids) AND trade_status = '01' ";
await this.customUpdate(sql, params, t);
}
async updateTradeByOrderId(orderId, tradeStatus, t) {
let sql = "UPDATE st_order_item SET trade_status = :tradeStatus WHERE order_id = :orderId";
await this.customUpdate(sql, {orderId: orderId, tradeStatus: tradeStatus}, t);
}
async updateInvoice(params, t) {
let sql = "UPDATE st_order_item SET saas_invoice_id = :saas_invoice_id WHERE id IN (:ids) ";
await this.customUpdate(sql, params, t);
}
async cancelInvoice(params, t) {
let sql = "UPDATE st_order_item SET saas_invoice_id = '' WHERE saas_invoice_id = :saas_invoice_id ";
await this.customUpdate(sql, params, t);
}
async cancelInvoiceByDataIds(params, t) {
let sql = "UPDATE st_order_item SET saas_invoice_id = '' WHERE id in (:data_ids) ";
await this.customUpdate(sql, params, t);
}
async countItems(params, t) {
let sql = "SELECT count(1) AS num FROM st_order_item WHERE order_id = :order_id AND trade_status = :trade_status";
let list = await this.customQuery(sql, params, t);
if (!list || list.length == 0) {
return 0;
}
return list[0].num || 0;
}
async listByIds(ids, attrs) {
if (!ids || ids.length == 0) {
return [];
}
let 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) {
let result = {};
if (!ids || ids.length == 0) {
return result;
}
let list = await this.findListByIds(ids, attrs);
if (!list || list.length == 0) {
return result;
}
for (var item of list) {
result[item.id] = item;
}
return result;
}
async genTradeNo(orderId, t) {
let sql = `UPDATE ${this.model.tableName} SET trade_no = CONCAT('T', id, SUBSTR(order_id, LENGTH(order_id) - 2, 4), SUBSTRING(REPLACE(RAND(),'.',''),3,4)) WHERE order_id = :orderId`;
return await this.customUpdate(sql, {orderId: orderId}, t);
}
async countByCondition(params) {
var sql = [];
sql.push("SELECT");
sql.push("count(1) as num");
sql.push("FROM");
sql.push(this.model.tableName);
sql.push("WHERE deleted_at IS NULL");
this.setCondition(sql, params);
let list = await this.customQuery(sql.join(" "), params);
if (!list || list.length == 0) {
return 0;
}
return list[0].num;
}
async listByCondition(params) {
params.startRow = Number(params.startRow || 0);
params.pageSize = Number(params.pageSize || 10);
let sql = [];
sql.push("SELECT");
sql.push(params.attrs || "*");
sql.push("FROM");
sql.push(this.model.tableName);
sql.push("WHERE deleted_at IS NULL");
this.setCondition(sql, params);
sql.push("ORDER BY created_at DESC");
sql.push("LIMIT :startRow, :pageSize");
return await this.customQuery(sql.join(" "), params);
}
setCondition(sql, params) {
if (!params || !sql) {
return;
}
if (params.saas_id) {
sql.push("AND saas_id = :saas_id");
}
if (params.saas_merchant_id) {
sql.push("AND saas_merchant_id = :saas_merchant_id");
}
if (params.order_id) {
sql.push("AND order_id = :order_id");
}
if (params.order_type) {
sql.push("AND order_type = :order_type");
}
if (params.saas_merchant_ids) {
sql.push("AND saas_merchant_id IN (:saas_merchant_ids)");
}
if (params.out_trade_no) {
sql.push("AND out_trade_no = :out_trade_no");
}
if (params.trade_status) {
sql.push("AND trade_status = :trade_status");
}
if (params.trade_status_array) {
sql.push("AND trade_status in (:trade_status_array)");
}
if (params.acc_name) {
params.acc_name_like = `%${params.acc_name}%`;
sql.push("AND acc_name LIKE :acc_name_like");
}
if (params.acc_no) {
sql.push("AND acc_no = :acc_no");
}
if (params.credit_code) {
sql.push("AND credit_code = :credit_code");
}
if(params.credit_code_array){
sql.push("AND credit_code in (:credit_code_array)");
}
if (params.createBegin) {
sql.push("AND created_at >= :createBegin");
}
if (params.createEnd) {
sql.push("AND created_at <= :createEnd");
}
if (params.unInvoice) {
sql.push("AND saas_invoice_id = ''");
}
if (params.saas_invoice_id) {
sql.push("AND saas_invoice_id = :saas_invoice_id");
}
if(params.data_ids && params.data_ids.length>0){
sql.push("AND id in (:data_ids)");
}
}
async invoiceTrade(params){
let sql = [];
sql.push(`select * from st_order_item `);
sql.push("WHERE deleted_at IS NULL and 1=1 ");
this.setCondition(sql, params);
sql.push("ORDER BY created_at DESC");
sql.push("LIMIT :startRow, :pageSize");
return await this.customQuery(sql.join(" "), params);
}
}
module.exports = StOrderItemDao;
const system = require("../../../system");
const Dao = require("../../dao.base");
class StPayDao extends Dao {
constructor() {
super(Dao.getModelName(StPayDao));
}
}
module.exports = StPayDao;
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
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
class DeliverService extends ServiceBase {
constructor() {
super("deliver", ServiceBase.getDaoName(DeliverService));
this.deliveruserDao = system.getObject("db.deliver.deliveruserDao");
this.deliverorgDao = system.getObject("db.deliver.deliverorgDao");
}
async apiAll(params) {
try {
return await this.allList();
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiPage(params) {
try {
return await this.page(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiSave(params) {
try {
return await this.save(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiInfo(params) {
try {
return await this.info(params);
} catch (error) {
console.log(error);
return system.getResult(null, "接口异常");
}
}
async apiDeleteByIds(params) {
var ids = params.ids;
if (!ids || ids.length == 0) {
return system.getResult(null, "传入参数错误:ids=" + JSON.stringify(ids));
}
try {
for (var id of ids) {
try {
await this.delById(id);
} catch (error) {
console.log(error);
}
}
return system.getResultSuccess(1);
} catch (error) {
return system.getResult(null, "接口异常");
}
}
// -----------------------以此间隔,上面为API,下面为service---------------------------------
async info(params) {
let id = params.id;
let item = await this.dao.getById(id);
this.handleDate(item, ["created_at"], null, -8);
let user = await this.deliveruserDao.getById(item.admin_id);
if (user) {
user.password = "";
item.real_name = user.real_name || "";
item.ucname = user.ucname || "";
item.user = user;
}
return system.getResultSuccess(item);
}
async login(params) {
let ucname = this.trim(params.ucname);
let password = this.trim(params.password);
let loginUser = await this.deliveruserDao.findByUcname(ucname);
if (!loginUser) {
return system.getResult(null, "用户名或密码错误");
}
let pwd = await this.getEncryptStr(password);
if (pwd != loginUser.password) {
return system.getResult(null, "用户名或密码错误");
}
loginUser.password = "";
loginUser.deliver = await this.dao.getById(loginUser.deliver_id) || {};
loginUser.isManager = loginUser.deliver.admin_id == loginUser.id;
this.setAuth(loginUser);
return system.getResultSuccess(loginUser);
}
async save(params) {
let id = params.id;
let deliver;
let user;
if (id) {
deliver = await this.dao.findById(id);
if (deliver.admin_id) {
user = await this.deliveruserDao.findById(deliver.admin_id);
}
} else {
deliver = {};
}
if (!user) {
let exists = await this.deliveruserDao.findOne({ ucname: params.ucname });
if (exists) {
return system.getResult(null, `用户名【${params.ucname}】已存在`);
}
}
deliver.name = this.trim(params.name);
deliver.businessmenDivide = 0;
deliver.invoiceDivide = 0;
deliver.isEnabled = params.isEnabled == 1 ? true : 0;
deliver.remark = this.trim(params.remark);
deliver.saas_id = this.trim(params.saas_id);
if (id) {
deliver = await deliver.save();
} else {
deliver = await this.dao.create(deliver);
}
user = user || {};
user.real_name = params.real_name;
user.auth = '1111';
if (user.id) {
user = await user.save();
} else {
user.saas_id = deliver.saas_id;
user.isAdmin = true;
user.deliver_id = deliver.id;
user.ucname = params.ucname;
user.password = await this.getEncryptStr(params.password);
user = await this.deliveruserDao.model.create(user);
}
deliver.admin_id = user.id;
await deliver.save();
if (user.org_id) {
let org = await this.deliverorgDao.findById(user.org_id);
org.name = deliver.name;
org.path = deliver.name + ".";
await org.save();
user.org_path = org.path;
await user.save();
} else {
let org = {
deliver_id: deliver.id,
name: deliver.name,
parent_id: 0,
path: deliver.name + ".",
type: '',
del_flag: 0,
group_type: 0
};
org = await this.deliverorgDao.model.create(org);
user.org_id = org.id;
user.org_path = org.path;
await user.save();
}
return system.getResultSuccess(deliver);
}
async updPassword(params) {
let user = await this.deliveruserDao.findById(params.admin_id);
if (!user) {
return system.getResult(null, '交付商管理员账户不存在');
}
user.password = await this.getEncryptStr(params.password);
await user.save();
return system.getResultSuccess();
}
async allList() {
var list = await this.dao.getList(1);
return system.getResultSuccess(list);
}
async delById(id) {
if (!id) {
return system.getResult(null, "删除失败");
}
await this.dao.delById(id);
return system.getResultSuccess(1);
}
async page(params) {
let currentPage = Number(params.currentPage || 1);
let pageSize = Number(params.pageSize || 10);
let where = {};
if(params.id){
where.id=this.trim(params.id);
}
if(params.name){
where.name=this.trim(params.name);
}
let orderby = [
["id", 'desc']
];
let page = await this.getPageList(currentPage, pageSize, where, orderby, null);
if (page && page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["created_at"], null, -8);
}
await this.setUser(page.rows);
}
return system.getResultSuccess(page);
}
async enable(params) {
let deliver = await this.findById(params.id);
deliver.isEnabled = params.isEnabled == 0 ? false : true;
await deliver.save();
return system.getResultSuccess();
}
async setUser(rows) {
if (!rows || rows.length == 0) {
return;
}
let ids = [];
for (let item of rows) {
if (item.admin_id) {
ids.push(item.admin_id);
}
}
let map = await this.deliveruserDao.findMapByIds(ids);
for (let item of rows) {
let user = map[item.admin_id] || {};
user.password = "";
item.real_name = user.real_name || "";
item.ucname = user.ucname || "";
item.user = user;
}
}
async deliverUsers(params) {
let sql = "SELECT * FROM d_deliver_user WHERE deliver_id = :deliver_id AND isAdmin = 0";
let list = await this.customQuery(sql, params);
if (list) {
for (let item of list) {
item.realName = item.real_name;
}
}
return system.getResultSuccess(list);
}
async deliverUserMap(params) {
if (!params.ids || params.ids.length == 0) {
return;
}
let sql = "SELECT * FROM d_deliver_user WHERE id IN (:ids)";
let list = await this.customQuery(sql, { ids: params.ids });
let result = {};
if (!list || list.length == 0) {
return result;
}
for (let item of list) {
result[item.id] = item;
}
return result;
}
async deliverUserPage(params) {
let currentPage = Number(params.currentPage || 1);
let pageSize = Number(params.pageSize || 10);
let deliver_id = params.deliver_id;
if (!deliver_id) {
return system.getResultSuccess({ count: 0, rows: [], msg: "deliver_id is empty" });
}
let where = {
deliver_id: deliver_id
};
if(params.org_id) {
let org = await this.deliverorgDao.findById(params.org_id);
if(!org) {
return system.getResultSuccess({ count: 0, rows: [], msg: "deliver_id is empty" });
}
where.org_path = {
[this.db.Op.like]: org.path + "%"
};
}
let orderby = [
["id", 'desc']
];
let page = await this.deliveruserDao.getPageList(currentPage, pageSize, where, orderby, null);
if (page && page.rows) {
for (var row of page.rows) {
row.password = "";
this.handleDate(row, ["created_at"], null, -8);
this.setAuth(row);
}
await this.setOrg(page.rows);
}
return system.getResultSuccess(page);
}
async deliverUserInfo(params) {
let id = params.id;
let user = await this.deliveruserDao.findById(id);
let deliver = await this.findById(user.deliver_id);
return system.getResult({
user: user,
deliver: deliver,
});
}
async deliverSynUpdate(params) {
let user = await this.deliveruserDao.findById(params.user_id);
let deliver = await this.findById(user.deliver_id);
if(!user.nt_user_id) {
user.nt_user_id = params.nt_user_id;
await user.save();
}
if(!deliver.nt_company_id) {
deliver.nt_company_id = params.nt_company_id;
await deliver.save();
}
return system.getResultSuccess();
}
setAuth(row) {
if (row.isManager) {
row.auth = [1, 2, 3, 4];
row.authNames = "管理员";
return;
}
let auth = row.auth;
if (!auth || auth.length < 4) {
row.auth = [];
row.authNames = "";
return;
}
let gsb = Number(row.auth[0] || 0);
let cwb = Number(row.auth[1] || 0);
let swb = Number(row.auth[2] || 0);
let pjb = Number(row.auth[3] || 0);
let authArr = [];
let authNames = [];
if (gsb) {
authArr.push(1);
authNames.push("工商宝");
}
if (cwb) {
authArr.push(2);
authNames.push("财务宝");
}
if (swb) {
authArr.push(3);
authNames.push("税务宝");
}
if (pjb) {
authArr.push(4);
authNames.push("票据宝");
}
row.auth = authArr;
row.authNames = authNames.join("、");
}
async setOrg(rows) {
if (!rows || rows.length == 0) {
return;
}
let orgIds = [];
for (let row of rows) {
orgIds.push(row.org_id);
}
let orgMap = await this.deliverorgDao.findMapByIds(orgIds);
for (let row of rows) {
row.org = orgMap[row.org_id] || {};
}
}
async deliverUserById(params) {
let id = params.id;
let user = await this.deliveruserDao.getById(id) || {};
user.password = "";
this.setAuth(user);
return system.getResultSuccess(user);
}
async deliverUserSave(params) {
let deliver_id = params.deliver_id;
if (!deliver_id) {
return system.getResult(null, "交付商不存在");
}
let id = params.id;
let real_name = this.trim(params.real_name);
let ucname = this.trim(params.ucname);
let org_id = params.org_id;
let password = params.password;
let isAdmin = Number(params.isAdmin || 0);
let authArr = [];
if (params.auth) {
for (let authCode of params.auth) {
if (authCode) {
authArr.push(Number(authCode));
}
}
}
let deliver = await this.dao.findById(deliver_id);
if (!deliver) {
return system.getResult(null, "交付商不存在");
}
let org = await this.deliverorgDao.findById(org_id);
if (!org) {
return system.getResult(null, "组织机构不存在");
}
let user;
if (id) {
user = await this.deliveruserDao.findById(id);
} else {
user = await this.deliveruserDao.findOne({ ucname: ucname });
if (user) {
return system.getResult(null, `账号【${ucname}】已存在`)
}
user = {};
}
user.real_name = real_name;
user.org_id = org_id;
user.org_path = org.path;
user.isAdmin = isAdmin ? true : false;
let auth = [];
for (let i = 1; i <= 4; i++) {
if (authArr.indexOf(i) == -1) {
auth.push("0");
} else {
auth.push("1");
}
}
user.auth = auth.join("");
if (user.id) {
await user.save();
} else {
user.saas_id = deliver.saas_id;
user.deliver_id = deliver.id;
user.ucname = params.ucname;
user.password = await this.getEncryptStr(params.password);
user = await this.deliveruserDao.model.create(user);
}
return system.getResultSuccess(user);
}
async orgTree(params) {
try {
let deliver_id = params.deliver_id;
if (!deliver_id) {
return system.getResult(null, "交付商不存在");
}
var all = await this.deliverorgDao.byDeliverId(params.deliver_id, '') || [];
for (let row of all) {
this.handleDate(row, ["created_at"], null, -8);
}
var pmap = {};
for (let item of all) {
item.label = item.name;
var list = pmap[item.parent_id] || [];
list.push(item);
pmap[item.parent_id] = list;
}
for (let item of all) {
item.children = pmap[item.id] || [];
}
return system.getResult(pmap[0]);
} catch (error) {
return system.getResult(-1, `系统错误 错误信息 ${error}`);
}
}
async orgById(params) {
let org = await this.deliverorgDao.getById(params.id) || "";
return system.getResultSuccess(org);
}
async allOrg(params) {
let deliver_id = params.deliver_id;
if (!deliver_id) {
return system.getResultSuccess([]);
}
var all = await this.deliverorgDao.byDeliverId(params.deliver_id, '') || [];
for (let row of all) {
this.handleDate(row, ["created_at"], null, -8);
}
return system.getResultSuccess(all);
}
async orgSave(params) {
let id = params.id;
let pid = params.parent_id;
let name = params.name;
let deliver_id = params.deliver_id;
if (!pid) {
return system.getResult(null, "请选择上级部门");
}
let parent = await this.deliverorgDao.findById(pid);
if (!parent) {
return system.getResult(null, "上级部门不存在");
}
if (!name) {
return system.getResult(null, "请填写部门名称");
}
if (!deliver_id) {
return system.getResult(null, "交付商不存在");
}
let org;
if (id) {
org = await this.deliverorgDao.findById(id);
} else {
org = {};
}
org.deliver_id = deliver_id;
org.name = name;
org.parent_id = pid;
org.path = parent.path + name + ".";
org.type = '';
org.del_flag = 0;
org.group_type = 0;
if (org.id) {
await org.save();
// TODO 修改该组织机构下用户树
} else {
org = await this.deliverorgDao.model.create(org);
}
return system.getResultSuccess();
}
}
module.exports = DeliverService;
// 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 StOrderService extends ServiceBase {
constructor() {
super("trade", ServiceBase.getDaoName(StOrderService));
this.storderitemDao = system.getObject("db.trade.storderitemDao");
this.dictionary = system.getObject("util.dictionary");
}
async test(params) {
return system.getResultSuccess("test");
}
// 打款列表页
async pageByCondition(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.dao.countByCondition(params);
if (page.count == 0) {
return system.getResultSuccess(page);
}
page.rows = await this.dao.listByCondition(params);
if (page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["created_at"], null);
if(row.acc_type == "00"){
row.acc_type_name = "银行";
}else if(row.acc_type == "01"){
row.acc_type_name = "支付宝";
}else if(row.acc_type ="02"){
row.acc_type_name ="微信"
}else{
row.acc_type_name = "其他";
}
}
this.dictionary.setRowsName("ORDER", page.rows, ["order_type", "acc_type", "trade_mode", "trade_status", "check_status"]);
}
return system.getResultSuccess(page);
}
async info(params) {
let order = await this.dao.getById(params.id);
if (!order) {
return system.getResult(null, "批次不存在");
}
this.handleDate(order, ["created_at"], null);
this.dictionary.setRowName("ORDER", order, ["order_type", "acc_type", "trade_mode", "trade_status", "check_status"]);
return system.getResultSuccess(order);
}
// 保存打款信息
async saveOrder(order) {
if (!order) {
return system.getResult(null, "批次不存在");
}
let itemList = order.itemList || [];
if (itemList.length == 0) {
return system.getResult(null, "批次明细不存在");
}
let self = this;
order = await this.db.transaction(async t => {
order = await self.dao.create(order, t);
for (let item of itemList) {
item.autoIncrement = true;
item.order_id = order.id;
item.order_type = order.order_type;
item.saas_merchant_id = order.saas_merchant_id;
item.out_trade_no = order.out_trade_no;
item.saas_id = order.saas_id;
}
await self.storderitemDao.bulkCreate(itemList, t);
await self.storderitemDao.genTradeNo(order.id, t);
return order;
});
return system.getResultSuccess(order);
}
async pay(params) {
let type = this.trim(params.type);
let rs;
if (type === "offline") {
rs = await this.offlinePay(params);
} else {
return system.getResult(null, "暂不支持在线付款");
}
return rs;
}
async offlinePay(params) {
let id = this.trim(params.id);
let order = await this.dao.findById(id);
if (!order) {
return system.getResult(null, "批次不存在");
}
if (order.pay_voucher) {
// 防止重复更新
return system.getResultSuccess();
}
if (!params.pay_voucher) {
return system.getResult(null, "请上传凭证");
}
order.pay_voucher = this.trim(params.pay_voucher);
let pay_bank_account = this.trim(params.pay_bank_account);
if (pay_bank_account) {
order.pay_bank_account = pay_bank_account;
}
let pay_bank_name = this.trim(params.pay_bank_name);
if (pay_bank_name) {
order.pay_bank_name = pay_bank_name;
}
let pay_bank_no = this.trim(params.pay_bank_no);
if (pay_bank_no) {
order.pay_bank_no = pay_bank_no;
}
// 一审
order.check_status = "01";
await order.save();
return system.getResultSuccess();
}
// 一审
async audit1(params) {
let _params = {
id: this.trim(params.id),
pre: "01",
status: Number(params.status || 0) == 1 ? "03" : "02",
remark: params.remark,
auditType: 1
}
return await this.doAudit(_params, async (order) => {
if (_params.status != "02") {
return;
}
order.trade_status = "02";
await order.save();
// 更新order_item状态
let rs = await this.storderitemDao.updateTradeByOrderId(order.id, order.trade_status);
console.log(rs);
});
}
// 二审
async audit2(params) {
let _params = {
id: this.trim(params.id),
pre: "03",
status: Number(params.status || 0) == 1 ? "05" : "04",
remark: params.remark,
auditType: 2
}
let rs = await this.doAudit(_params, async (order) => {
if (_params.status == "05") {
order.trade_status = "00";
} else if (_params.status == "04") {
order.trade_status = "02";
}
await order.save();
// 更新order_item状态
let rs = await this.storderitemDao.updateTradeByOrderId(order.id, order.trade_status);
console.log(rs);
});
return rs;
}
async doAudit(params, cb) {
let id = this.trim(params.id);
let pre = this.trim(params.pre);
let status = params.status;
let remark = this.trim(params.remark);
let auditType = params.auditType;
let auditName = auditType === 1 ? "一审" : "二审";
remark = this.trim(remark);
if (!remark) {
return system.getResult(null, `请填写${auditName}备注`);
}
let order = await this.dao.findById(id);
this.dictionary.setRowName("ORDER", order, ["check_status"]);
if (!order) {
return system.getResult(null, "批次不存在");
}
if (order.check_status !== pre) {
return system.getResult(null, `${auditName}失败,当前状态为[${order.check_status_name}]`);
}
order[`check${auditType}_remark`] = remark;
order.check_status = status;
await order.save();
if (cb) {
cb(order);
}
return system.getResultSuccess(order);
}
// 打款
async trade(params) {
// 打款模式 01系统打款 02手工打款
let trade_mode = this.trim(params.trade_mode);
if (!trade_mode || ["01", "02"].indexOf(trade_mode) == -1) {
return system.getResult(null, "打款模式错误");
}
if (trade_mode == "01") {
return system.getResult(null, "系统打款正在开发中,暂时只支持手工打款");
}
let order = await this.dao.findById(params.id);
if (!order) {
return system.getResult(null, "批次不存在");
}
if (order.check_status != "05") {
return system.getResult(null, "批次未审核通过,请等待审核操作");
}
if (order.trade_mode != "00") {
return system.getResult(null, "批次已经操作过打款,不要重复操作");
}
order.trade_mode = trade_mode;
order.trade_status = "01";
await order.save();
return system.getResultSuccess(order);
}
}
module.exports = StOrderService;
// 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 StOrderItemService extends ServiceBase {
constructor() {
super("trade", ServiceBase.getDaoName(StOrderItemService));
this.storderDao = system.getObject("db.trade.storderDao");
this.dictionary = system.getObject("util.dictionary");
}
async pageByCondition(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.dao.countByCondition(params);
if (page.count == 0) {
return system.getResultSuccess(page);
}
page.rows = await this.dao.listByCondition(params);
if (page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["created_at"], null);
}
this.dictionary.setRowsName("ORDER_ITEM", page.rows, ["trade_status"]);
}
return system.getResultSuccess(page);
}
async tradeOfflineCB(params) {
let item_ids = params.item_ids || [];
if (item_ids.length == 0) {
return system.getResultSuccess();
}
let trade_time = params.trade_time;
if (!trade_time) {
return system.getResult(null, "请填写交易时间");
}
let order = await this.storderDao.findById(params.order_id);
if (order.check_status != "05") {
return system.getResult(null, "批次未审核");
}
if (order.trade_mode == "00") {
return system.getResult(null, "批次未触发打款");
}
let itemParams = {
ids: item_ids,
trade_status: params.trade_status,
trade_desc: params.trade_desc,
trade_time: params.trade_time
};
let countParams = {
order_id: order.id,
trade_status: "00"
};
let orderParams = {
id: order.id
};
let self = this;
await this.db.transaction(async t => {
await self.dao.updateTrade(itemParams, t);
let count = await self.dao.countItems(countParams, t);
if (count == order.item_count) {}
orderParams.trade_status = count == order.item_count ? "00" : "03";
await self.storderDao.update(orderParams, t);
return order;
});
return system.getResultSuccess();
}
async tradeOnlineCB(params) {}
async updateInvoice(params) {
let rs = await this.dao.updateInvoice(params);
return system.getResult(rs);
}
async cancelInvoice(params) {
let rs = await this.dao.cancelInvoice(params);
return system.getResult(rs);
}
async byIds(params) {
let list = await this.dao.byIds(params);
return system.getResultSuccess(list);
}
async bySaasInvoiceId(params) {
let rs = await this.dao.bySaasInvoiceId(params);
return system.getResultSuccess(rs);
}
/**
* 根据 invoice_id 和 order_type 查询交易流水
* @param {*} params
*/
async invoiceTrade(params){
if(!params.id){
return system.getResult(null, `参数错误 ID不能为空`);
}
if(!params.order_type){
return system.getResult(null,`订单类型不能为空`);
}
try {
let tparam = {order_type:this.trim(params.order_type)};
if (params.data_ids && params.data_ids.length > 0) {
tparam.data_ids = params.data_ids;
} else if (params.id) {
tparam.saas_invoice_id = params.id;
} else {
return system.getResult([]);
}
let res = await this.dao.invoiceTrade(tparam) || [];
for(let item of res){
this.handleDate(item, ['updated_at', 'created_at'], 'YYYY-MM-DD HH:mm:ss');
}
return system.getResult(res);
} catch (error) {
console.log(error);
return system.getResult(null,`系统错误`);
}
}
/**
* 根据统一社会信用代码获取所有的订单流水
* @param params
* @returns {Promise<void>}
*/
async tradeItemBycreditCode(params){
if(!(params.credit_code_array instanceof Array) && params.credit_code_array.length <0){
return system.getResult(null, `参数格式错误`);
}
try{
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.dao.countByCondition(params);
if (page.count == 0) {
return system.getResultSuccess(page);
}
page.rows = await this.dao.invoiceTrade(params);
if(page.rows){
for (let item of page.rows) {
this.handleDate(item, ["created_at","trade_time"], null);
item.amt = system.f2y(item.amt);
item.actual_amt = system.f2y(item.actual_amt);
item.deduct_amt = system.f2y(item.deduct_amt);
item.service_tax = system.f2y(item.service_tax);
if(item.order_type == "10"){//00未设置 10平台交易 20商户交易
item.order_type_name = "平台交易";
}else if(item.order_type=="20"){
item.order_type_name = "商户交易";
}else{
item.order_type_name = "未设置";
}
if(item.trade_status=="00"){//交易状态 00 成功 01 待处理 02 失败
item.trade_status_name = "成功";
}else if(item.trade_status=="01"){
item.trade_status_name = "待处理";
}else if(item.trade_status=="02"){
item.trade_status_name = "失败";
}else{
item.trade_status_name = "";
}
}
}
return system.getResult(page);
}catch (e) {
console.log(e);
return system.getResult(null, `系统错误`);
}
}
/***
* fn:根据ID取消发票关联
* @param params
* @returns {Promise<void>}
*/
async cancelInvoiceByDataIds(params){
if(!params.data_ids || params.data_ids.length==0) {
return system.getResult(null, `参数错误 DATA_IDS 不能为空`);
}
try{
let res = await this.dao.cancelInvoiceByDataIds(params);
return res;
}catch (e) {
console.log(e);
return system.getResult(null, `系统错误`);
}
}
}
module.exports = StOrderItemService;
\ No newline at end of file
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
class StPayService extends ServiceBase {
constructor() {
super("trade", ServiceBase.getDaoName(StPayService));
this.PAY_TYUPE = ["1", '2']; //支付类型 1线下支付 2...
this.PAY_STATUS = ["10", "20"]; //支付状态 10待支付 20已支付
}
/**
* 创建交易流水
* @param params
* @returns {Promise<void>}
*/
async saveStPay(params) {
if (!params.busi_name) {
return system.getResult(`业务名称不能为空`);
}
if (!params.busi_id) {
return system.getResult(`业务ID不能为空`);
}
if (!this.PAY_TYUPE.includes(params.pay_type)) {
return system.getResult("支付类型错误")
}
if (!this.PAY_STATUS.includes(params.pay_status)) {
return system.getResult("支付状态错误")
}
let stpay = {
busi_id: this.trim(params.busi_id),
busi_name: this.trim(params.busi_name),
saas_id: this.trim(params.saas_id),
saas_merchant_id: this.trim(params.saas_merchant_id),
pay_type: this.trim(params.pay_type),
amount: this.trim(params.amount),
pay_status: this.trim(params.pay_status),
pay_voucher_img: this.trim(params.pay_voucher_img),
trade_no: this.trim(params.trade_no),
account_info: this.trim(params.account_info),
};
try {
let res = await this.dao.create(stpay);
return system.getResult(res);
} catch (e) {
console.log(e);
return system.getResult(`系统错误`)
}
}
/**
* 更新支付记录
* @param pay_status
* @param pay_voucher_img
* @param trade_no
* @returns {Promise<void>}
*/
async updateStatus (params) {
let _bean = await this.dao.model.findOne({
where: {
id: this.trim(params.id),
}
});
if (!_bean) {
return system.getResult(null, `业务${_bean.id}不存在`);
}
if(params.pay_status){
if (!this.PAY_STATUS.includes(params.pay_status)) {
return system.getResult("支付状态错误")
}
_bean.pay_status = this.trim(params.pay_status);
}
if (params.pay_voucher_img){
_bean.pay_voucher_img = this.trim(params.pay_voucher_img);
}
if (params.trade_no){
_bean.trade_no = this.trim(params.trade_no);
}
try{
let res = await _bean.save();
return system.getResult(res);
}catch (e) {
console.log(e);
return system.getResult(null, `系统错误`)
}
}
/**
* 获取业务支付记录
* @param busi_name
* @param busiIds
* @returns {Promise<void>}
*/
async mapByBusiIds(params) {
if (!params.busi_name) {
return system.getResult(`业务名称不能为空`);
}
try {
let list = await this.dao.model.findAll({
where: {
busi_name: this.trim(params.busi_name),
busi_id: {
[this.db.Op.in]: params.busiIds,
}
}
});
let map = {};
for (let element of list) {
if(element.pay_type=="1"){
element.pay_type_name = "线下支付";
}else{
element.pay_type_name = "其他支付";
}
if(element.pay_status=="10"){
element.pay_status_name = "待支付 ";
}else if(element.pay_status=="20"){
element.pay_status_name = "20已支付";
}else{
element.pay_status_name = "";
}
let temp = map[element.busi_id] || [];
temp.push(element);
map[element.busi_id]=temp;
}
return system.getResult(map);
}catch (e) {
console.log(e);
return system.getResult(`系统错误`);
}
}
}
module.exports = StPayService;
\ 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