RelInviter.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. // const bodyData = {};
  27. // const response = await that.app.curl('http://127.0.0.1:8105/oneshop/api/redEnvelopeProducts', {
  28. // method: 'GET', dataType: 'json', contentType: 'json', data: bodyData,
  29. // });
  30. // const response = await that.getCouldCashCommission(10);
  31. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', { commissionResult }, false));
  32. }
  33. async changOpenid() {
  34. const that = this;
  35. const page = 4;
  36. const limit = 100;
  37. const users = await that.app.model.Users.findAll({
  38. offset: (page - 1) * limit, limit,
  39. attributes: [ 'nickname', 'openid' ],
  40. order: [[ 'user_id', 'asc' ]],
  41. });
  42. const openids = [];
  43. for (let i = 0; i < users.length; i++) {
  44. openids.push(users[i].openid);
  45. }
  46. let index = 0;
  47. const interval = setInterval(() => {
  48. const that = this;
  49. const data = [];
  50. data.push(openids[index]);
  51. console.log('openids:');
  52. console.log(data);
  53. that.service.wechat.changeOpenid(data, '');
  54. index += 1;
  55. if (index >= openids.length) {
  56. clearInterval(interval);
  57. }
  58. }, 350);
  59. }
  60. async getCurrentCommission() {
  61. const that = this;
  62. const seq = that.app.Sequelize;
  63. const selectBean = await that.app.comoBean.instance({}, {
  64. where: { user_id: 10 }, // type-1提现失败类型
  65. include: [ {
  66. model: that.app.model.Orders,
  67. where: { order_status: { [seq.Op.lte]: 2 } },
  68. attributes: [ 'order_id', 'order_status', 'order_amount', ],
  69. as: 'order'
  70. } ],
  71. // attributes: [ 'user_id', [ seq.fn('sum', seq.col('commission')), 'all_cash' ] ],
  72. });
  73. return await that.service.base.select(selectBean, that.app.model.UsersCommissionLogs, '查询佣金失败,请稍候重试', false, true);
  74. }
  75. async selectInfo(order_id) {
  76. const that = this;
  77. const options = {
  78. where: { order_id }, include: [
  79. { model: that.app.model.PaysConfig, attributes: [ 'pay_name' ], as: 'pays_config' },
  80. { model: that.app.model.Users, as: 'users', attributes: [ 'account_name', 'nickname' ] },
  81. {
  82. model: that.app.model.OrdersProducts, as: 'orders_products', attributes: {
  83. exclude: [ 'product_id', 'create_time', 'order_id', 'activity_name', 'activity_id', 'activity_desc' ],
  84. },
  85. },
  86. { model: that.app.model.Payments, as: 'payments', attributes: [ 'create_time' ], required: false },
  87. ], attributes: {
  88. exclude: [ 'seller_remarks', 'province_id', 'city_id', 'county_id', 'shipping_id',
  89. 'shipping_fee', 'activity_id', 'activity_name', 'activity_desc' ],
  90. },
  91. };
  92. const selectBean = await that.app.comoBean.instance({}, options);
  93. return await that.service.base.select(selectBean, that.app.model.Orders, '查询订单详情失败,请稍候重试', false, false);
  94. }
  95. /**
  96. * 手动执行一次每日定时任务(完成订单分佣)
  97. * http://test.enroll.sizhijie.com/oneshop/api/executeTask
  98. * @return {Promise<void>}
  99. */
  100. async executeSchedule() {
  101. const that = this;
  102. await that.service.inviter.executeSchedule();
  103. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', { msg: '手动执行每日定时任务(完成订单分佣)一次' }, false));
  104. }
  105. };