|
@@ -5,10 +5,13 @@ namespace General\Controllers;
|
|
use General\Models\Channel\Channel;
|
|
use General\Models\Channel\Channel;
|
|
use General\Models\Channel\ChannelUser;
|
|
use General\Models\Channel\ChannelUser;
|
|
use General\Models\Channel\ChannelUsersInner;
|
|
use General\Models\Channel\ChannelUsersInner;
|
|
|
|
+use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @property int $channel_id 站点ID
|
|
* @property int $channel_id 站点ID
|
|
* @property string $phone 登录手机号
|
|
* @property string $phone 登录手机号
|
|
|
|
+ * @property array $inner_phones 登录手机号
|
|
|
|
+ * @property ChannelUser $channel_user 分销后台账号
|
|
* @property int $channel_user_id 分销后台账号ID
|
|
* @property int $channel_user_id 分销后台账号ID
|
|
* @property string $channel_name 分销渠道名称
|
|
* @property string $channel_name 分销渠道名称
|
|
* @property string $channel_domain 分销渠道域名
|
|
* @property string $channel_domain 分销渠道域名
|
|
@@ -16,133 +19,92 @@ use General\Models\Channel\ChannelUsersInner;
|
|
* @property array $company_channel_ids 公司属下所有渠道ID
|
|
* @property array $company_channel_ids 公司属下所有渠道ID
|
|
* @property array $user_channel_ids 账号属下所有渠道ID
|
|
* @property array $user_channel_ids 账号属下所有渠道ID
|
|
* @property bool $is_inner 是否为内部站点
|
|
* @property bool $is_inner 是否为内部站点
|
|
|
|
+ * @property int $sj_status 审计状态
|
|
|
|
+ * @property bool $is_sj_inner 是否为审计内部站点
|
|
*/
|
|
*/
|
|
trait BaseControllerConfig
|
|
trait BaseControllerConfig
|
|
{
|
|
{
|
|
- protected $field = [];
|
|
|
|
-
|
|
|
|
public function __get($name)
|
|
public function __get($name)
|
|
{
|
|
{
|
|
if (!isset($this->field[$name])) {
|
|
if (!isset($this->field[$name])) {
|
|
- switch ($name) {
|
|
|
|
- case 'channel_id':
|
|
|
|
- $this->field[$name] = (int)$this->getChannelId();
|
|
|
|
- break;
|
|
|
|
- case 'channel_user_id':
|
|
|
|
- $this->field[$name] = (int)$this->getChannelUserId();
|
|
|
|
- break;
|
|
|
|
- case 'channel_name':
|
|
|
|
- $this->field[$name] = $this->getChannelName();
|
|
|
|
- break;
|
|
|
|
- case 'channel_domain':
|
|
|
|
- $this->field[$name] = $this->getChannelDomain();
|
|
|
|
- break;
|
|
|
|
- case 'company_id':
|
|
|
|
- $this->field[$name] = (int)$this->getCompanyId();
|
|
|
|
- break;
|
|
|
|
- case 'company_channel_ids':
|
|
|
|
- $this->field[$name] = $this->getALLChannelIDByCompanyID();
|
|
|
|
- break;
|
|
|
|
- case 'user_channel_ids':
|
|
|
|
- $this->field[$name] = $this->getAllChannelIdByChannelUserId();
|
|
|
|
- break;
|
|
|
|
- case 'is_inner':
|
|
|
|
- $this->field[$name] = $this->isInnerRole();
|
|
|
|
- break;
|
|
|
|
- case 'phone':
|
|
|
|
- $this->field[$name] = $this->getLogPhone();
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- $this->field[$name] = $this->$name();
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ return $this->$name();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function channel(): Model
|
|
|
|
+ {
|
|
|
|
+ if (empty(session('ydychannel'))) {
|
|
|
|
+ if (env('APP_ENV') == 'local') return Channel::find(1);
|
|
}
|
|
}
|
|
- return $this->field[$name];
|
|
|
|
|
|
+ return unserialize(session('ydychannel'));
|
|
}
|
|
}
|
|
|
|
|
|
- function getShenjiStatus()
|
|
|
|
|
|
+ protected function sj_status()
|
|
{
|
|
{
|
|
return redisEnv('SHENJI_SWITCH') ? 1 : 0;
|
|
return redisEnv('SHENJI_SWITCH') ? 1 : 0;
|
|
}
|
|
}
|
|
|
|
|
|
- //获取分销渠道ID
|
|
|
|
- function getChannelId()
|
|
|
|
|
|
+ protected function is_sj_inner(): bool
|
|
{
|
|
{
|
|
- if (empty(session('ydychannel'))) {
|
|
|
|
- if (env('APP_ENV') == 'local') return 1;
|
|
|
|
- }
|
|
|
|
- $distribution_channel = unserialize(session('ydychannel'));
|
|
|
|
- if ($distribution_channel) {
|
|
|
|
- return $distribution_channel->id;
|
|
|
|
- } else {
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
|
|
+ return in_array($this->phone(), $this->getInnerPhone());
|
|
}
|
|
}
|
|
|
|
|
|
- //获取分销渠道名称
|
|
|
|
- function getChannelName()
|
|
|
|
|
|
+ protected function inner_phones(): array
|
|
{
|
|
{
|
|
- if (empty(session('ydychannel'))) {
|
|
|
|
- if (env('APP_ENV') == 'local') return '测试';
|
|
|
|
- }
|
|
|
|
- $distribution_channel = unserialize(session('ydychannel'));
|
|
|
|
- return $distribution_channel->distribution_channel_name;
|
|
|
|
|
|
+ return ChannelUsersInner::where('is_enable', 1)->pluck('phone')->all();
|
|
}
|
|
}
|
|
|
|
|
|
- //获取分销渠道域名
|
|
|
|
- function getChannelDomain()
|
|
|
|
|
|
+ protected function channel_id(): int
|
|
{
|
|
{
|
|
- if (empty(session('ydychannel'))) {
|
|
|
|
- if (env('APP_ENV') == 'local') return 'site1.aizhuishu.com';
|
|
|
|
- }
|
|
|
|
|
|
+ return $this->channel->id;
|
|
|
|
+ }
|
|
|
|
|
|
- $distribution_channel = unserialize(session('ydychannel'));
|
|
|
|
- return "site{$distribution_channel->id}.leyuee.com";
|
|
|
|
|
|
+ protected function channel_name(): string
|
|
|
|
+ {
|
|
|
|
+ return $this->channel->distribution_channel_name;
|
|
}
|
|
}
|
|
|
|
|
|
- //获取登陆用户ID
|
|
|
|
- function getChannelUserId()
|
|
|
|
|
|
+ protected function channel_domain(): string
|
|
|
|
+ {
|
|
|
|
+ return "site{$this->channel_id}.leyuee.com";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function channel_user_id(): int
|
|
{
|
|
{
|
|
return session('ydyauth');
|
|
return session('ydyauth');
|
|
}
|
|
}
|
|
|
|
|
|
- //获取登陆号码
|
|
|
|
- function getLogPhone()
|
|
|
|
|
|
+ protected function phone(): string
|
|
{
|
|
{
|
|
return session('ydylogphone');
|
|
return session('ydylogphone');
|
|
}
|
|
}
|
|
|
|
|
|
- function getCompanyId()
|
|
|
|
|
|
+ protected function company_id(): int
|
|
{
|
|
{
|
|
- $channel_info = ChannelUser::find($this->channel_user_id);
|
|
|
|
- if ($channel_info) {
|
|
|
|
- return $channel_info->company_id ? $channel_info->company_id : 0;
|
|
|
|
- }
|
|
|
|
- return 0;
|
|
|
|
|
|
+ return $this->channel_user->id;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected function channel_user(): ChannelUser
|
|
|
|
+ {
|
|
|
|
+ return ChannelUser::find($this->channel_user_id);
|
|
}
|
|
}
|
|
|
|
|
|
- function getALLChannelIDByCompanyID()
|
|
|
|
|
|
+ protected function company_channel_ids(): array
|
|
{
|
|
{
|
|
- return Channel::select('distribution_channels.id')
|
|
|
|
- ->join('channel_users', 'channel_users.id', '=', 'distribution_channels.channel_user_id')
|
|
|
|
- ->join('companies', 'companies.id', '=', 'channel_users.company_id')
|
|
|
|
- ->where('companies.id', $this->company_id)
|
|
|
|
- ->get()->pluck('id')
|
|
|
|
- ->all();
|
|
|
|
|
|
+ $channel_user_ids = ChannelUser::where('company_id', $this->company_id)->pluck('id')->all();
|
|
|
|
+ return Channel::whereIn('channel_user_id', $channel_user_ids)->pluck('id')->all();
|
|
}
|
|
}
|
|
|
|
|
|
- //判断是否为内部站点
|
|
|
|
- function isInnerRole()
|
|
|
|
|
|
+ protected function is_inner(): bool
|
|
{
|
|
{
|
|
- $lists = ChannelUsersInner::where('is_enable', 1)->get();
|
|
|
|
$inner_phones = [];
|
|
$inner_phones = [];
|
|
- foreach ($lists as $item) {
|
|
|
|
|
|
+ foreach ($this->inner_phones as $item) {
|
|
$inner_phones[] = $item->phone . '2';
|
|
$inner_phones[] = $item->phone . '2';
|
|
}
|
|
}
|
|
return in_array($this->phone, $inner_phones);
|
|
return in_array($this->phone, $inner_phones);
|
|
}
|
|
}
|
|
|
|
|
|
- public function getAllChannelIdByChannelUserId()
|
|
|
|
|
|
+ protected function user_channel_ids(): array
|
|
{
|
|
{
|
|
return Channel::where('channel_user_id', $this->channel_user_id)->get()->pluck('id')->all();
|
|
return Channel::where('channel_user_id', $this->channel_user_id)->get()->pluck('id')->all();
|
|
}
|
|
}
|