Exemple #1
0
 /**
  * 设置广告
  */
 public function add3Action()
 {
     if ($this->isPost()) {
         $iAdID = (int) $this->getParam('iAdID', 0);
         $aAd = Model_Ad::getDetail($iAdID);
         if (empty($aAd) || $aAd['iUserID'] != $this->aCurrUser['iUserID']) {
             return $this->show404();
         }
         $aErr = array();
         $aData = array();
         $aData['iAdID'] = $iAdID;
         $aData['iAdPos'] = (int) $this->getParam('iAdPos');
         $aData['iPlanTime'] = strtotime($this->getParam('iPlanTime'));
         if ($aData['iPlanTime'] < strtotime('+2hour')) {
             $aErr['iPlanTime'] = '投放时间必须晚于当前时间2小时';
         }
         if ($aData['iPlanTime'] > strtotime('+7day')) {
             $aErr['iPlanTime'] = '投放时间必须小于7天';
         }
         switch ($aAd['iMediaType']) {
             case Model_Media::TYPE_WEIXIN:
                 $aData['sImportUrl'] = $this->getParam('sImportUrl', '');
                 $aData['sWordFile'] = $this->getParam('sWordFile', '');
                 $aData['sTitle'] = $this->getParam('sTitle');
                 $aData['sCoverImg'] = $this->getParam('sCoverImg');
                 $aData['iIsCover'] = (int) $this->getParam('iIsCover');
                 $aData['sAbstract'] = $this->getParam('sAbstract');
                 $aData['sContent'] = $this->getParam('sContent');
                 $aData['sOriginalUrl'] = $this->getParam('sOriginalUrl');
                 if (!Util_Validate::isCLength($aData['sTitle'], 2, 50)) {
                     $aErr['sTitle'] = '请输入标题';
                 }
                 if ($aData['iIsCover'] && empty($aData['sCoverImg'])) {
                     $aErr['sCoverImg'] = '请上传封面图';
                 }
                 //                    if (empty($aData['sAbstract'])) {
                 //                        $aErr['sAbstract'] = '请输入摘要';
                 //                    }
                 if (!Util_Validate::isCLength($aData['sContent'], 20, 999999)) {
                     $aErr['sContent'] = '请输入内容至少20个字';
                 }
                 break;
             case Model_Media::TYPE_FRIEND:
             case Model_Media::TYPE_WEIBO:
                 $aData['sForwardUrl'] = $this->getParam('sForwardUrl', '');
                 $aData['sForwardText'] = $this->getParam('sForwardText', '');
                 $aForwardImg = $this->getParam('aForwardImg');
                 if ($aData['iAdPos'] == 1) {
                     if (!Util_Validate::isAbsoluteUrl($aData['sForwardUrl'])) {
                         $aErr['sForwardUrl'] = '请输入正确的投放地址';
                     }
                 } else {
                     if (!empty($aData['sForwardUrl']) && !Util_Validate::isAbsoluteUrl($aData['sForwardUrl'])) {
                         $aErr['sForwardUrl'] = '请输入正确的投放地址';
                     }
                 }
                 if (!Util_Validate::isCLength($aData['sForwardText'], 5, 200)) {
                     $aErr['sForwardText'] = '投放文字长度为5~200字之间';
                 }
                 $aData['sForwardImg'] = array();
                 foreach ($aForwardImg as $sForwardImg) {
                     if (!empty($sForwardImg)) {
                         $aData['sForwardImg'][] = $sForwardImg;
                     }
                 }
                 if (empty($aData['sForwardImg'])) {
                     $aErr['sForwardImg'] = '请至少选择一张投放配图';
                     $aForwardImg = array();
                 }
                 $aData['sForwardImg'] = join(',', $aData['sForwardImg']);
                 break;
         }
         if (!empty($aErr)) {
             return $this->showMsg($aErr, false);
         }
         Model_Ad::setSetting($aAd, $aData);
         return $this->showMsg($aAd['iAdID'], true);
     } else {
         $iAdID = (int) $this->getParam('id', 0);
         $aAd = Model_Ad::getDetail($iAdID);
         if (empty($aAd) || $aAd['iUserID'] != $this->aCurrUser['iUserID']) {
             return $this->show404();
         }
         $sCookieKey = 'media_choose_' . $aAd['iMediaType'];
         $aChooseID = isset($_COOKIE[$sCookieKey]) ? explode(',', $_COOKIE[$sCookieKey]) : array();
         if (!empty($aChooseID)) {
             Model_Ad::updMedia($iAdID, $aChooseID, $this->aCurrUser['iUserID']);
         }
         setcookie($sCookieKey, null, 0, '/');
         $aSetting = Model_Ad::getSetting($aAd);
         if (!empty($aSetting) && isset($aSetting['sForwardImg'])) {
             $aSetting['aForwardImg'] = explode(',', $aSetting['sForwardImg']);
         }
         $this->assign('aTitle', Model_Media::$aPos[$aAd['iMediaType']]);
         $this->assign('aSetting', $aSetting);
         $this->assign('aAd', $aAd);
         $this->assign('sTopMenu', 'aadd');
         $this->setMeta('ad_add', array('sTitle' => '添加推广计划 - 推广计划'));
     }
 }