RelInviter.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 'use strict';
  2. const Base = require('../base');
  3. const { setInterval } = require('timers');
  4. // 商品接口控制器
  5. module.exports = class RelInviterController extends Base {
  6. /**
  7. * 接口测试函数
  8. * http://test.enroll.sizhijie.com/oneshop/api/test
  9. * @return {Promise<*>}
  10. */
  11. async test() {
  12. const that = this;
  13. // const stateStr = that.app.szjcomo.base64_encode('http://test.enroll.sizhijie.com/#/shop/category?category_id=11');
  14. // const hh = that.app.szjcomo.base64_decode(stateStr);
  15. // 2023/2/21 获取当前待发的佣金总额
  16. const commissionResult = await that.getCurrentCommission();
  17. // 2023/2/21 替换更新openid
  18. // await that.changOpenid();
  19. // 2023/3/5 分佣发放
  20. that.service.commission.orderCommissionDispatchAfterPay(4);
  21. // 2023/3/5 餐币发放
  22. // const dispatchResult = that.service.diningCoin.orderDiningCoinDispatchAfterPay(362);
  23. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', { commissionResult }, false));
  24. }
  25. async changOpenid() {
  26. const that = this;
  27. const page = 4;
  28. const limit = 100;
  29. const users = await that.app.model.Users.findAll({
  30. offset: (page - 1) * limit, limit,
  31. attributes: [ 'nickname', 'openid' ],
  32. order: [[ 'user_id', 'asc' ]],
  33. });
  34. const openids = [];
  35. for (let i = 0; i < users.length; i++) {
  36. openids.push(users[i].openid);
  37. }
  38. let index = 0;
  39. const interval = setInterval(() => {
  40. const that = this;
  41. const data = [];
  42. data.push(openids[index]);
  43. console.log('openids:');
  44. console.log(data);
  45. that.service.wechat.changeOpenid(data, '');
  46. index += 1;
  47. if (index >= openids.length) {
  48. clearInterval(interval);
  49. }
  50. }, 350);
  51. }
  52. async getCurrentCommission() {
  53. const that = this;
  54. const seq = that.app.Sequelize;
  55. const selectBean = await that.app.comoBean.instance({}, {
  56. where: { type: { [seq.Op.ne]: -1 } }, // type-1提现失败类型
  57. attributes: [[ seq.fn('sum', seq.col('commission')), 'all_commission' ]],
  58. });
  59. return await that.service.base.select(selectBean, that.app.model.UsersCommissionLogs, '查询佣金失败,请稍候重试', false, false);
  60. }
  61. async selectInfo(order_id) {
  62. const that = this;
  63. const options = {
  64. where: { order_id }, include: [
  65. { model: that.app.model.PaysConfig, attributes: [ 'pay_name' ], as: 'pays_config' },
  66. { model: that.app.model.Users, as: 'users', attributes: [ 'account_name', 'nickname' ] },
  67. {
  68. model: that.app.model.OrdersProducts, as: 'orders_products', attributes: {
  69. exclude: [ 'product_id', 'create_time', 'order_id', 'activity_name', 'activity_id', 'activity_desc' ],
  70. },
  71. },
  72. { model: that.app.model.Payments, as: 'payments', attributes: [ 'create_time' ], required: false },
  73. ], attributes: {
  74. exclude: [ 'seller_remarks', 'province_id', 'city_id', 'county_id', 'shipping_id',
  75. 'shipping_fee', 'activity_id', 'activity_name', 'activity_desc' ],
  76. },
  77. };
  78. const selectBean = await that.app.comoBean.instance({}, options);
  79. return await that.service.base.select(selectBean, that.app.model.Orders, '查询订单详情失败,请稍候重试', false, false);
  80. }
  81. /**
  82. * 手动执行一次每日定时任务(完成订单分佣)
  83. * http://test.enroll.sizhijie.com/oneshop/api/executeTask
  84. * @return {Promise<void>}
  85. */
  86. async executeSchedule() {
  87. const that = this;
  88. await that.service.inviter.executeSchedule();
  89. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', { msg: '手动执行每日定时任务(完成订单分佣)一次' }, false));
  90. }
  91. };