/** * 添加自媒体 */ public function addAction() { if ($this->isPost()) { $aUser = $this->getCurrUser(Model_User::TYPE_MEDIA); if (empty($aUser)) { return $this->showMsg('请先登录!', false); } $iMediaID = (int) $this->getParam('iMediaID'); $aMedia = null; if ($iMediaID > 0) { $aMedia = Model_Media::getDetail($iMediaID); if ($aMedia['iUserID'] != $aUser['iUserID']) { return $this->showMsg('不要乱改别人的数据', false); } } $aData = array(); $aData['iUserID'] = $aUser['iUserID']; $aData['iMediaType'] = (int) $this->getParam('iMediaType'); $aData['sMediaName'] = $this->getParam('sMediaName'); $aData['sOpenName'] = $this->getParam('sOpenName'); $aData['iFollowerNum'] = (int) $this->getParam('iFollowerNum'); $aData['sFollowerImg'] = $this->getParam('sFollowerImg'); $aData['sAvatar'] = $this->getParam('sAvatar'); $aData['sQRCode'] = $this->getParam('sQRCode'); $aErr = array(); switch ($aData['iMediaType']) { case Model_Media::TYPE_WEIXIN: if ($aData['iFollowerNum'] == 0) { $aErr['iFollowerNum'] = '请输入丝粉数量'; } if (!Util_Validate::isLength($aData['sMediaName'], 2, 50)) { $aErr['sMediaName'] = '请输入微信名称'; } if (!preg_match('/[a-z][0-9a-z_\\-]{5,19}/i', $aData['sOpenName'])) { $aErr['sOpenName'] = '请输入正确的微信帐号'; } if (empty($aData['sFollowerImg'])) { $aErr['sFollowerImg'] = '请上传粉丝数截图'; } if (empty($aData['sAvatar'])) { $aErr['sAvatar'] = '请上传微信头像'; } if (empty($aData['sQRCode'])) { $aErr['sQRCode'] = '请上传二维码'; } $aOtherMedia = Model_Media::getMediaByOpenName($aData['iMediaType'], $aData['sOpenName'], $iMediaID); if (!empty($aOtherMedia)) { $aErr['sOpenName'] = '该自媒体已经存在!'; } break; case Model_Media::TYPE_FRIEND: if (empty($aData['sMediaName'])) { $aErr['sMediaName'] = '请输入账号名称'; } if ($aData['iFollowerNum'] == 0) { $aErr['iFollowerNum'] = '请输入好友数量'; } if (empty($aData['sFollowerImg'])) { $aErr['sFollowerImg'] = '请上传好友数截图'; } if (empty($aData['sAvatar'])) { $aErr['sAvatar'] = '请上传你微信头像'; } // 判断该自媒是否已经存在 $aOtherMedia = Model_Media::getMediaByName($aData['iMediaType'], $aData['sMediaName'], $iMediaID); if (!empty($aOtherMedia)) { $aErr['sMediaName'] = '该微信帐号已经存在!'; } break; case Model_Media::TYPE_WEIBO: if (empty($aData['sMediaName'])) { $aErr['sMediaName'] = '请输入账号名称'; } if ($aData['iFollowerNum'] == 0) { $aErr['iFollowerNum'] = '请输入好友数量'; } if (empty($aData['sFollowerImg'])) { $aErr['sFollowerImg'] = '请上传好友数截图'; } if (empty($aData['sAvatar'])) { $aErr['sAvatar'] = '请上传你微博头像'; } $aData['sUrl'] = $this->getParam('sUrl'); if (!Util_Validate::isAbsoluteUrl($aData['sUrl'])) { $aErr['sUrl'] = '请输入正确的微博地址'; } // 判断该自媒是否已经存在 $aOtherMedia = Model_Media::getMediaByName($aData['iMediaType'], $aData['sMediaName'], $iMediaID); if (!empty($aOtherMedia)) { $aErr['sMediaName'] = '该微博帐号已经存在!'; } break; } $aCatID = $this->getParam('aCatID'); $aCityID = $this->getParam('aCityID'); $aTagID = $this->getParam('aTagID'); // if (empty($aCatID)) { // $aErr['aCatID'] = '请选择媒体类别'; // } // if (! empty($aCatID) && count($aCatID) > 3) { // $aErr['aCatID'] = '最多选择3个媒体类别'; // } if (empty($aTagID)) { $aErr['aTagID'] = '请选择媒体标签'; } if (!empty($aTagID) && count($aTagID) > 6) { $aErr['aTagID'] = '最多选择6个媒体标签'; } if (empty($aCityID)) { $aErr['aCityID'] = '请选择城市/地区'; } if (!empty($aCityID) && count($aCityID) > 3) { $aErr['aCityID'] = '最多选择3个城市/地区'; } if (!empty($aErr)) { return $this->showMsg($aErr, false); } if (empty($aMedia)) { $aData['iStatus'] = 3; $aData['sVerifyCode'] = strtoupper(Util_Tools::passwdGen(32)); $iMediaID = Model_Media::addData($aData); } else { $aData['iStatus'] = 2; $aData['iMediaID'] = $aMedia['iMediaID']; Model_Media::updData($aData); } Model_User::updData(array('iUserID' => $this->aCurrUser['iUserID'], 'iFirst' => 'iFirst + 1')); if ($iMediaID > 0) { //Model_Media::updCategory($iMediaID, $aCatID); Model_Media::updCity($iMediaID, $aCityID); Model_Media::updTag($iMediaID, $aTagID); return $this->showMsg($iMediaID, true); } else { $aErr['sMediaName'] = '添加失败,请稍后再试'; return $this->showMsg($aErr, false); } } else { $aUser = $this->getCurrUser(Model_User::TYPE_MEDIA); if (empty($aUser)) { return $this->redirect('/user/login/type/' . Model_User::TYPE_MEDIA . '.html?ret=' . Util_Uri::getCurrUrl()); } $iMediaID = intval($this->getParam('id')); $aMedia = null; if ($iMediaID > 0) { $aMedia = Model_Media::getFullDetail($iMediaID); } if (empty($aMedia)) { $iType = intval($this->getParam('type', Model_Media::TYPE_WEIXIN)); } else { $iType = $aMedia['iMediaType']; } $aData = array(); switch ($iType) { case Model_Media::TYPE_WEIXIN: $aData['aCategory'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_WEIXIN_CATEGORY); $aData['aTag'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_WEIXIN_TAG); break; case Model_Media::TYPE_FRIEND: $aData['aCategory'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_FRIEND_CATEGORY); $aData['aTag'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_FRIEND_TAG); break; case Model_Media::TYPE_WEIBO: $aData['aCategory'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_WEIBO_CATEGORY); $aData['aTag'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_WEIBO_TAG); break; case Model_Media::TYPE_NEWS: $aData['aCategory'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_NEWS_CATEGORY); $aData['aTag'] = Model_Domain::getOption(Model_Domain::TYPE_MEDIA_NEWS_TAG); break; } $aData['aCity'] = Model_City::getPairCitys(Model_City::TYPE_FRONT); // array_unshift($aData['aCategory'], '不限'); // array_unshift($aData['aCity'], '不限'); // array_unshift($aData['aTag'], '不限'); $aType = Model_Media::$aType; unset($aType[Model_Media::TYPE_NEWS]); $this->assign('iType', $iType); $this->assign('aType', $aType); $this->assign('aData', $aData); $this->assign('aMedia', $aMedia); $this->assign('aUser', Model_User::getDetail($this->aCurrUser['iUserID'])); $this->assign('sTopMenu', 'madd'); $sRandCode = Util_Tools::passwdGen(8, Util_Tools::FLAG_ALPHANUMERIC); Util_Cookie::set('media_verify_code', $sRandCode); $this->assign('sRandCode', $sRandCode); $this->setMeta('media_add', array('sTitle' => '添加媒体')); } }