Пример #1
0
 /**
  * 通过主键,删除一条记录
  * @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);
 }
Пример #2
0
 /**
  * 通过主键,删除一条记录
  * @param integer $rankId
  * @return integer
  */
 public function removeByPk($rankId)
 {
     if (($rankId = (int) $rankId) <= 1) {
         return false;
     }
     $tableName = $this->getTblprefix() . TableNames::getRanks();
     $sql = $this->getCommandBuilder()->createDelete($tableName, '`rank_id` = ?');
     $rowCount = $this->delete($sql, $rankId);
     return $rowCount;
 }
Пример #3
0
 /**
  * 获取“登录名”验证规则
  * @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;
 }
Пример #4
0
 /**
  * 通过主键,编辑一条记录
  * @param integer $memberId
  * @param array $params
  * @return integer
  */
 public function modifyByPk($memberId, array $params = array())
 {
     if (($memberId = (int) $memberId) <= 0) {
         return false;
     }
     $attributes = array();
     if (isset($params['realname'])) {
         $attributes['realname'] = trim($params['realname']);
     }
     if (isset($params['sex'])) {
         $sex = trim($params['sex']);
         if ($sex !== '') {
             $attributes['sex'] = $sex;
         } else {
             return false;
         }
     }
     if (isset($params['birth_ymd'])) {
         $birthYmd = trim($params['birth_ymd']);
         if ($birthYmd !== '') {
             $attributes['birth_ymd'] = $birthYmd;
         }
     }
     if (isset($params['is_pub_birth'])) {
         $isPubBirth = trim($params['is_pub_birth']);
         if ($isPubBirth !== '') {
             $attributes['is_pub_birth'] = $isPubBirth;
         } else {
             return false;
         }
     }
     if (isset($params['birth_md'])) {
         $attributes['birth_md'] = trim($params['birth_md']);
     }
     if (isset($params['anniversary'])) {
         $attributes['anniversary'] = trim($params['anniversary']);
     }
     if (isset($params['is_pub_anniversary'])) {
         $isPubAnniversary = trim($params['is_pub_anniversary']);
         if ($isPubAnniversary !== '') {
             $attributes['is_pub_anniversary'] = $isPubAnniversary;
         } else {
             return false;
         }
     }
     if (isset($params['head_portrait'])) {
         $attributes['head_portrait'] = trim($params['head_portrait']);
     }
     if (isset($params['introduce'])) {
         $attributes['introduce'] = trim($params['introduce']);
     }
     if (isset($params['interests'])) {
         $attributes['interests'] = trim($params['interests']);
     }
     if (isset($params['is_pub_interests'])) {
         $isPubInterests = trim($params['is_pub_interests']);
         if ($isPubInterests !== '') {
             $attributes['is_pub_interests'] = $isPubInterests;
         } else {
             return false;
         }
     }
     if (isset($params['telephone'])) {
         $attributes['telephone'] = trim($params['telephone']);
     }
     if (isset($params['mobiphone'])) {
         $attributes['mobiphone'] = trim($params['mobiphone']);
     }
     if (isset($params['is_pub_mobiphone'])) {
         $isPubMobiphone = trim($params['is_pub_mobiphone']);
         if ($isPubMobiphone !== '') {
             $attributes['is_pub_mobiphone'] = $isPubMobiphone;
         } else {
             return false;
         }
     }
     if (isset($params['email'])) {
         $attributes['email'] = trim($params['email']);
     }
     if (isset($params['is_pub_email'])) {
         $isPubEmail = trim($params['is_pub_email']);
         if ($isPubEmail !== '') {
             $attributes['is_pub_email'] = $isPubEmail;
         } else {
             return false;
         }
     }
     if (isset($params['live_country_id'])) {
         $attributes['live_country_id'] = (int) $params['live_country_id'];
     }
     if (isset($params['live_country'])) {
         $attributes['live_country'] = trim($params['live_country']);
     }
     if (isset($params['live_province_id'])) {
         $attributes['live_province_id'] = (int) $params['live_province_id'];
     }
     if (isset($params['live_province'])) {
         $attributes['live_province'] = trim($params['live_province']);
     }
     if (isset($params['live_city_id'])) {
         $attributes['live_city_id'] = (int) $params['live_city_id'];
     }
     if (isset($params['live_city'])) {
         $attributes['live_city'] = trim($params['live_city']);
     }
     if (isset($params['live_district_id'])) {
         $attributes['live_district_id'] = (int) $params['live_district_id'];
     }
     if (isset($params['live_district'])) {
         $attributes['live_district'] = trim($params['live_district']);
     }
     if (isset($params['live_street'])) {
         $attributes['live_street'] = trim($params['live_street']);
     }
     if (isset($params['live_zipcode'])) {
         $attributes['live_zipcode'] = trim($params['live_zipcode']);
     }
     if (isset($params['address_country_id'])) {
         $attributes['address_country_id'] = (int) $params['address_country_id'];
     }
     if (isset($params['address_country'])) {
         $attributes['address_country'] = trim($params['address_country']);
     }
     if (isset($params['address_province_id'])) {
         $attributes['address_province_id'] = (int) $params['address_province_id'];
     }
     if (isset($params['address_province'])) {
         $attributes['address_province'] = trim($params['address_province']);
     }
     if (isset($params['address_city_id'])) {
         $attributes['address_city_id'] = (int) $params['address_city_id'];
     }
     if (isset($params['address_city'])) {
         $attributes['address_city'] = trim($params['address_city']);
     }
     if (isset($params['address_district_id'])) {
         $attributes['address_district_id'] = (int) $params['address_district_id'];
     }
     if (isset($params['address_district'])) {
         $attributes['address_district'] = trim($params['address_district']);
     }
     if (isset($params['address_street'])) {
         $attributes['address_street'] = trim($params['address_street']);
     }
     if (isset($params['address_zipcode'])) {
         $attributes['address_zipcode'] = trim($params['address_zipcode']);
     }
     if (isset($params['qq'])) {
         $attributes['qq'] = (int) $params['qq'];
     }
     if (isset($params['msn'])) {
         $attributes['msn'] = trim($params['msn']);
     }
     if (isset($params['skypeid'])) {
         $attributes['skypeid'] = trim($params['skypeid']);
     }
     if (isset($params['wangwang'])) {
         $attributes['wangwang'] = trim($params['wangwang']);
     }
     if (isset($params['weibo'])) {
         $attributes['weibo'] = trim($params['weibo']);
     }
     if (isset($params['blog'])) {
         $attributes['blog'] = trim($params['blog']);
     }
     if (isset($params['website'])) {
         $attributes['website'] = trim($params['website']);
     }
     if (isset($params['fax'])) {
         $attributes['fax'] = trim($params['fax']);
     }
     $rowCount = 0;
     if ($attributes === array()) {
         return $rowCount;
     }
     $tableName = $this->getTblprefix() . TableNames::getSocial();
     $sql = $this->getCommandBuilder()->createUpdate($tableName, array_keys($attributes), '`member_id` = ?');
     $attributes['member_id'] = $memberId;
     $rowCount = $this->update($sql, $attributes);
     return $rowCount;
 }
Пример #5
0
 /**
  * 获取“类型名”验证规则
  * @param mixed $value
  * @return array
  */
 public function getTypeNameRule($value)
 {
     return array('MinLength' => new validator\MinLengthValidator($value, 2, Lang::_('SRV_FILTER_MEMBER_TYPES_TYPE_NAME_MINLENGTH')), 'MaxLength' => new validator\MaxLengthValidator($value, 50, Lang::_('SRV_FILTER_MEMBER_TYPES_TYPE_NAME_MAXLENGTH')), 'DbExists' => new validator\DbExistsValidator($value, false, Lang::_('SRV_FILTER_MEMBER_TYPES_TYPE_NAME_UNIQUE'), $this->getDbProxy(), TableNames::getTypes(), 'type_name'));
 }
Пример #6
0
 /**
  * 通过主键,删除一条记录
  * @param integer $addressId
  * @return integer
  */
 public function removeByPk($addressId)
 {
     if (($addressId = (int) $addressId) <= 0) {
         return false;
     }
     $tableName = $this->getTblprefix() . TableNames::getAddresses();
     $sql = $this->getCommandBuilder()->createDelete($tableName, '`address_id` = ?');
     $rowCount = $this->delete($sql, $addressId);
     return $rowCount;
 }
Пример #7
0
 /**
  * 操作积分
  * @param string $opType increase:增加、reduce:扣除、freeze:冻结、unfreeze:解冻、reduce_freeze:扣除冻结积分
  * @param integer $memberId
  * @param integer $points
  * @param string $source
  * @param string $remarks
  * @param integer $creatorId
  * @return boolean
  */
 public function opPoints($opType, $memberId, $points, $source, $remarks, $creatorId)
 {
     if ($opType !== 'increase' && $opType !== 'reduce' && $opType !== 'freeze' && $opType !== 'unfreeze' && $opType !== 'reduce_freeze') {
         return false;
     }
     if (($memberId = (int) $memberId) <= 0) {
         return false;
     }
     if (($points = (int) $points) <= 0) {
         return false;
     }
     if (($source = trim($source)) === '') {
         return false;
     }
     $tableName = $this->getTblprefix() . TableNames::getMembers();
     $logTblName = $this->getTblprefix() . TableNames::getPointsLogs();
     $sql = 'SELECT `points`, `points_freeze` FROM `' . $tableName . '` WHERE `member_id` = ?';
     $row = $this->fetch($sql, $memberId);
     if (!$row || !is_array($row) || !isset($row['points'])) {
         return false;
     }
     $beforePoints = (int) $row['points'];
     $beforeFreezePoints = (int) $row['points_freeze'];
     $freezePoints = 0;
     if ($opType === 'freeze' || $opType === 'unfreeze' || $opType === 'reduce_freeze') {
         $freezePoints = $points;
         $points = 0;
     }
     $afterFreezePoints = $opType === 'freeze' ? $beforeFreezePoints + $freezePoints : $beforeFreezePoints - $freezePoints;
     switch (true) {
         case $opType === 'increase':
             $afterPoints = $beforePoints + $points;
             break;
         case $opType === 'reduce':
             $afterPoints = $beforePoints - $points;
             break;
         case $opType === 'freeze':
             $afterPoints = $beforePoints - $freezePoints;
             break;
         case $opType === 'unfreeze':
             $afterPoints = $beforePoints + $freezePoints;
             break;
         case $opType === 'reduce_freeze':
         default:
             $afterPoints = $beforePoints;
             break;
     }
     if ($afterPoints < 0 || $afterFreezePoints < 0) {
         return false;
     }
     $attributes = array('member_id' => $memberId, 'op_type' => $opType, 'before_points' => $beforePoints, 'after_points' => $afterPoints, 'points' => $points, 'before_freeze_points' => $beforeFreezePoints, 'after_freeze_points' => $afterFreezePoints, 'freeze_points' => $freezePoints, 'source' => $source, 'remarks' => $remarks, 'creator_id' => (int) $creatorId, 'dt_created' => date('Y-m-d H:i:s'));
     $commands = array(array('sql' => 'UPDATE `' . $tableName . '` SET `points` = ?, `points_freeze` = ? WHERE `member_id` = ?', 'params' => array('points' => $afterPoints, 'points_freeze' => $afterFreezePoints, 'member_id' => $memberId)), array('sql' => $this->getCommandBuilder()->createInsert($logTblName, array_keys($attributes)), 'params' => $attributes));
     return $this->doTransaction($commands);
 }