fly 4 år sedan
förälder
incheckning
13eab7e401

+ 146 - 0
src/Controllers/BaseControllerConfig.php

@@ -0,0 +1,146 @@
+<?php
+
+namespace General\Controllers;
+
+use General\Models\Channel\Channel;
+use General\Models\Channel\ChannelUser;
+use General\Models\Channel\ChannelUsersInner;
+
+/**
+ * @property int $channel_id 站点ID
+ * @property string $phone 登录手机号
+ * @property int $channel_user_id 分销后台账号ID
+ * @property string $channel_name 分销渠道名称
+ * @property string $channel_domain 分销渠道域名
+ * @property int $company_id 公司ID
+ * @property array $company_channel_ids 公司属下所有渠道ID
+ * @property array $user_channel_ids 账号属下所有渠道ID
+ * @property bool $is_inner 是否为内部站点
+ */
+trait BaseControllerConfig
+{
+    private $field = [];
+
+    public function __get($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;
+            }
+        }
+        return $this->field[$name];
+    }
+
+    function getShenjiStatus()
+    {
+        return redisEnv('SHENJI_SWITCH') ? 1 : 0;
+    }
+
+    //获取分销渠道ID
+    function getChannelId()
+    {
+        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;
+        }
+    }
+
+    //获取分销渠道名称
+    function getChannelName()
+    {
+        if (empty(session('ydychannel'))) {
+            if (env('APP_ENV') == 'local') return '测试';
+        }
+        $distribution_channel = unserialize(session('ydychannel'));
+        return $distribution_channel->distribution_channel_name;
+    }
+
+    //获取分销渠道域名
+    function getChannelDomain()
+    {
+        if (empty(session('ydychannel'))) {
+            if (env('APP_ENV') == 'local') return 'site1.aizhuishu.com';
+        }
+
+        $distribution_channel = unserialize(session('ydychannel'));
+        return "site{$distribution_channel->id}.leyuee.com";
+    }
+
+    //获取登陆用户ID
+    function getChannelUserId()
+    {
+        return session('ydyauth');
+    }
+
+    //获取登陆号码
+    function getLogPhone()
+    {
+        return session('ydylogphone');
+    }
+
+    function getCompanyId()
+    {
+        $channel_info = ChannelUser::find($this->channel_user_id);
+        if ($channel_info) {
+            return $channel_info->company_id ? $channel_info->company_id : 0;
+        }
+        return 0;
+    }
+
+    function getALLChannelIDByCompanyID()
+    {
+        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();
+    }
+
+    //判断是否为内部站点
+    function isInnerRole()
+    {
+        $lists = ChannelUsersInner::where('is_enable', 1)->get();
+        $inner_phones = [];
+        foreach ($lists as $item) {
+            $inner_phones[] = $item->phone . '2';
+        }
+        return in_array($this->phone, $inner_phones);
+    }
+
+    public function getAllChannelIdByChannelUserId()
+    {
+        return Channel::where('channel_user_id', $this->channel_user_id)->get()->pluck('id')->all();
+    }
+}

+ 5 - 2
src/Controllers/LandingPage/LinkController.php

@@ -2,9 +2,10 @@
 
 namespace General\Controllers\LandingPage;
 
-use App\Http\Controllers\Channel\BaseController;
+use App\Http\Controllers\Controller;
 use App\Jobs\AutoCheckLandingPage;
 use App\Libs\AliOSS;
+use General\Controllers\BaseControllerConfig;
 use General\Controllers\LandingPage\Transformers\BaiDuAdAccountTransformer;
 use General\Controllers\LandingPage\Transformers\LinkTransformer;
 use General\Controllers\LandingPage\Transformers\ReportOrderTramsformer;
@@ -19,8 +20,10 @@ use General\Services\Config\ConfigService;
 use Illuminate\Http\Request;
 use General\Services\LandingPage\LandingPageLinkService;
 
-class LinkController extends BaseController
+class LinkController extends Controller
 {
+    use BaseControllerConfig;
+
     private $service;
 
     public function __construct()

+ 30 - 0
src/Models/Channel/ChannelUsersInner.php

@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: Hardy
+ * Date: 2020/11/10
+ * Time: 14:50
+ */
+
+
+namespace General\Models\Channel;
+
+
+use Illuminate\Database\Eloquent\Model;
+
+class ChannelUsersInner extends Model
+{
+    protected $table = 'channel_users_inner';
+    protected $fillable = [
+        'id',
+        'phone',
+        'group_id',
+        'is_enable',
+        'output_is_enable',
+        'created_at',
+        'updated_at',
+        'desc',
+        'customer_msg_type'
+    ];
+}

+ 18 - 0
src/Models/Qapp/QappPackageInfo.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace General\Models\Qapp;
+
+use Illuminate\Database\Eloquent\Model;
+
+class QappPackageInfo extends Model
+{
+    protected $table = 'qapp_package_info';
+    protected $fillable = [
+        'channel_id',
+        'package',
+        'company',
+        'app_pay_merchat_id',
+        'h5_pay_merchat_id',
+        'ali_pay_merchat_id',
+    ];
+}

+ 1 - 1
src/Services/LandingPage/LandingPageLinkService.php

@@ -102,7 +102,7 @@ class LandingPageLinkService
     public function updateLinkStatus(int $id, int $status, string $remark)
     {
         if ($status) {
-            self::saveLink(['id' => $id, 'status' => $status, 'remark' => $remark]);
+            $this->saveLink(['id' => $id, 'status' => $status, 'remark' => $remark]);
             LandingPageLinkLog::create(['link_id' => $id, 'status' => $status, 'remark' => $remark]);
         }
     }