Model *Bonus_Point_Log* ``` const BonusPointLog = DB.define('BonusPointLog', { id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true }, member_id: { type: Sequelize.INTEGER, allowNull: false, des: "ID thành viên" }, point: { type: Sequelize.INTEGER, allowNull: false, default: 0, des: "Điểm" }, bonus_point: { type: Sequelize.INTEGER, allowNull: false, default: 0, des: "Điểm thưởng" }, year_point: { type: Sequelize.INTEGER, allowNull: false, default: 0, des: "Điểm năm" }, type: { type: Sequelize.INTEGER, allowNull: false, default: 1, des: "Phân loại" }, note: { type: Sequelize.TEXT, allowNull: false, default: 1, des: "Ghi chú" }, meta: { type: Sequelize.TEXT, allowNull: false, default: null }, }, { tableName: 'bonus_point_log', createdAt: 'created_at', updatedAt: 'updated_at', deletedAt: 'deleted_at', timestamps: true, underscored: true }); BonusPointLog.TYPE_OTHER = 0; //"Loại khác", BonusPointLog.TYPE_REDEMPTION = 1; //"Điểm tặng gia hạn chu kỳ", BonusPointLog.TYPE_LIXI = 2; // "Lì xì", BonusPointLog.TYPE_PROMOTION1119 = 3; //"CTKM Đặc Biệt - Sinh nhật DiDiDi lần 3 (01/11/2019 - 29/02/2020)", BonusPointLog.TYPE_BIRTHDAY = 4; //"Điểm tặng sinh nhật", BonusPointLog.TYPE_RANK_UP = 5; //"Điểm tặng thay đổi hạng thẻ", ``` Model *Cheating_Logs* ``` const CheatingLogs = DB.define('CheatingLogs', { id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true, autoIncrement: true, des: "ID" }, member_id: { type: Sequelize.INTEGER, allowNull: false, des: "ID thành viên" }, point: { type: Sequelize.INTEGER, allowNull: false, default: 0, des: "Điểm" }, status: { type: Sequelize.INTEGER, default: 1, des: "Trạng thái" }, extend_data: { type: Sequelize.TEXT, des: "Dữ liệu thêm/mở rộng" }, alert_data: { type: Sequelize.DATE, des: "" }, turn: { type: Sequelize.INTEGER, default: 0, des: "Số lượt quét" }, day_point: { type: Sequelize.INTEGER, default: 0, des: "Điểm ngày" } }, { tableName: 'cheating_logs', createdAt: 'created_at', updatedAt: 'updated_at', deletedAt: 'deleted_at', timestamps: true, underscored: true }); CheatingLogs.STATUS_NEW = { id: 1, value: "Chú ý" } CheatingLogs.STATUS_VIEWED = { id: 2, value: "Đã xử lý" } CheatingLogs.ZONE_YELLOW = { id: 1, value: "Vàng" } CheatingLogs.ZONE_GREEN = { id: 2, value: "Xanh" } CheatingLogs.ZONE_ORANGE = { id: 3, value: "Cam" } CheatingLogs.ZONE_RED = { id: 4, value: "Đỏ" } ``` Các quan hệ cần có giữa 3 table *Member, Cheating_Logs, Bonus_Point_Log* ``` Member.hasMany(CheatingLogs, { as: 'cheating_logs', foreignKey: 'member_id', sourceKey: 'id' }) BonusPointLog.belongsTo(Member, { as: 'info_member', foreignKey: 'member_id', sourceKey: 'id', }); ``` giá trị tương ứng cho trang *Điểm thưởng tuần - DIDIDI CRM* ``` - Danh sách điểm thưởng + ID -> cột "id" của table "Member"(quan hệ từ info_member) + Mã Thành Viên> cột "code" của table "Member"(quan hệ từ info_member) + Họ Tên -> cột "name" của table "Member"(quan hệ từ info_member) + SĐT ->cột "mobile" của table "Member"(quan hệ từ info_member) + Điểm tích lũy hiện tại -> ta lấy "bonus_point" ở table "Bonus_Point_Log"(theo thời gian/tuần dựa vào Client nhập) + tổng point dựa theo member_id(trong table Cheating_Logs) ta sẽ được điểm tích lũy + Điểm thưởng trong tuần -> ta lấy "bonus_point" ở table "Bonus_Point_Log"(theo thời gian/tuần dựa vào Client nhập) + Phân loại -> cột "type"(enum) từ table "Bonus_Point_Log" + Lý do -> cột "note" từ table "Bonus_Point_Log" + Thời gian tặng điểm -> cột "created_at" từ table "Bonus_Point_Log" => Lưu ý: thời gian khi hiển thị CRM đang khác với trong DB (hiển thị CRM là timezone UTC +0 và timezone trong DB là Asia/Ho_Chi_Minh +7) moment("2019-02-02 13:37:39.000").tz("UTC").format('DD/MM/YYYY HH:mm:ss') - Filter + created_to - created_from (dựa theo cột created_at của table "Bonus_Point_Log" là "Thời gian tặng điểm") + type (enum) của table "Bonus_Point_Log" là "Loại điểm thưởng" + member_id là id của thành viên trong table "Member" (quan hệ từ info_member) - Xuất dữ liệu + Dựa theo dữ liệu danh sách điểm thưởng bên trên để xuất dữ liệu tương ứng với từng cột ```