RelInviter.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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://ysjj.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. const stateStr = that.app.szjcomo.base64_encode('http://ysjj.sizhijie.com/#/shop/officeHome');
  16. console.log(stateStr);
  17. // https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7713e08a353ffcd7&redirect_uri=http%3A%2F%2Fysjj.sizhijie.com%2F%23%2Fshop%2Fwxauth&response_type=code&scope=snsapi_userinfo&state=aHR0cDovL3lzamouc2l6aGlqaWUuY29tLyMvc2hvcC9vZmZpY2VIb21l#wechat_redirect
  18. // 2023/2/21 获取当前待发的佣金总额
  19. const commissionResult = await that.getCurrentCommission();
  20. // 2023/2/21 替换更新openid
  21. // await that.changOpenid();
  22. // 2023/3/5 分佣发放
  23. // that.service.commission.orderCommissionDispatchAfterPay(17);
  24. // 2023/3/5 餐币发放
  25. // const dispatchResult = that.service.diningCoin.orderDiningCoinDispatchAfterPay(362);
  26. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', { commissionResult }, false));
  27. }
  28. async changOpenid() {
  29. const that = this;
  30. const page = 4;
  31. const limit = 100;
  32. const users = await that.app.model.Users.findAll({
  33. offset: (page - 1) * limit, limit,
  34. attributes: [ 'nickname', 'openid' ],
  35. order: [[ 'user_id', 'asc' ]],
  36. });
  37. const openids = [];
  38. for (let i = 0; i < users.length; i++) {
  39. openids.push(users[i].openid);
  40. }
  41. let index = 0;
  42. const interval = setInterval(() => {
  43. const that = this;
  44. const data = [];
  45. data.push(openids[index]);
  46. console.log('openids:');
  47. console.log(data);
  48. that.service.wechat.changeOpenid(data, '');
  49. index += 1;
  50. if (index >= openids.length) {
  51. clearInterval(interval);
  52. }
  53. }, 350);
  54. }
  55. async getCurrentCommission() {
  56. const that = this;
  57. const seq = that.app.Sequelize;
  58. const selectBean = await that.app.comoBean.instance({}, {
  59. where: { type: { [seq.Op.ne]: -1 } }, // type-1提现失败类型
  60. attributes: [[ seq.fn('sum', seq.col('commission')), 'all_commission' ]],
  61. });
  62. return await that.service.base.select(selectBean, that.app.model.UsersCommissionLogs, '查询佣金失败,请稍候重试', false, false);
  63. }
  64. async selectInfo(order_id) {
  65. const that = this;
  66. const options = {
  67. where: { order_id }, include: [
  68. { model: that.app.model.PaysConfig, attributes: [ 'pay_name' ], as: 'pays_config' },
  69. { model: that.app.model.Users, as: 'users', attributes: [ 'account_name', 'nickname' ] },
  70. {
  71. model: that.app.model.OrdersProducts, as: 'orders_products', attributes: {
  72. exclude: [ 'product_id', 'create_time', 'order_id', 'activity_name', 'activity_id', 'activity_desc' ],
  73. },
  74. },
  75. { model: that.app.model.Payments, as: 'payments', attributes: [ 'create_time' ], required: false },
  76. ], attributes: {
  77. exclude: [ 'seller_remarks', 'province_id', 'city_id', 'county_id', 'shipping_id',
  78. 'shipping_fee', 'activity_id', 'activity_name', 'activity_desc' ],
  79. },
  80. };
  81. const selectBean = await that.app.comoBean.instance({}, options);
  82. return await that.service.base.select(selectBean, that.app.model.Orders, '查询订单详情失败,请稍候重试', false, false);
  83. }
  84. /**
  85. * 手动执行一次每日定时任务(完成订单分佣)
  86. * http://test.enroll.sizhijie.com/oneshop/api/executeTask
  87. * @return {Promise<void>}
  88. */
  89. async executeSchedule() {
  90. const that = this;
  91. await that.service.inviter.executeSchedule();
  92. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', { msg: '手动执行每日定时任务(完成订单分佣)一次' }, false));
  93. }
  94. };