partner.js
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"use strict";
const moment = require('moment');
const pull = require('./pull');
const logger = require('./logger').get();
var config;
var matrix;
function init(options) {
config = options.config;
matrix = options.matrix;
}
function _buy(task) {
let destination = Number(task.destination);
if (destination % 2) {
let msg = 'Isi ' + task.remote_product + ' ke ' + task.destination + ' gagal karena nomor tujuan ganjil';
pull.report(task.trx_id, '14', msg);
} else {
let sn = moment().format('YYYYMMDDHHmmssSSS')
let msg = 'Isi ' + task.remote_product + ' ke ' + task.destination + ' berhasil karena nomor tujuan genap dengan SN=' + sn;
pull.report(task.trx_id, '00', msg, sn);
}
}
function buy(_task) {
let task = JSON.parse(JSON.stringify(_task));
logger.verbose('Buy on partner', {task: task});
setTimeout(
function() {
_buy(task);
},
(config.max_result_timeout_ms || 2000) * Math.random()
)
}
exports.init = init;
exports.buy = buy;