|
@@ -234,7 +234,7 @@ module.exports = class UserController extends shopController {
|
|
|
// include: [
|
|
|
// { model: that.app.model.ProxyApplyLogs, as: 'proxyApplyLogs', attributes: [ 'verify_status' ] },
|
|
|
// ],
|
|
|
- attributes: [ 'user_id', 'account_name', 'nickname', 'headimgurl', 'openid', 'intergral', 'is_proxy', 'partner_id', 'is_office', 'is_family' ],
|
|
|
+ attributes: [ 'user_id', 'account_name', 'nickname', 'headimgurl', 'openid', 'intergral', 'is_proxy', 'partner_id', 'is_office', 'is_family', 'lucky_time' ],
|
|
|
raw: true,
|
|
|
});
|
|
|
if (!user) throw new Error('登录失败,请检查账号密码是否正确');
|
|
@@ -326,7 +326,7 @@ module.exports = class UserController extends shopController {
|
|
|
// console.log('==========inviteCode========== : ' + inviter_id);
|
|
|
const options = {
|
|
|
where: { openid: userInfo.openid },
|
|
|
- attributes: [ 'user_id', 'account_name', 'nickname', 'headimgurl', 'openid', 'partner_id', 'is_office', 'is_family' ],
|
|
|
+ attributes: [ 'user_id', 'account_name', 'nickname', 'headimgurl', 'openid', 'partner_id', 'is_office', 'is_family', 'lucky_time' ],
|
|
|
raw: true,
|
|
|
};
|
|
|
let user = await that.useModel.findOne(options);
|
|
@@ -428,7 +428,7 @@ module.exports = class UserController extends shopController {
|
|
|
offset: (data.page - 1) * data.limit,
|
|
|
limit: data.limit,
|
|
|
where: { user_id: data.user_id },
|
|
|
- order: [[ 'log_id', 'desc' ]],
|
|
|
+ order: [ [ 'log_id', 'desc' ] ],
|
|
|
attributes: [ 'log_id', 'log_desc', 'change_time', 'money', 'type', 'inviter_id', 'inviter_name', 'inviter_img' ],
|
|
|
});
|
|
|
const result = await that.service.base.select(selectBean, that.app.model.UsersMoneyLogs, '查询资金明细失败,请稍候重试', true, true);
|
|
@@ -449,7 +449,7 @@ module.exports = class UserController extends shopController {
|
|
|
const selectBean = await that.app.comoBean.instance(data, {
|
|
|
// offset: (data.page - 1) * data.limit, limit: data.limit,
|
|
|
where: { user_id: data.user_id },
|
|
|
- order: [[ 'log_id', 'desc' ]],
|
|
|
+ order: [ [ 'log_id', 'desc' ] ],
|
|
|
attributes: [ 'log_desc', 'create_time', 'commission', 'type', 'inviter_id', 'inviter_name', 'inviter_img' ],
|
|
|
});
|
|
|
// 2022/11/28 直接查询所有数据 不分页
|
|
@@ -470,7 +470,7 @@ module.exports = class UserController extends shopController {
|
|
|
const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
|
|
|
const selectBean = await that.app.comoBean.instance(data, {
|
|
|
where: { user_id: data.user_id },
|
|
|
- order: [[ 'log_id', 'desc' ]],
|
|
|
+ order: [ [ 'log_id', 'desc' ] ],
|
|
|
});
|
|
|
// 2022/11/28 直接查询所有数据 不分页
|
|
|
const result = await that.service.base.select(selectBean, that.app.model.DinnerCoinLogs, '查询分佣明细失败,请稍候重试', false, true);
|
|
@@ -543,7 +543,7 @@ module.exports = class UserController extends shopController {
|
|
|
partner_id: { [seq.Op.in]: [ businessInfo.partner_id, 1 ] },
|
|
|
expired: false,
|
|
|
},
|
|
|
- attributes: [[ seq.fn('sum', seq.col('account')), 'account' ]],
|
|
|
+ attributes: [ [ seq.fn('sum', seq.col('account')), 'account' ] ],
|
|
|
});
|
|
|
const result = await that.service.base.select(selectBean, that.app.model.DinnerCoins, '查询餐饮币账户余额失败,请稍候重试', false, false);
|
|
|
const res = JSON.parse(JSON.stringify(result));
|
|
@@ -600,7 +600,7 @@ module.exports = class UserController extends shopController {
|
|
|
create_time: { [seq.Op.lte]: endDateTime },
|
|
|
account: { [seq.Op.gte]: 0 },
|
|
|
},
|
|
|
- attributes: [[ seq.fn('sum', seq.col('account')), 'account' ]],
|
|
|
+ attributes: [ [ seq.fn('sum', seq.col('account')), 'account' ] ],
|
|
|
});
|
|
|
const coinResult = await that.service.base.select(selectBean, that.app.model.DinnerCoinLogs, '查询商家可提现餐币金额失败,请稍候重试', false, false);
|
|
|
const selectBean2 = await that.app.comoBean.instance({}, {
|
|
@@ -610,7 +610,7 @@ module.exports = class UserController extends shopController {
|
|
|
account: { [seq.Op.lte]: 0 },
|
|
|
type: { [seq.Op.ne]: -1 },
|
|
|
},
|
|
|
- attributes: [[ seq.fn('sum', seq.col('account')), 'account' ]],
|
|
|
+ attributes: [ [ seq.fn('sum', seq.col('account')), 'account' ] ],
|
|
|
});
|
|
|
const cashResult = await that.service.base.select(selectBean2, that.app.model.DinnerCoinLogs, '查询商家可提现餐币金额失败,请稍候重试', false, false);
|
|
|
const coinRes = JSON.parse(JSON.stringify(coinResult));
|
|
@@ -654,7 +654,7 @@ module.exports = class UserController extends shopController {
|
|
|
partner_id: { [seq.Op.in]: [ transferParams.partner_id, 1 ] },
|
|
|
expired: false,
|
|
|
},
|
|
|
- order: [[ 'partner_id', 'desc' ], [ 'ori_partner', 'desc' ]],
|
|
|
+ order: [ [ 'partner_id', 'desc' ], [ 'ori_partner', 'desc' ] ],
|
|
|
});
|
|
|
// 2023/2/28 查询所有指定商家餐币
|
|
|
const result = await that.service.base.select(selectBean, that.app.model.DinnerCoins, '查询餐饮币账户失败,请稍候重试', false, true);
|
|
@@ -859,12 +859,12 @@ module.exports = class UserController extends shopController {
|
|
|
// 2022/11/28 查询7天前的所得分佣总和 以及所有时间得提现总和 再求和 即为 可提现金额
|
|
|
const selectBean = await that.app.comoBean.instance({ user_id }, {
|
|
|
where: { user_id, create_time: { [seq.Op.lte]: endDateTime }, commission: { [seq.Op.gte]: 0 } },
|
|
|
- attributes: [ 'user_id', [ seq.fn('sum', seq.col('commission')), 'all_commission' ]],
|
|
|
+ attributes: [ 'user_id', [ seq.fn('sum', seq.col('commission')), 'all_commission' ] ],
|
|
|
});
|
|
|
const commissionResult = await that.service.base.select(selectBean, that.app.model.UsersCommissionLogs, '查询佣金失败,请稍候重试', false, false);
|
|
|
const selectBean2 = await that.app.comoBean.instance({ user_id }, {
|
|
|
where: { user_id, commission: { [seq.Op.lte]: 0 }, type: { [seq.Op.ne]: -1 } }, // type-1提现失败类型
|
|
|
- attributes: [ 'user_id', [ seq.fn('sum', seq.col('commission')), 'all_cash' ]],
|
|
|
+ attributes: [ 'user_id', [ seq.fn('sum', seq.col('commission')), 'all_cash' ] ],
|
|
|
});
|
|
|
const cashResult = await that.service.base.select(selectBean2, that.app.model.UsersCommissionLogs, '查询佣金失败,请稍候重试', false, false);
|
|
|
const commRes = JSON.parse(JSON.stringify(commissionResult));
|
|
@@ -950,7 +950,7 @@ module.exports = class UserController extends shopController {
|
|
|
user_id: data.user_id,
|
|
|
type: { [seq.Op.in]: [ 1, 2 ] },
|
|
|
},
|
|
|
- order: [[ 'type', 'asc' ]],
|
|
|
+ order: [ [ 'type', 'asc' ] ],
|
|
|
});
|
|
|
const result = await that.service.base.select(selectBean, that.app.model.UsersMoneyLogs, '新用户福利查询失败,请稍候重试', true, true);
|
|
|
return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
|
|
@@ -967,27 +967,54 @@ module.exports = class UserController extends shopController {
|
|
|
const that = this;
|
|
|
try {
|
|
|
const data = await that.ctx.validate(that.luckyValidate, await that.ctx.anyParse());
|
|
|
- // 2023/11/17 todo: 用户今天抽奖校验
|
|
|
+ // 2023/11/17 用户今天是否已经抽奖
|
|
|
const user = await that.useModel.findOne({
|
|
|
where: { user_id: data.user_id },
|
|
|
});
|
|
|
-
|
|
|
- // 2023/11/17 todo: 发起概率抽奖 发放奖项 (红包上限)
|
|
|
- const seq = that.app.Sequelize;
|
|
|
- const selectBean = await that.app.comoBean.instance(data, {
|
|
|
- offset: (data.page - 1) * data.limit, limit: data.limit, where: {
|
|
|
- user_id: data.user_id,
|
|
|
- type: { [seq.Op.in]: [ 1, 2 ] },
|
|
|
- },
|
|
|
- order: [[ 'type', 'asc' ]],
|
|
|
- });
|
|
|
- const result = await that.service.base.select(selectBean, that.app.model.UsersMoneyLogs, '新用户福利查询失败,请稍候重试', true, true);
|
|
|
- return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
|
|
|
+ const isTodayLucky = await that.service.baseUtils.isToday(user.lucky_time);
|
|
|
+ // const isTodayLucky = false;
|
|
|
+ if (isTodayLucky) {
|
|
|
+ throw new Error('您今天已经抽奖了哦,明天再来吧!');
|
|
|
+ } else {
|
|
|
+ // 2023/11/17 : 发起概率抽奖 发放奖项 (todo 红包上限)
|
|
|
+ const prizes = [
|
|
|
+ { reward: 6, weight: 4 },
|
|
|
+ { reward: 1, weight: 1 },
|
|
|
+ { reward: 10, weight: 30 },
|
|
|
+ { reward: 8, weight: 5 },
|
|
|
+ { reward: 30, weight: 10 },
|
|
|
+ { reward: 20, weight: 50 }
|
|
|
+ ];
|
|
|
+ const prizeAward = await that.lottery(prizes);
|
|
|
+ // 2023/11/21 发放红包奖励
|
|
|
+ // console.log(prizeAward);
|
|
|
+ await that.service.shop.userMoneyAdd(user.user_id, prizeAward.reward, null, '每日抽奖红包', 0, 4);
|
|
|
+ return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', prizeAward, false));
|
|
|
+ }
|
|
|
} catch (err) {
|
|
|
return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //权重抽奖函数
|
|
|
+ async lottery(prizes) {
|
|
|
+ let total = 0;
|
|
|
+ let percent;
|
|
|
+ //下标标记数组
|
|
|
+ let index = [];
|
|
|
+ for (let i = 0; i < prizes.length; i++) {
|
|
|
+ //判断元素的权重,为了实现小数权重,先将所有的值放大100倍
|
|
|
+ percent = 'undefined' != typeof (prizes[i].weight) ? prizes[i].weight : 0;
|
|
|
+ for (let j = 0; j < percent; j++) {
|
|
|
+ index.push(i);
|
|
|
+ }
|
|
|
+ total += percent;
|
|
|
+ }
|
|
|
+ //随机数值
|
|
|
+ let rand = Math.floor(Math.random() * total);
|
|
|
+ return prizes[index[rand]];
|
|
|
+ };
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 更新用户信息
|