/** * 增加自媒体 */ public function addAction() { if ($this->_request->isPost()) { $aMedia = $this->_checkData('add'); if (empty($aMedia)) { return null; } // if (Model_Media::getCityByName($aMedia['sCityName'])) { // return $this->showMsg('自媒体已经存在!', false); // } //标签 $sTagID = $aMedia['sTagID']; unset($aMedia['sTagID']); //所属类目 $sCategoryID = $aMedia['sCategoryID']; unset($aMedia['sCategoryID']); //行业圈子 $sCricleID = $aMedia['sCricleID']; unset($aMedia['sCricleID']); //城市 $sCityID = $aMedia['sCityID']; unset($aMedia['sCityID']); if (Model_Media::addData($aMedia) > 0) { //标签 if ($sTagID != '') { $sTagID = explode(',', $sTagID); $add = array(); $add['iMediaID'] = $aMedia['iMediaID']; $add['iStatus'] = 1; $add['iCreateTime'] = time(); $add['iUpdateTime'] = time(); foreach ($sTagID as $val) { $add['iTagID'] = $val; Model_MediaTag::addData($add); } } //所属类目 if ($sCategoryID != '') { $sCategoryID = explode(',', $sCategoryID); $add = array(); $add['iMediaID'] = $aMedia['iMediaID']; $add['iStatus'] = 1; $add['iCreateTime'] = time(); $add['iUpdateTime'] = time(); foreach ($sCategoryID as $val) { $add['iCategoryID'] = $val; Model_MediaCategory::addData($add); } } //行业圈子 if ($sCricleID != '') { $sCricleID = explode(',', $sCricleID); $add = array(); $add['iMediaID'] = $aMedia['iMediaID']; $add['iStatus'] = 1; $add['iCreateTime'] = time(); $add['iUpdateTime'] = time(); foreach ($sCricleID as $val) { $add['iCricleID'] = $val; Model_MediaCricle::addData($add); } } //城市 if ($sCityID != '') { $sCityID = explode(',', $sCityID); $add = array(); $add['iMediaID'] = $aMedia['iMediaID']; $add['iStatus'] = 1; $add['iCreateTime'] = time(); $add['iUpdateTime'] = time(); foreach ($sCityID as $val) { $add['iCityID'] = $val; Model_MediaCity::addData($add); } } return $this->showMsg('自媒体增加成功!', true); } else { return $this->showMsg('自媒体增加失败!', false); } } $iMediaType = $this->getParam('iMediaType'); $this->assign('iMediaType', $iMediaType); //属性 if ($iMediaType == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aAttribute', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_ATTRIBUTE)); } else { if ($iMediaType == Model_Media::TYPE_FRIEND) { // 微信朋友圈 $this->assign('aAttribute', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_FRIEND_ATTRIBUTE)); } else { if ($iMediaType == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aAttribute', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_ATTRIBUTE)); } else { if ($iMediaType == Model_Media::TYPE_NEWS) { // 新闻&论坛 $this->assign('aAttribute', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_NEWS_ATTRIBUTE)); } } } } //分类 if ($iMediaType == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aTypeInfo', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_CATEGORY)); } else { if ($iMediaType == Model_Media::TYPE_FRIEND) { // 微信朋友圈 $this->assign('aTypeInfo', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_FRIEND_CATEGORY)); } else { if ($iMediaType == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aTypeInfo', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_CATEGORY)); } else { if ($iMediaType == Model_Media::TYPE_NEWS) { // 新闻&论坛 $this->assign('aTypeInfo', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_NEWS_CATEGORY)); } } } } //合作等级 if ($iMediaType == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aCooperateLevel', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_COOPERATELEVEL)); } else { if ($iMediaType == Model_Media::TYPE_FRIEND) { // 微信朋友圈 $this->assign('aCooperateLevel', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_FRIEND_COOPERATELEVEL)); } else { if ($iMediaType == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aCooperateLevel', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_COOPERATELEVEL)); } else { if ($iMediaType == Model_Media::TYPE_NEWS) { // 新闻&论坛 $this->assign('aCooperateLevel', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_NEWS_COOPERATELEVEL)); } } } } //行业圈子 if ($iMediaType == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aIndustryCircle', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_INDUSTRY)); } else { if ($iMediaType == Model_Media::TYPE_FRIEND) { // 微信朋友圈 $this->assign('aIndustryCircle', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_FRIEND_INDUSTRY)); } else { if ($iMediaType == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aIndustryCircle', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_INDUSTRY)); } else { if ($iMediaType == Model_Media::TYPE_NEWS) { // 新闻&论坛 $this->assign('aIndustryCircle', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_NEWS_INDUSTRY)); } } } } //认证 if ($iMediaType == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aVerifyState', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_VERIFY)); } else { if ($iMediaType == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aVerifyState', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_VERIFY)); } } //标签 if ($iMediaType == Model_Media::TYPE_WEIXIN) { // 微信公众号 $this->assign('aTag', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIXIN_TAG)); } else { if ($iMediaType == Model_Media::TYPE_FRIEND) { // 微信朋友圈 $this->assign('aTag', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_FRIEND_TAG)); } else { if ($iMediaType == Model_Media::TYPE_WEIBO) { // 新浪微博 $this->assign('aTag', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_WEIBO_TAG)); } else { if ($iMediaType == Model_Media::TYPE_NEWS) { // 新闻&论坛 $this->assign('aTag', Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_NEWS_TAG)); } } } } //资源推荐 $aRecommend = Model_Domain::getPairDomain(Model_Domain::TYPE_MEDIA_RECOMMEND); $this->assign('aRecommend', $aRecommend); //后台管理用户 $adminData = Model_Admin::getAll(array('where' => array('iStatus' => 1))); $this->assign('adminData', $adminData); //城市 $this->assign('aCity', Model_City::getPairCitys()); }
/** * 添加自媒体 */ 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' => '添加媒体')); } }