Selaa lähdekoodia

1、区分用户 办公/家用;

Lawsun_M 1 vuosi sitten
vanhempi
commit
48ab7ac3ad
3 muutettua tiedostoa jossa 52 lisäystä ja 4 poistoa
  1. 42 4
      app/controller/home/user.js
  2. 8 0
      app/models/mysql/users.js
  3. 2 0
      app/routers/home/shop.js

+ 42 - 4
app/controller/home/user.js

@@ -68,6 +68,18 @@ module.exports = class UserController extends shopController {
     };
   }
 
+  /**
+   * 更新用户信息
+   * @date:2023/10/20
+   */
+  get updateValidate() {
+    const that = this;
+    return {
+      user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
+        .number(),
+    };
+  }
+
   /**
    * [wxuserValidate 微信用户写入]
    * @return {[type]} [description]
@@ -202,7 +214,7 @@ module.exports = class UserController extends shopController {
 
 
   /**
-   * [login 用户登录]
+   * [login 用户登录 - 账号密码]
    * @return {[type]} [description]
    */
   async login() {
@@ -214,7 +226,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' ],
+        attributes: [ 'user_id', 'account_name', 'nickname', 'headimgurl', 'openid', 'intergral', 'is_proxy', 'partner_id', 'is_office', 'is_family' ],
         raw: true,
       });
       if (!user) throw new Error('登录失败,请检查账号密码是否正确');
@@ -256,7 +268,7 @@ module.exports = class UserController extends shopController {
   }
 
   /**
-   * [wxRegisterAdnLogin 微信登录和注册]
+   * [wxRegisterAdnLogin 用户登录 - 微信注册登录]
    * @return {[type]} [description]
    */
   async wxRegisterAdnLogin() {
@@ -306,7 +318,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' ],
+      attributes: [ 'user_id', 'account_name', 'nickname', 'headimgurl', 'openid', 'partner_id', 'is_office', 'is_family' ],
       raw: true,
     };
     let user = await that.useModel.findOne(options);
@@ -361,6 +373,8 @@ module.exports = class UserController extends shopController {
       headimgurl: result.dataValues.headimgurl,
       openid: result.dataValues.openid,
       unionid: result.dataValues.unionid,
+      is_office: result.dataValues.is_office,
+      is_family: result.dataValues.is_family,
     };
   }
 
@@ -937,5 +951,29 @@ module.exports = class UserController extends shopController {
     }
   }
 
+  /**
+   * 更新用户信息
+   * @date:2023/10/20
+   */
+  async updateUserInfo() {
+    const that = this;
+    try {
+      const data = await that.ctx.validate(that.updateValidate, await that.ctx.anyParse());
+      // 2023/10/20  更新用户信息
+      const dataParam = {};
+      if (data.is_office) {
+        dataParam.is_office = true;
+      }
+      if (data.is_family) {
+        dataParam.is_family = true;
+      }
+      dataParam.update_ttime = that.app.szjcomo.date('Y-m-d H:i:s');
+      const updateBean = await that.app.comoBean.instance(dataParam, { where: { user_id: data.user_id } });
+      const result = await that.service.base.update(updateBean, that.useModel, '微信用户信息更新失败,请重试');
+      return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
+    } catch (e) {
+      return that.ctx.appJson(that.app.szjcomo.appResult(e.message));
+    }
+  }
 
 };

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

@@ -94,6 +94,14 @@ module.exports = app => {
       type: DataTypes.INTEGER(1).UNSIGNED,
       allowNull: true,
     },
+    is_office: {
+      type: DataTypes.INTEGER(1).UNSIGNED,
+      allowNull: true,
+    },
+    is_family: {
+      type: DataTypes.INTEGER(1).UNSIGNED,
+      allowNull: true,
+    },
     partner_id: {
       type: DataTypes.INTEGER(11),
       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.put('/user/updateUserInfo', webLogin, shops.user.updateUserInfo);
   // 查看配送信息
   subRouter.get('/order/deliver', webLogin, shops.order.orderDeliver);
   // 商品评论提交