This commit is contained in:
chaosBreaking
2019-08-31 14:59:13 +08:00
commit dc5423d356
65 changed files with 3813 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
'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,
};