Browse Source

goodslist

master
林一峰 7 years ago
parent
commit
74f5b9e933
  1. 114
      app/Http/Controllers/Home/IndexController.php
  2. 2
      resources/views/home/index/goods.blade.php
  3. 23
      resources/views/home/index/goodscat.blade.php
  4. 127
      resources/views/home/index/goodslist.blade.php

114
app/Http/Controllers/Home/IndexController.php

@ -3,6 +3,7 @@ namespace App\Http\Controllers\Home;
use App\Http\Controllers\Home\CommonController;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class IndexController extends CommonController
{
@ -24,6 +25,64 @@ class IndexController extends CommonController
return view('home.index.index',$data);
}
//商品列表页
public function goodslist(Request $request)
{
$cat = $request->input('id', '');
$page = $request->input('page', '');
$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")); //获取分页列表
$data['goods_type_list'] = object_to_array(DB::table('goods_type')->where(['pid'=>0,'status'=>1])->select('id','name')->take(30)->orderBy('listorder','asc')->get());
$data['id'] = $cat;
return view('home.index.goodslist', $data);
}
//商品详情页
public function goods($id)
{
if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');}
$post = object_to_array(DB::table('goods')->where(['id'=>$id,'status'=>0])->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['type_name'] = DB::table('goods_type')->where('id', $post['typeid'])->value('name');
if($post)
{
$data['post'] = $post;
}
else
{
return redirect()->route('page404');
}
$data['tj_list'] = object_to_array(DB::table('goods')->where(['tuijian'=>1,'status'=>0])->get());
return view('home.index.goods', $data);
}
//列表页
public function category($cat, $page=0)
{
@ -190,61 +249,6 @@ class IndexController extends CommonController
return view('home.index.'.$post['template'], $data);
}
//商品列表页
public function goodslist($cat, $page=0)
{
$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);
}
//商品详情页
public function goods($id)
{
if(empty($id) || !preg_match('/[0-9]+/',$id)){return redirect()->route('page404');}
$post = object_to_array(DB::table('goods')->where(['id'=>$id,'status'=>0])->first(), 1);if(empty($post)){return redirect()->route('page404');}$post['type_name'] = DB::table('goods_type')->where('id', $post['typeid'])->value('name');
if($post)
{
$data['post'] = $post;
}
else
{
return redirect()->route('page404');
}
$data['tj_list'] = object_to_array(DB::table('goods')->where(['tuijian'=>1,'status'=>0])->get());
return view('home.index.goods', $data);
}
//sitemap页面
public function sitemap()
{

2
resources/views/home/index/goods.blade.php

@ -99,7 +99,7 @@
</div>
<div class="recom-list"><ul><?php if($tj_list){foreach($tj_list as $k=>$v){ ?>
<li class="tab-pannel" style="float: none; overflow: hidden; height: 222px; display: block;"><a target="_blank" href="<?php echo route('home_goods',array('id'=>$v['id'])); ?>"><img src="<?php echo $v['litpic']; ?>" alt="<?php echo $v["title"]; ?>"><div class="look-price"><div>¥<?php echo $v["price"]; ?></div><p><?php echo $v["title"]; ?></p></div></a></li>
<li class="tab-pannel" style="float: none; overflow: hidden; height: 222px; display: block;"><a href="<?php echo route('home_goods',array('id'=>$v['id'])); ?>"><img src="<?php echo $v['litpic']; ?>" alt="<?php echo $v["title"]; ?>"><div class="look-price"><div>¥<?php echo $v["price"]; ?></div><p><?php echo $v["title"]; ?></p></div></a></li>
<?php }} ?></ul></div>
</div>

23
resources/views/home/index/goodscat.blade.php

@ -1,23 +0,0 @@
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?php if(empty($post["seotitle"])){echo $post["name"];}else{echo $post["seotitle"];} ?></title>
<link rel="stylesheet" href="/css/bootstrap.min.css"><link rel="stylesheet" href="/css/style.css"><script src="/js/jquery.min.js"></script><script src="/js/bootstrap.min.js"></script><script src="<?php echo sysconfig('CMS_BASEHOST'); ?>/js/ad.js"></script></head><body>
@include('home.common.header')
<div class="container"><div class="row">
<div class="bread"><a href="<?php echo sysconfig('CMS_BASEHOST'); ?>"><?php echo sysconfig('CMS_INDEXNAME'); ?></a> > <?php echo $post["name"]; ?></div>
<?php if($posts){foreach($posts as $row){ ?>
<div class="col-xs-6 col-sm-3" style="margin-top:20px;margin-bottom:10px;">
<a href="<?php echo get_front_url(array("id"=>$row['id'],"type"=>'productdetail')); ?>" target="_blank">
<img src="<?php echo $row['litpic']; ?>" alt="<?php echo $row['title']; ?>" class="imgzsy">
<p style="padding-top:10px;"><?php echo $row['title']; ?></p>
</a></div><?php }} ?>
<br class="cl">
<div class="pages"><ul><?php echo $pagenav; ?></ul><div class="cl"></div></div>
</div></div><!-- /.container -->
<script>
$(function(){
$(".imgzsy").height(function(){return $(this).width()*2/3;});
});
</script>
@include('home.common.footer')</body></html>

127
resources/views/home/index/goodslist.blade.php

@ -0,0 +1,127 @@
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title><?php echo sysconfig('CMS_WEBNAME'); ?></title><meta name="keywords" content="{dede:field.keywords/}" /><meta name="description" content="{dede:field.description function='html2text(@me)'/}" /><link rel="stylesheet" href="<?php echo sysconfig('CMS_BASEHOST'); ?>/css/style.css"></head><body>
@include('home.common.header')
<style>
.cat-menu-h {padding:8px 0;background-color: #fff;}
.cat-menu-h ul {font-size: 14px;}
.cat-menu-h ul li {float: left;}
.cat-menu-h ul a {display: block;padding: 2px 10px;text-align: center;color: #666;white-space: nowrap;}
.cat-menu-h ul a:hover,.cat-menu-h ul .hover{background-color: #e61414;color: #fff;}
.cat-menu-h ul a.forecast:hover {background-color: #26a96d;color: #fff;}
.cat-menu-h ul a.forecast {color: #26a96d;}
</style>
<div class="box">
<div class="cat-menu-h">
<ul class="clearfix">
<?php if($goods_type_list){foreach($goods_type_list as $k=>$v){ ?>
<li><a<?php if($v['id']==$id){echo ' class="hover"';} ?> href="<?php echo route('home_goodslist',array('id'=>$v['id'])); ?>"><?php echo $v['name']; ?></a></li><?php }} ?>
<li><a class="forecast" target="_blank" href="//ju.taobao.com/tg/forecast.htm"> [明日预告] </a></li>
</ul>
<form method="get" target="_blank" class="m-sch fr" name="formsearch" action="/plus/search.php"><input class="sch-txt" name="q" type="text" value="搜索 按Enter键" onfocus="if(value=='搜索 按Enter键') {value=''}" onblur="if(value=='') {value='搜索 按Enter键'}"></form>
<div class="cl"></div></div>
</div>
<div style="background-color:#f6f6f6;padding:15px 0;">
<div class="box">
<ul class="pul">
<?php if($posts){foreach($posts as $k=>$v){ ?>
<li><a href="<?php echo route('home_goods',array('id'=>$v['id'])); ?>" target="_blank"><img src="<?php echo $v['litpic']; ?>" alt="<?php echo $v['title']; ?>">
<p class="title"><?php echo $v['title']; ?></p>
<p class="desc"><span class="price-point"><i></i>库存(<?php echo $v['goods_number']; ?>)</span> <?php echo $v['title']; ?>撒个地方官发个话说得好电话公司电话</p>
<div class="item-prices red"><div class="item-link">立即<br>抢购</div><div class="item-info"><div class="price"><i>¥</i><em class="J_actPrice"><span class="yen"><?php echo $v['price']; ?></span></em></div>
<div class="dock"><div class="dock-price"><del class="orig-price">¥<?php echo $v['market_price']; ?></del> <span class="benefit">退货赔运费</span></div><div class="prompt"><div class="sold-num"><em><?php echo $v['sale']; ?></em> 件已付款</div></div></div>
</div></div>
</a></li>
<?php }} ?>
</ul></div>
<div class="pages"><ul><?php echo $pagenav; ?></ul><div class="cl"></div></div>
</div><!-- box end -->@include('home.common.footer')
<script>//图片幻灯
var glide =new function(){
function $id(id){return document.getElementById(id);};
this.layerGlide=function(auto,oEventCont,oTxtCont,oSlider,sSingleSize,second,fSpeed,point){
var oSubLi = $id(oEventCont).getElementsByTagName('li');
var oTxtLi = $id(oTxtCont).getElementsByTagName('li');
var interval,timeout,oslideRange;
var time=1;
var speed = fSpeed
var sum = oSubLi.length;
var a=0;
var delay=second * 1000;
var setValLeft=function(s){
return function(){
oslideRange = Math.abs(parseInt($id(oSlider).style[point]));
$id(oSlider).style[point] =-Math.floor(oslideRange+(parseInt(s*sSingleSize) - oslideRange)*speed) +'px';
if(oslideRange==[(sSingleSize * s)]){
clearInterval(interval);
a=s;
}
}
};
var setValRight=function(s){
return function(){
oslideRange = Math.abs(parseInt($id(oSlider).style[point]));
$id(oSlider).style[point] =-Math.ceil(oslideRange+(parseInt(s*sSingleSize) - oslideRange)*speed) +'px';
if(oslideRange==[(sSingleSize * s)]){
clearInterval(interval);
a=s;
}
}
}
function autoGlide(){
for(var c=0;c<sum;c++){oSubLi[c].className='';oTxtLi[c].className='';};
clearTimeout(interval);
if(a==(parseInt(sum)-1)){
for(var c=0;c<sum;c++){oSubLi[c].className='';oTxtLi[c].className='';};
a=0;
oSubLi[a].className="active";
oTxtLi[a].className = "active";
interval = setInterval(setValLeft(a),time);
timeout = setTimeout(autoGlide,delay);
}else{
a++;
oSubLi[a].className="active";
oTxtLi[a].className = "active";
interval = setInterval(setValRight(a),time);
timeout = setTimeout(autoGlide,delay);
}
}
if(auto){timeout = setTimeout(autoGlide,delay);};
for(var i=0;i<sum;i++){
oSubLi[i].onmouseover = (function(i){
return function(){
for(var c=0;c<sum;c++){oSubLi[c].className='';oTxtLi[c].className='';};
clearTimeout(timeout);
clearInterval(interval);
oSubLi[i].className = "active";
oTxtLi[i].className = "active";
if(Math.abs(parseInt($id(oSlider).style[point]))>[(sSingleSize * i)]){
interval = setInterval(setValLeft(i),time);
this.onmouseout=function(){if(auto){timeout = setTimeout(autoGlide,delay);};};
}else if(Math.abs(parseInt($id(oSlider).style[point]))<[(sSingleSize * i)]){
interval = setInterval(setValRight(i),time);
this.onmouseout=function(){if(auto){timeout = setTimeout(autoGlide,delay);};};
}
}
})(i)
}
}
}
//调用语句
glide.layerGlide(
true, //设置是否自动滚动
'iconBall', //对应索引按钮
'textBall', //标题内容文本
'show_pic', //焦点图片容器
740, //设置滚动图片位移像素
2, //设置滚动时间2秒
0.1, //设置过渡滚动速度
'left' //设置滚动方向“向左”
);</script></body></html>
Loading…
Cancel
Save