123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\main\service;
- use app\main\constants\MqConstants;
- use app\main\InternalInterface\SingletonService;
- class ChangeMenuService extends BaseService {
- const EXCHANGE_NAME ='cps.ex.topic';
- private $map = [
- 'is_push' => true,
- 'find' => null,
- 'channel' => null,
- 'replace' => null,
- 'params' => null,
- ];
- /**
- * @var ChangeMenuService
- */
- protected static $self = null;
- /**
- * @return BaseService|ChangeMenuService
- */
- public static function instance()
- {
- if (self::$self == NULL) {
- self::$self = new self();
- }
- return self::$self;
- }
- /**
- * 不推送到微信
- */
- public function noPushWeChat(){
- $this->map['is_push'] = false;
- return $this;
- }
- /**
- * 设置要查找替换的域名
- * @param $host
- * @return $this
- * @throws \Exception
- */
- public function setFindHost($host){
- if(!is_string($host)){
- throw new \Exception("参数错误");
- }
- $this->map['find'] = $host;
- return $this;
- }
- /**
- * 根据业务域名ID查找替换
- * @param int $host_id
- * @return $this
- * @throws \Exception
- */
- public function setFindHostById($host_id){
- if(!is_numeric($host_id)){
- throw new \Exception("参数错误");
- }
- $host_info = model('Ophost')->getInfoById($host_id);
- $host = $host_info['host'] ?? null;
- $this->map['find'] = $host;
- return $this;
- }
- /**
- * 设置要替换的域名ID
- * @param int $host_id
- * @return $this
- * @throws \Exception
- */
- public function setReplaceHostById($host_id){
- if(!is_numeric($host_id)){
- throw new \Exception("参数错误");
- }
- $host_info = model('Ophost')->getInfoById($host_id);
- $host = $host_info['host'] ?? null;
- $this->map['replace'] = $host;
- return $this;
- }
- /**
- * 设置要替换的域名
- * @param $host
- * @return $this
- * @throws \Exception
- */
- public function setReplaceHost($host){
- if(!is_string($host)){
- throw new \Exception("参数错误");
- }
- $this->map['replace'] = $host;
- return $this;
- }
- /**
- * 设置要替换的渠道ID
- * @param $channel_id
- * @return ChangeMenuService
- */
- public function setChannelId($channel_id){
- $this->map['channel'] = $channel_id;
- return $this;
- }
- /**
- * 设置要追加的参数
- * @param array $params
- * @return $this
- */
- public function setAppendParams(array $params){
- $this->map['params'] = $params;
- return $this;
- }
- /**
- * 推送MQ消息
- */
- public function push(){
- $mq = MqService::instance()->getDotMqInstance();
- $mq->transferExchange($this->map, self::EXCHANGE_NAME, MqConstants::CHANNEL_CHANGE_MENU, 'topic');
- }
- }
|