Exemplo n.º 1
0
 /**
  * do群发消息
  *
  * @return void
  */
 public function doSendAction()
 {
     list($type, $content, $title, $step, $countStep) = $this->getInput(array('type', 'content', 'title', 'step', 'countStep'));
     !$content && $this->showError('Message:content.empty');
     if ($step > $countStep) {
         $this->showMessage("ADMIN:success");
     }
     $step = $step ? $step : 1;
     switch ($type) {
         case 1:
             // 根据用户组
             list($user_groups, $grouptype) = $this->getInput(array('user_groups', 'grouptype'));
             Wind::import('SRV:user.vo.PwUserSo');
             $vo = new PwUserSo();
             $searchDs = Wekit::load('SRV:user.PwUserSearch');
             if (!$user_groups) {
                 $this->showError('Message:user.groups.empty');
             }
             if ($grouptype == 'memberid') {
                 $vo->setMemberid($user_groups);
             } else {
                 $vo->setGid($user_groups);
             }
             $count = $searchDs->countSearchUser($vo);
             $countStep = ceil($count / $this->perstep);
             if ($step <= $countStep) {
                 list($start, $limit) = Pw::page2limit($step, $this->perstep);
                 $userInfos = $searchDs->searchUser($vo, $limit, $start);
             }
             break;
         case 2:
             // 根据用户名
             $touser = $this->getInput('touser');
             !$touser && $this->showError('Message:receive.user.empty');
             $touser = explode(' ', $touser);
             $count = count($touser);
             $countStep = ceil($count / $this->perstep);
             if ($step <= $countStep) {
                 $userDs = Wekit::load('user.PwUser');
                 list($start, $limit) = Pw::page2limit($step, $this->perstep);
                 $userInfos = $userDs->fetchUserByName(array_slice($touser, $start, $limit));
             }
             break;
         case 3:
             // 根据在线用户(精确在线)
             $onlineService = Wekit::load('online.srv.PwOnlineCountService');
             list($count, $userInfos) = $onlineService->getVisitorList('', $step, $this->perstep, true);
             $countStep = ceil($count / $this->perstep);
             break;
     }
     $result = $this->sendNoticeByUsers((array) $userInfos, $content, strip_tags($title));
     if ($result instanceof PwError) {
         $this->showError($result->getError());
     }
     $haveBuild = $step * $this->perstep;
     $haveBuild = $haveBuild > $count ? $count : $haveBuild;
     $step++;
     usleep(500);
     $data = array('step' => $step, 'countStep' => $countStep, 'count' => $count, 'haveBuild' => $haveBuild);
     echo Pw::jsonEncode(array('data' => $data));
     exit;
 }