Guild.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * 开发联盟的公共控制器类
  4. *
  5. */
  6. namespace app\mcpsapi\controller;
  7. use app\common\controller\Base;
  8. use think\Config;
  9. class Guild extends Base
  10. {
  11. protected $channelIds; //登录渠道自己及子渠道ID集
  12. protected $sub_channelIds; //登录渠道子渠道ID集(不包含自身)
  13. protected $_channelLevel; //渠道等级
  14. protected $current_node; //当前操作的action
  15. protected $_adminId; //当前操作的渠道管理员ID
  16. protected $_channelIdPath; //当前渠道路径
  17. /**
  18. * 初始化操作
  19. */
  20. protected function _initialize()
  21. {
  22. //已登录
  23. if (session('guild_info')) {
  24. $channelModel = model('Common/Channel');
  25. $channelIds = $channelModel->getChildIds(session('guild_info')['channel_id']);
  26. $this->sub_channelIds = $channelIds;
  27. if(!empty($channelIds)){
  28. array_push($channelIds,session('guild_info')['channel_id']);
  29. $this->channelIds = $channelIds;
  30. }
  31. else{
  32. $this->channelIds = session('guild_info')['channel_id'];
  33. }
  34. $this->_channelLevel = get_channel_level(session('guild_info')['channel_id']);
  35. $this->_channelId = session('guild_info')['channel_id'];
  36. $this->_channelName = session('guild_info')['channel_name'];
  37. $this->_adminId = session('guild_info')['id'];
  38. $ParentIdPath = model('Channel')->where(['id'=>$this->_channelId])->value('id_path');
  39. if($ParentIdPath){
  40. $this->_channelIdPath = $ParentIdPath.$this->_channelId.',';
  41. }
  42. else{
  43. $this->_channelIdPath = ','.$this->_channelId.',';
  44. }
  45. }
  46. else{
  47. json(['data'=>'','code'=>10007,'msg'=>'您还没有登录!'])->send();
  48. exit;
  49. }
  50. $this->input = input();
  51. }
  52. /**
  53. * 插入操作日志
  54. *
  55. * @param string $node
  56. * @param string $content
  57. * @param number $type
  58. * @param string $admin_id
  59. * @param string $username
  60. * @return mixed
  61. */
  62. protected function insertLog($node = '', $content = '', $type = 0, $admin_id = '', $username = '')
  63. {
  64. if (empty($admin_id)) {
  65. $admin_id = session('guild_info')['id'] ?: 1;
  66. }
  67. if (empty($username)) {
  68. $username = session('guild_info')['username'] ?: '';
  69. }
  70. return \app\common\logic\Log::insertOperateLog($node, $content, $type, $admin_id, $username);
  71. }
  72. /**
  73. * 获取参数
  74. * @param string $key 数组index
  75. * @param string $default 默认值
  76. * @return mixed|null
  77. */
  78. protected function input($key, $default = null)
  79. {
  80. return isset($this->input[$key]) ? $this->input[$key] : ($default!==null ? $default : null);
  81. }
  82. /**
  83. * 返回封装后的 API json数据到客户端
  84. * @access protected
  85. * @param mixed $data 要返回的数据
  86. * @param int $code 返回的 code
  87. * @param mixed $msg 提示信息
  88. * @param $isExit boolean 是否强制退出,默认true
  89. * @return void
  90. *
  91. */
  92. public function jsonResult($data, $code = 0, $msg = '',$isExit=true)
  93. {
  94. $result = [
  95. 'code' => $code,
  96. 'msg' => $msg,
  97. 'time' => request()->server('REQUEST_TIME'),
  98. 'data' => $data,
  99. ];
  100. echo json_encode($result);
  101. //为了使用fastcgi_finish_request等函数时,后续的执行能够继续生效
  102. if($isExit) exit;
  103. }
  104. }