Commit c0c1ca50 by 孙亚楠

dd

parent 61cb6800
......@@ -6,6 +6,7 @@ class ActionAPI extends APIBase {
super();
this.storderSve = system.getObject("service.trade.storderSve");
this.storderitemSve = system.getObject("service.trade.storderitemSve");
this.stpaySve = system.getObject("service.trade.stpaySve");
}
/**
* 接口跳转
......@@ -81,8 +82,15 @@ class ActionAPI extends APIBase {
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;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......
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("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: '交易流水号' }
}, {
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")
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)
};
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