From 592811187787e8babf20f6efeff509b72ea3c6b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BD=AD=E6=A1=83?= <1098598843@qq.com> Date: Mon, 27 Feb 2023 16:47:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=90=8E=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/nk/Article.php | 2 +- app/admin/controller/nk/Life.php | 12 ++++- app/admin/view/nk/life/add.html | 27 +++++++--- app/admin/view/nk/life/edit.html | 27 +++++++--- app/api/controller/Article.php | 76 ++++++++++++++++++++++++++++- 5 files changed, 128 insertions(+), 16 deletions(-) diff --git a/app/admin/controller/nk/Article.php b/app/admin/controller/nk/Article.php index f3f85fb..dffa5ff 100644 --- a/app/admin/controller/nk/Article.php +++ b/app/admin/controller/nk/Article.php @@ -44,7 +44,7 @@ class Article extends BaseController $category_id =$params['category_id']; if($category_id){ - $map[] = ['category_id','=',$category_id]; + $map[] = ['category_id','in',$category_id]; }else{ $map = []; } diff --git a/app/admin/controller/nk/Life.php b/app/admin/controller/nk/Life.php index 282772a..cae5962 100644 --- a/app/admin/controller/nk/Life.php +++ b/app/admin/controller/nk/Life.php @@ -35,7 +35,7 @@ class Life extends BaseController { if (request()->isAjax()) { $params= get_params(); - $params['category_id']=$this->category_id; + $params['category_id'] = Db::table('fa_category')->where(['status' => 'normal', 'pid' => '360'])->column('id'); (new Article())->index($params); } return view('nk/life/index',['url'=>$this->url]); @@ -47,7 +47,6 @@ class Life extends BaseController { if (request()->isAjax()) { $param= get_params(); - $param['category_id']=$this->category_id; // 检验完整性 try { @@ -112,6 +111,9 @@ class Life extends BaseController ->field('area_id id,area_code code,area_name name') ->select(); View::assign('street', $street); +// 分类 + $category = Db::table('fa_category')->where(['status' => 'normal', 'pid' => '360'])->select(); + View::assign('category', $category); return view('nk/life/add'); } } @@ -175,6 +177,9 @@ class Life extends BaseController ->field('area_id id,area_code code,area_name name') ->select(); View::assign('street', $street); + // 分类 + $category = Db::table('fa_category')->where(['status' => 'normal', 'pid' => '360'])->select(); + View::assign('category', $category); return view('nk/life/edit',['url'=>$this->url]); } else{ @@ -205,6 +210,9 @@ class Life extends BaseController $detail['lat'] = $ress['lat']; $detail['lng'] = $ress['lng']; View::assign('detail', $detail); + // 分类 + $category = Db::table('fa_category')->where(['status' => 'normal', 'pid' => '360'])->select(); + View::assign('category', $category); View::assign('admin_id', $this->adminInfo['id']); } else{ diff --git a/app/admin/view/nk/life/add.html b/app/admin/view/nk/life/add.html index b5c8623..1a6c391 100644 --- a/app/admin/view/nk/life/add.html +++ b/app/admin/view/nk/life/add.html @@ -96,6 +96,20 @@ {/if} + + 分类* + +
+ +
+ + + 价格* - - 坐标 - -
- - 文章内容 @@ -131,6 +139,13 @@ + + 坐标 + +
+ + +
diff --git a/app/admin/view/nk/life/edit.html b/app/admin/view/nk/life/edit.html index b553246..b21936b 100644 --- a/app/admin/view/nk/life/edit.html +++ b/app/admin/view/nk/life/edit.html @@ -106,6 +106,19 @@ {/if} + + 分类* + +
+ +
+ + 价格* @@ -126,12 +139,6 @@ - - 坐标 - -
- - 文章内容 @@ -142,6 +149,14 @@ id="container_content">{$detail.content} + + + 坐标 + +
+ + +
diff --git a/app/api/controller/Article.php b/app/api/controller/Article.php index 316da53..5659497 100644 --- a/app/api/controller/Article.php +++ b/app/api/controller/Article.php @@ -16,7 +16,7 @@ class Article extends BaseController * @var array */ protected $middleware = [ - Auth::class => ['except' => ['index','hot_list','getArticleList','details','indexs'] ] + Auth::class => ['except' => ['index','hot_list','getArticleList','details','indexs','get_list','detail'] ] ]; public function index($search = '', $category_id = 1, $page = 1, $is_time = 0, $category_type = 0) @@ -837,5 +837,79 @@ class Article extends BaseController $this->apiSuccess('ok', ['list' => $select, 'cun'=>$cun_arr, 'count' => ['count' => $count, 'month_count' => $month_count]]); } +// 获取生活服务推荐文章列表 + public function get_list($search = '', $category_id = 360, $page = 1, $category_type = 0) + { + $param = get_params(); + + $all_category = Db::table('fa_category')->where(['status' => 'normal', 'pid' => $category_id])->column('id'); + if($all_category){ + $category_id = $all_category; + } + $where = [ + ['status', '=', 1], + ['category_id', 'in', $category_id] + ]; + + if(isset($param['street_id']) && !empty($param['street_id'])){ + $where[] = ['township', '=', $param['street_id']]; + } + if(isset($param['village_id']) && !empty($param['village_id'])){ + $where[] = ['village', '=', $param['village_id']]; + } + $where[] = ['is_tj', '=', 1]; + //总条数 + $count = Db::table('fa_article')->where($where)->count(); + //当月条数 + $month_count = Db::table('fa_article')->where($where)->whereMonth('view_time')->count(); + if ($search != '') { + $where[] = ['title', 'like', '%' . $search . '%']; + } + if ($category_type != 0) { + $where[] = ['category_type', '=', $category_type]; + } + foreach ($where as $key =>$value){ + $where[$key][0] = 'a.'.$value[0]; + } + + //查询 + $select = Db::table('fa_article')->where($where)->page($page)->limit(20) + ->alias('a') + ->join(['fa_article_life' => 'l'],"a.id = l.article_id") + ->field('a.id,a.title,a.describe,a.user_id,a.view,a.view_time,a.image,a.end_time,a.is_solve,a.is_vote,a.is_nickname,a.video,a.category_type,l.price,l.star,l.lng,l.lat') + ->order('a.id DESC')->select()->toArray(); + + $this->apiSuccess('ok', ['count' => $count,'list' => $select]); + } + +// 获取详情 + public function detail() + { + $param = get_params(); + if(empty($param['id'])){ + $this->apiError('缺少参数'); + } + $where = [ + ['a.id', '=', $param['id']], + ]; + + //查询 + $select = Db::table('fa_article')->where($where) + ->alias('a') + ->join(['fa_article_life' => 'l'],"a.id = l.article_id") + ->field('a.id,a.title,a.category_id,a.describe,a.user_id,a.view,a.view_time,a.image,a.end_time,a.is_solve,a.is_vote,a.is_nickname,a.video,a.category_type,l.price,l.star,l.lng,l.lat') + ->withAttr('category', function ($data, $value) { + if ($value['category_id'] != 0) { + $find = Db::table('fa_category')->where('id', $value['category_id'])->find(); + return $find['name']; + }else{ + return ''; + } + }) + ->find(); + + $this->apiSuccess('获取成功', ['list' => $select]); + } + }