Browse Source

1、抽奖接口待逻辑实现;

Lawsun_M 1 year ago
parent
commit
5def1a9741
4 changed files with 68 additions and 1 deletions
  1. 39 1
      app/controller/home/user.js
  2. 4 0
      app/models/mysql/users.js
  3. 2 0
      app/routers/home/shop.js
  4. 23 0
      app/utils/BaseUtils.js

+ 39 - 1
app/controller/home/user.js

@@ -154,6 +154,14 @@ module.exports = class UserController extends shopController {
     };
   }
 
+  get luckyValidate() {
+    const that = this;
+    return {
+      user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
+        .number(),
+    };
+  }
+
   get userTransferValidate() {
     const that = this;
     return {
@@ -899,7 +907,7 @@ module.exports = class UserController extends shopController {
    * @return {Promise<void>}
    */
   async commission2DiningCoin() {
-
+    // 2023/11/17 todo: 佣金转电子餐费
   }
 
   /**
@@ -951,6 +959,36 @@ module.exports = class UserController extends shopController {
     }
   }
 
+  /**
+   * [newUserBenefits 获取每日红包]
+   * @return {[type]} [description]
+   */
+  async dayLucky() {
+    const that = this;
+    try {
+      const data = await that.ctx.validate(that.luckyValidate, await that.ctx.anyParse());
+      // 2023/11/17 todo:  用户今天抽奖校验
+      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));
+    } catch (err) {
+      return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
+    }
+  }
+
+
   /**
    * 更新用户信息
    * @date:2023/10/20

+ 4 - 0
app/models/mysql/users.js

@@ -86,6 +86,10 @@ module.exports = app => {
       type: DataTypes.DATE,
       allowNull: true,
     },
+    lucky_time: {
+      type: DataTypes.DATE,
+      allowNull: true,
+    },
     is_proxy: {
       type: DataTypes.INTEGER(1).UNSIGNED,
       allowNull: true,

+ 2 - 0
app/routers/home/shop.js

@@ -83,6 +83,8 @@ module.exports = app => {
   subRouter.get('/user/diningCoin', webLogin, shops.user.userDiningCoin);
   // 获取新用户福利记录
   subRouter.get('/user/money/newUserBenefits', webLogin, shops.user.newUserBenefits);
+  // 用户红包每日一抽
+  subRouter.get('/user/money/dayLucky', webLogin, shops.user.dayLucky);
   // 更新用户信息
   subRouter.put('/user/updateUserInfo', webLogin, shops.user.updateUserInfo);
   // 查看配送信息

+ 23 - 0
app/utils/BaseUtils.js

@@ -0,0 +1,23 @@
+'use strict';
+
+// 基类服务
+const Service = require('egg').Service;
+
+module.exports = class BaseUtils extends Service {
+
+  /**
+   * 判断时间 是否在 今天
+   * @date:2023/11/16
+   */
+  async isToday(timeDate = '2023-11-16') {
+    // 把今天的日期时分秒设置为00:00:00,返回一个时间戳,
+    // todayDate就是今天00:00:00时刻的时间戳
+    const todayDate = new Date().setHours(0, 0, 0, 0);
+    // 给new Date()传入时间,并返回传入时间的时间戳
+    const paramsDate = new Date(timeDate).setHours(0, 0, 0, 0);
+
+    // 时间戳相同时 True 就为今天
+    return (todayDate === paramsDate);
+  }
+
+};