/** * 获取广告 * @date: 2016年1月22日 * @author: 545 */ private function getAdvert($city_id, $where = null, $order = null, $groupby = null) { $where = empty($where) ? "city_id = {$city_id} " : $where . " AND city_id = {$city_id} "; if (!empty($groupby)) { $where .= " GROUP BY {$groupby}"; } $advert = Advertisement::query()->columns(['advertisement_id', 'advertisement_cover', 'advertisement_title', 'position', 'type', 'advertisement_intro', 'out_link'])->where($where)->orderBy($order)->execute()->toArray(); return $advert; }
/** * 修改广告位 * @date: 2016年1月7日 * @author: chenxiaolin */ public function advertisementEditAction() { $this->setLeftNav('advertisementEdit'); $req = $this->request; if (!$req->isPost()) { $id = $req->getQuery('id'); $info = Advertisement::findFirst("advertisement_id = {$id}"); $info->advertisement_cover = PicUrl::AdvertisementPic($info->advertisement_cover, $this->getDI()); $this->view->setVar('info', $info); $this->view->setVar('openCity', $this->openCityList()); return; } else { $response = new ResponseResult(); $response->callback = $req->getPost('callback', null, 'parent.setFormResult'); $response->callbackJavascriptTag = true; $id = $req->getPost('advertisement_id'); $title = $req->getPost('advertisement_title'); $position = $req->getPost('position'); $type = $req->getPost('type'); $intro = $req->getPost('advertisement_intro'); $out_link = $req->getPost('out_link'); //判断空数据 if ($type <= 0 || empty($title) || $position <= 0 || $city < 0) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!'); return $response; } //判断图文介绍还是外链地址 if ($type == 1 && empty($intro)) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '请填写图文介绍!'); return $response; } if ($type == 2 && empty($out_link)) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '请填写外链地址!'); return $response; } //判断外链地址是否合法 if ($type == 2 && !Util::CheckUrl($out_link)) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '外链地址不合法!'); return $response; } //判断该广告位是否有数据 $data = Advertisement::findFirst("advertisement_id = {$id}"); if ($data->position != $position) { $city = $data->city_id; //判断当前城市的此广告位是否已有数据 $ad = Advertisement::findFirst("city_id = {$city} and position = {$position}"); if ($ad) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '此广告位已有数据!'); return $response; } //修改全国数据时:判断此广告位是否已被其他城市占用 if ($city == 0) { $num = Advertisement::count("city_id not in ( 0 ) and position = {$position}"); if ($num > 0) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '此广告位已被城市占用!'); return $response; } } else { //修改城市数据时:判断此广告位是否已被全国占用 $countryAd = Advertisement::findFirst("city_id = 0 and position = {$position}"); if ($countryAd) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '此广告位已被全国占用!'); return $response; } } } //修改封面 if ($_FILES['advertisement_cover']['name'] != '') { $uploadFile = new UploadPic(); $uploadFile->request = $req; $cover = $uploadFile->advertisementPics(); if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) { if ($_FILES['advertisement_cover']['error'] == 1) { $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '封面大小不能超过1M!'); } else { $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '封面必须上传!'); } return $response; } $data->advertisement_cover = $cover[0]; } $data->advertisement_title = $title; $data->position = $position; $data->type = $type; if ($type == 1) { $data->advertisement_intro = $intro; $data->out_link = ''; } if ($type == 2) { $data->out_link = $out_link; $data->advertisement_intro = ''; } if ($data->save()) { $response->sendResult('ok'); return $response; } } }