Selaa lähdekoodia

1、统计;

Lawsun 1 vuosi sitten
vanhempi
commit
e41ecce10c

+ 22 - 16
.idea/workspace.xml

@@ -1,10 +1,14 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="ChangeListManager">
-    <list default="true" id="08cfebb0-a4a4-47ee-a307-566aa06f29bb" name="Default Changelist" comment="1.暂存;">
+    <list default="true" id="08cfebb0-a4a4-47ee-a307-566aa06f29bb" name="Default Changelist" comment="1.gte 大于等于 ;">
+      <change afterPath="$PROJECT_DIR$/app/controller/home/statistic.js" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/app/models/mysql/usersEventLogs.js" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/app/models/mysql/usersProductBrowseLogs.js" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/app/controller/home/products.js" beforeDir="false" afterPath="$PROJECT_DIR$/app/controller/home/products.js" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/app/routers/home/shop.js" beforeDir="false" afterPath="$PROJECT_DIR$/app/routers/home/shop.js" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/node_modules/egg-ts-helper/.tmp/eggInfo.json" beforeDir="false" afterPath="$PROJECT_DIR$/node_modules/egg-ts-helper/.tmp/eggInfo.json" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/typings/app/controller/index.d.ts" beforeDir="false" afterPath="$PROJECT_DIR$/typings/app/controller/index.d.ts" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -55,7 +59,7 @@
     "RunOnceActivity.ShowReadmeOnStart": "true",
     "SHARE_PROJECT_CONFIGURATION_FILES": "true",
     "WebServerToolWindowFactoryState": "false",
-    "last_opened_file_path": "D:/ysjjCode/shop-system",
+    "last_opened_file_path": "D:/ysjjCode/shop-system/app/models/mysql",
     "node.js.detected.package.eslint": "true",
     "node.js.selected.package.eslint": "(autodetect)",
     "nodejs_package_manager_path": "npm",
@@ -71,11 +75,11 @@
 }]]></component>
   <component name="RecentsManager">
     <key name="CopyFile.RECENT_KEYS">
+      <recent name="D:\ysjjCode\shop-system\app\models\mysql" />
+      <recent name="D:\ysjjCode\shop-system\app\controller\home" />
       <recent name="D:\ysjjCode\shop-system\app\service" />
       <recent name="D:\IdeaWorkSpace\wsProjects\shop-system\app\models\mysql" />
       <recent name="D:\IdeaWorkSpace\wsProjects\shop-system\app\controller\home" />
-      <recent name="D:\IdeaWorkSpace\wsProjects\shop-system\app\service" />
-      <recent name="D:\IdeaWorkSpace\wsProjects\shop-system\app\schedule" />
     </key>
     <key name="MoveFile.RECENT_KEYS">
       <recent name="D:\IdeaWorkSpace\wsProjects\shop-system\app\service" />
@@ -251,14 +255,9 @@
       <workItem from="1688610355850" duration="5828000" />
       <workItem from="1688949661834" duration="4497000" />
       <workItem from="1689209473126" duration="4787000" />
-      <workItem from="1689240225909" duration="648000" />
-    </task>
-    <task id="LOCAL-00020" summary="1.商品排序;">
-      <created>1670322027650</created>
-      <option name="number" value="00020" />
-      <option name="presentableId" value="LOCAL-00020" />
-      <option name="project" value="LOCAL" />
-      <updated>1670322027650</updated>
+      <workItem from="1689240225909" duration="2672000" />
+      <workItem from="1689384833956" duration="6286000" />
+      <workItem from="1689558398171" duration="36717000" />
     </task>
     <task id="LOCAL-00021" summary="1.修复偶现无法提交订单的bug(微信支付下单金额为精确到分的正整数);">
       <created>1670640071817</created>
@@ -596,7 +595,14 @@
       <option name="project" value="LOCAL" />
       <updated>1689236035801</updated>
     </task>
-    <option name="localTasksCounter" value="69" />
+    <task id="LOCAL-00069" summary="1.gte 大于等于 ;">
+      <created>1689240933591</created>
+      <option name="number" value="00069" />
+      <option name="presentableId" value="LOCAL-00069" />
+      <option name="project" value="LOCAL" />
+      <updated>1689240933591</updated>
+    </task>
+    <option name="localTasksCounter" value="70" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
@@ -642,7 +648,6 @@
     </option>
   </component>
   <component name="VcsManagerConfiguration">
-    <MESSAGE value="1.餐币钱包有效期90天;" />
     <MESSAGE value="1.餐币明细,客源信息;" />
     <MESSAGE value="1.餐币有效期;" />
     <MESSAGE value="1.修复餐币发放数量错误的bug;" />
@@ -667,7 +672,8 @@
     <MESSAGE value="1...;" />
     <MESSAGE value="1.邀请分享红包调整;" />
     <MESSAGE value="1.暂存;" />
-    <option name="LAST_COMMIT_MESSAGE" value="1.暂存;" />
+    <MESSAGE value="1.gte 大于等于 ;" />
+    <option name="LAST_COMMIT_MESSAGE" value="1.gte 大于等于 ;" />
   </component>
   <component name="XDebuggerManager">
     <breakpoint-manager>

+ 154 - 0
app/controller/home/statistic.js

@@ -0,0 +1,154 @@
+'use strict';
+const Base = require('../base');
+
+/**
+ * 用户统计
+ */
+module.exports = class StatisticController extends Base {
+
+  get loginValidate() {
+    const that = this;
+    return {
+      user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
+        .number(),
+    };
+  }
+
+  /**
+   * 统计
+   * @return {Promise<*>}
+   */
+  async statisticLogs() {
+    const that = this;
+    const transaction = await that.app.model.transaction();
+    try {
+      // const dataParse = await that.ctx.postParse();
+      const dataParse = await that.ctx.validate(that.loginValidate, await that.ctx.anyParse());
+      console.log(dataParse);
+      // 2023/7/25 更新用户行为积分
+      const updateBean = await that.app.comoBean.instance({
+        intergral: that.app.Sequelize.literal('intergral + ' + 1),
+        update_ttime: that.app.szjcomo.date('Y-m-d H:i:s'),
+      }, { where: { user_id: dataParse.user_id }, transaction });
+      await that.app.comoBean.update(updateBean, that.app.model.Users, '用户积分更新失败,请稍候重试');
+
+      // 2023/7/25 记录用户行为事件
+      if (dataParse.type === 1) { // 商品浏览
+        // 2023/7/25 查询用户浏览商品记录
+        const result = await that.app.model.UsersProductBrowseLogs.findOne({
+          where: {
+            user_id: dataParse.user_id,
+            product_id: dataParse.product_id,
+          },
+        });
+        if (result) {
+          // 2023/7/26 update 商品浏览
+          const updateBrowse = await that.app.comoBean.instance({
+            browse_count: that.app.Sequelize.literal('browse_count + ' + 1),
+            product_name: dataParse.product_name,
+            browse_params: dataParse.browse_params ? dataParse.browse_params : '{}',
+            update_time: that.app.szjcomo.date('Y-m-d H:i:s'),
+          }, { where: { user_id: dataParse.user_id, product_id: dataParse.product_id }, transaction });
+          await that.app.comoBean.update(updateBrowse, that.app.model.UsersProductBrowseLogs, '商品浏览记录更新失败,请稍候重试');
+        } else {
+          // 2023/7/26 create 商品浏览
+          const createBrowse = await that.app.comoBean.instance({
+            user_id: dataParse.user_id,
+            product_id: dataParse.product_id,
+            browse_count: 1,
+            product_name: dataParse.product_name,
+            browse_params: dataParse.browse_params ? dataParse.browse_params : '{}',
+            update_time: that.app.szjcomo.date('Y-m-d H:i:s'),
+            create_time: that.app.szjcomo.date('Y-m-d H:i:s'),
+          }, { transaction });
+          await that.app.comoBean.create(createBrowse, that.app.model.UsersProductBrowseLogs, '商品浏览记录添加失败,请稍候重试');
+        }
+      } else if (dataParse.type === 2) { // 动作记录
+        // 2023/7/25 查询用户行为记录
+        const result = await that.app.model.UsersEventLogs.findOne({
+          where: {
+            user_id: dataParse.user_id,
+            event_name: dataParse.event_name,
+          },
+        });
+        if (result) {
+          // 2023/7/26 update 用户行为
+          const updateBrowse = await that.app.comoBean.instance({
+            event_count: that.app.Sequelize.literal('event_count + ' + 1),
+            event_params: dataParse.event_params ? dataParse.event_params : '{}',
+            update_time: that.app.szjcomo.date('Y-m-d H:i:s'),
+          }, { where: { user_id: dataParse.user_id, event_name: dataParse.event_name }, transaction });
+          await that.app.comoBean.update(updateBrowse, that.app.model.UsersEventLogs, '用户行为记录更新失败,请稍候重试');
+        } else {
+          // 2023/7/26 create 用户行为
+          const createBrowse = await that.app.comoBean.instance({
+            user_id: dataParse.user_id,
+            event_name: dataParse.event_name,
+            event_count: 1,
+            event_params: dataParse.event_params ? dataParse.event_params : '{}',
+            update_time: that.app.szjcomo.date('Y-m-d H:i:s'),
+            create_time: that.app.szjcomo.date('Y-m-d H:i:s'),
+          }, { transaction });
+          await that.app.comoBean.create(createBrowse, that.app.model.UsersEventLogs, '用户行为记录添加失败,请稍候重试');
+        }
+      }
+
+      // 2023/7/26 事务提交
+      transaction.commit();
+
+      return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', {}, false));
+    } catch (err) {
+      console.log(err);
+      if (transaction) {
+        transaction.rollback();
+      }
+      // return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
+    }
+  }
+
+  /**
+   * 用户行为统计记录
+   * @return {Promise<*>}
+   */
+  async statisticLogsList() {
+    const that = this;
+    // const transaction = await that.app.model.transaction();
+    try {
+      const dataParse = await that.ctx.validate(that.loginValidate, await that.ctx.anyParse());
+      console.log(dataParse);
+      // 2023/7/26 查询
+      // todo : 用户统计记录列表
+
+      return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', {}, false));
+    } catch (err) {
+      console.log(err);
+      return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
+    }
+  }
+
+  /**
+   *  活跃用户列表
+   * @return {Promise<*>}
+   */
+  async activeUsers() {
+    const that = this;
+    // const transaction = await that.app.model.transaction();
+    const seq = that.app.Sequelize;
+    try {
+      // const dataParse = await that.ctx.validate(that.loginValidate, await that.ctx.anyParse());
+      const dataParse = await that.ctx.anyParse();
+      console.log(dataParse);
+      // 2023/7/26 查询
+      const users = await that.app.model.Users.findAll({
+        attributes: [ 'user_id', 'nickname', 'intergral', 'money', 'commission', 'headimgurl' ],
+        order: [[ 'intergral', 'desc' ]],
+        where: { intergral: { [seq.Op.gte]: 1 } },
+      });
+      return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', { users }, false));
+    } catch (err) {
+      console.log(err);
+      return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
+    }
+  }
+
+};

+ 48 - 0
app/models/mysql/usersEventLogs.js

@@ -0,0 +1,48 @@
+/* indent size: 2 */
+
+// eslint-disable-next-line strict
+module.exports = app => {
+  const DataTypes = app.Sequelize;
+
+  const Model = app.model.define('UsersEventLogs', {
+    id: {
+      type: DataTypes.INTEGER(10).UNSIGNED,
+      allowNull: false,
+      primaryKey: true,
+      autoIncrement: true,
+    },
+    user_id: {
+      type: DataTypes.INTEGER(10).UNSIGNED,
+      allowNull: true,
+    },
+    event_count: {
+      type: DataTypes.INTEGER(10),
+      allowNull: true,
+    },
+    event_name: {
+      type: DataTypes.STRING(255),
+      allowNull: true,
+    },
+    event_params: {
+      type: DataTypes.STRING(255),
+      allowNull: true,
+    },
+    update_time: {
+      type: DataTypes.TIME,
+      allowNull: true,
+    },
+    create_time: {
+      type: DataTypes.DATE,
+      allowNull: true,
+    },
+  }, {
+    tableName: 'szj_users_event_logs',
+  });
+
+  Model.associate = function() {
+
+  };
+  // 同步:没有就新建,有就不变
+  Model.sync();
+  return Model;
+};

+ 52 - 0
app/models/mysql/usersProductBrowseLogs.js

@@ -0,0 +1,52 @@
+/* indent size: 2 */
+
+// eslint-disable-next-line strict
+module.exports = app => {
+  const DataTypes = app.Sequelize;
+
+  const Model = app.model.define('UsersProductBrowseLogs', {
+    id: {
+      type: DataTypes.INTEGER(10).UNSIGNED,
+      allowNull: false,
+      primaryKey: true,
+      autoIncrement: true,
+    },
+    user_id: {
+      type: DataTypes.INTEGER(10).UNSIGNED,
+      allowNull: true,
+    },
+    product_id: {
+      type: DataTypes.INTEGER(10).UNSIGNED,
+      allowNull: true,
+    },
+    browse_count: {
+      type: DataTypes.INTEGER(10),
+      allowNull: true,
+    },
+    product_name: {
+      type: DataTypes.STRING(255),
+      allowNull: true,
+    },
+    browse_params: {
+      type: DataTypes.STRING(255),
+      allowNull: true,
+    },
+    update_time: {
+      type: DataTypes.TIME,
+      allowNull: true,
+    },
+    create_time: {
+      type: DataTypes.DATE,
+      allowNull: true,
+    },
+  }, {
+    tableName: 'szj_users_product_browse_logs',
+  });
+
+  Model.associate = function() {
+
+  };
+  // 同步:没有就新建,有就不变
+  Model.sync();
+  return Model;
+};

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

@@ -120,4 +120,11 @@ module.exports = app => {
   // 查询合作餐店列表接口
   subRouter.get('/partnerList', shops.partnerInfo.select);
   subRouter.get('/partnerListAll', shops.partnerInfo.selectAll);
+  // 2023/7/25 统计
+  subRouter.post('/statisticLogs', webLogin, shops.statistic.statisticLogs);
+  // 2023/7/25 用户行为记录列表
+  subRouter.get('/statisticLogs', webLogin, shops.statistic.statisticLogsList);
+  // 2023/7/25 活跃用户列表
+  subRouter.get('/activeUsers', shops.statistic.activeUsers);
+
 };

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
node_modules/egg-ts-helper/.tmp/eggInfo.json


+ 2 - 0
typings/app/controller/index.d.ts

@@ -13,6 +13,7 @@ import ExportHomeProducts = require('../../../app/controller/home/products');
 import ExportHomeProxyApplyLogs = require('../../../app/controller/home/ProxyApplyLogs');
 import ExportHomeRelInviter = require('../../../app/controller/home/RelInviter');
 import ExportHomeShop = require('../../../app/controller/home/shop');
+import ExportHomeStatistic = require('../../../app/controller/home/statistic');
 import ExportHomeUser = require('../../../app/controller/home/user');
 import ExportManagerAccesss = require('../../../app/controller/manager/accesss');
 import ExportManagerAdminUser = require('../../../app/controller/manager/admin_user');
@@ -48,6 +49,7 @@ declare module 'egg' {
       proxyApplyLogs: ExportHomeProxyApplyLogs;
       relInviter: ExportHomeRelInviter;
       shop: ExportHomeShop;
+      statistic: ExportHomeStatistic;
       user: ExportHomeUser;
     }
     manager: {

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä