123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- 'use strict';
- const BaseService = require('./base.js');
- module.exports = class ManagerService extends BaseService {
-
-
- ActionAdminUserId() {
- const that = this;
- const token = that.ctx.request.header.authorization;
- const user = that.app.jwt.verify(token, that.app.config.jwt.secret);
- return user.admin_id;
- }
-
- ActionAdminUser() {
- const that = this;
- const token = that.ctx.request.header.authorization;
- const user = that.app.jwt.verify(token, that.app.config.jwt.secret);
- return user;
- }
-
- async getRoleAuth(role_id, is_checked = false, mobile = 0) {
- const that = this;
-
- let idxs = [];
- let result = [];
- const options = {
- attributes: [ 'access_id', 'access_name', 'access_icon', 'pid', 'is_nav', 'router_name', 'router_path', 'vuecomponent', 'mobile_show' ],
- raw: true, where: { access_status: 1 }, order: [[ 'access_sort', 'asc' ], [ 'access_id', 'asc' ]],
- };
- if (mobile) options.where.mobile_show = 1;
- const access = await that.app.model.Accesss.findAll(options);
- if (role_id > 0) {
- const tmpOptions = { where: { role_id }, attributes: [ 'access_id' ], raw: true };
- const tmpAccess = await that.app.model.AccessRole.findOne(tmpOptions);
- if (tmpAccess) idxs = (tmpAccess.access_id.split(','));
- } else {
- result = access;
- }
- if (result.length == 0) {
- access.forEach(item => {
- if (that.app.szjcomo.inArray(idxs, `${item.access_id}`)) {
- item.checked = true;
- } else {
- item.checked = false;
- }
- if (is_checked == false) {
- result.push(item);
- } else {
- if (item.checked) result.push(item);
- }
- });
- }
- const finalResult = that.app.szjcomo.arrayRecursion(result, 0, 'pid', 'access_id', 'child');
- return finalResult;
- }
-
- async getLevel(pid = 0, actionModel = null, options = {}) {
- if (pid == 0) return 1;
- const result = await actionModel.findOne(options);
- return (result.level + 1);
- }
-
-
- async console() {
- const that = this;
- const cacheKey = `${process.env.APP_CUSTOME}_console_data`;
- let result = await that.service.redis.get(cacheKey);
- if (!result) {
- result = {
-
- quick_data: [
- { icon: '', title: '控制台', router_name: 'system_dashboard' },
- { icon: '', title: '管理员列表', router_name: 'admin_user' },
- { icon: '', title: '订单列表', router_name: 'select_orders' },
- { icon: '', title: '商品列表', router_name: 'select_products' },
- { icon: '', title: '配置设置', router_name: 'config_setting' },
- { icon: '', title: '用户列表', router_name: 'select_users' },
- { icon: '', title: '支付配置', router_name: 'select_pays_config' },
- { icon: '', title: '商品分类', router_name: 'select_product_category' },
- ],
- baseData: await that.service.order.orderDataCount(),
- saleData: await that.service.order.saleDataCount(),
- };
- await that.service.redis.set(cacheKey, result, 10 * 60);
- }
- return result;
- }
-
- async adminConfig() {
- const that = this;
- const configs = await that.app.model.Configs.findAll({
- where: { field_index: { [that.app.Sequelize.Op.in]: [ 'website_title', 'files_upload_uri', 'image_ocr_uri', 'editor_templates_uri' ] } },
- attributes: [ 'field_value', 'field_index' ], raw: true,
- });
- const result = {};
- configs.forEach(item => {
- result[item.field_index] = item.field_value;
- });
- return result;
- }
- };
|