54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace app\master\service\push;
|
|
|
|
use think\Db;
|
|
|
|
/**
|
|
* 推送器基类:提供数据表句柄、凭证读取等公共能力
|
|
*/
|
|
abstract class AbstractPusher implements PusherInterface
|
|
{
|
|
protected $journal_obj;
|
|
protected $journal_stage_obj;
|
|
protected $article_obj;
|
|
protected $article_author_obj;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->journal_obj = Db::name('journal');
|
|
$this->journal_stage_obj = Db::name('journal_stage');
|
|
$this->article_obj = Db::name('article');
|
|
$this->article_author_obj = Db::name('article_author');
|
|
}
|
|
|
|
/**
|
|
* 读取某个数据库的凭证配置
|
|
* @param string $key credentials.<key>
|
|
* @return array
|
|
*/
|
|
protected function cred($key)
|
|
{
|
|
$all = config('dbpush.credentials');
|
|
return isset($all[$key]) ? $all[$key] : [];
|
|
}
|
|
|
|
/**
|
|
* 读取顶层 dbpush 配置项
|
|
*/
|
|
protected function conf($key, $default = null)
|
|
{
|
|
$val = config('dbpush.' . $key);
|
|
return $val === null ? $default : $val;
|
|
}
|
|
|
|
/**
|
|
* 组合文章作者名(逗号分隔)
|
|
*/
|
|
protected function getAuthorNames($articleId)
|
|
{
|
|
$list = $this->article_author_obj->where('article_id', $articleId)->where('state', 0)->column('author_name');
|
|
return implode(', ', $list);
|
|
}
|
|
}
|