From 4dbc898a4673dd1b22662268e5f09e3d20122225 Mon Sep 17 00:00:00 2001 From: "ZLW-PC\\Administrator" <374861669@qq.com> Date: Mon, 25 Sep 2017 20:57:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 3 +- app/Common/Helper.php | 11 +++++ .../Controllers/Api/ArticleController.php | 15 +++++++ .../Controllers/Weixin/IndexController.php | 44 +++++++++---------- app/Http/Model/Article.php | 17 ++++++- app/Http/Model/Goods.php | 12 ++++- resources/views/weixin/404.blade.php | 6 ++- resources/views/weixin/index/index.blade.php | 13 +++--- routes/web.php | 22 +++++----- 9 files changed, 95 insertions(+), 48 deletions(-) diff --git a/.env.example b/.env.example index e896d19..e931227 100644 --- a/.env.example +++ b/.env.example @@ -6,7 +6,8 @@ APP_LOG_LEVEL=debug APP_URL=http://localhost APP_DOMAIN=www.lqycms.com APP_SUBDOMAIN=m.lqycms.com -APP_API_URL=http://localhost/dataapi +APP_API_URL=http://www.lqycms.com/dataapi +APP_WEIXIN_URL=http://www.lqycms.com/weixin DB_CONNECTION=mysql DB_HOST=127.0.0.1 diff --git a/app/Common/Helper.php b/app/Common/Helper.php index 7b51d72..31a7c35 100644 --- a/app/Common/Helper.php +++ b/app/Common/Helper.php @@ -274,4 +274,15 @@ class Helper return $result; } + + //判断访问终端是否是微信浏览器 + public static function isWechatBrowser() + { + if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) + { + return true; + } + + return false; + } } \ No newline at end of file diff --git a/app/Http/Controllers/Api/ArticleController.php b/app/Http/Controllers/Api/ArticleController.php index c11080b..4c10a8a 100644 --- a/app/Http/Controllers/Api/ArticleController.php +++ b/app/Http/Controllers/Api/ArticleController.php @@ -30,4 +30,19 @@ class ArticleController extends CommonController return ReturnData::create(ReturnData::SUCCESS,$res); } + + public function articleDetail(Request $request) + { + //参数 + $data['id'] = $request->input('id'); + $data['ischeck'] = Article::IS_CHECK; + + $res = Article::getOne($data); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } } \ No newline at end of file diff --git a/app/Http/Controllers/Weixin/IndexController.php b/app/Http/Controllers/Weixin/IndexController.php index 6d6754a..7111c12 100644 --- a/app/Http/Controllers/Weixin/IndexController.php +++ b/app/Http/Controllers/Weixin/IndexController.php @@ -19,7 +19,7 @@ class IndexController extends CommonController 'limit' => 5, 'offset' => 0 ); - $url = env('APP_API')."/slide_list"; + $url = env('APP_API_URL')."/slide_list"; $slide_list = json_decode(http_request_post($url,$postdata,'GET'),true); $data['slide_list'] = $slide_list['data']['list']; @@ -28,10 +28,19 @@ class IndexController extends CommonController 'limit' => 5, 'offset' => 0 ); - $url = env('APP_API')."/article_list"; + $url = env('APP_API_URL')."/article_list"; $article_list = json_decode(http_request_post($url,$postdata,'GET'),true); $data['article_list'] = $article_list['data']['list']; + //商品列表 + $postdata = array( + 'limit' => 10, + 'offset' => 0 + ); + $url = env('APP_API_URL')."/goods_list"; + $goods_list = json_decode(http_request_post($url,$postdata,'GET'),true); + $data['goods_list'] = $goods_list['data']['list']; + return view('weixin.index.index',$data); } @@ -75,26 +84,17 @@ class IndexController extends CommonController //文章详情页 public function detail($id) { - if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');} - - if(cache("detailid$id")){$post = cache("detailid$id");}else{$post = object_to_array(DB::table('article')->where('id', $id)->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['name'] = DB::table('arctype')->where('id', $post['typeid'])->value('name');cache(["detailid$id"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} - if($post) - { - $cat = $post['typeid']; - $post['body'] = ReplaceKeyword($post['body']); - if(!empty($post['writer'])){$post['writertitle']=$post['title'].' '.$post['writer'];} - - $data['post'] = $post; - $data['pre'] = get_article_prenext(array('aid'=>$post["id"],'typeid'=>$post["typeid"],'type'=>"pre")); - } - else - { - return redirect()->route('page404'); - } - - if(cache("catid$cat")){$post=cache("catid$cat");}else{$post = object_to_array(DB::table('arctype')->where('id', $cat)->first(), 1);cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} + //文章详情 + $postdata = array( + 'id' => $id, + 'aa' => 1 + ); + $url = env('APP_API_URL')."/article_detail"; + $article_detail = json_decode(http_request_post($url,$postdata,'GET'),true);dd(http_request_post($url,$postdata,'GET')); + //if(empty($article_detail['data'])){return redirect()->route('weixin_page404');} + //$data['article_detail'] = $article_detail['data']; - return view('home.index.'.$post['temparticle'], $data); + return view('weixin.index.detail', $data); } //标签详情页,共有3种显示方式,1正常列表,2列表显示文章,3显示描述 @@ -271,7 +271,7 @@ class IndexController extends CommonController //404页面 public function page404() { - return view('home.404'); + return view('weixin.404'); } //测试页面 diff --git a/app/Http/Model/Article.php b/app/Http/Model/Article.php index 6513997..96394c9 100644 --- a/app/Http/Model/Article.php +++ b/app/Http/Model/Article.php @@ -86,6 +86,14 @@ class Article extends BaseModel if($res['count']>0) { $res['list'] = $model->select(self::$common_field)->orderBy('id', 'desc')->skip($offset)->take($limit)->get(); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k]->article_detail_url = route('weixin_article_detail',array('id'=>$v->id)); + } + } } else { @@ -95,9 +103,14 @@ class Article extends BaseModel return $res; } - public static function getOne($id) + public static function getOne($param) { - return self::where('id', $id)->first(); + extract($param); + + $where['id'] = $id; + if(isset($ischeck)){$where['ischeck'] = $ischeck;} + + return self::where($where)->first(); } public static function add(array $data) diff --git a/app/Http/Model/Goods.php b/app/Http/Model/Goods.php index fac7315..388f2c4 100644 --- a/app/Http/Model/Goods.php +++ b/app/Http/Model/Goods.php @@ -96,7 +96,15 @@ class Goods extends BaseModel if($res['count']>0) { - $res['list'] = $model->select(self::$common_field)->skip($offset)->take($limit)->orderBy('id','desc')->get()->toArray(); + $res['list'] = $model->select(self::$common_field)->skip($offset)->take($limit)->orderBy('id','desc')->get(); + + if($res['list']) + { + foreach($res['list'] as $k=>$v) + { + $res['list'][$k]->goods_detail_url = route('weixin_goods_detail',array('id'=>$v->id)); + } + } } return $res; @@ -107,7 +115,7 @@ class Goods extends BaseModel if(isset($status)){$where['status'] = $status;}else{$where['status'] = self::STATUS;} $where['id'] = $id; - $goods = self::where($where)->first()->toArray(); + $goods = self::where($where)->first(); $goods['price'] = self::get_final_price($id); diff --git a/resources/views/weixin/404.blade.php b/resources/views/weixin/404.blade.php index cf6e77b..2deecc9 100644 --- a/resources/views/weixin/404.blade.php +++ b/resources/views/weixin/404.blade.php @@ -1,10 +1,12 @@
+