/** * 添加Banner * @date: 2016年1月5日 * @author: chenxiaolin */ public function bannerAddAction() { $this->setLeftNav('bannerAdd'); $req = $this->request; if (!$req->isPost()) { $this->view->setVar('openCity', $this->openCityList()); return; } else { $response = new ResponseResult(); $response->callback = $req->getPost('callback', null, 'parent.setFormResult'); $response->callbackJavascriptTag = true; $city = $req->getPost('city'); $banner_name = $req->getPost('banner_name'); $handle_type = $req->getPost('handle_type'); $handle_data = $req->getPost('handle_data'); //判断空数据 if (empty($city) || empty($banner_name) || empty($handle_type)) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!'); return $response; } if ($handle_type != 'none' && empty($handle_data)) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '填写处理数据!'); return $response; } //判断Url是否合法 if ($handle_type == 'url' && !Util::CheckUrl($handle_data)) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, 'Url不合法!'); return $response; } //不跳转 if ($handle_type == 'none') { $handle_data = ''; } //内部打开网页 if ($handle_type == 'url') { $handle_data_arr = ['link' => $handle_data]; } //跳转详情 if ($handle_type != 'none' && $handle_type != 'url') { $handle_data_arr = ['id' => $handle_data]; } //上传封面 $uploadFile = new UploadPic(); $uploadFile->request = $req; $cover = $uploadFile->bannerPics(); if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) { if ($_FILES['banner_cover']['error'] == 1) { $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了1M!'); return $response; } else { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, 'banner封面必须上传!'); return $response; } } $arr = ['url' => $cover[0], 'link_type' => $handle_type, 'link_data' => json_encode($handle_data_arr)]; //循环添加数据 foreach ($city as $k => $v) { $banner = new OmBanner(); $banner->city_id = $v; $banner->banner_name = $banner_name; $banner->banner_addtime = date('Y-m-d H:i:m'); $banner->banner_update_time = date('Y-m-d H:i:m'); $banner->banner_data = json_encode($arr); $banner->state = 1; $id = $banner->save(); if ($id) { //添加成功 $response->sendResult($id); } else { //添加失败 $this->databaseErrorLog($banner); $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常!'); } } return $response; } }
/** * 首页推荐美容院列表 * @date: 2016-1-8 * @author: futao */ public function bannerBpAction() { $this->setLeftNav('bannerbp'); $key = 'index_bp'; $req = $this->request; if (!$req->isPost()) { $filterCity = intval($req->getQuery('City', null, 0)); $this->view->setVar('openCity', $this->openCityList()); $this->view->setVar('filterCity', $filterCity); $page = intval($req->getQuery('page', null, 1)); $page = $page > 0 ? $page : 1; $limit = $this->pageNavLimit; $offset = $limit * ($page - 1); $count = CosPointBp::count(['conditions' => "addr = {$filterCity}"]); $list = CosPointBp::query()->where("addr = '{$filterCity}'")->limit($limit, $offset)->execute()->toArray(); foreach ($list as $k => $v) { $tmp = SysOpenCity::findFirst("city_id = " . $list[$k]['addr'])->toArray(); $list[$k]['city_name'] = $tmp['city_name']; $list[$k]['img_url'] = "http://img.meelier.com/" . $list[$k]['img_url']; } $this->view->setVar("total", $count); $this->view->setVar("limit", $limit); $this->view->setVar("page", $page); $this->view->setVar("list", $list); $this->view->setVar('filterCity', $filterCity); $this->view->pick('bp/bannerBp'); return; } else { //1.0版本代码,2.0没使用 $response = new ResponseResult(); $bpId = intval($req->getPost('bpid', null, 0)); $city = intval($req->getPost('city', null, 0)); //判断参数是否合法 if ($bpId < 1 || $city < 1) { return $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常'); } // 查询美容院是否存在 if (BeautyParlor::count('bp_id = ' . $bpId) == 0) { return $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '美容院不存在!'); } $bannerData = OmBanner::query()->where('city_id = :cid: AND banner_name = :key:', ['cid' => $city, 'key' => $key])->execute()->getFirst(); if ($bannerData) { $bannerData->update(['banner_data' => $bpId, 'banner_update_time' => new RawValue('NOW()')]); $response->sendResult($bannerData->banner_id); } else { $bannerData = new OmBanner(); $bannerData->city_id = $city; $bannerData->banner_name = $key; $bannerData->banner_data = $bpId; if ($bannerData->save() == false) { $this->databaseErrorLog($bannerData); $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常'); } else { $response->sendResult($bannerData->banner_id); } } return $response; } }
/** * 首页推荐美容院 */ public function bannerBpAction() { $this->setLeftNav('bannerBp'); $key = 'index_bp'; $req = $this->request; if (!$req->isPost()) { $filterCity = intval($req->getQuery('City', null, 0)); $this->view->setVar('openCity', $this->openCityList()); $this->view->setVar('filterCity', $filterCity); $page = intval($req->getQuery('page', null, 1)); $page = $page > 0 ? $page : 1; $limit = $this->pageNavLimit; $offset = $limit * ($page - 1); $count = CosPointBp::count(['conditions' => "addr = {$filterCity}"]); $list = CosPointBp::query()->where("addr = '{$filterCity}'")->limit($limit, $offset)->execute()->toArray(); foreach ($list as $k => $v) { $tmp = SysOpenCity::findFirst("city_id = " . $list[$k]['addr'])->toArray(); $list[$k]['city_name'] = $tmp['city_name']; $list[$k]['img_url'] = "http://img.meelier.com/" . $list[$k]['img_url']; } $this->view->setVar("total", $count); $this->view->setVar("limit", $limit); $this->view->setVar("page", $page); $this->view->setVar("list", $list); /* $data = null; $bpData = []; if($filterCity > 0) { $bannerData = OmBanner::query() ->columns('banner_data') ->where('city_id = :cid: AND banner_name = :key:', ['cid' => $filterCity, 'key' => $key]) ->execute() ->getFirst(); if($bannerData) { $data = $bannerData->banner_data; } } if($data != null) { $columns = [ 'bp_id', 'bp_name', 'bp_cover', 'bp_address', 'bp_district', 'FULL_NAME district', 'bp_coordinate', 'bp_tel', 'bp_intro', 'bp_state', 'bp_is_sell', 'bp_medal', 'bp_addtime' ]; $bpData = BeautyParlor::query() ->columns($columns) ->leftJoin('Apps\Common\Models\SysAreaZipDistrictPhonecode', 'K_ID=bp_district', 'area') ->where('bp_id = :id:', ['id'=>$data]) ->execute(); } $this->view->setVar('data', $data); $this->view->setVar('bpData', $bpData); */ $this->view->setVar('filterCity', $filterCity); return; } else { $response = new ResponseResult(); $response = new ResponseResult(); $bpId = intval($req->getPost('bpid', null, 0)); $city = intval($req->getPost('city', null, 0)); if ($bpId < 1 || $city < 1) { return $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常'); } // 查询美容院是否存在 if (BeautyParlor::count('bp_id = ' . $bpId) == 0) { return $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '美容院不存在!'); } $bannerData = OmBanner::query()->where('city_id = :cid: AND banner_name = :key:', ['cid' => $city, 'key' => $key])->execute()->getFirst(); if ($bannerData) { $bannerData->update(['banner_data' => $bpId, 'banner_update_time' => new RawValue('NOW()')]); $response->sendResult($bannerData->banner_id); } else { $bannerData = new OmBanner(); $bannerData->city_id = $city; $bannerData->banner_name = $key; $bannerData->banner_data = $bpId; if ($bannerData->save() == false) { $this->databaseErrorLog($bannerData); $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常'); } else { $response->sendResult($bannerData->banner_id); } } return $response; } }