diff --git a/app/Http/Controllers/Api/ArctypeController.php b/app/Http/Controllers/Api/ArctypeController.php new file mode 100644 index 0000000..49d6ec3 --- /dev/null +++ b/app/Http/Controllers/Api/ArctypeController.php @@ -0,0 +1,57 @@ +input('limit', 10); + $data['offset'] = $request->input('offset', 0); + if($request->input('pid', null) !== null){$data['pid'] = $request->input('pid');} + $data['is_show'] = Arctype::IS_SHOW; + + $res = Arctype::getList($data); + if($res == false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + foreach($res as $k=>$v) + { + $res['list'][$k]->addtime = date('Y-m-d H:i',$v->addtime); + $res['list'][$k]->category_list_url = route('weixin_article_category',array('id'=>$v->id)); + } + + return ReturnData::create(ReturnData::SUCCESS,$res); + } + + public function arctypeDetail(Request $request) + { + //参数 + $data['id'] = $request->input('id'); + $data['is_show'] = Arctype::IS_SHOW; + + $res = Arctype::getOne($data); + if($res === false) + { + return ReturnData::create(ReturnData::SYSTEM_FAIL); + } + + $res->addtime = date('Y-m-d H:i',$res->addtime); + + return ReturnData::create(ReturnData::SUCCESS,$res); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Api/ArticleController.php b/app/Http/Controllers/Api/ArticleController.php index aec6265..89b5224 100644 --- a/app/Http/Controllers/Api/ArticleController.php +++ b/app/Http/Controllers/Api/ArticleController.php @@ -24,11 +24,18 @@ class ArticleController extends CommonController $data['ischeck'] = Article::IS_CHECK; $res = Article::getList($data); - if($res == false) + if($res === false) { return ReturnData::create(ReturnData::SYSTEM_FAIL); } + foreach($res['list'] as $k=>$v) + { + $res['list'][$k]->pubdate = date('Y-m-d H:i',$v->pubdate); + $res['list'][$k]->addtime = date('Y-m-d H:i',$v->addtime); + $res['list'][$k]->article_detail_url = route('weixin_article_detail',array('id'=>$v->id)); + } + return ReturnData::create(ReturnData::SUCCESS,$res); } @@ -44,6 +51,9 @@ class ArticleController extends CommonController return ReturnData::create(ReturnData::SYSTEM_FAIL); } + $res->pubdate = date('Y-m-d H:i',$res->pubdate); + $res->addtime = date('Y-m-d H:i',$res->addtime); + 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 e1a946a..8a68c33 100644 --- a/app/Http/Controllers/Weixin/IndexController.php +++ b/app/Http/Controllers/Weixin/IndexController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Weixin; use App\Http\Controllers\Weixin\CommonController; use Illuminate\Support\Facades\DB; +use Illuminate\Http\Request; class IndexController extends CommonController { @@ -20,7 +21,7 @@ class IndexController extends CommonController 'offset' => 0 ); $url = env('APP_API_URL')."/slide_list"; - $slide_list = json_decode(curl_request($url,$postdata,'GET'),true); + $slide_list = curl_request($url,$postdata,'GET'); $data['slide_list'] = $slide_list['data']['list']; //最新资讯 @@ -29,7 +30,7 @@ class IndexController extends CommonController 'offset' => 0 ); $url = env('APP_API_URL')."/article_list"; - $article_list = json_decode(curl_request($url,$postdata,'GET'),true); + $article_list = curl_request($url,$postdata,'GET'); $data['article_list'] = $article_list['data']['list']; //商品列表 @@ -38,47 +39,33 @@ class IndexController extends CommonController 'offset' => 0 ); $url = env('APP_API_URL')."/goods_list"; - $goods_list = json_decode(curl_request($url,$postdata,'GET'),true); + $goods_list = curl_request($url,$postdata,'GET'); $data['goods_list'] = $goods_list['data']['list']; return view('weixin.index.index',$data); } //列表页 - public function category($cat, $page=0) + public function category($cat) { - $pagenow = $page; - - if(empty($cat) || !preg_match('/[0-9]+/',$cat)){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);if(empty($post)){return redirect()->route('page404');} cache(["catid$cat"=>$post], \Carbon\Carbon::now()->addMinutes(2592000));} - $data['post'] = $post; - - $subcat="";$sql=""; - $post2 = object_to_array(DB::table('arctype')->select('id')->where('pid', $cat)->get()); - if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} - $subcat=$subcat."typeid=".$cat; - $sql=$subcat." or typeid2 in (".$cat.")";//echo $subcat2;exit; - $data['sql'] = $sql; - - $counts = DB::table("article")->whereRaw($sql)->count(); - if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);} - $pagesize = sysconfig('CMS_PAGESIZE');$page=0; - if($counts % $pagesize){//取总数据量除以每页数的余数 - $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果 - }else{$pages = $counts/$pagesize;} - if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} - $data['page'] = $page; - $data['pages'] = $pages; - $data['counts'] = $counts; - $start = $page*$pagesize; - - $data['posts'] = arclist(array("sql"=>$sql, "limit"=>"$start,$pagesize")); //获取列表 - $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat)); //获取分页列表 + //文章分类 + $postdata = array( + 'id' => $cat + ); + $url = env('APP_API_URL')."/arctype_detail"; + $arctype_detail = curl_request($url,$postdata,'GET'); + $data['post'] = $arctype_detail['data']; - if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} + //文章列表 + $postdata = array( + 'limit' => 10, + 'offset' => 0 + ); + $url = env('APP_API_URL')."/article_list"; + $article_list = curl_request($url,$postdata,'GET'); + $data['article_list'] = $article_list['data']['list']; - return view('home.index.'.$post['templist'], $data); + return view('weixin.index.category', $data); } //文章详情页 @@ -145,29 +132,19 @@ class IndexController extends CommonController if($post['template']=='tag2' || $post['template']=='tag3'){if(!empty($pagenow)){return redirect()->route('page404');}} - return view('home.index.'.$post['template'], $data); + return view('weixin.index.'.$post['template'], $data); } //标签页 public function tags() { - return view('home.index.tags'); + return view('weixin.index.tags'); } //搜索页 - public function search($keyword) + public function search() { - if(empty($keyword)) - { - echo '请输入正确的关键词';exit; - } - - if(strstr($keyword,"&")) exit; - - $data['posts']= object_to_array(DB::table("article")->where("title", "like", "%$keyword%")->orderBy('id', 'desc')->take(30)->get()); - $data['keyword']= $keyword; - - return view('home.index.search', $data); + return view('weixin.index.search'); } //单页面 @@ -197,43 +174,22 @@ class IndexController extends CommonController $data['posts'] = object_to_array(DB::table('page')->orderBy(\DB::raw('rand()'))->take(5)->get()); - return view('home.index.'.$post['template'], $data); + return view('weixin.index.'.$post['template'], $data); } //商品列表页 - public function goodstype($cat, $page=0) + public function goodslist(Request $request) { - $pagenow = $page; - - if(empty($cat) || !preg_match('/[0-9]+/',$cat)){return redirect()->route('page404');} - - $post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1);if(empty($post)){return redirect()->route('page404');} - $data['post'] = $post; - - $subcat=""; - $post2 = object_to_array(DB::table('goods_type')->select('id')->where('pid', $cat)->get()); - if(!empty($post2)){foreach($post2 as $row){$subcat=$subcat."typeid=".$row["id"]." or ";}} - $subcat=$subcat."typeid=".$cat; - $data['sql'] = $subcat; - - $counts = DB::table("goods")->whereRaw($subcat)->count(); - if($counts>sysconfig('CMS_MAXARC')){$counts=sysconfig('CMS_MAXARC');dd($counts);} - $pagesize = sysconfig('CMS_PAGESIZE');$page=0; - if($counts % $pagesize){//取总数据量除以每页数的余数 - $pages = intval($counts/$pagesize) + 1; //如果有余数,则页数等于总数据量除以每页数的结果取整再加一,如果没有余数,则页数等于总数据量除以每页数的结果 - }else{$pages = $counts/$pagesize;} - if(!empty($pagenow)){if($pagenow==1 || $pagenow>$pages){return redirect()->route('page404');}$page = $pagenow-1;$nextpage=$pagenow+1;$previouspage=$pagenow-1;}else{$page = 0;$nextpage=2;$previouspage=0;} - $data['page'] = $page; - $data['pages'] = $pages; - $data['counts'] = $counts; - $start = $page*$pagesize; - - $data['posts'] = arclist(array("table"=>"goods","sql"=>$subcat, "limit"=>"$start,$pagesize")); //获取列表 - $data['pagenav'] = get_listnav(array("counts"=>$counts,"pagesize"=>$pagesize,"pagenow"=>$page+1,"catid"=>$cat,"urltype"=>"goods")); //获取分页列表 - - if($post['templist']=='category2'){if(!empty($pagenow)){return redirect()->route('page404');}} - - return view('home.index.'.$post['templist'], $data); + if($request->input('typeid', '') != ''){$data['typeid'] = $request->input('typeid');} + if($request->input('tuijian', '') != ''){$data['tuijian'] = $request->input('tuijian');} + if($request->input('keyword', '') != ''){$data['keyword'] = $request->input('keyword');} + if($request->input('status', '') != ''){$data['status'] = $request->input('status');} + if($request->input('is_promote', '') != ''){$data['is_promote'] = $request->input('is_promote');} + if($request->input('orderby', '') != ''){$data['orderby'] = $request->input('orderby');} + if($request->input('max_price', '') != ''){$data['max_price'] = $request->input('max_price');}else{$data['max_price'] = 99999;} + if($request->input('min_price', '') != ''){$data['min_price'] = $request->input('min_price');}else{$data['min_price'] = 0;} + + return view('weixin.index.goodslist', $data); } //商品详情页 @@ -258,13 +214,13 @@ class IndexController extends CommonController $post = object_to_array(DB::table('goods_type')->where('id', $cat)->first(), 1); - return view('home.index.'.$post['temparticle'], $data); + return view('weixin.index.'.$post['temparticle'], $data); } //sitemap页面 public function sitemap() { - return view('home.index.sitemap'); + return view('weixin.index.sitemap'); } //404页面 @@ -275,7 +231,7 @@ class IndexController extends CommonController //测试页面 public function test() - {return view('home.index.test'); + {return view('weixin.index.test'); //return base_path('resources/org'); //$qrcode = new \SimpleSoftwareIO\QrCode\BaconQrCodeGenerator; //return $qrcode->size(500)->generate('Make a qrcode without Laravel!'); diff --git a/app/Http/Model/Arctype.php b/app/Http/Model/Arctype.php index 3ae0c9b..ca3b549 100644 --- a/app/Http/Model/Arctype.php +++ b/app/Http/Model/Arctype.php @@ -29,6 +29,14 @@ class Arctype extends Model */ //protected $connection = 'connection-name'; + const IS_SHOW = 0; // 显示 + const UN_SHOW = 1; // 不显示 + + //常用字段 + protected static $common_field = array( + 'id', 'pid', 'addtime', 'name', 'seotitle', 'keywords', 'description','typedir', 'templist', 'temparticle', 'litpic', 'listorder', 'is_show' + ); + /** * 获取分类对应的文章 */ @@ -37,4 +45,90 @@ class Arctype extends Model return $this->hasMany(Article::class, 'typeid', 'id'); } + public static function getList(array $param) + { + extract($param); //参数:group_id,limit,offset + + $limit = isset($limit) ? $limit : 10; + $offset = isset($offset) ? $offset : 0; + + $model = new Arctype; + + if(isset($pid)){$where['pid'] = $pid;} + if(isset($is_show)){$where['is_show'] = $is_show;} + if(isset($keyword)){$model = $model->where("name", "like", "%$keyword%");} //关键词搜索 + + if($where){$model = $model->where($where);} + + $res['count'] = $model->count(); + $res['list'] = array(); + + //排序 + if(isset($orderby)) + { + switch ($orderby) + { + case 1: + $model = $model->orderBy('listorder','desc'); //排序 + break; + case 2: + $model = $model->orderBy('addtime','desc'); //添加时间从高到低 + break; + default: + $model = $model->orderBy('id','desc'); //id从高到低 + } + } + + if($res['count']>0) + { + $res['list'] = $model->select(self::$common_field)->orderBy('id', 'desc')->skip($offset)->take($limit)->get(); + } + else + { + return false; + } + + return $res; + } + + public static function getOne(array $param) + { + extract($param); + + $where['id'] = $id; + if(isset($is_show)){$where['is_show'] = $is_show;} + + return self::where($where)->first(); + } + + public static function add(array $data) + { + if ($id = self::insertGetId($data)) + { + return $id; + } + + return false; + } + + public static function modify($where, array $data) + { + if (self::where($where)->update($data)!==false) + { + return true; + } + + return false; + } + + //删除一条记录 + public static function remove($id) + { + if (!self::whereIn('id', explode(',', $id))->delete()) + { + return false; + } + + return true; + } } diff --git a/app/Http/Model/Article.php b/app/Http/Model/Article.php index ba2dcc7..c7bd212 100644 --- a/app/Http/Model/Article.php +++ b/app/Http/Model/Article.php @@ -85,19 +85,7 @@ 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 - { - return false; + $res['list'] = $model->select(self::$common_field)->orderBy('id', 'desc')->skip($offset)->take($limit)->get(); } return $res; diff --git a/lqycms.sql b/lqycms.sql index 8048e05..605a3d8 100644 --- a/lqycms.sql +++ b/lqycms.sql @@ -166,6 +166,7 @@ CREATE TABLE `fl_arctype` ( `seokeyword` varchar(60) DEFAULT '' COMMENT '判断相关,可不填', `model` int(4) DEFAULT '0' COMMENT '栏目所属的模型', `listorder` smallint(5) DEFAULT '50' COMMENT '排序', + `is_show` tinyint(1) DEFAULT '0' COMMENT '是否显示,默认0显示', PRIMARY KEY (`id`), UNIQUE KEY `typename` (`name`), UNIQUE KEY `typedir` (`typedir`) @@ -173,7 +174,7 @@ CREATE TABLE `fl_arctype` ( /*Data for the table `fl_arctype` */ -insert into `fl_arctype`(`id`,`pid`,`addtime`,`name`,`seotitle`,`keywords`,`description`,`content`,`typedir`,`templist`,`temparticle`,`litpic`,`seokeyword`,`model`,`listorder`) values (1,0,1483345707,'新闻中心','','新闻中心','新闻中心','
新闻中心
','news','category','detail','','新闻中心',0,50),(2,0,1476063429,'案例中心','','案例中心','案例中心','案例中心
','case','category','detail','','案例中心',0,50),(3,1,1476063419,'行业新闻','','行业新闻','行业新闻','行业新闻
','hangye','category','detail','','行业新闻',0,50),(4,1,1476068069,'企业新闻','','企业新闻','企业新闻','企业新闻
','qiye','category','detail','','企业新闻',0,50); +insert into `fl_arctype`(`id`,`pid`,`addtime`,`name`,`seotitle`,`keywords`,`description`,`content`,`typedir`,`templist`,`temparticle`,`litpic`,`seokeyword`,`model`,`listorder`,`is_show`) values (1,0,1483345707,'新闻中心','','新闻中心','新闻中心','新闻中心
','news','category','detail','','新闻中心',0,50,0),(2,0,1476063429,'案例中心','','案例中心','案例中心','案例中心
','case','category','detail','','案例中心',0,50,0),(3,1,1476063419,'行业新闻','','行业新闻','行业新闻','行业新闻
','hangye','category','detail','','行业新闻',0,50,0),(4,1,1476068069,'企业新闻','','企业新闻','企业新闻','企业新闻
','qiye','category','detail','','企业新闻',0,50,0); /*Table structure for table `fl_article` */ @@ -391,7 +392,7 @@ CREATE TABLE `fl_goods` ( /*Data for the table `fl_goods` */ -insert into `fl_goods`(`id`,`typeid`,`tuijian`,`click`,`title`,`body`,`sn`,`price`,`litpic`,`pubdate`,`add_time`,`keywords`,`seotitle`,`description`,`status`,`shipping_fee`,`market_price`,`goods_number`,`user_id`,`sale`,`cost_price`,`goods_weight`,`point`,`comments`,`promote_start_date`,`promote_price`,`promote_end_date`,`goods_img`,`warn_number`,`spec`,`listorder`) values (1,2,0,5653,'示例产品一',NULL,'sn123456','45000.00','/uploads/2017/06/201706041951031181.jpg',1496577749,1496577749,'示例,产品,一','','',0,'0.00','50000.00',21,1,0,'0.00','0.00',NULL,NULL,NULL,'0.00',NULL,NULL,NULL,NULL,50),(2,1,0,3,'示例产品二',NULL,'sn987','1.00','/uploads/2017/06/201706042011354141.jpg',1496578330,1496578313,'产品,示例,二','','',0,'3.00','2.00',3,1,3,'0.00','0.00',NULL,NULL,NULL,'0.00',NULL,NULL,NULL,NULL,50),(3,1,0,3,'示例产品三',NULL,'sn232143','5.00','/uploads/2017/06/201706042012428057.jpg',1496578380,1496578380,'示例,产品,三','','',0,'3.00','4.00',3,1,1,'0.00','0.00',NULL,NULL,NULL,'0.00',NULL,NULL,NULL,NULL,50),(4,1,0,7,'示例产品四2',NULL,'sn9809702','5.00','/uploads/2017/06/201706042013331349.jpg',1500994245,1496578429,'示例,产品,四','','',0,'3.00','6.00',7,1,4,'0.00','0.00',NULL,NULL,NULL,'0.00',NULL,NULL,NULL,NULL,50); +insert into `fl_goods`(`id`,`typeid`,`tuijian`,`click`,`title`,`body`,`sn`,`price`,`litpic`,`pubdate`,`add_time`,`keywords`,`seotitle`,`description`,`status`,`shipping_fee`,`market_price`,`goods_number`,`user_id`,`sale`,`cost_price`,`goods_weight`,`point`,`comments`,`promote_start_date`,`promote_price`,`promote_end_date`,`goods_img`,`warn_number`,`spec`,`listorder`) values (1,2,0,5653,'示例产品一','是的发生','sn123456','45000.00','/uploads/2017/06/201706041951031181.jpg',1496577749,1496577749,'示例,产品,一','','',0,'0.00','50000.00',21,1,0,'0.00','0.00',NULL,NULL,NULL,'0.00',NULL,NULL,NULL,NULL,50),(2,1,0,3,'示例产品二',NULL,'sn987','1.00','/uploads/2017/06/201706042011354141.jpg',1496578330,1496578313,'产品,示例,二','','',0,'3.00','2.00',3,1,3,'0.00','0.00',NULL,NULL,NULL,'0.00',NULL,NULL,NULL,NULL,50),(3,1,0,3,'示例产品三',NULL,'sn232143','5.00','/uploads/2017/06/201706042012428057.jpg',1496578380,1496578380,'示例,产品,三','','',0,'3.00','4.00',3,1,1,'0.00','0.00',NULL,NULL,NULL,'0.00',NULL,NULL,NULL,NULL,50),(4,1,0,7,'示例产品四2',NULL,'sn9809702','5.00','/uploads/2017/06/201706042013331349.jpg',1500994245,1496578429,'示例,产品,四','','',0,'3.00','6.00',7,1,4,'0.00','0.00',NULL,NULL,NULL,'0.00',NULL,NULL,NULL,NULL,50); /*Table structure for table `fl_goods_photo` */ @@ -414,20 +415,21 @@ DROP TABLE IF EXISTS `fl_goods_type`; CREATE TABLE `fl_goods_type` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, - `pid` smallint(5) DEFAULT '0' COMMENT '父级栏目id', - `addtime` int(11) DEFAULT '0' COMMENT '添加时间', + `pid` smallint(5) NOT NULL DEFAULT '0' COMMENT '父级栏目id', + `addtime` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间', `name` varchar(30) NOT NULL DEFAULT '' COMMENT '栏目名称', - `seotitle` varchar(150) DEFAULT '' COMMENT 'seo标题', - `keywords` varchar(60) DEFAULT '' COMMENT '关键词', - `description` varchar(255) DEFAULT '' COMMENT '描述', + `seotitle` varchar(150) NOT NULL DEFAULT '' COMMENT 'seo标题', + `keywords` varchar(60) NOT NULL DEFAULT '' COMMENT '关键词', + `description` varchar(255) NOT NULL DEFAULT '' COMMENT '描述', `content` text COMMENT '内容', `typedir` varchar(30) NOT NULL DEFAULT '' COMMENT '别名', - `templist` varchar(50) DEFAULT '' COMMENT '列表页模板', - `temparticle` varchar(50) DEFAULT '' COMMENT '详情页模板', - `litpic` varchar(100) DEFAULT '' COMMENT '封面或缩略图', - `seokeyword` varchar(60) DEFAULT '' COMMENT '判断相关,可不填', - `status` smallint(1) DEFAULT '1' COMMENT '是否显示', - `listorder` smallint(5) DEFAULT '50' COMMENT '排序', + `templist` varchar(50) NOT NULL DEFAULT '' COMMENT '列表页模板', + `temparticle` varchar(50) NOT NULL DEFAULT '' COMMENT '详情页模板', + `litpic` varchar(100) NOT NULL DEFAULT '' COMMENT '缩略图', + `seokeyword` varchar(60) NOT NULL DEFAULT '' COMMENT '判断相关,可不填', + `status` smallint(1) NOT NULL DEFAULT '1' COMMENT '是否显示', + `listorder` smallint(5) NOT NULL DEFAULT '50' COMMENT '排序', + `cover` varchar(100) NOT NULL DEFAULT '' COMMENT '封面', PRIMARY KEY (`id`), UNIQUE KEY `typename` (`name`), UNIQUE KEY `typedir` (`typedir`) @@ -435,7 +437,7 @@ CREATE TABLE `fl_goods_type` ( /*Data for the table `fl_goods_type` */ -insert into `fl_goods_type`(`id`,`pid`,`addtime`,`name`,`seotitle`,`keywords`,`description`,`content`,`typedir`,`templist`,`temparticle`,`litpic`,`seokeyword`,`status`,`listorder`) values (1,0,1496576972,'书籍','','','','书籍
','book','productcat','product','','',1,50),(2,0,1496576993,'数码','','','',NULL,'shuma','productcat','product','','',1,50),(3,0,1500994389,'qq','qq','qq','','书籍
','book','goodscat','goods','','',1,50,''),(2,0,1496576993,'数码','','','',NULL,'shuma','goodscat','goods','','',1,50,''),(3,0,1500994389,'qq','qq','qq','','