×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: usera0798
Added: Jul 14, 2016 6:47 PM
Views: 6
Tags: no tags
  1. <?php
  2.  
  3. // +----------------------------------------------------------------------
  4. // | OneThink [ WE CAN DO IT JUST THINK IT ]
  5. // +----------------------------------------------------------------------
  6. // | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
  7. // +----------------------------------------------------------------------
  8. // | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
  9. // +----------------------------------------------------------------------
  10.  
  11. namespace Home\Controller;
  12.  
  13. use OT\DataDictionary;
  14.  
  15. /**
  16.  * 前台首页控制器
  17.  * 主要获取首页聚合数据
  18.  */
  19. class IndexController extends HomeController {
  20.  
  21.     protected $goods_info = 'id,goods_name,goods_ico,goods_introduct,tox_money_need,goods_num,changetime,status,createtime,category_id,is_new,sell_num';
  22.  
  23.     //系统首页
  24.     public function index() {
  25.         //轮播右推荐位
  26.         $map['is_new'] = 1;
  27.         $map['status'] = 1;
  28.         $new = M('Shop')->where($map)->order('createtime desc')->limit(3)->field('id,goods_name,tox_money_need,goods_ico')->select();
  29.         $this->assign('new', $new);
  30.         //限时推荐
  31.         $map['is_new'] = 1;
  32.         $map['status'] = 1;
  33.         $map['goods_people'] = 0;
  34.         $goods_list_new = D('shop')->where($map)->order('changetime desc')->limit(3)->field($this->goods_info)->select();
  35.         $this->assign('recommend', $goods_list_new);
  36.         //爱情鲜花
  37.         $map['is_new'] = 1;
  38.         $map['status'] = 1;
  39.         $map['goods_people'] = 0;
  40.         $loveflow = D('shop')->where($map)->order('createtime desc')->limit(8)->field($this->goods_info)->select();
  41.         $this->assign('love', $loveflow);
  42.         //长辈鲜花
  43.         $map['is_new'] = 1;
  44.         $map['status'] = 1;
  45.         $map['goods_people'] = 1;
  46.         $elder = D('shop')->where($map)->order('createtime desc')->limit(8)->field($this->goods_info)->select();
  47.         $this->assign('elder', $elder);
  48.         //长生花
  49.         $map['is_new'] = 1;
  50.         $map['status'] = 1;
  51.         $map['goods_people'] = 2;
  52.         $longevity = D('shop')->where($map)->order('createtime desc')->limit(8)->field($this->goods_info)->select();
  53.         $this->assign('longevity', $longevity);
  54.         //礼品
  55.         $map['is_new'] = 1;
  56.         $map['status'] = 1;
  57.         $map['goods_people'] = 3;
  58.         $gift = D('shop')->where($map)->order('createtime desc')->limit(8)->field($this->goods_info)->select();
  59.         $this->assign('gift', $gift);
  60.         //热销商品
  61.         $hot_num = D('shop_config')->where(array('ename' => 'min_sell_num'))->getField('cname');
  62.         $map_hot['sell_num'] = array('egt', $hot_num);
  63.         $map_hot['status'] = 1;
  64.         $goods_list_hot = D('shop')->where($map_hot)->order('sell_num desc')->limit(8)->field($this->goods_info)->select();
  65.         $this->assign('contents_hot', $goods_list_hot);
  66.  
  67.         $this->display();
  68.     }
  69.  
  70.     //商品列表
  71.     public function lists($type = '', $page = 1) {
  72.         $page_count = C("SHOP_PAGE_NUM");
  73.         $fit = $_GET['fit'];
  74.         $keyword = $_GET['keyword'];
  75.         $by = $_GET['by'];
  76.         if (!empty($keyword)) {
  77.             $map['goods_name'] = array('like', '%' . $keyword . '%');
  78.         }
  79.         if (!empty($fit)) {
  80.             $map['goods_people'] = $fit;
  81.         }
  82.  
  83.         if (!empty($type)) {
  84.             $map['_string'] = 'FIND_IN_SET(' . $type . ', category_id)';
  85.         }
  86.         if (!empty($by)) {
  87.             if ($by == 'all') {
  88.                 $order = array('createtime' => 'desc', 'sell_num' => 'desc');
  89.             } elseif ($by == 'sell_num') {
  90.                 $order = 'sell_num desc';
  91.             } elseif ($by == 'price') {
  92.                 $order = 'tox_money_need desc';
  93.             } elseif ($by == 'new') {
  94.                 $order = 'createtime desc';
  95.             }
  96.         } else {
  97.             $order = 'createtime desc';
  98.         }
  99.         $list = M('Shop')->where($map)->order($order)->page($page, $page_count)->select();
  100.         $totalCount = D('shop')->where($map)->count();
  101.         ##热销鲜花
  102.        $hot = M('Shop')->where(array('status' => 1))->order('sell_num desc')->limit(5)->select();
  103.         $this->assign('list', $list);
  104.         $this->assign('totalPageCount', $totalCount);
  105.         $this->assign('page_count', $page_count);
  106.         $this->assign('hot', $hot);
  107.         $this->assign('by', $by);
  108.         $this->assign('keyword', $keyword);
  109.         $this->display();
  110.     }
  111.  
  112.     //商品详情页面
  113.     public function info($id) {
  114.         if (empty($id)) {
  115.             $this->error('Home/index/index', '参数错误');
  116.         }
  117.         $info = M('Shop')->where(array('id' => $id))->find();
  118.         $info['is_new_text'] = $info['is_new'] ? "新品特惠" : "";
  119.         $info['show_path'] = str2arr($info['show_id']);
  120. //        dump($info);
  121. //        exit;
  122.         ##热销鲜花
  123.        $hot = M('Shop')->where(array('status' => 1))->order('sell_num desc')->limit(5)->select();
  124.         $wxprice = $info['tox_money_need'] - 4;
  125.         $this->assign('hot', $hot);
  126.         $this->assign('info', $info);
  127.         $this->assign('wxprice', $wxprice);
  128.         $this->display();
  129.     }
  130.  
  131.     private function assignPostCount() {
  132.         $post_count = S('home_post_count');
  133.         if (empty($post_count)) {
  134.             $post_count = D('ForumPost')->where(array('status' => 1))->count();
  135.             S('home_post_count', $post_count, 600);
  136.         }
  137.         $this->assign('post_count', $post_count);
  138.     }
  139.  
  140.     private function assignWeiboCount() {
  141.         $weibo_count = S('home_weibo_count');
  142.         if (empty($weibo_count)) {
  143.             $weibo_count = D('Weibo')->where(array('status' => 1))->count();
  144.             S('home_weibo_count', $weibo_count, 600);
  145.         }
  146.         $this->assign('weibo_count', $weibo_count);
  147.     }
  148.  
  149.     private function assignEventCount() {
  150.         $event_count = S('home_event_count');
  151.         if (empty($event_count)) {
  152.             $event_count = D('Event')->where(array('status' => 1))->count();
  153.             S('home_event_count', $event_count, 600);
  154.         }
  155.         $this->assign('event_count', $event_count);
  156.     }
  157.  
  158.     private function assignEvents() {
  159.         $events = S('home_events');
  160.         if (empty($events)) {
  161.             $events = D('Event')->where(array('status' => 1, 'create_time > ' . (time() - 604800)))->order('reply_count')->limit(3)->select();
  162.             S('home_events', $events, 600);
  163.         }
  164.         $this->assign('events', $events);
  165.     }
  166.  
  167.     private function assignPosts() {
  168.         $data = S('home_posts');
  169.         if (empty($events)) {
  170.             $data = D('ForumPost')->where(array('status' => 1, 'create_time > ' . (time() - 604800)))->order('reply_count')->limit(4)->select();
  171.             S('home_posts', $data, 600);
  172.         }
  173.         $this->assign('posts', $data);
  174.     }
  175.  
  176.     private function assignWeibos() {
  177.         $data = S('home_weibos');
  178.         if (empty($events)) {
  179.             $data = D('Weibo')->where(array('status' => 1, 'create_time > ' . (time() - 604800)))->order('comment_count')->limit(4)->select();
  180.             S('home_weibos', $data, 600);
  181.         }
  182.         $this->assign('weibos', $data);
  183.     }
  184.  
  185.     /**
  186.      * 获取表情列表。
  187.      */
  188.     public function getSmile() {
  189.         //这段代码不是测试代码,请勿删除
  190.         exit(json_encode(D('Common/Expression')->getAllExpression()));
  191.     }
  192.  
  193. }
  194.