123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- 'use strict';
- //基类服务
- const BaseService = require('./base.js');
- /**
- * [exports 后台管理经理基类服务]
- * @type {[type]}
- */
- module.exports = class ManagerService extends BaseService {
- /*==================================session相关=====================================*/
- /**
- * [ActionAdminUserId 当前后台操作的管理员ID]
- * @author szjcomo
- * @date 2020-11-02
- */
- ActionAdminUserId() {
- let that = this;
- let token = that.ctx.request.header.authorization;
- let user = that.app.jwt.verify(token,that.app.config.jwt.secret);
- return user.admin_id;
- }
- /**
- * [ActionAdminUser 获取当前管理员]
- * @author szjcomo
- * @date 2021-02-27
- */
- ActionAdminUser() {
- let that = this;
- let token = that.ctx.request.header.authorization;
- let user = that.app.jwt.verify(token,that.app.config.jwt.secret);
- return user;
- }
- /**
- * [getRoleAuth 获取角色权限]
- * @author szjcomo
- * @date 2020-11-02
- * @param {[type]} role_id [description]
- * @param {Boolean} is_checked [description]
- * @param {Number} mobile [是否手机端访问]
- * @return {[type]} [description]
- */
- async getRoleAuth(role_id,is_checked = false,mobile = 0) {
- let that = this;
- let seq = that.app.Sequelize;
- let idxs = [];
- let result = [];
- let 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;
- let access = await that.app.model.Accesss.findAll(options);
- if(role_id > 0) {
- let tmpOptions = {where:{role_id:role_id},attributes:['access_id'],raw:true};
- let 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);
- }
- })
- }
- let finalResult = that.app.szjcomo.arrayRecursion(result,0,'pid','access_id','child');
- return finalResult;
- }
- /**
- * [getLevel 获取分类节点等级]
- * @author szjcomo
- * @date 2020-10-26
- * @param {Number} pid [description]
- * @param {[type]} actionModel [description]
- * @param {Object} options [description]
- * @return {[type]} [description]
- */
- async getLevel(pid = 0,actionModel = null,options = {}) {
- if(pid == 0) return 1;
- let result = await actionModel.findOne(options);
- return (result.level + 1);
- }
- /*==================================临时方法=====================================*/
- /**
- * [console 控制台数据]
- * @author szjcomo
- * @date 2020-11-02
- * @return {[type]} [description]
- */
- async console() {
- let that = this;
- let cacheKey = `${process.env.APP_CUSTOME}_console_data`;
- let result = await that.service.redis.get(cacheKey);
- if(!result) {
- result = {
- /**
- * [quick_data 快捷处理]
- * @type {Array}
- */
- 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;
- }
- /**
- * [adminConfig 后台管理配置]
- * @author szjcomo
- * @date 2021-08-08
- * @return {[type]} [description]
- */
- async adminConfig(){
- let that = this;
- let 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
- });
- let result = {};
- configs.forEach(item => {
- result[item.field_index] = item.field_value;
- })
- return result;
- }
- }
|