/** * 禁止用户 */ public function dorunAction() { $this->getRequest()->isPost() || $this->showError('operate.fail'); $key = $this->getInput('key', 'post'); if (!in_array($key, array('1', '2'))) { $this->showError('USER:ban.error.data.format'); } $array = array(); list($end_time, $reason, $types) = $this->getInput(array('end_time', 'reason', 'type'), 'post'); $userInfos = $this->_getUids(explode(',', $this->getInput('value', 'post')), intval($key)); if (!$userInfos) { $this->showError('USER:ban.user.illegal'); } //如果是创始人 则自动设置为system $_uid = $this->loginUser->uid; $_operator = $this->loginUser->username; if ($this->isFounder($_operator)) { $_operator = 'system'; $_uid = 0; } if ($end_time > 0) { $end_time = Pw::str2time($end_time); } Wind::import('SRV:user.dm.PwUserBanInfoDm'); $_notice = array(); $rightTypes = array_keys($this->_getService()->getBanType()); foreach ($types as $type) { if (!in_array($type, $rightTypes)) { continue; } foreach ($userInfos as $uid => $info) { $dm = new PwUserBanInfoDm(); $dm->setUid($uid)->setEndTime(intval($end_time))->setTypeid($type)->setReason($reason)->setOperator($_operator)->setCreatedUid($_uid); $array[] = $dm; isset($_notice[$uid]) || ($_notice[$uid] = array()); $_notice[$uid]['end_time'] = $end_time; $_notice[$uid]['reason'] = $reason; $_notice[$uid]['type'][] = $type; $_notice[$uid]['operator'] = $_operator; } } $r = $this->_getService()->banUser($array); if ($r instanceof PwError) { $this->showError($r->getError(), 'u/forbidden/run'); } $this->_getService()->sendNotice($_notice, 1); $this->showMessage('USER:ban.success', 'u/forbidden/run'); }
public function banUser($uid) { $this->user = new PwUserBo($uid); if (!$this->user->isExists()) { return $this->buildResponse(USER_NOT_EXISTS); } Wind::import('SRV:user.PwUserBan'); Wind::import('SRV:user.dm.PwUserBanInfoDm'); $rightType = array(PwUserBan::BAN_AVATAR, PwUserBan::BAN_SIGN, PwUserBan::BAN_SPEAK); $dmArray = array(); foreach ($rightType as $k => $v) { $dm = new PwUserBanInfoDm(); $dm->setUid($uid)->setTypeid($v)->setReason('App ban'); $dmArray[] = $dm; } $result = $this->getUserBanService()->banUser($dmArray); if ($result instanceof PwError) { return $this->buildResponse(-1, $result->getError()); } return $this->buildResponse(0, $result); }
/** * 构建禁止的对象 * * @return array */ private function _buildBanDm() { Wind::import('SRV:user.dm.PwUserBanInfoDm'); Wind::import('SRV:user.PwUserBan'); $rightTypes = array(PwUserBan::BAN_AVATAR, PwUserBan::BAN_SIGN, PwUserBan::BAN_SPEAK); if ($this->banInfo->end_time > 0) { $this->banInfo->end_time = Pw::str2time($this->banInfo->end_time); } $data = $_notice = array(); foreach ($this->banInfo->types as $type) { if (!in_array($type, $rightTypes)) { continue; } foreach ($this->selectBanUsers as $uid => $_item) { $dm = new PwUserBanInfoDm(); $dm->setUid($uid)->setBanAllAccount($this->banInfo->ban_others)->setCreateTime(Pw::getTime())->setCreatedUid($this->loginUser->uid)->setOperator($this->loginUser->username)->setEndTime(intval($this->banInfo->end_time))->setTypeid($type)->setReason($this->banInfo->reason)->setFid(0); $data[] = $dm; isset($_notice[$uid]) || ($_notice[$uid] = array()); $_notice[$uid]['end_time'] = $this->banInfo->end_time; $_notice[$uid]['reason'] = $this->banInfo->reason; $_notice[$uid]['type'][] = $type; $_notice[$uid]['operator'] = $this->loginUser->username; } } return array($data, $_notice); }