Example #1
0
 public function updateadsAction()
 {
     $adsid = reqnum('adsid', 0);
     $adsType = reqnum('adsType', 0);
     $cityid = $_POST['cityid'];
     $ispost = reqnum('ispost', 0);
     if ($ispost == 0) {
         $this->forward = "adsallot";
         return;
     }
     $m = new Psys_AdsRule();
     if ($adsType == '5') {
         //删除所有车站这个广告
         $where = array();
         $stationads = $m->getonecity('adsone');
         foreach ($stationads as $key => $val) {
             $stationOne = $val['adsone'];
             $naArr = explode(',', $stationOne);
             for ($i = 0; $i < count($naArr); $i++) {
                 if ($naArr[$i] == $adsid) {
                     unset($naArr[$i]);
                 }
             }
             $naArr = implode(',', $naArr);
             $data = array('adsone' => $naArr);
             $whereCid = array('id' => $val['id']);
             $m->UpdateCityOne($data, $whereCid);
         }
         //添加所选车站所选广告
         foreach ($cityid as $key => $val) {
             $adone = '';
             $where = array('id' => $val);
             $city = $m->getonecity($where, '*');
             $cityone = $city[0]['adsone'];
             $nameArr = explode(',', $cityone);
             for ($i = 0; $i < count($nameArr); $i++) {
                 if ($nameArr[$i] == $adsid) {
                     $adone = 'have';
                 }
             }
             if ($adone == '') {
                 array_push($nameArr, $adsid);
                 if ($nameArr[0] == '') {
                     unset($nameArr[0]);
                 }
                 $cityone = implode(',', $nameArr);
                 $data = array('adsone' => $cityone);
                 $m->UpdateCityOne($data, $where);
             }
         }
     }
     if ($adsType == '6') {
         //删除所有车站这个广告
         $where = array();
         $stationads = $m->getonecity('adstwo');
         foreach ($stationads as $key => $val) {
             $stationTwo = $val['adstwo'];
             $naArr = explode(',', $stationTwo);
             for ($i = 0; $i < count($naArr); $i++) {
                 if ($naArr[$i] == $adsid) {
                     unset($naArr[$i]);
                 }
             }
             $naArr = implode(',', $naArr);
             $data = array('adsTwo' => $naArr);
             $whereCid = array('id' => $val['id']);
             $m->UpdateCityOne($data, $whereCid);
         }
         //添加所选车站所选广告
         foreach ($cityid as $key => $val) {
             $adtwo = '';
             $where = array('id' => $val);
             $city = $m->getonecity($where, '*');
             $citytwo = $city[0]['adstwo'];
             $nameArr = explode(',', $citytwo);
             for ($i = 0; $i < count($nameArr); $i++) {
                 if ($nameArr[$i] == $adsid) {
                     $adtwo = 'have';
                 }
             }
             if ($adtwo == '') {
                 array_push($nameArr, $adsid);
                 if ($nameArr[0] == '') {
                     unset($nameArr[0]);
                 }
                 $cityone = implode(',', $nameArr);
                 $data = array('adstwo' => $cityone);
                 $m->UpdateCityOne($data, $where);
             }
         }
     }
     echo "<script>window.location.href='/fullads/index';alert('修改成功');</script>";
 }