作者 郭盛
1 个管道 的构建 通过 耗费 1 秒

修改搜索

@@ -207,6 +207,104 @@ class Farm extends Api @@ -207,6 +207,104 @@ class Farm extends Api
207 */ 207 */
208 public function sou() 208 public function sou()
209 { 209 {
  210 + $token = $this->request->header('token');
  211 + if(empty($token)){
  212 + $page = $this->request->param('page',1,'intval');
  213 + $pageNum = $this->request->param('pageNum',10,'intval');
  214 + $param = $this->request->param();
  215 + if(empty($param['keyword']) && empty($param['area'])){
  216 + $this->error('请输入搜索关键字');
  217 + }
  218 + if(empty($param['keyword'])){
  219 + $data = Db::name('farm')
  220 + ->alias('a')
  221 + ->join('user b','a.user_id = b.id')
  222 + ->field('a.id,a.user_id,a.name,a.content,a.province,a.fun_num,b.avatar,b.score')
  223 + ->whereLike('a.province',"%$param[area]%")
  224 + ->order('a.createtime desc')
  225 + ->page($page,$pageNum)
  226 + ->select();
  227 + foreach ($data as &$v){
  228 + $is_ren = Db::name('attestation')
  229 + ->where('farm_id',$v['id'])
  230 + ->field('user_id,status')
  231 + ->find();
  232 + if($is_ren){
  233 + if($is_ren['status'] == 1){
  234 + $v['is_ren'] = 1;
  235 + }else{
  236 + $v['is_ren'] = 2;
  237 + }
  238 + }else{
  239 + $v['is_ren'] = 0;
  240 + }
  241 +
  242 + $v['status'] = 1;
  243 + $v['is_guan'] = 2;
  244 + }
  245 + $this->success('success',$data);
  246 + }elseif (empty($param['area'])){
  247 + $data = Db::name('farm')
  248 + ->alias('a')
  249 + ->join('user b','a.user_id = b.id')
  250 + ->field('a.id,a.user_id,a.name,a.content,a.province,a.fun_num,b.avatar,b.score')
  251 + ->whereLike('a.name',"%$param[keyword]%")
  252 + ->order('a.createtime desc')
  253 + ->page($page,$pageNum)
  254 + ->select();
  255 + foreach ($data as &$v){
  256 + $is_ren = Db::name('attestation')
  257 + ->where('farm_id',$v['id'])
  258 + ->field('user_id,status')
  259 + ->find();
  260 + if($is_ren){
  261 + if($is_ren['status'] == 1){
  262 + $v['is_ren'] = 1;
  263 + }else{
  264 + $v['is_ren'] = 2;
  265 + }
  266 + }else{
  267 + $v['is_ren'] = 0;
  268 + }
  269 +
  270 + $v['status'] = 1;
  271 + $v['is_guan'] = 2;
  272 +
  273 + }
  274 + $this->success('success',$data);
  275 + }else{
  276 + $data = Db::name('farm')
  277 + ->alias('a')
  278 + ->join('user b','a.user_id = b.id')
  279 + ->field('a.id,a.user_id,a.name,a.content,a.province,a.fun_num,b.avatar,b.score')
  280 + ->whereLike('a.name',"%$param[keyword]%")
  281 + ->whereLike('a.province',"%$param[area]%")
  282 + ->order('a.createtime desc')
  283 + ->page($page,$pageNum)
  284 + ->select();
  285 + foreach ($data as &$v){
  286 + $is_ren = Db::name('attestation')
  287 + ->where('farm_id',$v['id'])
  288 + ->field('user_id,status')
  289 + ->find();
  290 + if($is_ren){
  291 + if($is_ren['status'] == 1){
  292 + $v['is_ren'] = 1;
  293 + }else{
  294 + $v['is_ren'] = 2;
  295 + }
  296 + }else{
  297 + $v['is_ren'] = 0;
  298 + }
  299 +
  300 +
  301 + $v['status'] = 1;
  302 + $v['is_guan'] = 2;
  303 +
  304 + }
  305 + $this->success('success',$data);
  306 + }
  307 + }
210 $user_id = $this->getUserId(); 308 $user_id = $this->getUserId();
211 $page = $this->request->param('page',1,'intval'); 309 $page = $this->request->param('page',1,'intval');
212 $pageNum = $this->request->param('pageNum',10,'intval'); 310 $pageNum = $this->request->param('pageNum',10,'intval');