Commit fed88914 by 王昆

gsb

parent 925bbbc2
......@@ -5,6 +5,7 @@ class ActionAPI extends APIBase {
constructor() {
super();
this.storderSve = system.getObject("service.trade.storderSve");
this.storderitemSve = system.getObject("service.trade.storderitemSve");
}
/**
* 接口跳转
......@@ -37,9 +38,19 @@ class ActionAPI extends APIBase {
case "test":
opResult = await this.storderSve.test(action_body);
break;
case "saveOrder":
case "orderPage":
opResult = await this.storderSve.pageByCondition(action_body);
break;
case "orderAdd":
opResult = await this.storderSve.saveOrder(action_body);
break;
case "orderPay":
opResult = await this.storderSve.pay(action_body);
break;
case "itemPage":
opResult = await this.storderitemSve.pageByCondition(action_body);
break;
default:
opResult = system.getResult(null, "action_type参数错误");
......
......@@ -41,7 +41,7 @@ class StOrderDao extends Dao {
sql.push("SELECT");
sql.push("count(1) as num");
sql.push("FROM");
sql.push("st_order");
sql.push(this.model.tableName);
sql.push("WHERE deleted_at IS NULL");
this.setCondition(sql, params);
......@@ -58,14 +58,14 @@ class StOrderDao extends Dao {
params.pageSize = Number(params.pageSize || 10);
var sql = [];
sql.push("SELECT");
sql.push("t1.*");
sql.push(params.attrs || "*");
sql.push("FROM");
sql.push("st_order");
sql.push(this.model.tableName);
sql.push("WHERE deleted_at IS NULL");
this.setCondition(sql, params);
sql.push("ORDER BY id DESC");
sql.push("ORDER BY created_at DESC");
sql.push("LIMIT :startRow, :pageSize");
return await this.customQuery(sql.join(" "), params);
}
......@@ -102,6 +102,7 @@ class StOrderDao extends Dao {
sql.push("AND created_at <= :createEnd");
}
}
}
module.exports = StOrderDao;
......@@ -4,8 +4,7 @@ class StOrderItemDao extends Dao {
constructor() {
super(Dao.getModelName(StOrderItemDao));
}
async findListByIds(ids, attrs) {
async listByIds(ids, attrs) {
if (!ids || ids.length == 0) {
return [];
}
......@@ -20,7 +19,7 @@ class StOrderItemDao extends Dao {
}) || [];
}
async findMapByIds(ids, attrs) {
async mapByIds(ids, attrs) {
var result = {};
if (!ids || ids.length == 0) {
return result;
......@@ -34,5 +33,80 @@ class StOrderItemDao extends Dao {
}
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);
var 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);
var 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.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.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.createBegin) {
sql.push("AND created_at >= :createBegin");
}
if (params.createEnd) {
sql.push("AND created_at <= :createEnd");
}
}
}
module.exports = StOrderItemDao;
......@@ -11,7 +11,7 @@ module.exports = (db, DataTypes) => {
deduct_amt: DataTypes.BIGINT, // 扣款金额
service_tax: DataTypes.BIGINT, // 服务费
item_count: DataTypes.INTEGER, // 打款笔数
order_type: DataTypes.STRING, // 订单类型 00钱过公司宝 01 钱不过公司宝 02 微信
order_type: DataTypes.STRING, // 订单类型 00未选择 01钱过公司宝 02钱不过公司宝
acc_type: DataTypes.STRING, // 打款通道 00 银行 01 支付宝 02 微信
trade_mode: DataTypes.STRING, // 打款模式 00 未选择 01 系统打款 02 手工打款
trade_status: DataTypes.STRING, // 交易状态 00 成功 01 待处理 02 失败 03 部分成功
......@@ -64,6 +64,6 @@ module.exports = (db, DataTypes) => {
// method: 'BTREE',
// fields: ['author', {attribute: 'title', collate: 'en_US', order: 'DESC', length: 5}]
// }
]
],
});
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ 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
out_trade_no: DataTypes.STRING, // 商户订单号
......@@ -20,6 +21,7 @@ module.exports = (db, DataTypes) => {
trade_desc: DataTypes.STRING, // 交易描述
trade_receipt: DataTypes.STRING, // 回执
remark: DataTypes.STRING, // 上传备注
saas_id: DataTypes.STRING, // saas id
}, {
paranoid: true, //假的删除
......
......@@ -5,6 +5,7 @@ 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) {
......@@ -12,7 +13,7 @@ class StOrderService extends ServiceBase {
}
// 打款列表页
async orderPage(params) {
async pageByCondition(params) {
let page = {
count: 0,
rows: []
......@@ -29,11 +30,9 @@ class StOrderService extends ServiceBase {
page.rows = await this.dao.listByCondition(params);
if (page.rows) {
for (var row of page.rows) {
this.handleDate(row, ["created_at"], null, -8);
this.handleDate(row, ["created_at"], null);
}
await this.setBminfo(page.rows);
await this.setOrderStatus(page.rows);
this.dictionary.setRowsName("ORDER", page.rows, ["order_type", "acc_type", "trade_mode", "trade_status", "check_status"]);
}
return system.getResultSuccess(page);
}
......@@ -54,6 +53,7 @@ class StOrderService extends ServiceBase {
order = await self.dao.create(order, t);
for (let item of itemList) {
item.autoIncrement = true;
item.order_id = order.id;
item.saas_merchant_id = order.saas_merchant_id;
item.out_trade_no = order.out_trade_no;
......@@ -61,12 +61,55 @@ class StOrderService extends ServiceBase {
item.trade_status = "01";
}
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;
}
await order.save();
return system.getResultSuccess();
}
// 详情
......@@ -82,9 +125,6 @@ class StOrderService extends ServiceBase {
// 结果反馈-批量
// 交易列表页
async page(params) {
let currentPage = Number(params.currentPage || 1);
let pageSize = Number(params.pageSize || 10);
......
const system = require("../../../system");
const ServiceBase = require("../../sve.base")
class StOrderItemService extends ServiceBase {
constructor() {
super("trade", ServiceBase.getDaoName(StOrderItemService));
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);
}
}
module.exports = StOrderItemService;
// 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");
class Dictionary {
constructor() {
// 交易字典
this.ORDER = {
// 订单类型 00未设置 01钱过公司宝 02钱不过公司宝
order_type: {"00": "未设置", "01": "公司宝账户", "02": "客户账"},
acc_type: {"00": "银行", "01": "支付宝", "02": "微信"},
trade_mode: {"00": "未设置", "01": "系统打款", "02": "手工打款"},
trade_status: {"00": "成功", "01": "待处理", "02": "失败", "03": "部分成功"},
check_status: {"00": "待处理", "01": "一审", "02": "一审失败", "03": "二审", "04": "二审失败", "05": "审核通过"},
};
this.ORDER_ITEM = {
trade_status: {"00": "成功", "01": "待处理", "02": "失败"}
}
}
getDict(module, field) {
return (this[(module || "")] || {})[field] || {};
}
setRowName(module, row, fields, concat) {
if(!module || !row || !fields || fields.length == 0) {
return;
}
concat = concat || "_";
for (let field of fields) {
row[field + concat + "name"] = this.getDict(module, field)[row[field] || ""] || "";
}
}
setRowsName(module, rows, fields, concat) {
if(!module || !rows || !fields || fields.length == 0) {
return;
}
for(let row of rows) {
this.setRowName(module, row, fields, concat)
}
}
}
module.exports = Dictionary;
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