Files
vic-server-mongo/src/modules/action/action.handler.js
chaosBreaking dc5423d356 init
2019-08-31 14:59:13 +08:00

107 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const Action = require('./action.model');
/**
* [0] 充值LOG
* [1] 提现
* [2] 购买地产
* [3] 分红
* [4] 场外买入
* [5] 场外卖出
*/
function createAction (actCode, data) {
switch (actCode) {
case 0: return createDepositAction(data);
case 1: return createWithdrawAction(data);
case 2: return createPurchaseAction(data);
case 3: return createBonusAction(data);
case 4: return createOtcBuyAction(data);
case 5: return createOtcSellAction(data);
}
}
function createDepositAction(data = {}) {
// 充值要记录: 发起人,充值目标地址,充值货币类型,充值金额
// 只创建action并返回不保存保存交给具体的业务在事务内执行
const { actor, amount, tokenType, toAddress, remain } = data;
if (!actor || !amount || !tokenType || !toAddress) return false;
return new Action({
actor,
type: 0,
op: 1,
amount,
remain,
detail: { toAddress, tokenType }
});
}
function createWithdrawAction(data = {}) {
const { actor, amount, remain } = data;
return new Action({
actor,
type: 1,
op: 0,
amount,
remain,
detail: {
}
});
}
function createPurchaseAction(data = {}) {
const { actor, estate, amount, remain } = data;
return new Action({
actor,
type: 2,
op: 0,
amount,
remain,
detail: {
...estate
}
});
}
function createBonusAction(data = {}) {
const { actor, estate, amount, remain } = data;
return new Action({
actor,
type: 3,
op: 1,
amount,
remain,
detail: {
...estate
}
});
}
function createOtcBuyAction(data = {}) {
// 场外交易的actor是交易活动的发起者也就是去买市场挂单的人。
const { actor, otcOrder, adv, amount, remain } = data;
return new Action({
actor,
type: 4,
op: 1,
amount,
remain,
detail: {
order: otcOrder,
adv
}
});
}
function createOtcSellAction(data = {}) {
const { actor, otcOrder, amount, remain } = data;
return new Action({
actor,
type: 5,
op: 0,
amount,
remain,
detail: {
...otcOrder
}
});
}
module.exports = {
createAction,
};