/** * 通过主键,删除一条记录 * @param integer $memberId * @return integer */ public function removeByPk($memberId) { if (($memberId = (int) $memberId) <= 0) { return false; } $portalTblName = $this->getTblprefix() . TableNames::getPortal(); $membersTblName = $this->getTblprefix() . TableNames::getMembers(); $socialTblName = $this->getTblprefix() . TableNames::getSocial(); $sql = 'SELECT `p`.*, `m`.*, `s`.* FROM `' . $portalTblName . '` AS `p` LEFT JOIN `' . $membersTblName . '` AS `m` ON `p`.`member_id` = `m`.`member_id` LEFT JOIN `' . $socialTblName . '` AS `s` ON `m`.`member_id` = `s`.`member_id` WHERE `m`.`member_id` = ?'; $row = $this->fetchAssoc($sql, $memberId); if (!$row || !is_array($row) || !isset($row['member_id'])) { return false; } Log::info(sprintf('Portal backup before remove: %s', serialize($row)), 0, __METHOD__); $commands = array(array('sql' => 'DELETE FROM `' . $portalTblName . '` WHERE `member_id` = ?', 'params' => $memberId), array('sql' => 'DELETE FROM `' . $membersTblName . '` WHERE `member_id` = ?', 'params' => $memberId), array('sql' => 'DELETE FROM `' . $socialTblName . '` WHERE `member_id` = ?', 'params' => $memberId)); return $this->doTransaction($commands); }
/** * 查询多条记录 * @param array $params * @param string $order * @param integer $limit * @param integer $offset * @param string $option * @return array */ public function findAll(array $params = array(), $order = '', $limit = 0, $offset = 0, $option = '') { $commandBuilder = $this->getCommandBuilder(); $portalTblName = $this->getTblprefix() . TableNames::getPortal(); $socialTblName = $this->getTblprefix() . TableNames::getSocial(); $sql = 'SELECT ' . $option . ' `p`.`member_id`, `p`.`login_name`, `p`.`member_name`, `p`.`member_mail`, `p`.`member_phone`, `s`.* FROM `' . $socialTblName . '` AS `s` LEFT JOIN `' . $portalTblName . '` AS `p` ON `s`.`member_id` = `p`.`member_id`'; $condition = '`p`.`trash` = ' . $commandBuilder::PLACE_HOLDERS; $attributes = array('trash' => 'n'); if (isset($params['login_name'])) { $loginName = trim($params['login_name']); if ($loginName !== '') { $condition .= ' AND `p`.`login_name` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['login_name'] = $loginName; } } if (isset($params['login_type'])) { $loginType = trim($params['login_type']); if ($loginType !== '') { $condition .= ' AND `p`.`login_type` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['login_type'] = $loginType; } } if (isset($params['member_name'])) { $memberName = trim($params['member_name']); $condition .= ' AND `p`.`member_name` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['member_name'] = $memberName; } if (isset($params['member_mail'])) { $memberMail = trim($params['member_mail']); $condition .= ' AND `p`.`member_mail` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['member_mail'] = $memberMail; } if (isset($params['member_phone'])) { $memberPhone = trim($params['member_phone']); $condition .= ' AND `p`.`member_phone` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['member_phone'] = $memberPhone; } if (isset($params['realname'])) { $realname = trim($params['realname']); if ($realname !== '') { $condition .= ' AND `s`.`realname` LIKE ' . $commandBuilder::PLACE_HOLDERS; $attributes['realname'] = '%' . $realname . '%'; } } if (isset($params['sex'])) { $sex = trim($params['sex']); if ($sex !== '') { $condition .= ' AND `s`.`sex` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['sex'] = $sex; } } if (isset($params['birth_md'])) { $birthMd = trim($params['birth_md']); if ($birthMd !== '') { $condition .= ' AND `s`.`birth_md` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['birth_md'] = $birthMd; } } if (isset($params['anniversary'])) { $anniversary = trim($params['anniversary']); if ($anniversary !== '') { $condition .= ' AND `s`.`anniversary` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['anniversary'] = $anniversary; } } if (isset($params['qq'])) { $qq = (int) $params['qq']; if ($qq > 0) { $condition .= ' AND `s`.`qq` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['qq'] = $qq; } } if (isset($params['member_id'])) { $memberId = (int) $params['member_id']; if ($memberId > 0) { $condition .= ' AND `s`.`member_id` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['member_id'] = $memberId; } } $sql = $commandBuilder->applyCondition($sql, $condition); $sql = $commandBuilder->applyOrder($sql, $order); $sql = $commandBuilder->applyLimit($sql, $limit, $offset); if ($option === 'SQL_CALC_FOUND_ROWS') { $ret = $this->fetchAllNoCache($sql, $attributes); if (isset($attributes['realname'])) { $attributes['realname'] = $realname; } if (is_array($ret)) { $ret['attributes'] = $attributes; $ret['order'] = $order; $ret['limit'] = $limit; $ret['offset'] = $offset; } } else { $ret = $this->fetchAll($sql, $attributes); } return $ret; }
/** * 获取“登录名”验证规则 * @param mixed $value * @return array */ public function getLoginNameRule($value) { $rules = array('MinLength' => new validator\MinLengthValidator($value, 6, Lang::_('SRV_FILTER_MEMBER_PORTAL_LOGIN_NAME_MINLENGTH')), 'MaxLength' => new validator\MaxLengthValidator($value, 18, Lang::_('SRV_FILTER_MEMBER_PORTAL_LOGIN_NAME_MAXLENGTH'))); if ($this->_object->isMailLogin($this->login_type)) { $rules['Mail'] = new validator\MailValidator($value, true, Lang::_('SRV_FILTER_MEMBER_PORTAL_LOGIN_NAME_MAIL')); } elseif ($this->_object->isPhoneLogin($this->login_type)) { $rules['Phone'] = new validator\PhoneValidator($value, true, Lang::_('SRV_FILTER_MEMBER_PORTAL_LOGIN_NAME_PHONE')); } else { $rules['AlphaNum'] = new validator\AlphaNumValidator($value, true, Lang::_('SRV_FILTER_MEMBER_PORTAL_LOGIN_NAME_ALPHANUM')); } $rules['DbExists'] = new validator\DbExistsValidator($value, false, Lang::_('SRV_FILTER_MEMBER_PORTAL_LOGIN_NAME_UNIQUE'), $this->getDbProxy(), TableNames::getPortal(), 'login_name'); return $rules; }
/** * 查询多条记录 * @param array $params * @param string $order * @param integer $limit * @param integer $offset * @param string $option * @return array */ public function findAll(array $params = array(), $order = '', $limit = 0, $offset = 0, $option = '') { $commandBuilder = $this->getCommandBuilder(); $membersTblName = $this->getTblprefix() . TableNames::getMembers(); $portalTblName = $this->getTblprefix() . TableNames::getPortal(); $sql = 'SELECT ' . $option . ' `m`.`member_id`, `p`.`login_name`, `p`.`member_name`, `p`.`member_mail`, `p`.`member_phone`, `m`.`type_id`, `m`.`rank_id`, `m`.`experience`, `m`.`balance`, `m`.`balance_freeze`, `m`.`points`, `m`.`points_freeze`, `m`.`consum`, `m`.`orders`, `m`.`description`, `m`.`dt_last_rerank`, `m`.`dt_created` FROM `' . $membersTblName . '` AS `m` LEFT JOIN `' . $portalTblName . '` AS `p` ON `m`.`member_id` = `p`.`member_id`'; $condition = '`p`.`trash` = ' . $commandBuilder::PLACE_HOLDERS; $attributes = array('trash' => 'n'); if (isset($params['login_name'])) { $loginName = trim($params['login_name']); if ($loginName !== '') { $condition .= ' AND `p`.`login_name` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['login_name'] = $loginName; } } if (isset($params['login_type'])) { $loginType = trim($params['login_type']); if ($loginType !== '') { $condition .= ' AND `p`.`login_type` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['login_type'] = $loginType; } } if (isset($params['member_name'])) { $memberName = trim($params['member_name']); $condition .= ' AND `p`.`member_name` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['member_name'] = $memberName; } if (isset($params['member_mail'])) { $memberMail = trim($params['member_mail']); $condition .= ' AND `p`.`member_mail` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['member_mail'] = $memberMail; } if (isset($params['member_phone'])) { $memberPhone = trim($params['member_phone']); $condition .= ' AND `p`.`member_phone` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['member_phone'] = $memberPhone; } if (isset($params['type_id'])) { $typeId = (int) $params['type_id']; if ($typeId > 0) { $condition .= ' AND `m`.`type_id` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['type_id'] = $typeId; } } if (isset($params['rank_id'])) { $rankId = (int) $params['rank_id']; if ($rankId > 0) { $condition .= ' AND `m`.`rank_id` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['rank_id'] = $rankId; } } if (isset($params['member_id'])) { $memberId = (int) $params['member_id']; if ($memberId > 0) { $condition .= ' AND `m`.`member_id` = ' . $commandBuilder::PLACE_HOLDERS; $attributes['member_id'] = $memberId; } } $sql = $commandBuilder->applyCondition($sql, $condition); $sql = $commandBuilder->applyOrder($sql, $order); $sql = $commandBuilder->applyLimit($sql, $limit, $offset); if ($option === 'SQL_CALC_FOUND_ROWS') { $ret = $this->fetchAllNoCache($sql, $attributes); if (is_array($ret)) { $ret['attributes'] = $attributes; $ret['order'] = $order; $ret['limit'] = $limit; $ret['offset'] = $offset; } } else { $ret = $this->fetchAll($sql, $attributes); } return $ret; }