|
@@ -214,7 +214,7 @@ module.exports = class UserController extends shopController {
|
|
.required()
|
|
.required()
|
|
.notEmpty()
|
|
.notEmpty()
|
|
.number(),
|
|
.number(),
|
|
- diningCoinCode: that.ctx.rules.name('餐币二维码特征')
|
|
|
|
|
|
+ couponCode: that.ctx.rules.name('餐币二维码特征')
|
|
.required()
|
|
.required()
|
|
.notEmpty(),
|
|
.notEmpty(),
|
|
};
|
|
};
|
|
@@ -254,6 +254,8 @@ module.exports = class UserController extends shopController {
|
|
*/
|
|
*/
|
|
async loginHandle(user = {}) {
|
|
async loginHandle(user = {}) {
|
|
const that = this;
|
|
const that = this;
|
|
|
|
+ // 2023/2/28 UIOT现金券发放
|
|
|
|
+ that.service.coupon.dispatchCoupon(user.user_id);
|
|
const token = that.app.jwt.sign(user, that.app.config.jwt.secret, { expiresIn: '24h' });
|
|
const token = that.app.jwt.sign(user, that.app.config.jwt.secret, { expiresIn: '24h' });
|
|
const result = { token, user };
|
|
const result = { token, user };
|
|
return result;
|
|
return result;
|
|
@@ -486,8 +488,8 @@ module.exports = class UserController extends shopController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // 2023/2/28 用户餐饮币账户列表
|
|
|
|
- async userDiningCoin() {
|
|
|
|
|
|
+ // 2023/2/28 用户卡券账户列表
|
|
|
|
+ async userCoupon() {
|
|
const that = this;
|
|
const that = this;
|
|
try {
|
|
try {
|
|
const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
|
|
const data = await that.ctx.validate(that.userMoneyValidate, await that.ctx.getParse());
|
|
@@ -523,11 +525,11 @@ module.exports = class UserController extends shopController {
|
|
*/
|
|
*/
|
|
async getCouldTransferCoin(data) {
|
|
async getCouldTransferCoin(data) {
|
|
const that = this;
|
|
const that = this;
|
|
- if (!data.diningCoinCode) {
|
|
|
|
|
|
+ if (!data.couponCode) {
|
|
throw new Error('参数错误');
|
|
throw new Error('参数错误');
|
|
}
|
|
}
|
|
const userInfo = await that.app.model.Users.findOne({
|
|
const userInfo = await that.app.model.Users.findOne({
|
|
- where: { openid: data.diningCoinCode },
|
|
|
|
|
|
+ where: { openid: data.couponCode },
|
|
attributes: [ 'user_id' ],
|
|
attributes: [ 'user_id' ],
|
|
});
|
|
});
|
|
if (!userInfo || userInfo.user_id < 0) {
|
|
if (!userInfo || userInfo.user_id < 0) {
|
|
@@ -632,7 +634,7 @@ module.exports = class UserController extends shopController {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 商家申请核销餐币
|
|
|
|
|
|
+ * 商家申请核销顾客卡券
|
|
* @return {Promise<void>}
|
|
* @return {Promise<void>}
|
|
*/
|
|
*/
|
|
async coinTransfer() {
|
|
async coinTransfer() {
|
|
@@ -644,91 +646,45 @@ module.exports = class UserController extends shopController {
|
|
// 2023/2/28 获取可核销餐币
|
|
// 2023/2/28 获取可核销餐币
|
|
const intervalTime = Date.parse(that.app.szjcomo.date('Y-m-d H:i:s')) - data.time;
|
|
const intervalTime = Date.parse(that.app.szjcomo.date('Y-m-d H:i:s')) - data.time;
|
|
if (intervalTime > 10 * 60 * 1000) {
|
|
if (intervalTime > 10 * 60 * 1000) {
|
|
- throw new Error('顾客付款码已超时失效,请重新扫码!');
|
|
|
|
|
|
+ throw new Error('顾客卡券二维码已超时失效,请重新扫码!');
|
|
}
|
|
}
|
|
const transferParams = await that.getCouldTransferCoin(data);
|
|
const transferParams = await that.getCouldTransferCoin(data);
|
|
if (data.coinAmount > 0 && data.coinAmount <= transferParams.account) {
|
|
if (data.coinAmount > 0 && data.coinAmount <= transferParams.account) {
|
|
- // 2023/2/28 发起核销收取餐币
|
|
|
|
|
|
+ // 2023/2/28 核销卡券的商家信息
|
|
const partnerInfo = await that.app.model.PartnerInfo.findOne({
|
|
const partnerInfo = await that.app.model.PartnerInfo.findOne({
|
|
where: { id: transferParams.partner_id },
|
|
where: { id: transferParams.partner_id },
|
|
});
|
|
});
|
|
- // 2023/4/12 核销餐币 包含通用电子餐币
|
|
|
|
- const selectBean = await that.app.comoBean.instance({}, {
|
|
|
|
|
|
+
|
|
|
|
+ // 2024/9/13 被核销用户卡券信息
|
|
|
|
+ const result = await that.app.model.DinnerCoins.findOne({
|
|
where: {
|
|
where: {
|
|
user_id: transferParams.customer_id,
|
|
user_id: transferParams.customer_id,
|
|
// partner_id: transferParams.partner_id,
|
|
// partner_id: transferParams.partner_id,
|
|
partner_id: { [seq.Op.in]: [ transferParams.partner_id, 1 ] },
|
|
partner_id: { [seq.Op.in]: [ transferParams.partner_id, 1 ] },
|
|
expired: false,
|
|
expired: false,
|
|
- },
|
|
|
|
- order: [ [ 'partner_id', 'desc' ], [ 'ori_partner', 'desc' ] ],
|
|
|
|
- });
|
|
|
|
- // 2023/2/28 查询所有指定商家餐币
|
|
|
|
- const result = await that.service.base.select(selectBean, that.app.model.DinnerCoins, '查询餐饮币账户失败,请稍候重试', false, true);
|
|
|
|
- const customerAccounts = [];
|
|
|
|
- let needAccount = 0;
|
|
|
|
- for (const resultElement of result) {
|
|
|
|
- needAccount += resultElement.account;
|
|
|
|
- customerAccounts.push(JSON.parse(JSON.stringify(resultElement)));
|
|
|
|
- if (needAccount >= data.coinAmount) {
|
|
|
|
- break;
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
- let firstCoinAmount;
|
|
|
|
- let secondCoinAmount;
|
|
|
|
- let thirdCoinAmount;
|
|
|
|
- let fourthCoinAmount;
|
|
|
|
- let incomeCoinAmount = 0;
|
|
|
|
- switch (customerAccounts.length) {
|
|
|
|
- case 1:
|
|
|
|
- firstCoinAmount = data.coinAmount;
|
|
|
|
- secondCoinAmount = 0;
|
|
|
|
- thirdCoinAmount = 0;
|
|
|
|
- fourthCoinAmount = 0;
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- firstCoinAmount = customerAccounts[0].account;
|
|
|
|
- secondCoinAmount = data.coinAmount - firstCoinAmount;
|
|
|
|
- thirdCoinAmount = 0;
|
|
|
|
- fourthCoinAmount = 0;
|
|
|
|
- break;
|
|
|
|
- case 3:
|
|
|
|
- firstCoinAmount = customerAccounts[0].account;
|
|
|
|
- secondCoinAmount = customerAccounts[1].account;
|
|
|
|
- thirdCoinAmount = data.coinAmount - firstCoinAmount - secondCoinAmount;
|
|
|
|
- fourthCoinAmount = 0;
|
|
|
|
- break;
|
|
|
|
- case 4:
|
|
|
|
- firstCoinAmount = customerAccounts[0].account;
|
|
|
|
- secondCoinAmount = customerAccounts[1].account;
|
|
|
|
- thirdCoinAmount = customerAccounts[2].account;
|
|
|
|
- fourthCoinAmount = data.coinAmount - firstCoinAmount - secondCoinAmount - thirdCoinAmount;
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- // =========================================== 2023/3/1 第一个账户划账======================================
|
|
|
|
- await that.doTransferCoins(that, transferParams, firstCoinAmount, partnerInfo, transaction, customerAccounts, 0);
|
|
|
|
- incomeCoinAmount += firstCoinAmount * (customerAccounts[0].ori_partner ? partnerInfo.rate_from_partner : partnerInfo.rate_default);
|
|
|
|
- // =============================== 2023/3/1 需要第二个账户来继续划账 ==========================================
|
|
|
|
- if (customerAccounts.length > 1 && secondCoinAmount > 0) {
|
|
|
|
- await that.doTransferCoins(that, transferParams, secondCoinAmount, partnerInfo, transaction, customerAccounts, 1);
|
|
|
|
- incomeCoinAmount += secondCoinAmount * (customerAccounts[1].ori_partner ? partnerInfo.rate_from_partner : partnerInfo.rate_default);
|
|
|
|
- }
|
|
|
|
- // =============================== 2023/3/18 需要第三个账户来继续划账 ==========================================
|
|
|
|
- if (customerAccounts.length > 2 && thirdCoinAmount > 0) {
|
|
|
|
- await that.doTransferCoins(that, transferParams, thirdCoinAmount, partnerInfo, transaction, customerAccounts, 2);
|
|
|
|
- incomeCoinAmount += thirdCoinAmount * (customerAccounts[2].ori_partner ? partnerInfo.rate_from_partner : partnerInfo.rate_default);
|
|
|
|
- }
|
|
|
|
- // =============================== 2023/3/18 需要第四个账户来继续划账 ==========================================
|
|
|
|
- if (customerAccounts.length > 3 && fourthCoinAmount > 0) {
|
|
|
|
- await that.doTransferCoins(that, transferParams, fourthCoinAmount, partnerInfo, transaction, customerAccounts, 3);
|
|
|
|
- incomeCoinAmount += fourthCoinAmount * (customerAccounts[3].ori_partner ? partnerInfo.rate_from_partner : partnerInfo.rate_default);
|
|
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ if (result) {
|
|
|
|
+ // 2024/9/13 核销 更新顾客账户
|
|
|
|
+ const customerAccountBean = await that.app.comoBean.instance({
|
|
|
|
+ expired: true,
|
|
|
|
+ update_time: that.app.szjcomo.date('Y-m-d H:i:s'),
|
|
|
|
+ expired_time: that.app.szjcomo.date('Y-m-d H:i:s'),
|
|
|
|
+ }, {
|
|
|
|
+ where: {
|
|
|
|
+ user_id: transferParams.customer_id,
|
|
|
|
+ partner_id: transferParams.partner_id,
|
|
|
|
+ expired: false,
|
|
|
|
+ }, transaction,
|
|
|
|
+ });
|
|
|
|
+ await that.service.base.update(customerAccountBean, that.app.model.DinnerCoins, '顾客餐饮币余额更新失败,请重试');
|
|
|
|
+ } else {
|
|
|
|
+ throw new Error('当前客户没有符合条件的卡券或者卡券已过期!');
|
|
}
|
|
}
|
|
await transaction.commit();
|
|
await transaction.commit();
|
|
- incomeCoinAmount = incomeCoinAmount.toFixed(2);
|
|
|
|
return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', {
|
|
return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', {
|
|
- incomeCoinAmount,
|
|
|
|
- transferCoinAmount: data.coinAmount,
|
|
|
|
|
|
+ expired: true,
|
|
}, false));
|
|
}, false));
|
|
}
|
|
}
|
|
throw new Error('输入的核销金额有误,请稍后重试');
|
|
throw new Error('输入的核销金额有误,请稍后重试');
|