Пример #1
0
 public function invoke($arrInput)
 {
     //用于登录
     $id = (int) $arrInput['id'];
     $dataService = new Service_Data_Message_V2_Message();
     $data = $dataService->get_operation_message_details($id);
     $message = $data[0];
     if (!$message) {
         return array('errno' => '1', 'errmsg' => 'message not found');
     }
     $cid = $message['cid'];
     $opt = json_decode($message['opt'], true);
     $app_version = $message['app_versiont'];
     if (!$opt['push_response']) {
         return array('errno' => 1, 'errmsg' => '暂无统计');
     }
     // push_reponse 是以city_code 作为键值
     // "push_response":{"131":{"3":["msgid#8452819436143893891"],"4":["msgid#1259143845097668564"]},"289":{"3":["msgid#7402617256944954515"],"4":["msgid#2232901761059640260"]},"340":{"3":["msgid#7206400091464665875"],"4":["msgid#4420386400034273812"]}}
     // {"3":["msgid#3386917452281572931"],"4":["msgid#2528194748361896020"]} 全国推或者按照版本推
     $broadcast = array();
     $group = array();
     $reponses = $opt['push_response'];
     foreach ($reponses as $k => $v) {
         if ($k == 0 && !$app_version) {
             //广播
             $broadcast = $v;
         }
         if ($k == 0 && $app_version) {
             //按版本号推送
             $group['ver_' . $app_version] = $v;
         }
         if ($k > 0) {
             //按城市的组播
             $group[$k] = $v;
         }
     }
     $rebroadcast = $regroup = array();
     if ($broadcast) {
         // 查询广播绑定人数
         // 广播成功接收用户数,只有android数据
         foreach ($broadcast as $os => $msids) {
             //目前只有一个
             foreach ($msids as $msgid) {
                 $id = $this->stripMsgid($msgid);
                 $ret = Net_Util::getMsgCountByResourceId($id);
                 foreach ($ret['ack_counts'] as $t => $cnt) {
                     $rebroadcast['detail'][$os]['count'] += $cnt;
                     $rebroadcast['sum'] += $cnt;
                 }
             }
         }
     }
     //组播
     if ($group) {
         foreach ($group as $tag => $msgids) {
             $ret = Net_Util::getUserCountByTag($tag);
             if ($ret) {
                 // ios and android
                 foreach ($msgids as $os => $srcIDs) {
                     //其实只有一个msgid
                     foreach ($srcIDs as $oneID) {
                         $msgid = $this->stripMsgid($oneID);
                         $tagCntReturn = Net_Util::getGroupMesageArriveCount($ret['tid'], $msgid);
                         $regroup['tags'][$tag]['os'][$os]['usercount'] += $tagCntReturn['usercount'];
                         $regroup['tags'][$tag]['os'][$os]['success_count'] += $tagCntReturn['success_count'];
                         $regroup['tags'][$tag]['sum']['usercount'] = $tagCntReturn['usercount'];
                         $regroup['tags'][$tag]['sum']['success_count'] += $tagCntReturn['success_count'];
                         //其实 ios 和 android 返回的usercount是一样的,表示tag的绑定用户数
                         $regroup['sum']['usercount'] += $tagCntReturn['usercount'];
                         $regroup['sum']['success_count'] += $tagCntReturn['success_count'];
                     }
                 }
             }
         }
         $regroup['sum']['usercount'] = $regroup['sum']['usercount'] >> 1;
         //算重了
     }
     $return['errno'] = 0;
     $return['data']['broadcast'] = $rebroadcast;
     $return['data']['group'] = $regroup;
     return $return;
 }