<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Home\Controller;
use OT\DataDictionary;
/**
* 前台首页控制器
* 主要获取首页聚合数据
*/
class IndexController extends HomeController {
protected $goods_info = 'id,goods_name,goods_ico,goods_introduct,tox_money_need,goods_num,changetime,status,createtime,category_id,is_new,sell_num';
//系统首页
public function index() {
//轮播右推荐位
$map['is_new'] = 1;
$map['status'] = 1;
$new = M('Shop')->where($map)->order('createtime desc')->limit(3)->field('id,goods_name,tox_money_need,goods_ico')->select();
$this->assign('new', $new);
//限时推荐
$map['is_new'] = 1;
$map['status'] = 1;
$map['goods_people'] = 0;
$goods_list_new = D('shop')->where($map)->order('changetime desc')->limit(3)->field($this->goods_info)->select();
$this->assign('recommend', $goods_list_new);
//爱情鲜花
$map['is_new'] = 1;
$map['status'] = 1;
$map['goods_people'] = 0;
$loveflow = D('shop')->where($map)->order('createtime desc')->limit(8)->field($this->goods_info)->select();
$this->assign('love', $loveflow);
//长辈鲜花
$map['is_new'] = 1;
$map['status'] = 1;
$map['goods_people'] = 1;
$elder = D('shop')->where($map)->order('createtime desc')->limit(8)->field($this->goods_info)->select();
$this->assign('elder', $elder);
//长生花
$map['is_new'] = 1;
$map['status'] = 1;
$map['goods_people'] = 2;
$longevity = D('shop')->where($map)->order('createtime desc')->limit(8)->field($this->goods_info)->select();
$this->assign('longevity', $longevity);
//礼品
$map['is_new'] = 1;
$map['status'] = 1;
$map['goods_people'] = 3;
$gift = D('shop')->where($map)->order('createtime desc')->limit(8)->field($this->goods_info)->select();
$this->assign('gift', $gift);
//热销商品
$hot_num = D
('shop_config')->where(array('ename' => 'min_sell_num'))->getField('cname');
$map_hot['sell_num'] = array('egt', $hot_num);
$map_hot['status'] = 1;
$goods_list_hot = D('shop')->where($map_hot)->order('sell_num desc')->limit(8)->field($this->goods_info)->select();
$this->assign('contents_hot', $goods_list_hot);
$this->display();
}
//商品列表
public function lists($type = '', $page = 1) {
$page_count = C("SHOP_PAGE_NUM");
$fit = $_GET['fit'];
$keyword = $_GET['keyword'];
$by = $_GET['by'];
$map['goods_name'] = array('like', '%' . $keyword . '%');
}
$map['goods_people'] = $fit;
}
$map['_string'] = 'FIND_IN_SET(' . $type . ', category_id)';
}
if ($by == 'all') {
$order = array('createtime' => 'desc', 'sell_num' => 'desc');
} elseif ($by == 'sell_num') {
$order = 'sell_num desc';
} elseif ($by == 'price') {
$order = 'tox_money_need desc';
} elseif ($by == 'new') {
$order = 'createtime desc';
}
} else {
$order = 'createtime desc';
}
$list = M('Shop')->where($map)->order($order)->page($page, $page_count)->select();
$totalCount = D
('shop')->where($map)->count();
##热销鲜花
$hot = M
('Shop')->where(array('status' => 1))->order('sell_num desc')->limit(5)->select();
$this->assign('list', $list);
$this->assign('totalPageCount', $totalCount);
$this->assign('page_count', $page_count);
$this->assign('hot', $hot);
$this->assign('by', $by);
$this->assign('keyword', $keyword);
$this->display();
}
//商品详情页面
public function info($id) {
$this->error('Home/index/index', '参数错误');
}
$info = M
('Shop')->where(array('id' => $id))->find();
$info['is_new_text'] = $info['is_new'] ? "新品特惠" : "";
$info['show_path'] = str2arr($info['show_id']);
// dump($info);
// exit;
##热销鲜花
$hot = M
('Shop')->where(array('status' => 1))->order('sell_num desc')->limit(5)->select();
$wxprice = $info['tox_money_need'] - 4;
$this->assign('hot', $hot);
$this->assign('info', $info);
$this->assign('wxprice', $wxprice);
$this->display();
}
private function assignPostCount() {
$post_count = S('home_post_count');
if (empty($post_count)) {
$post_count = D
('ForumPost')->where(array('status' => 1))->count();
S('home_post_count', $post_count, 600);
}
$this->assign('post_count', $post_count);
}
private function assignWeiboCount() {
$weibo_count = S('home_weibo_count');
if (empty($weibo_count)) {
$weibo_count = D
('Weibo')->where(array('status' => 1))->count();
S('home_weibo_count', $weibo_count, 600);
}
$this->assign('weibo_count', $weibo_count);
}
private function assignEventCount() {
$event_count = S('home_event_count');
if (empty($event_count)) {
$event_count = D
('Event')->where(array('status' => 1))->count();
S('home_event_count', $event_count, 600);
}
$this->assign('event_count', $event_count);
}
private function assignEvents() {
$events = S('home_events');
$events = D
('Event')->where(array('status' => 1, 'create_time > ' . (time() - 604800)))->order('reply_count')->limit(3)->select();
S('home_events', $events, 600);
}
$this->assign('events', $events);
}
private function assignPosts() {
$data = S('home_posts');
$data = D
('ForumPost')->where(array('status' => 1, 'create_time > ' . (time() - 604800)))->order('reply_count')->limit(4)->select();
S('home_posts', $data, 600);
}
$this->assign('posts', $data);
}
private function assignWeibos() {
$data = S('home_weibos');
$data = D
('Weibo')->where(array('status' => 1, 'create_time > ' . (time() - 604800)))->order('comment_count')->limit(4)->select();
S('home_weibos', $data, 600);
}
$this->assign('weibos', $data);
}
/**
* 获取表情列表。
*/
public function getSmile() {
//这段代码不是测试代码,请勿删除
}
}