283 lines
13 KiB
PHP
283 lines
13 KiB
PHP
<?php
|
|
|
|
namespace app\home\controller;
|
|
use think\facade\View;
|
|
use think\facade\Db;
|
|
use think\facade\Lang;
|
|
/**
|
|
* ============================================================================
|
|
* 联课教育商城系统
|
|
* ============================================================================
|
|
* 版权所有 2022 刻羽互动科技有限公司,并保留所有权利。
|
|
* 网站地址: http://www.o1h.cn
|
|
* ----------------------------------------------------------------------------
|
|
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
|
|
* 不允许对程序代码以任何形式任何目的的再发布。
|
|
* ============================================================================
|
|
* 控制器
|
|
*/
|
|
class Index extends BaseMall {
|
|
|
|
public function initialize() {
|
|
parent::initialize();
|
|
Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/index.lang.php');
|
|
}
|
|
|
|
|
|
|
|
public function index() {
|
|
View::assign('index_sign', 'index');
|
|
|
|
$this->getIndexData();
|
|
|
|
|
|
//查询热门课程推荐
|
|
$goods_model = model('goods');
|
|
$goodsclass_model = model('goods_class');
|
|
$recommend = $goods_model->getGoodsCommendList(12);
|
|
foreach ($recommend as &$val) {
|
|
$gc = $goodsclass_model->getGoodsclassList(['gc_id' => $val['gc_id']], 'gc_name');
|
|
$val['gc_name'] = $gc[0]['gc_name'];
|
|
}
|
|
|
|
View::assign('recommend', $recommend);
|
|
|
|
//文章
|
|
$article_model = model('article');
|
|
$condition = array();
|
|
$condition[]=array('article_show','=','1');
|
|
$condition[]=array('ac_id','=','8');
|
|
$article_list = $article_model->getAllArticle($condition, 3);
|
|
foreach ($article_list as &$val) {
|
|
$val['article_date'] = date('m/d/Y H:i:s',$val['article_time']);
|
|
|
|
/* preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $val['article_content'], $matches);
|
|
|
|
$str = join('', $matches[0]);
|
|
$val['article'] = mb_substr($str,0,200);*/
|
|
}
|
|
|
|
View::assign('article',array_slice($article_list,0,3));
|
|
|
|
|
|
//首页项目
|
|
$program = $this->_get_header_categories()[765]['class2'];
|
|
View::assign('program', $program);
|
|
|
|
//SEO 设置
|
|
$seo = model('seo')->type('index')->show();
|
|
|
|
//愿景
|
|
$wish = config('ds_config.our_wish');
|
|
View::assign('wish', $wish);
|
|
$wish_en = config('ds_config.our_wish_en');
|
|
View::assign('wish_en', $wish_en);
|
|
|
|
|
|
//热门课程
|
|
$feature_credit = config('ds_config.feature_credit');
|
|
View::assign('feature_credit', $feature_credit);
|
|
$feature_credit_en= config('ds_config.feature_credit_en');
|
|
View::assign('feature_credit_en', $feature_credit_en);
|
|
|
|
|
|
//留学项目
|
|
$study_abroad= config('ds_config.study_abroad');
|
|
View::assign('study_abroad', $study_abroad);
|
|
$study_abroad_en = config('ds_config.study_abroad_en');
|
|
View::assign('study_abroad_en', $study_abroad_en);
|
|
|
|
$this->_assign_seo($seo);
|
|
return View::fetch($this->template_dir . 'index');
|
|
}
|
|
|
|
private function getIndexData()
|
|
{
|
|
$index_data = rcache("index_data");
|
|
if (empty($index_data)) {
|
|
$goods_model=model('goods');
|
|
$index_data = array();
|
|
$index_data['recommend_list'] = $goods_model->getGoodsUnionList(array(array('goodscommon.goods_commend','=',1)), 'goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_image,goods.goods_promotion_price,goodscommon.goods_price','goodscommon.goods_sort asc','goodscommon.goods_commonid', 0,5);
|
|
foreach($index_data['recommend_list'] as $key => $val){
|
|
if(!$val['goods_storage']){
|
|
$goods_info=$goods_model->getGoodsStorageByCommonId($val['goods_commonid']);
|
|
if($goods_info){
|
|
$index_data['recommend_list'][$key]['goods_id']=$goods_info['goods_id'];
|
|
$index_data['recommend_list'][$key]['goods_storage']=$goods_info['goods_storage'];
|
|
$index_data['recommend_list'][$key]['goods_promotion_price']=$goods_info['goods_promotion_price'];
|
|
}
|
|
}
|
|
}
|
|
//限时折扣
|
|
$index_data['promotion_list'] = model('pxianshigoods')->getXianshigoodsCommendList(5);
|
|
$index_data['new_list'] = $goods_model->getGoodsUnionList(array(), 'goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_image,goods.goods_promotion_price,goodscommon.goods_price','goodscommon.goods_addtime desc','goodscommon.goods_commonid', 0,5);
|
|
foreach($index_data['new_list'] as $key => $val){
|
|
if(!$val['goods_storage']){
|
|
$goods_info=$goods_model->getGoodsStorageByCommonId($val['goods_commonid']);
|
|
if($goods_info){
|
|
$index_data['new_list'][$key]['goods_id']=$goods_info['goods_id'];
|
|
$index_data['new_list'][$key]['goods_storage']=$goods_info['goods_storage'];
|
|
$index_data['new_list'][$key]['goods_promotion_price']=$goods_info['goods_promotion_price'];
|
|
}
|
|
}
|
|
}
|
|
$index_data['groupbuy_list'] = model('groupbuy')->getGroupbuyCommendedList(5);
|
|
//友情链接
|
|
$index_data['link_list'] = model('link')->getLinkList();
|
|
//获取第一文章分类的前三篇文章
|
|
$index_data['index_articles'] = Db::name('article')->where('ac.ac_code', 'notice')->where('a.article_show', 1)->alias('a')->field('a.article_id,a.article_url,a.article_title')->order('a.article_sort asc,a.article_time desc')->limit(3)->join('articleclass ac', 'a.ac_id=ac.ac_id')->select()->toArray();
|
|
wcache('index_data',$index_data);
|
|
}
|
|
View::assign('recommend_list', $index_data['recommend_list']);
|
|
View::assign('promotion_list', $index_data['promotion_list']);
|
|
View::assign('new_list', $index_data['new_list']);
|
|
View::assign('groupbuy_list', $index_data['groupbuy_list']);
|
|
View::assign('link_list', $index_data['link_list']);
|
|
View::assign('index_articles', $index_data['index_articles']);
|
|
}
|
|
|
|
|
|
private function getFloorList($cate_id) {
|
|
$prefix = 'home-index-floor-';
|
|
$result = rcache($cate_id,$prefix);
|
|
if (empty($result)) {
|
|
$goods_model=model('goods');
|
|
//获取此楼层下的所有分类
|
|
$goods_class_list = Db::name('goodsclass')->where('gc_parent_id=' . $cate_id)->select()->toArray();
|
|
//获取每个分类下的商品
|
|
$goods_list = array();
|
|
$goods_list[0]['gc_name'] = lang('hot_recommended');
|
|
$goods_list[0]['gc_id'] = $cate_id;
|
|
$condition=$goods_model->_getRecursiveClass(array(),$cate_id,'goodscommon');
|
|
$goods_list[0]['gc_list'] = $goods_model->getGoodsUnionList($condition,'goods.*,goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.goods_marketprice,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_image,goods.goods_promotion_price,goodscommon.goods_price','goodscommon.goods_commend desc,goodscommon.goods_sort asc','goodscommon.goods_commonid', 0,10);
|
|
|
|
foreach($goods_list[0]['gc_list'] as $key => $val){
|
|
if(!$val['goods_storage']){
|
|
$goods_info=$goods_model->getGoodsStorageByCommonId($val['goods_commonid']);
|
|
if($goods_info){
|
|
$goods_list[0]['gc_list'][$key]['goods_id']=$goods_info['goods_id'];
|
|
$goods_list[0]['gc_list'][$key]['goods_promotion_price']=$goods_info['goods_promotion_price'];
|
|
}
|
|
}
|
|
}
|
|
$hot_goods_class_list = Db::name('goodsclass')->where('gc_parent_id=' . $cate_id)->order('gc_sort asc')->limit(5)->select()->toArray();
|
|
foreach ($hot_goods_class_list as $key => $hot_goods_class) {
|
|
$data = array();
|
|
$data['gc_name'] = $hot_goods_class['gc_name'];
|
|
$data['gc_id'] = $hot_goods_class['gc_id'];
|
|
$condition=$goods_model->_getRecursiveClass(array(),$data['gc_id'],'goodscommon');
|
|
$data['gc_list'] = $goods_model->getGoodsUnionList($condition,'goods.*,goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.goods_marketprice,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_image,goods.goods_promotion_price,goodscommon.goods_price','goodscommon.goods_commend desc,goodscommon.goods_sort asc','goodscommon.goods_commonid', 0,10);
|
|
foreach($data['gc_list'] as $k => $v){
|
|
if(!$v['goods_storage']){
|
|
$goods_info=$goods_model->getGoodsStorageByCommonId($v['goods_commonid']);
|
|
if($goods_info){
|
|
$data['gc_list'][$k]['goods_id']=$goods_info['goods_id'];
|
|
$data['gc_list'][$k]['goods_promotion_price']=$goods_info['goods_promotion_price'];
|
|
}
|
|
}
|
|
}
|
|
$goods_list[] = $data;
|
|
}
|
|
$result['goods_list'] = $goods_list;
|
|
$result['goods_class_list'] = $goods_class_list;
|
|
wcache($cate_id, $result,$prefix, 3600);
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
//json输出商品分类
|
|
public function josn_class() {
|
|
/**
|
|
* 实例化商品分类模型
|
|
*/
|
|
$goodsclass_model = model('goodsclass');
|
|
$goods_class = $goodsclass_model->getGoodsclassListByParentId(intval(input('get.gc_id')));
|
|
$array = array();
|
|
if (is_array($goods_class) and count($goods_class) > 0) {
|
|
foreach ($goods_class as $val) {
|
|
$array[$val['gc_id']] = array(
|
|
'gc_id' => $val['gc_id'],
|
|
'gc_name' => htmlspecialchars($val['gc_name']),
|
|
'gc_parent_id' => $val['gc_parent_id'],
|
|
'gc_sort' => $val['gc_sort']
|
|
);
|
|
}
|
|
}
|
|
|
|
echo input('param.callback') . '(' . json_encode($array) . ')';
|
|
}
|
|
|
|
/**
|
|
* json输出地址数组 public/static/plugins/area_datas.js
|
|
*/
|
|
public function json_area() {
|
|
echo input('param.callback') . '(' . json_encode(model('area')->getAreaArrayForJson()) . ')';
|
|
}
|
|
|
|
/**
|
|
* json输出地址数组
|
|
*/
|
|
public function json_area_show() {
|
|
$area_info['text'] = model('area')->getTopAreaName(intval($_GET['area_id']));
|
|
echo input('param.callback') . '(' . json_encode($area_info) . ')';
|
|
}
|
|
|
|
//判断是否登录
|
|
public function login() {
|
|
echo (session('is_login') == '1') ? '1' : '0';
|
|
}
|
|
|
|
/**
|
|
* 查询每月的周数组
|
|
*/
|
|
public function getweekofmonth() {
|
|
include_once root_path(). 'extend/mall/datehelper.php';
|
|
$year = input('get.y');
|
|
$month = input('get.m');
|
|
$week_arr = getMonthWeekArr($year, $month);
|
|
echo json_encode($week_arr);
|
|
die;
|
|
}
|
|
|
|
/**
|
|
* 头部最近浏览的商品
|
|
*/
|
|
public function viewed_info() {
|
|
$info = array();
|
|
if (session('is_login') == '1') {
|
|
$member_id = session('member_id');
|
|
$info['m_id'] = $member_id;
|
|
if (config('ds_config.voucher_allow') == 1) {
|
|
$time_to = TIMESTAMP; //当前日期
|
|
$condition = array();
|
|
$condition[] = array('voucher_owner_id','=',$member_id);
|
|
$condition[] = array('voucher_state','=',1);
|
|
$condition[] = array('voucher_startdate','<=',$time_to);
|
|
$condition[] = array('voucher_enddate','>=',$time_to);
|
|
$info['voucher'] = Db::name('voucher')->where($condition)->count();
|
|
}
|
|
$time_to = strtotime(date('Y-m-d')); //当前日期
|
|
$time_from = date('Y-m-d', ($time_to - 60 * 60 * 24 * 7)); //7天前
|
|
$consult_mod=model('consult');
|
|
$condition = array();
|
|
$condition[] = array('member_id','=',$member_id);
|
|
$condition[] = array('consult_replytime','>',strtotime($time_from));
|
|
$condition[] = array('consult_replytime','<',$time_to + 60 * 60 * 24);
|
|
$info['consult'] = $consult_mod->getConsultCount($condition);
|
|
}
|
|
$goods_list = model('goodsbrowse')->getViewedGoodsList(session('member_id'), 5);
|
|
if (is_array($goods_list) && !empty($goods_list)) {
|
|
$viewed_goods = array();
|
|
foreach ($goods_list as $key => $val) {
|
|
$goods_id = $val['goods_id'];
|
|
$val['url'] = (string)url('Goods/index', ['goods_id' => $goods_id]);
|
|
$val['goods_image'] = goods_thumb($val, 60);
|
|
$viewed_goods[$goods_id] = $val;
|
|
}
|
|
$info['viewed_goods'] = $viewed_goods;
|
|
}
|
|
echo json_encode($info);
|
|
}
|
|
|
|
}
|