/**
  * Job执行逻辑
  */
 public function handle_request()
 {
     //读取公告列表数据
     $queueList = $this->readAnnounceQueueInfo($this->announceId);
     if (!empty($queueList)) {
         $broker_queue = $this->brokerId;
         //从ajk_dw_stats库里读取本次操作的经纪人信息
         $DwStatsBll = Bll_DwStatsBiz::get_instance();
         $where = " broker_id>{$broker_queue} order by broker_id asc limit 1";
         $DwStats_broker = $DwStatsBll->get_distinct_broker($where);
         if (!empty($DwStats_broker)) {
             //添加逻辑判断待发送信息的经纪人是否开通微聊
             $activeBorker = Model_Mobile_BrokerChatInfo::getActiveBroker($DwStats_broker[0]['broker_id'], array('chatId'));
             $chatId = $activeBorker['chatId'];
             foreach ($queueList as $list) {
                 if (!empty($activeBorker)) {
                     //发送公众号信息
                     $msg_map = APF::get_instance()->get_config('msg_conf', 'mobile_api');
                     $text = $msg_map['ANNOUNCE_PUSH'] . $list['announce_content'];
                     $result = Bll_Chat::sendPublicMsg($chatId, $text);
                 } else {
                     $this->write_redis($DwStats_broker[0]['broker_id'], 'ANNOUNCE_PUSH', $list['announce_content'], 'mobile-ajk-broker');
                     $this->writeLog($this->log_dir . 'broker_queue.id', $DwStats_broker[0]['broker_id']);
                 }
             }
         } else {
             $this->writeLog($this->log_dir . 'broker_queue.id', 0);
             foreach ($queueList as $list) {
                 //更新公告队列
                 Dao_Msgpush_Announce::update($list['announce_id']);
                 $this->writeLog($this->log_dir . 'announce_queue.id', $list['announce_id']);
             }
         }
     }
 }
Beispiel #2
0
 public function handle_request_internal()
 {
     if (!$this->ip_check()) {
         return Util_MobileAPI::error_tmp('ip_invalid', $this->error_map('ip_invalid'));
     }
     if (!isset($this->_params['user_id'])) {
         return Util_MobileAPI::error_tmp('user_id_miss', $this->error_map('user_id_miss'));
     }
     if (!$this->check_msg_code($this->_params['msg_code'])) {
         return Util_MobileAPI::error_tmp('msg_code_invalid', $this->error_map('msg_code_invalid'));
     }
     $user_id = $this->_params['user_id'];
     $msg_code = $this->_params['msg_code'];
     $addon = $this->_params['addon'] ?: '';
     $from = $this->_params['from'] ?: '';
     $msg = $this->gen_msg($user_id, $msg_code, $addon, $from);
     $redis = $this->get_redis();
     try {
         //添加逻辑判断待发送信息的经纪人是否开通微聊
         $activeBorker = Model_Mobile_BrokerChatInfo::getActiveBroker($user_id, array('chatId'));
         if (empty($activeBorker)) {
             $redis->lPush($this->queue_name, $msg);
         } else {
             //添加发送公众号信息逻辑
             //发送公众号信息
             if ($activeBorker['chatId']) {
                 $msg_map = APF::get_instance()->get_config('msg_conf', 'mobile_api');
                 $text = $msg_map[$msg_code];
                 if ($msg_code === 'BROKER_PLAN_LIMIT') {
                     //定价计划限额到达需要特殊处理。
                     $text = $addon . $text;
                 }
                 apf_require_class('Bll_Chat');
                 $result = Bll_Chat::sendPublicMsg($activeBorker['chatId'], $text);
             }
         }
     } catch (RedisException $e) {
         return Util_MobileAPI::error_tmp('push_failed', $e->getMessage());
     }
     return array('status' => 'ok', 'data' => '操作成功');
 }