update_cash_out_log.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. const Subscription = require('egg').Subscription;
  3. // 2023/2/2 提现结果定时查询任务
  4. class UpdateCashOutLog extends Subscription {
  5. // 通过 schedule 属性来设置定时任务的执行间隔等配置
  6. static get schedule() {
  7. return {
  8. interval: '60m', // 60 分钟间隔
  9. // interval: '3s', // 10s
  10. type: 'all', // 指定所有的 worker 都需要执行
  11. };
  12. }
  13. // subscribe 是真正定时任务执行时被运行的函数
  14. async subscribe() {
  15. const that = this;
  16. // 2023/2/2 查询正在转账中的分佣提现记录
  17. const result = await that.service.cash.getCommissionCashingLog();
  18. // 2023/2/2 查询 提现结果并更新记录
  19. if (result.length) {
  20. for (let i = 0; i < result.length; i++) {
  21. await that.service.wxPay.getTransferResult({
  22. out_batch_no: result[i].out_batch_no,
  23. out_detail_no: result[i].out_detail_no,
  24. user_id: result[i].user_id,
  25. cash: result[i].cash,
  26. });
  27. }
  28. }
  29. // 2023/2/2 查询正在转账中的餐币提现记录
  30. const result2 = await that.service.cash.getCoinsCashingLog();
  31. // 2023/2/2 查询 提现结果并更新记录
  32. if (result2.length) {
  33. for (let i = 0; i < result2.length; i++) {
  34. await that.service.businessPayService.getTransferResult({
  35. out_batch_no: result2[i].out_batch_no,
  36. out_detail_no: result2[i].out_detail_no,
  37. user_id: result2[i].user_id,
  38. cash: result2[i].cash,
  39. });
  40. }
  41. }
  42. }
  43. }
  44. module.exports = UpdateCashOutLog;