GalleryController.class.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Home\Controller;
  15. class GalleryController extends CommonController {
  16. //显示全部产品
  17. public function all(){
  18. $count=M('goods')->where(array('status'=>1))->count();
  19. $Page = new \Think\Page($count,C('FRONT_PAGE_NUM'));
  20. $show = $Page->show();// 分页显示输出
  21. $sql='SELECT goods_id,image,name,price FROM '.C('DB_PREFIX').'goods WHERE status=1 order by goods_id desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  22. $list=M()->query($sql);
  23. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  24. foreach ($list as $k => $v) {
  25. $list[$k]['goods_id']=$hashids->encode($v['goods_id']);
  26. $list[$k]['image']=resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  27. }
  28. $this->title='全部产品图册-';
  29. $this->category='全部产品图册';
  30. $this->meta_keywords=C('SITE_DESCRIPTION');
  31. $this->meta_description=C('SITE_NAME').'产品图册';
  32. $show=str_replace("/gallery/all/p/","/gallerys/", $show);
  33. $this->assign('empty','没有数据');// 赋值数据集
  34. $this->assign('list',$list);// 赋值数据集
  35. $this->assign('page',$show);// 赋值分页输出
  36. $this->display();
  37. }
  38. //按分类显示产品
  39. public function category(){
  40. $id=get_url_id('id');
  41. $sql='SELECT p.goods_id,p.image,p.name,p.price FROM '.C('DB_PREFIX').'goods p,'.
  42. C('DB_PREFIX').'goods_to_category ptc '.
  43. ' WHERE p.goods_id=ptc.goods_id AND p.status=1 AND ptc.category_id='.$id;
  44. $count=count(M()->query($sql));
  45. $Page = new \Think\Page($count,C('FRONT_PAGE_NUM'));
  46. $show = $Page->show();// 分页显示输出
  47. $sql.=' order by p.goods_id desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  48. $list=M()->query($sql);
  49. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  50. foreach ($list as $k => $v) {
  51. $list[$k]['goods_id']=$hashids->encode($v['goods_id']);
  52. $list[$k]['image']=resize($v['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  53. }
  54. $category=M('goods_category')->find($id);
  55. $this->title=$category['name'].'-';
  56. $this->category=$category['name'];
  57. $this->meta_keywords=$category['meta_keyword'];
  58. $this->meta_description=$category['meta_description'];
  59. $show=str_replace("/gallery/category/id/","/gcategory/", $show);
  60. $this->assign('empty','没有数据');// 赋值数据集
  61. $this->assign('list',$list);// 赋值数据集
  62. $this->assign('page',$show);// 赋值分页输出
  63. $this->display('all');
  64. }
  65. //产品详情
  66. public function pshow(){
  67. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  68. $id=get_url_id('id');
  69. $sql='SELECT p.goods_id,p.model,pi.image,pd.summary,p.name,pd.meta_description,pd.meta_keyword FROM '.
  70. C('DB_PREFIX').'goods p,'.
  71. C('DB_PREFIX').'goods_image pi,'.
  72. C('DB_PREFIX').'goods_description pd where p.goods_id=pd.goods_id and p.goods_id=pi.goods_id and p.status=1 and p.goods_id='.$id;
  73. $list=M()->query($sql);
  74. if(isset($list)){
  75. foreach ($list as $k => $v) {
  76. $list[$k]['thumb']=resize($v['image'], C('gallery_thumb_width'), C('gallery_thumb_height'));
  77. }
  78. $this->goods_image=$list;
  79. $goods=array(
  80. 'name'=>$list[0]['name'],
  81. 'model'=>$list[0]['model'],
  82. 'summary'=>$list[0]['summary'],
  83. );
  84. $this->goods=$goods;
  85. $other=M()->query('select goods_id,image from '.C('DB_PREFIX').'goods order by rand() limit 6');
  86. foreach ($other as $k => $v) {
  87. $other[$k]['goods_id']=$hashids->encode($v['goods_id']);
  88. $other[$k]['image']=resize($v['image'], C('gallery_related_thumb_width'), C('gallery_related_thumb_height'));
  89. }
  90. $this->other_goods=$other;
  91. $this->title=$list[0]['name'].'-';
  92. $this->meta_keywords=$list[0]['meta_keyword'];
  93. $this->meta_description=$list[0]['meta_description'];
  94. $this->display();
  95. }
  96. }
  97. }