BaseControllerConfig.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace General\Controllers;
  3. use General\Models\Channel\Channel;
  4. use General\Models\Channel\ChannelUser;
  5. use General\Models\Channel\ChannelUsersInner;
  6. /**
  7. * @property int $channel_id 站点ID
  8. * @property string $phone 登录手机号
  9. * @property int $channel_user_id 分销后台账号ID
  10. * @property string $channel_name 分销渠道名称
  11. * @property string $channel_domain 分销渠道域名
  12. * @property int $company_id 公司ID
  13. * @property array $company_channel_ids 公司属下所有渠道ID
  14. * @property array $user_channel_ids 账号属下所有渠道ID
  15. * @property bool $is_inner 是否为内部站点
  16. */
  17. trait BaseControllerConfig
  18. {
  19. private $field = [];
  20. public function __get($name)
  21. {
  22. if (!isset($this->field[$name])) {
  23. switch ($name) {
  24. case 'channel_id':
  25. $this->field[$name] = (int)$this->getChannelId();
  26. break;
  27. case 'channel_user_id':
  28. $this->field[$name] = (int)$this->getChannelUserId();
  29. break;
  30. case 'channel_name':
  31. $this->field[$name] = $this->getChannelName();
  32. break;
  33. case 'channel_domain':
  34. $this->field[$name] = $this->getChannelDomain();
  35. break;
  36. case 'company_id':
  37. $this->field[$name] = (int)$this->getCompanyId();
  38. break;
  39. case 'company_channel_ids':
  40. $this->field[$name] = $this->getALLChannelIDByCompanyID();
  41. break;
  42. case 'user_channel_ids':
  43. $this->field[$name] = $this->getAllChannelIdByChannelUserId();
  44. break;
  45. case 'is_inner':
  46. $this->field[$name] = $this->isInnerRole();
  47. break;
  48. case 'phone':
  49. $this->field[$name] = $this->getLogPhone();
  50. break;
  51. }
  52. }
  53. return $this->field[$name];
  54. }
  55. function getShenjiStatus()
  56. {
  57. return redisEnv('SHENJI_SWITCH') ? 1 : 0;
  58. }
  59. //获取分销渠道ID
  60. function getChannelId()
  61. {
  62. if (empty(session('ydychannel'))) {
  63. if (env('APP_ENV') == 'local') return 1;
  64. }
  65. $distribution_channel = unserialize(session('ydychannel'));
  66. if ($distribution_channel) {
  67. return $distribution_channel->id;
  68. } else {
  69. return 0;
  70. }
  71. }
  72. //获取分销渠道名称
  73. function getChannelName()
  74. {
  75. if (empty(session('ydychannel'))) {
  76. if (env('APP_ENV') == 'local') return '测试';
  77. }
  78. $distribution_channel = unserialize(session('ydychannel'));
  79. return $distribution_channel->distribution_channel_name;
  80. }
  81. //获取分销渠道域名
  82. function getChannelDomain()
  83. {
  84. if (empty(session('ydychannel'))) {
  85. if (env('APP_ENV') == 'local') return 'site1.aizhuishu.com';
  86. }
  87. $distribution_channel = unserialize(session('ydychannel'));
  88. return "site{$distribution_channel->id}.leyuee.com";
  89. }
  90. //获取登陆用户ID
  91. function getChannelUserId()
  92. {
  93. return session('ydyauth');
  94. }
  95. //获取登陆号码
  96. function getLogPhone()
  97. {
  98. return session('ydylogphone');
  99. }
  100. function getCompanyId()
  101. {
  102. $channel_info = ChannelUser::find($this->channel_user_id);
  103. if ($channel_info) {
  104. return $channel_info->company_id ? $channel_info->company_id : 0;
  105. }
  106. return 0;
  107. }
  108. function getALLChannelIDByCompanyID()
  109. {
  110. return Channel::select('distribution_channels.id')
  111. ->join('channel_users', 'channel_users.id', '=', 'distribution_channels.channel_user_id')
  112. ->join('companies', 'companies.id', '=', 'channel_users.company_id')
  113. ->where('companies.id', $this->company_id)
  114. ->get()->pluck('id')
  115. ->all();
  116. }
  117. //判断是否为内部站点
  118. function isInnerRole()
  119. {
  120. $lists = ChannelUsersInner::where('is_enable', 1)->get();
  121. $inner_phones = [];
  122. foreach ($lists as $item) {
  123. $inner_phones[] = $item->phone . '2';
  124. }
  125. return in_array($this->phone, $inner_phones);
  126. }
  127. public function getAllChannelIdByChannelUserId()
  128. {
  129. return Channel::where('channel_user_id', $this->channel_user_id)->get()->pluck('id')->all();
  130. }
  131. }