/** * 首页推荐美容院列表 * @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 bannerBpAddAction() { $this->setLeftNav('bannerBp'); $req = $this->request; if (!$req->isPost()) { $this->view->setVar('openCity', $this->openCityList()); $this->view->pick("om/bannerBpAdd"); return; } $response = new ResponseResult(); $response->callback = $req->getPost('callback', null, 'parent.setFormResult'); $response->callbackJavascriptTag = true; $bp_id = intval($req->getPost('bp_id')); $city = $req->getPost('city'); $addr = $city; $sort = $req->getPost('sort'); // 判断空数据 if (empty($bp_id) || empty($addr) || empty($sort)) { $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!'); return $response; } //判断要推荐的美容是否存在 $bp = BeautyParlor::findFirst(" bp_id = {$bp_id} and bp_state = 1"); if (empty($bp)) { $response->sendError(ResponseResultStatus::BUSINESS, '当前推荐的美容院不存在或未发布或已删除!'); return $response; } //保存推荐美容院图片 $uploadFile = new UploadPic(); $uploadFile->request = $req; $cover = $uploadFile->beautyParlorCover(); if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) { if ($_FILES['bp_cover']['error'] == 1) { $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了1M!'); } return $response; } //判断美容院是否已经存在3个 if (CosPointBp::count("addr = {$addr}") >= 3) { $response->sendError(ResponseResultStatus::BUSINESS, '首页推荐美容院只能添加3个!'); return $response; } //判断要添加的美容院是否已存在 if (CosPointBp::count('bp_id = ' . $bp_id . ' and addr = ' . $addr)) { $response->sendError(ResponseResultStatus::BUSINESS, '该美容院已经加入首页推荐!'); return $response; } elseif (CosPointBp::count('sort = ' . $sort . ' and addr = ' . $addr)) { $response->sendError(ResponseResultStatus::BUSINESS, '排序已经存在!'); return $response; } //实例化Model,组装数据 $cosPointBp = new CosPointBp(); $cosPointBp->bp_id = $bp_id; $cosPointBp->addr = $addr; $cosPointBp->sort = $sort; $cosPointBp->img_url = $cover[0]; //保存数据 if ($cosPointBp->save() == false) { $this->databaseErrorLog($cosPointBp); $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常!'); } else { $response->sendResult($cosPointBp->id); } return $response; }