|
@@ -2848,6 +2848,144 @@ proto.mailInfo = P.coroutine(function* (msg, session, next) {
|
|
|
return next(null, { code: C.OK, data: data });
|
|
return next(null, { code: C.OK, data: data });
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+proto.withdrawStart = P.coroutine(function* (msg, session, next){
|
|
|
|
|
+ if (!session.uid) {
|
|
|
|
|
+ return next(null, { code: C.ERROR, msg: C.GAME_PARAM_ERROR });
|
|
|
|
|
+ }
|
|
|
|
|
+ var playerId = msg._id
|
|
|
|
|
+ if (!playerId) {
|
|
|
|
|
+ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
|
|
|
|
|
+ }
|
|
|
|
|
+ var player = yield this.app.models.Player.findByIdAsync(session.uid);
|
|
|
|
|
+ if (!player) {
|
|
|
|
|
+ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (player.userId != msg._id) {
|
|
|
|
|
+ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
|
|
|
|
|
+ }
|
|
|
|
|
+ console.warn("610")
|
|
|
|
|
+ let sgjconfigs = yield this.app.models.SGJConfig.findMongoAsync();
|
|
|
|
|
+ var sgjconfig = sgjconfigs[0]
|
|
|
|
|
+ console.warn("612")
|
|
|
|
|
+ var amount = msg.amount
|
|
|
|
|
+ if (!amount) {
|
|
|
|
|
+ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (amount < sgjconfig.withdrawlowlimit || amount <= 0) {
|
|
|
|
|
+ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (player.diamond < amount) {
|
|
|
|
|
+ return next(null, { code: C.ERROR, msg: "you not have much money" });
|
|
|
|
|
+ }
|
|
|
|
|
+ var targetAddress = msg.targetAddress
|
|
|
|
|
+ if (!targetAddress) {
|
|
|
|
|
+ return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!this.checkUSDTSign(msg)) {
|
|
|
|
|
+ //return next(null, { code: C.FAILD, msg: C.GAME_PARAM_ERROR });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //var data = yield this.withdrawSubmit(amount-sgjconfig.withdrawfee, targetAddress, userid)
|
|
|
|
|
+ //if (!data.success) {
|
|
|
|
|
+ // return this.writeOut(data, res);
|
|
|
|
|
+ //}
|
|
|
|
|
+ var beforeusdt = player.diamond
|
|
|
|
|
+ var afterusdt = player.diamond - amount
|
|
|
|
|
+ var app = this.app
|
|
|
|
|
+ var self = this
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ var timestamp = Date.now()
|
|
|
|
|
+ console.warn("sgjconfig:",sgjconfig)
|
|
|
|
|
+ var record = new app.models.UsdtWithdrawRecord({
|
|
|
|
|
+ _id: uuid.v1(), // 订单号
|
|
|
|
|
+ chainCode: "tron", // 玩家ID
|
|
|
|
|
+ clientId: player.userId, // 支付玩家ID
|
|
|
|
|
+ code: "usdt", // 总金额
|
|
|
|
|
+ amount: msg.amount, // 支付方式 0为微信 1为支付宝
|
|
|
|
|
+ targetAddress: msg.targetAddress, // 充值奖励
|
|
|
|
|
+ submitTime: Date.now(), // 充值奖励
|
|
|
|
|
+ sign: msg.sign, // 充值奖励
|
|
|
|
|
+ refOrderId: "ORDER"+timestamp,//data.data.refOrderId,
|
|
|
|
|
+ status:100,
|
|
|
|
|
+ submitfee: sgjconfig.withdrawfee,
|
|
|
|
|
+ userId :player.userId,
|
|
|
|
|
+ beforeusdt: beforeusdt,
|
|
|
|
|
+ afterusdt: afterusdt,
|
|
|
|
|
+ });
|
|
|
|
|
+ console.warn("274")
|
|
|
|
|
+ player.diamond -= amount
|
|
|
|
|
+ var diamondrecord = new app.models.DiamondRecord({
|
|
|
|
|
+ _id: uuid.v1(),
|
|
|
|
|
+ playerId: player._id,
|
|
|
|
|
+ dType: 23,//withdraw fail
|
|
|
|
|
+ dSource: beforeusdt ,
|
|
|
|
|
+ dSwap: record.amount,
|
|
|
|
|
+ dNow: afterusdt,
|
|
|
|
|
+ tableId: -amount
|
|
|
|
|
+ });
|
|
|
|
|
+ var SGJUserTongjis = yield app.models.SGJUserTongji.findMongoAsync({todaytime:self.getTodaySJC()})
|
|
|
|
|
+ var SGJUserTongji = null
|
|
|
|
|
+ if (SGJUserTongjis.length == 0) {
|
|
|
|
|
+ SGJUserTongji = app.models.SGJUserTongji({
|
|
|
|
|
+ _id: uuid.v1(),
|
|
|
|
|
+ //userId: player.userId,
|
|
|
|
|
+ usdt: afterusdt,
|
|
|
|
|
+ feeconfigusdt: sgjconfig.withdrawfee,//下注
|
|
|
|
|
+ todaytime: self.getTodaySJC()
|
|
|
|
|
+ });
|
|
|
|
|
+ yield SGJUserTongji.saveAsync()
|
|
|
|
|
+ }else {
|
|
|
|
|
+ SGJUserTongji = SGJUserTongjis[0]
|
|
|
|
|
+ console.warn("SGJUserTongji:",SGJUserTongji)
|
|
|
|
|
+ //SGJUserTongji.usdt = afterusdt
|
|
|
|
|
+ SGJUserTongji.feeconfigusdt = (Number(SGJUserTongji.feeconfigusdt) +Number(sgjconfig.withdrawfee)).toFixed(2)//下注
|
|
|
|
|
+
|
|
|
|
|
+ yield SGJUserTongji.saveAsync()
|
|
|
|
|
+ }
|
|
|
|
|
+ console.warn("304")
|
|
|
|
|
+ yield diamondrecord.saveAsync()
|
|
|
|
|
+ console.warn("306")
|
|
|
|
|
+ yield record.saveAsync();
|
|
|
|
|
+ console.warn("308")
|
|
|
|
|
+ yield player.saveAsync()
|
|
|
|
|
+ console.warn("310")
|
|
|
|
|
+
|
|
|
|
|
+ var data = yield self.withdrawSubmit(amount-sgjconfig.withdrawfee, targetAddress, player.userId,timestamp,sgjconfig.coinurl)
|
|
|
|
|
+ console.warn("Data:",data)
|
|
|
|
|
+ if (!data.success) {
|
|
|
|
|
+ beforeusdt = player.diamond
|
|
|
|
|
+ afterusdt = (Number(player.diamond) + Number(amount)).toFixed(2)
|
|
|
|
|
+ player.diamond = (Number(player.diamond)+Number(amount)).toFixed(2)
|
|
|
|
|
+
|
|
|
|
|
+ var diamondrecord = new app.models.DiamondRecord({
|
|
|
|
|
+ _id: uuid.v1(),
|
|
|
|
|
+ playerId: player._id,
|
|
|
|
|
+ dType: 24,//withdraw fail
|
|
|
|
|
+ dSource: beforeusdt ,
|
|
|
|
|
+ dSwap: record.amount,
|
|
|
|
|
+ dNow: afterusdt,
|
|
|
|
|
+ tableId: amount
|
|
|
|
|
+ });
|
|
|
|
|
+ SGJUserTongji.usdt = afterusdt
|
|
|
|
|
+ SGJUserTongji.feeconfigusdt = (Number(SGJUserTongji.feeconfigusdt) -Number(sgjconfig.withdrawfee)).toFixed(2)//下注
|
|
|
|
|
+ record.time = Date.now()
|
|
|
|
|
+ record.callBackTime = Date.now()
|
|
|
|
|
+ record.msg = data.message
|
|
|
|
|
+ record.status = 2
|
|
|
|
|
+ yield record.saveAsync();
|
|
|
|
|
+ yield player.saveAsync()
|
|
|
|
|
+ yield diamondrecord.saveAsync()
|
|
|
|
|
+ yield SGJUserTongji.saveAsync()
|
|
|
|
|
+ return next(null, { code: C.FAILD, msg: record.msg });
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return next(null, { code: C.OK,data:{usdt: player.diamond} });
|
|
|
|
|
+ }
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
proto.sgjConfig = P.coroutine(function* (msg, session, next) {
|
|
proto.sgjConfig = P.coroutine(function* (msg, session, next) {
|
|
|
if (!session.uid) {
|
|
if (!session.uid) {
|
|
|
return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
|
|
return next(null, { code: C.ERROR, msg: C.PLAYER_NOT_LOGIN });
|
|
@@ -3110,4 +3248,97 @@ proto.shiyongJPQ = P.coroutine(function* (msg, session, next) {
|
|
|
}
|
|
}
|
|
|
let data = {jpqsysj: czts*86400000}
|
|
let data = {jpqsysj: czts*86400000}
|
|
|
return next(null, { code: C.OK, data: data });
|
|
return next(null, { code: C.OK, data: data });
|
|
|
-});
|
|
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+proto.withdrawSubmit = P.coroutine(function* (amount, targetAddress, userid,timestamp, coinurl) {
|
|
|
|
|
+ // https://bar-coinpay.ala456.com/api/withdraw/submit?additionalAudit=false&amount=0.01&chainCode=tron&refOrderId=ORDER20260228001&targetAddress=TD92sxkgUHHadcoSiHY6Bus5fA9rsAYAKZ×tamp=1772270280000&tokenCode=usdt&userId=123&sign=bfb1d7bf14f5217cac9204b929ca4334
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ var suffix = "additionalAudit=false&amount="+amount+"&chainCode=tron&refOrderId=ORDER"+timestamp+"&targetAddress="+targetAddress+"×tamp="+timestamp+"&tokenCode=usdt&userId="+userid
|
|
|
|
|
+ console.warn("suffix:",suffix)
|
|
|
|
|
+ var md5str = suffix+"&key=1bU4uOEs4kZoQA0D55mzAwBr2NlN9o40"
|
|
|
|
|
+ var sign = md5(md5str).toLowerCase();
|
|
|
|
|
+ console.warn("sign:",sign)
|
|
|
|
|
+ suffix = suffix +"&sign="+sign
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ let postDataStr = '';
|
|
|
|
|
+
|
|
|
|
|
+ let options = {
|
|
|
|
|
+ hostname: coinurl,
|
|
|
|
|
+ port: '',
|
|
|
|
|
+ path: '/api/withdraw/submit?'+suffix,
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ rejectUnauthorized: false,
|
|
|
|
|
+ requestCert: true,
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ 'Content-Type': 'Application/json',
|
|
|
|
|
+ "Content-Length":Buffer.byteLength(JSON.stringify(postDataStr)),
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ //const url = 'https://bar-coinpay.ala456.com/api/withdraw/submit?' + suffix;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ var req = https.request(options, (res) => {
|
|
|
|
|
+ res.setEncoding('utf8');
|
|
|
|
|
+
|
|
|
|
|
+ // if (res.statusCode !== 200) {
|
|
|
|
|
+ // console.warn(res)
|
|
|
|
|
+ // const errMsg = `请求失败,状态码: ${res.statusCode}`;
|
|
|
|
|
+ // console.warn("res:", res.statusCode);
|
|
|
|
|
+ // return reject(new Error(errMsg));
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ let data = '';
|
|
|
|
|
+ res.on('data', (chunk) => {
|
|
|
|
|
+ console.warn("chunk:", chunk);
|
|
|
|
|
+ data += chunk;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ res.on('end', function() {
|
|
|
|
|
+ console.warn("end");
|
|
|
|
|
+ try {
|
|
|
|
|
+ const parsedData = JSON.parse(data);
|
|
|
|
|
+ //console.warn("226 player:", userid, parsedData.data.address);
|
|
|
|
|
+ // 这里返回解析后的数据,供后续yield使用
|
|
|
|
|
+ resolve(parsedData);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ const parseErr = new Error(`JSON 解析失败: ${e.message}`);
|
|
|
|
|
+ console.warn(parseErr.message);
|
|
|
|
|
+ reject(parseErr);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }).on('error', err => {
|
|
|
|
|
+ console.error('请求错误:', err);
|
|
|
|
|
+ reject(err);
|
|
|
|
|
+ });
|
|
|
|
|
+ req.write(JSON.stringify(postDataStr));
|
|
|
|
|
+ });
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+proto.checkUSDTSign = function (query) {
|
|
|
|
|
+ var sortedKeys = Object.keys(query)
|
|
|
|
|
+ .filter(function(key) {
|
|
|
|
|
+ if (key == 'hash') {
|
|
|
|
|
+ return query[key].length > 0
|
|
|
|
|
+ }// 替换箭头函数为 function 声明
|
|
|
|
|
+ return key !== 'sign'; // 跳过 sign 参数
|
|
|
|
|
+ })
|
|
|
|
|
+ .sort();
|
|
|
|
|
+ // 3. 拼接键值对(替换箭头函数)
|
|
|
|
|
+ var queryStr = sortedKeys
|
|
|
|
|
+ .map(function(key) {
|
|
|
|
|
+ if (key=='hash' && query[key]=='') {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ var value = (query[key] === undefined || query[key] === null) ? '' : String(query[key]);
|
|
|
|
|
+ return key + '=' + value; // 避免模板字符串,用字符串拼接更兼容
|
|
|
|
|
+ })
|
|
|
|
|
+ .join('&');
|
|
|
|
|
+ var signKey = md5(queryStr+"&key=GV8J4nkBNFurtnR288ch2B6300FAy8gu").toLowerCase();
|
|
|
|
|
+ console.warn("queryStr:",queryStr)
|
|
|
|
|
+ console.warn("signKey:",signKey)
|
|
|
|
|
+ var sign = query["sign"]
|
|
|
|
|
+ console.warn("sign:",sign)
|
|
|
|
|
+ if (sign!=signKey) return false;
|
|
|
|
|
+ return true;
|
|
|
|
|
+};
|