xjf_log_task.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. import { Inject, Logger, Provide } from '@midwayjs/decorator';
  2. import { BaseService } from 'midwayjs-cool-core';
  3. import { ILogger } from '@midwayjs/logger';
  4. import { Utils } from '../../../comm/utils';
  5. import * as _ from 'lodash';
  6. import { InjectEntityModel } from '@midwayjs/orm';
  7. import { Repository } from 'typeorm';
  8. import { ShuyouAbnormalRateEntity } from '../../shuyou/entity/data_abnormal_rate';
  9. import { ShuyouUtilsService } from '../../shuyou/service/utils';
  10. /**
  11. * 描述
  12. */
  13. @Provide()
  14. export class XjfLogTaskService extends BaseService {
  15. @Logger()
  16. logger: ILogger;
  17. @Inject()
  18. utils: Utils;
  19. @InjectEntityModel(ShuyouAbnormalRateEntity)
  20. ShuyouAbnormalRateEntity: Repository<ShuyouAbnormalRateEntity>;
  21. @Inject()
  22. shuyouUtilsService: ShuyouUtilsService;
  23. async syncAbnormalRate() {
  24. let new_date = this.utils.formatDate(new Date())
  25. let hour = new Date().getHours()
  26. // console.log(hour)
  27. let updateTime = new Date()
  28. this.logger.info('syncAbnormalRate>>>' + updateTime);
  29. const sql = `
  30. SELECT
  31. a.task_id,
  32. a.task_name,
  33. a.new_date,
  34. a.directorId,
  35. b.login_modeId,
  36. b.xjf_id
  37. from
  38. shuyou_game_target a
  39. LEFT JOIN shuyou_game_task b ON a.task_id = b.id
  40. where 1 = 1
  41. ${this.setSql(new_date, 'and a.new_date = ? ORDER BY a.task_id', [new_date])}
  42. `;
  43. // console.log(sql)
  44. const targetList = await this.nativeQuery(sql);
  45. if (_.isEmpty(targetList)) {
  46. return 'syncAbnormalRate >>> shuyou_game_target is null >>> ' + updateTime;
  47. }
  48. const logs = [
  49. { action: '教程主线', action_result: '冻结' },
  50. { action: '拉取账号', action_result: '成功' },
  51. { action: '启动模拟器', action_result: '成功' },
  52. { action: '启动游戏', action_result: '查询IP' },
  53. { action: '脚本启动', action_result: '成功' },
  54. { action: '启动游戏', action_result: '成功' },
  55. { action: '登陆', action_result: '成功' },
  56. { action: '教程主线', action_result: '进入游戏' },
  57. { action: '教程主线', action_result: '新增成功' },
  58. { action: '教程主线', action_result: '留存成功' },
  59. { action: '付费充值', action_result: '付费成功' },
  60. { action: '教程主线', action_result: '可以付费' },
  61. { action: '留存账号总数', action_result: '留存账号总数' },
  62. { action: '询问付费', action_result: '付费' }
  63. ]
  64. let data3 = await queryNewComputerRoom(new_date)
  65. let newComputerRoomData = []
  66. if (_.isEmpty(data3) || data3 == -1) {
  67. // this.logger.warn('新机房后台数据错误')
  68. newComputerRoomData = []
  69. } else {
  70. newComputerRoomData = JSON.parse(data3 + '')
  71. }
  72. await ykhForeach(targetList, async (item, index) => {
  73. let task_id = item.task_id
  74. let task_name = item.task_name
  75. let directorId = item.directorId
  76. let login_modeId = item.login_modeId
  77. let xjf_id = item.xjf_id
  78. // console.log(xjf_id)
  79. let useXjf = false
  80. let game_id = xjf_id
  81. let xjfData
  82. if (xjf_id != 0) {
  83. let queryXjf
  84. queryXjf = await queryXjfId(xjf_id)
  85. // console.log(queryXjf)
  86. if (_.isEmpty(queryXjf) || queryXjf == -1) {
  87. xjfData = {
  88. "IdDong": 0,
  89. "IdYang": 0
  90. }
  91. } else {
  92. xjfData = JSON.parse(queryXjf + '')
  93. }
  94. // console.log(xjfData)
  95. // console.log(xjfData.IdYang)
  96. if (xjfData.IdYang == task_id) {
  97. useXjf = true
  98. } else {
  99. // return 'syncAbnormalRate Fail>>>gameid is null' + updateTime;
  100. }
  101. let num_arr = []
  102. if (useXjf == true) {
  103. await ykhForeach(logs, async (e, i) => {
  104. let action = e.action
  105. const action_result = e.action_result
  106. let num_xjfLog
  107. if (i == 6) {
  108. if (login_modeId == 1) {
  109. //小绵羊登录 小绵羊登陆
  110. let xmy1 = await queryXjfLog(new_date, '小绵羊登录', action_result, game_id)
  111. let xmy2 = await queryXjfLog(new_date, '小绵羊登陆', action_result, game_id)
  112. num_xjfLog = parseInt(xmy1 + '') + parseInt(xmy2 + '')
  113. } else if (login_modeId == 2) {
  114. //魅族登录 魅族登陆
  115. let mz1 = await queryXjfLog(new_date, '魅族登录', action_result, game_id)
  116. let mz2 = await queryXjfLog(new_date, '魅族登陆', action_result, game_id)
  117. num_xjfLog = parseInt(mz1 + '') + parseInt(mz2 + '')
  118. } else if (login_modeId == 3 || login_modeId == 5 || login_modeId == 6) {
  119. //QQ登录 QQ登陆 微信登录 微信登陆
  120. let num_xjfLog1 = await queryXjfLog(new_date, 'QQ登录', action_result, game_id)
  121. let num_xjfLog2 = await queryXjfLog(new_date, '微信登录', action_result, game_id)
  122. let num_xjfLog3 = await queryXjfLog(new_date, 'QQ登陆', action_result, game_id)
  123. let num_xjfLog4 = await queryXjfLog(new_date, '微信登陆', action_result, game_id)
  124. num_xjfLog = parseInt(num_xjfLog1 + '') + parseInt(num_xjfLog2 + '') + parseInt(num_xjfLog3 + '') + parseInt(num_xjfLog4 + '')
  125. } else if (login_modeId == 4) {
  126. //网易登录 网易登陆
  127. let wy1 = await queryXjfLog(new_date, '网易登录', action_result, game_id)
  128. let wy2 = await queryXjfLog(new_date, '网易登陆', action_result, game_id)
  129. num_xjfLog = parseInt(wy1 + '') + parseInt(wy2 + '')
  130. } else {
  131. }
  132. } else {
  133. num_xjfLog = await queryXjfLog(new_date, action, action_result, game_id)
  134. }
  135. num_arr.push(num_xjfLog)
  136. })
  137. // console.log(num_arr)
  138. let rate_all_step = 0
  139. if (num_arr[7] != 0 && num_arr[5] != 0) {
  140. rate_all_step = parseFloat(num_arr[7]) / parseFloat(num_arr[5])
  141. }
  142. let order_success_rate = '-/-/-%'
  143. //
  144. for (let newvalue of newComputerRoomData) {
  145. if (newvalue.game_id == xjf_id) {
  146. order_success_rate = newvalue.order_success_rate
  147. break;
  148. }
  149. }
  150. //
  151. let rateObj = {
  152. task_id: task_id,
  153. task_name: task_name,
  154. directorId: directorId,
  155. new_date: new_date,
  156. hour: hour,
  157. num_frozen: num_arr[0],
  158. num_pull_account: num_arr[1],
  159. num_start_simulator: num_arr[2],
  160. num_ip: num_arr[3],
  161. num_start_script: num_arr[4],
  162. num_start_game: num_arr[5],
  163. num_login_success: num_arr[6],
  164. num_into_game: num_arr[7],
  165. num_new_success: num_arr[8],
  166. num_lc_success: num_arr[9],
  167. num_pay_success: num_arr[10],
  168. rate_all_step: rate_all_step,
  169. num_could_pay: num_arr[11], // 可以付费的账号
  170. num_account_lc: num_arr[12], //留存账号总数
  171. num_pull_pay: num_arr[13], // 下发付费账号
  172. order_success_rate: order_success_rate
  173. }
  174. // console.log(rateObj)
  175. const AbnormalRateEntity = await this.ShuyouAbnormalRateEntity.findOne({
  176. new_date: new_date,
  177. hour: hour,
  178. task_id: task_id
  179. });
  180. if (AbnormalRateEntity) {
  181. await this.ShuyouAbnormalRateEntity
  182. .createQueryBuilder()
  183. .update()
  184. .set(rateObj)
  185. .where('new_date = :new_date and hour = :hour and task_id = :task_id', {
  186. new_date: new_date,
  187. hour: hour,
  188. task_id: task_id
  189. })
  190. .execute();
  191. } else {
  192. await this.ShuyouAbnormalRateEntity
  193. .createQueryBuilder()
  194. .insert()
  195. .into(ShuyouAbnormalRateEntity)
  196. .values(rateObj)
  197. .execute();
  198. }
  199. } else {
  200. // return 'syncAbnormalRate Fail>>> 2' + updateTime;
  201. }
  202. }
  203. })
  204. // ====================================
  205. return 'syncAbnormalRate SUCCESS>>>' + updateTime;
  206. }
  207. /**
  208. *
  209. * 快速批量查询游戏异常率
  210. * @return {*}
  211. * @memberof XjfLogTaskService
  212. */
  213. async syncAbnormalRateByBatch() {
  214. let new_date = this.utils.formatDate(new Date())
  215. let hour = new Date().getHours()
  216. // console.log(hour)
  217. let updateTime = new Date()
  218. this.logger.info('syncAbnormalRateByBatch>>>' + updateTime);
  219. const sql = `
  220. SELECT
  221. a.task_id,
  222. a.task_name,
  223. a.new_date,
  224. a.directorId,
  225. b.login_modeId,
  226. b.xjf_id
  227. from
  228. shuyou_game_target a
  229. LEFT JOIN shuyou_game_task b ON a.task_id = b.id
  230. where 1 = 1
  231. ${this.setSql(new_date, 'and a.new_date = ? ORDER BY a.task_id', [new_date])}
  232. `;
  233. // console.log(sql)
  234. const targetList = await this.nativeQuery(sql);
  235. if (_.isEmpty(targetList)) {
  236. return 'syncAbnormalRateByBatch >>> shuyou_game_target is null >>> ' + updateTime;
  237. }
  238. // this.logger.info(targetList)
  239. const logs = [
  240. { action: '教程主线', action_result: '冻结' },
  241. { action: '拉取账号', action_result: '成功' },
  242. { action: '启动模拟器', action_result: '成功' },
  243. { action: '启动游戏', action_result: '查询IP' },
  244. { action: '脚本启动', action_result: '成功' },
  245. { action: '启动游戏', action_result: '成功' },
  246. { action: '登陆', action_result: '成功' },
  247. { action: '教程主线', action_result: '进入游戏' },
  248. { action: '教程主线', action_result: '新增成功' },
  249. { action: '教程主线', action_result: '留存成功' },
  250. { action: '付费充值', action_result: '付费成功' },
  251. { action: '教程主线', action_result: '可以付费' },
  252. { action: '留存账号总数', action_result: '留存账号总数' },
  253. { action: '询问付费', action_result: '付费' }
  254. ]
  255. let data3 = await queryNewComputerRoom(new_date)
  256. let newComputerRoomData = []
  257. if (_.isEmpty(data3) || data3 == -1) {
  258. // this.logger.warn('新机房后台数据错误')
  259. newComputerRoomData = []
  260. } else {
  261. newComputerRoomData = JSON.parse(data3 + '')
  262. }
  263. let num_arr0 = []
  264. let num_arr1 = []
  265. let num_arr2 = []
  266. let num_arr3 = []
  267. let num_arr4 = []
  268. let num_arr5 = []
  269. let num_arr6 = []
  270. let num_arr7 = []
  271. let num_arr8 = []
  272. let num_arr9 = []
  273. let num_arr10 = []
  274. let num_arr11 = []
  275. let num_arr12 = []
  276. let num_arr13 = []
  277. //查询所有日志结果start===============
  278. await ykhForeach(logs, async (e, i) => {
  279. const action = e.action
  280. const action_result = e.action_result
  281. let arr_i
  282. if (i == 6) {
  283. //小绵羊登录 小绵羊登陆
  284. arr_i = await queryXjfLogByBatch(new_date, '小绵羊登录', action_result)
  285. if (arr_i != 'null') {
  286. num_arr6.push(...JSON.parse(arr_i + ''))
  287. }
  288. arr_i = await queryXjfLogByBatch(new_date, '小绵羊登陆', action_result)
  289. if (arr_i != 'null') {
  290. num_arr6.push(...JSON.parse(arr_i + ''))
  291. }
  292. //魅族登录 魅族登陆
  293. arr_i = await queryXjfLogByBatch(new_date, '魅族登录', action_result)
  294. if (arr_i != 'null') {
  295. num_arr6.push(...JSON.parse(arr_i + ''))
  296. }
  297. arr_i = await queryXjfLogByBatch(new_date, '魅族登陆', action_result)
  298. if (arr_i != 'null') {
  299. num_arr6.push(...JSON.parse(arr_i + ''))
  300. }
  301. //QQ登录 QQ登陆 微信登录 微信登陆
  302. arr_i = await queryXjfLogByBatch(new_date, 'QQ登录', action_result)
  303. if (arr_i != 'null') {
  304. num_arr6.push(...JSON.parse(arr_i + ''))
  305. }
  306. arr_i = await queryXjfLogByBatch(new_date, '微信登录', action_result)
  307. if (arr_i != 'null') {
  308. num_arr6.push(...JSON.parse(arr_i + ''))
  309. }
  310. arr_i = await queryXjfLogByBatch(new_date, 'QQ登陆', action_result)
  311. if (arr_i != 'null') {
  312. num_arr6.push(...JSON.parse(arr_i + ''))
  313. }
  314. arr_i = await queryXjfLogByBatch(new_date, '微信登陆', action_result)
  315. if (arr_i != 'null') {
  316. num_arr6.push(...JSON.parse(arr_i + ''))
  317. }
  318. //网易登录 网易登陆
  319. arr_i = await queryXjfLogByBatch(new_date, '网易登录', action_result)
  320. if (arr_i != 'null') {
  321. num_arr6.push(...JSON.parse(arr_i + ''))
  322. }
  323. arr_i = await queryXjfLogByBatch(new_date, '网易登陆', action_result)
  324. if (arr_i != 'null') {
  325. num_arr6.push(...JSON.parse(arr_i + ''))
  326. }
  327. } else {
  328. arr_i = await queryXjfLogByBatch(new_date, action, action_result)
  329. }
  330. if (arr_i != 'null') {
  331. switch (i) {
  332. case 0: num_arr0.push(arr_i)
  333. break;
  334. case 1: num_arr1.push(arr_i)
  335. break;
  336. case 2: num_arr2.push(arr_i)
  337. break;
  338. case 3: num_arr3.push(arr_i)
  339. break;
  340. case 4: num_arr4.push(arr_i)
  341. break;
  342. case 5: num_arr5.push(arr_i)
  343. break;
  344. case 7: num_arr7.push(arr_i)
  345. break;
  346. case 8: num_arr8.push(arr_i)
  347. break;
  348. case 9: num_arr9.push(arr_i)
  349. break;
  350. case 10: num_arr10.push(arr_i)
  351. break;
  352. case 11: num_arr11.push(arr_i)
  353. break;
  354. case 12: num_arr12.push(arr_i)
  355. break;
  356. case 13: num_arr13.push(arr_i)
  357. break;
  358. }
  359. }
  360. })
  361. if (!_.isEmpty(num_arr0)) {
  362. num_arr0 = JSON.parse(num_arr0 + '')
  363. }
  364. if (!_.isEmpty(num_arr1)) {
  365. num_arr1 = JSON.parse(num_arr1 + '')
  366. }
  367. if (!_.isEmpty(num_arr2)) {
  368. num_arr2 = JSON.parse(num_arr2 + '')
  369. }
  370. if (!_.isEmpty(num_arr3)) {
  371. num_arr3 = JSON.parse(num_arr3 + '')
  372. }
  373. if (!_.isEmpty(num_arr4)) {
  374. num_arr4 = JSON.parse(num_arr4 + '')
  375. }
  376. if (!_.isEmpty(num_arr5)) {
  377. num_arr5 = JSON.parse(num_arr5 + '')
  378. }
  379. if (!_.isEmpty(num_arr7)) {
  380. num_arr7 = JSON.parse(num_arr7 + '')
  381. }
  382. if (!_.isEmpty(num_arr8)) {
  383. num_arr8 = JSON.parse(num_arr8 + '')
  384. }
  385. if (!_.isEmpty(num_arr9)) {
  386. num_arr9 = JSON.parse(num_arr9 + '')
  387. }
  388. if (!_.isEmpty(num_arr10)) {
  389. num_arr10 = JSON.parse(num_arr10 + '')
  390. }
  391. if (!_.isEmpty(num_arr11)) {
  392. num_arr11 = JSON.parse(num_arr11 + '')
  393. }
  394. if (!_.isEmpty(num_arr12)) {
  395. num_arr12 = JSON.parse(num_arr12 + '')
  396. }
  397. if (!_.isEmpty(num_arr13)) {
  398. num_arr13 = JSON.parse(num_arr13 + '')
  399. }
  400. //查询所有日志结果end ===============
  401. //遍历游戏表
  402. await ykhForeach(targetList, async (target) => {
  403. let task_id = target.task_id
  404. let task_name = target.task_name
  405. let directorId = target.directorId
  406. // let login_modeId = target.login_modeId
  407. let xjf_id = target.xjf_id
  408. // console.log(xjf_id)
  409. let num_frozen = 0
  410. let num_pull_account = 0
  411. let num_start_simulator = 0
  412. let num_ip = 0
  413. let num_start_script = 0
  414. let num_start_game = 0
  415. let num_login_success = 0
  416. let num_into_game = 0
  417. let num_new_success = 0
  418. let num_lc_success = 0
  419. let num_pay_success = 0
  420. let rate_all_step = 0
  421. let num_could_pay = 0 // 可以付费的账号
  422. let num_account_lc = 0 //留存账号总数
  423. let num_pull_pay = 0 // 下发付费账号
  424. let order_success_rate = '-/-/-%'
  425. for (let num of num_arr0) {
  426. if (xjf_id == num.game_id) {
  427. num_frozen = num.total
  428. break;
  429. }
  430. }
  431. for (let num of num_arr1) {
  432. if (xjf_id == num.game_id) {
  433. // this.logger.info(num)
  434. num_pull_account = num.total
  435. break;
  436. }
  437. }
  438. for (let num of num_arr2) {
  439. if (xjf_id == num.game_id) {
  440. num_start_simulator = num.total
  441. break;
  442. }
  443. }
  444. for (let num of num_arr3) {
  445. if (xjf_id == num.game_id) {
  446. num_ip = num.total
  447. break;
  448. }
  449. }
  450. for (let num of num_arr4) {
  451. if (xjf_id == num.game_id) {
  452. num_start_script = num.total
  453. break;
  454. }
  455. }
  456. for (let num of num_arr5) {
  457. if (xjf_id == num.game_id) {
  458. num_start_game = num.total
  459. break;
  460. }
  461. }
  462. for (let num of num_arr6) {
  463. if (xjf_id == num.game_id) {
  464. num_login_success = num_login_success + num.total
  465. }
  466. }
  467. for (let num of num_arr7) {
  468. if (xjf_id == num.game_id) {
  469. num_into_game = num.total
  470. break;
  471. }
  472. }
  473. for (let num of num_arr8) {
  474. if (xjf_id == num.game_id) {
  475. num_new_success = num.total
  476. break;
  477. }
  478. }
  479. for (let num of num_arr9) {
  480. if (xjf_id == num.game_id) {
  481. num_lc_success = num.total
  482. break;
  483. }
  484. }
  485. for (let num of num_arr10) {
  486. if (xjf_id == num.game_id) {
  487. num_pay_success = num.total
  488. break;
  489. }
  490. }
  491. for (let num of num_arr11) {
  492. if (xjf_id == num.game_id) {
  493. num_could_pay = num.total
  494. break;
  495. }
  496. }
  497. for (let num of num_arr12) {
  498. if (xjf_id == num.game_id) {
  499. num_account_lc = num.total
  500. break;
  501. }
  502. }
  503. for (let num of num_arr13) {
  504. if (xjf_id == num.game_id) {
  505. num_pull_pay = num.total
  506. break;
  507. }
  508. }
  509. if (num_into_game != 0 && num_start_game != 0) {
  510. rate_all_step = parseFloat(num_into_game + '') / parseFloat(num_start_game + '')
  511. }
  512. //
  513. for (let new_value of newComputerRoomData) {
  514. if (new_value.game_id == xjf_id) {
  515. order_success_rate = new_value.order_success_rate
  516. break;
  517. }
  518. }
  519. let rateObj = {
  520. task_id: task_id,
  521. task_name: task_name,
  522. directorId: directorId,
  523. new_date: new_date,
  524. hour: hour,
  525. num_frozen: num_frozen,
  526. num_pull_account: num_pull_account,
  527. num_start_simulator: num_start_simulator,
  528. num_ip: num_ip,
  529. num_start_script: num_start_script,
  530. num_start_game: num_start_game,
  531. num_login_success: num_login_success,
  532. num_into_game: num_into_game,
  533. num_new_success: num_new_success,
  534. num_lc_success: num_lc_success,
  535. num_pay_success: num_pay_success,
  536. rate_all_step: rate_all_step,
  537. num_could_pay: num_could_pay, // 可以付费的账号
  538. num_account_lc: num_account_lc, //留存账号总数
  539. num_pull_pay: num_pull_pay, // 下发付费账号
  540. order_success_rate: order_success_rate
  541. }
  542. // console.log(rateObj)
  543. const AbnormalRateEntity = await this.ShuyouAbnormalRateEntity.findOne({
  544. new_date: new_date,
  545. hour: hour,
  546. task_id: task_id
  547. });
  548. if (AbnormalRateEntity) {
  549. await this.ShuyouAbnormalRateEntity
  550. .createQueryBuilder()
  551. .update()
  552. .set(rateObj)
  553. .where('new_date = :new_date and hour = :hour and task_id = :task_id', {
  554. new_date: new_date,
  555. hour: hour,
  556. task_id: task_id
  557. })
  558. .execute();
  559. } else {
  560. await this.ShuyouAbnormalRateEntity
  561. .createQueryBuilder()
  562. .insert()
  563. .into(ShuyouAbnormalRateEntity)
  564. .values(rateObj)
  565. .execute();
  566. }
  567. })
  568. // ====================================
  569. this.logger.info('syncAbnormalRateByBatch SUCCESS>>>' + updateTime);
  570. return 'syncAbnormalRateByBatch SUCCESS>>>' + updateTime;
  571. }
  572. /**
  573. * 定时查询QQ卡剩余张数,少于5张,则报警
  574. *
  575. * @memberof XjfLogTaskService
  576. */
  577. async queryQQCardCount() {
  578. let updateTime = new Date()
  579. let data
  580. data = await queryQQCardCount()
  581. // console.log('data:' + data)
  582. let text = ''
  583. if (parseInt(data + '') < 5) {
  584. // console.log('QQ卡即将用尽')
  585. text = ">##### QQ卡即将用尽,请及时补充,当前剩余" + data + " \n"
  586. await this.shuyouUtilsService.postRobotEnterpriseWeChat3(text)
  587. }
  588. data = await queryMzBalance()
  589. // console.log('data:' + data)
  590. if (parseInt(data + '') <= 500) {
  591. // console.log('QQ卡即将用尽')
  592. text = ">##### 魅族云点即将用尽,请及时补充,当前剩余" + data + " \n"
  593. await this.shuyouUtilsService.postRobotEnterpriseWeChat3(text)
  594. }
  595. return 'queryQQCardCount SUCCESS>>>' + updateTime;
  596. }
  597. }
  598. //==========================================================================================
  599. // 根据gameid获取新机房信息
  600. let queryXjfId = function (game_id) {
  601. var url = 'http://xjf.lianyou.fun:8099/v1/task_statistics/get_data_id?game_id=' + game_id
  602. var http = require('http');
  603. var pm = new Promise(function (resolve, reject) {
  604. http.get(url, function (res) {
  605. var html = '';
  606. res.on('data', function (d) {
  607. html += d.toString()
  608. });
  609. res.on('end', function () {
  610. resolve(html);
  611. });
  612. }).on('error', function (e) {
  613. // reject(e)
  614. resolve(-1)
  615. });
  616. });
  617. return pm;
  618. }
  619. // 获取新机房游戏数据
  620. let queryNewComputerRoom = function (new_date) {
  621. var url = 'http://xjf.lianyou.fun:8099/v1/task_statistics?query=date:' + new_date + ',type:machine'
  622. var http = require('http');
  623. var pm = new Promise(function (resolve, reject) {
  624. http.get(url, function (res) {
  625. var html = '';
  626. res.on('data', function (d) {
  627. html += d.toString()
  628. });
  629. res.on('end', function () {
  630. resolve(html);
  631. });
  632. }).on('error', function (e) {
  633. // reject(e)
  634. resolve(-1)
  635. });
  636. });
  637. return pm;
  638. }
  639. // 获取新机房日志
  640. let queryXjfLog = function (new_date, action, action_result, game_id) {
  641. var url = 'http://xjf.lianyou.fun:8099/v1/device/get_log?date=' + new_date + '&action=' + action + '&action_result=' + action_result + '&game_id=' + game_id
  642. var http = require('http');
  643. var pm = new Promise(function (resolve, reject) {
  644. http.get(url, function (res) {
  645. var html = '';
  646. res.on('data', function (d) {
  647. html += d.toString()
  648. });
  649. res.on('end', function () {
  650. resolve(html);
  651. });
  652. }).on('error', function (e) {
  653. // reject(e)
  654. resolve(-1)
  655. });
  656. });
  657. return pm;
  658. }
  659. // 批量获取新机房日志
  660. let queryXjfLogByBatch = function (new_date, action, action_result) {
  661. var url = 'http://xjf.lianyou.fun:8099/v1/device/get_log_by_game?date=' + new_date + '&action=' + action + '&action_result=' + action_result
  662. var http = require('http');
  663. var pm = new Promise(function (resolve, reject) {
  664. http.get(url, function (res) {
  665. var html = '';
  666. res.on('data', function (d) {
  667. html += d.toString()
  668. });
  669. res.on('end', function () {
  670. resolve(html);
  671. });
  672. }).on('error', function (e) {
  673. // reject(e)
  674. resolve(-1)
  675. });
  676. });
  677. return pm;
  678. }
  679. // 获取QQ卡剩余张数
  680. let queryQQCardCount = function () {
  681. var url = 'http://xjf.lianyou.fun:8099/v1/device/qq_card_count'
  682. var http = require('http');
  683. var pm = new Promise(function (resolve, reject) {
  684. http.get(url, function (res) {
  685. var html = '';
  686. res.on('data', function (d) {
  687. html += d.toString()
  688. });
  689. res.on('end', function () {
  690. resolve(html);
  691. });
  692. }).on('error', function (e) {
  693. // reject(e)
  694. resolve(-1)
  695. });
  696. });
  697. return pm;
  698. }
  699. // 获取魅族云点余额
  700. let queryMzBalance = function () {
  701. var url = 'http://xjf.lianyou.fun:8099/v1/device/setAccountLog?action=付费充值&action_result=查询魅族云点&account=meizu'
  702. var http = require('http');
  703. var pm = new Promise(function (resolve, reject) {
  704. http.get(url, function (res) {
  705. var html = '';
  706. res.on('data', function (d) {
  707. html += d.toString()
  708. });
  709. res.on('end', function () {
  710. resolve(html);
  711. });
  712. }).on('error', function (e) {
  713. // reject(e)
  714. resolve(-1)
  715. });
  716. });
  717. return pm;
  718. }
  719. // foreach加上async/await
  720. const ykhForeach = async (arr, callback) => {
  721. const length = arr.length;
  722. const O = Object(arr);
  723. let k = 0;
  724. while (k < length) {
  725. if (k in O) {
  726. // console.log('doing foreach...');
  727. const kValue = O[k];
  728. await callback(kValue, k, O);
  729. }
  730. k++;
  731. }
  732. };