123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 'use strict';
- const BaseService = require('./base.js');
- // 邀请绑定服务类
- class InviterService extends BaseService {
- /**
- * 记录邀请用户关系绑定
- * @param user_id
- * @param inviter_id
- * @return {Promise<type[]>}
- */
- async addRelUserInviter(user_id, inviter_id) {
- const that = this;
- const createBean = await that.app.comoBean.instance({
- user_id,
- inviter_id,
- create_time: that.app.szjcomo.date('Y-m-d H:i:s'),
- }, {});
- const result = await that.create(createBean, that.app.model.RelUserInviter, '记录邀请用户关系绑定失败');
- return result;
- }
- /**
- * 手动执行一次每日定时任务(完成订单分佣)
- * @return {Promise<void>}
- */
- async executeSchedule() {
- /* const that = this;
- // 2022/11/17 每日凌晨零点查询过去一周确认收货的订单
- that.logger.error('定时任务执行,时间为:%s', this.app.szjcomo.date('Y-m-d H:i:s'));
- const seq = that.app.Sequelize;
- const currentDateTime = that.app.szjcomo.date('Y-m-d H:i:s');
- // 2022/11/18 :当前测试调试时间 ,正式发布前时间需要调整
- const sevenDayTime = 7 * 24 * 60 * 60 * 1000;
- const endTimeStamp = Date.parse(currentDateTime);
- const startTimeStamp = endTimeStamp - sevenDayTime;
- const endDateTime = that.app.szjcomo.date('Y-m-d H:i:s', endTimeStamp / 1000);
- const startDateTime = that.app.szjcomo.date('Y-m-d H:i:s', startTimeStamp / 1000);
- const opts = {
- where: {// 订单有邀请人id 且 没有分佣记录 且 订单状态是已收货状态( 1 待发货 2待收货 3待评价 4已完成)
- inviter_id: { [seq.Op.gte]: 0 },
- commission_log_id: -1,
- order_status: { [seq.Op.in]: [ 1, 2, 3, 4 ] },
- // query_time: { [seq.Op.between]: [ startDateTime, endDateTime ] }, 订单创建时间
- create_time: { [seq.Op.between]: [ startDateTime, endDateTime ] },
- },
- // /!*include: [
- // { model: that.app.model.PaysConfig, attributes: [ 'pay_name' ], as: 'pays_config' },
- // { model: that.app.model.Users, as: 'users', attributes: [ 'account_name', 'nickname' ] },
- // {
- // model: that.app.model.OrdersProducts, as: 'orders_products', attributes: {
- // exclude: [ 'product_id', 'create_time', 'order_id', 'activity_name', 'activity_id', 'activity_desc' ],
- // }, order: [[ 'rec_id', 'asc' ]],
- // },
- // ],*!/
- attributes: {
- exclude: [ 'seller_remarks', 'province_id', 'city_id', 'county_id', 'shipping_id', 'shipping_fee', 'activity_id', 'activity_name', 'activity_desc' ],
- }, order: [[ 'order_id', 'desc' ]],
- };
- const selectBean = await that.app.comoBean.instance({}, opts);
- const result = await that.app.comoBean.select(selectBean, that.app.model.Orders, true, true, '定时查询待分佣订单列表失败');
- if (result.count > 0) {
- result.rows.forEach(order => {
- // 2022/11/17 发放分佣并记录
- const dispatchResult = that.service.commission.dispatchCommission(order);
- let commission_log_id = -1;
- dispatchResult.then(log_id => {
- commission_log_id = log_id;
- if (commission_log_id >= 0) {
- // 2022/11/17 更新订单信息
- const updateBean = that.app.comoBean.instance({ commission_log_id }, {
- where: { order_id: order.order_id },
- });
- that.service.base.update(updateBean, that.app.model.Orders, '发放分佣后更新订单状态失败,请稍候重试');
- } else {
- that.logger.error('发放分佣记录失败,对应订单order_id: %s , 订单金额为:%s', order.order_id, order.order_amount);
- }
- });
- });
- }*/
- }
- }
- module.exports = InviterService;
|