|
@@ -7,16 +7,19 @@ use app\admin\model\AuthRule;
|
|
|
use traits\think\Instance;
|
|
|
|
|
|
class SubService{
|
|
|
- use Instance;
|
|
|
/** @var Admin */
|
|
|
protected $admin;
|
|
|
protected $chanId;
|
|
|
protected $rules=[];
|
|
|
|
|
|
- public function __construct($chanId)
|
|
|
+ public function __construct($chanId,$fromWhere)
|
|
|
{
|
|
|
$this->chanId=$chanId;
|
|
|
- $this->admin=Admin::get($chanId);
|
|
|
+ if($fromWhere=='admin'){
|
|
|
+ $this->admin=Admin::get($chanId);
|
|
|
+ }elseif ($fromWhere=='api'){
|
|
|
+ $this->admin=Admin::sub()->find($chanId);
|
|
|
+ }
|
|
|
$this->getRules();
|
|
|
}
|
|
|
|
|
@@ -37,9 +40,13 @@ class SubService{
|
|
|
/**
|
|
|
* @return Admin
|
|
|
*/
|
|
|
- public function getAdmin()
|
|
|
+ public function getAdmin($field=null)
|
|
|
{
|
|
|
- return $this->admin;
|
|
|
+ if(is_null($field)) {
|
|
|
+ return $this->admin;
|
|
|
+ }else{
|
|
|
+ return $this->admin[$field]??null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -78,6 +85,11 @@ class SubService{
|
|
|
return in_array($id,$this->rules);
|
|
|
}
|
|
|
|
|
|
+ public function hasAllowWxQrPower(){
|
|
|
+ $id=$this->getRuleIdByName('admin/_allow_wx_qr_power');
|
|
|
+ return in_array($id,$this->rules);
|
|
|
+ }
|
|
|
+
|
|
|
protected function getRuleIdByName($name){
|
|
|
static $names=[];
|
|
|
if(!isset($names[$name])){
|
|
@@ -89,4 +101,21 @@ class SubService{
|
|
|
public function isFastHand(){
|
|
|
return $this->chanId=='kuaishou';
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var null|static 实例对象
|
|
|
+ */
|
|
|
+ protected static $instance = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取示例
|
|
|
+ * @param array $options 实例配置
|
|
|
+ * @return static
|
|
|
+ */
|
|
|
+ public static function instance($chanId,$fromWhere)
|
|
|
+ {
|
|
|
+ if (is_null(self::$instance)) self::$instance = new self($chanId,$fromWhere);
|
|
|
+
|
|
|
+ return self::$instance;
|
|
|
+ }
|
|
|
}
|