You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
209 lines
8.3 KiB
209 lines
8.3 KiB
<?php
|
|
namespace apps\site\controllers;
|
|
use apps\base\controllers\FrontendController;
|
|
|
|
class IndexController extends FrontendController {
|
|
private $page = 1;
|
|
private $size = 10;
|
|
private $user_id = 0;
|
|
private $goods_id = 0;
|
|
private $region_id = 0;
|
|
private $area_info = array();
|
|
|
|
/**
|
|
* 首页信息
|
|
*/
|
|
public function actionIndex()
|
|
{
|
|
$this->init_params();
|
|
//是否开启wap
|
|
if(!$GLOBALS['_CFG']['wap_config']){
|
|
die(L('wap_config'));
|
|
}
|
|
// if(I('app')){
|
|
// $_SESSION('openid',I('app'));
|
|
// }
|
|
$this->assign('cart_number', cart_number());//购物车数量
|
|
$this->assign('hot_click', get_hot_click());// 获取热门搜索
|
|
$this->assign('store', get_store());// 获取店铺
|
|
$this->assign('brand_list', get_brand());// 获取brand
|
|
$this->assign('promotion_goods', limit_grab());// 限时购
|
|
foreach(limit_grab() as $key => $val){
|
|
$start_time = $val['promote_start_date'];
|
|
$end_time = $val['promote_end_date'];
|
|
break;
|
|
}
|
|
$logo = empty($GLOBALS['_CFG']['wap_logo']) ? __ROOT__.'themes/default/img/d_logo.png' : $GLOBALS['_CFG']['wap_logo'];
|
|
$app = $GLOBALS['_CFG']['wap_index_pro'] ? 1 :0 ;
|
|
$this->assign('app',$app);
|
|
$this->assign('logo',$logo);
|
|
$this->assign('end_time',$end_time);
|
|
$this->assign('best_goods', goods_list('best', $this->page, $this->size,$this->region_id, $this->area_info['region_id'])); // 推荐商品
|
|
$sql = "SELECT * FROM {pre}touch_nav WHERE ifshow=1 order by vieworder asc, id asc";
|
|
$nav = $this->db->getAll($sql);
|
|
$position = assign_ur_here($goods['cat_id'], $goods['goods_name']);
|
|
$this->assign('page_title', $position['title']);
|
|
$this->assign('nav',$nav);
|
|
//get_ads('index');
|
|
|
|
$this->display('index');
|
|
}
|
|
/**
|
|
* 异步加载商品列表
|
|
*/
|
|
|
|
public function actionAsyncList(){
|
|
if(IS_AJAX){
|
|
$this->init_params();
|
|
$this->size = I('size');
|
|
$this->page = I('page');
|
|
$get_goods_list = goods_list('hot', $this->page, $this->size, $this->region_id, $this->area_info['region_id']);
|
|
$count = count_number('hot');
|
|
$count = ceil($count/$this->size);
|
|
shuffle($get_goods_list);
|
|
die(json_encode(array('list'=>($get_goods_list), 'totalPage'=>$count)));
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 更多
|
|
*/
|
|
public function actionMore(){
|
|
//取得店铺标题
|
|
$page_title = $GLOBALS['_CFG']['shop_title'];
|
|
$this->assign('page_title',$page_title);
|
|
$this->display('more');
|
|
}
|
|
|
|
/**
|
|
* 初始化参数
|
|
*/
|
|
private function init_params(){
|
|
#需要查询的IP start
|
|
|
|
if(!isset($_COOKIE['province'])){
|
|
$area_array = get_ip_area_name();
|
|
|
|
if($area_array['county_level'] == 2){
|
|
$date = array('region_id', 'parent_id', 'region_name');
|
|
$where = "region_name = '" .$area_array['area_name']. "' AND region_type = 2";
|
|
$city_info = get_table_date('region', $where, $date, 1);
|
|
|
|
$date = array('region_id', 'region_name');
|
|
$where = "region_id = '" .$city_info[0]['parent_id']. "'";
|
|
$province_info = get_table_date('region', $where, $date);
|
|
|
|
$where = "parent_id = '" .$city_info[0]['region_id']. "' order by region_id asc limit 0, 1";
|
|
$district_info = get_table_date('region', $where, $date, 1);
|
|
|
|
}elseif($area_array['county_level'] == 1){
|
|
$area_name = $area_array['area_name'];
|
|
|
|
$date = array('region_id', 'region_name');
|
|
$where = "region_name = '$area_name'";
|
|
$province_info = get_table_date('region', $where, $date);
|
|
|
|
$where = "parent_id = '" .$province_info['region_id']. "' order by region_id asc limit 0, 1";
|
|
$city_info = get_table_date('region', $where, $date, 1);
|
|
|
|
$where = "parent_id = '" .$city_info[0]['region_id']. "' order by region_id asc limit 0, 1";
|
|
$district_info = get_table_date('region', $where, $date, 1);
|
|
}
|
|
}
|
|
#需要查询的IP end
|
|
$order_area = get_user_order_area($this->user_id);
|
|
$user_area = get_user_area_reg($this->user_id); //2014-02-25
|
|
|
|
if($order_area['province'] && $this->user_id > 0){
|
|
$this->province_id = $order_area['province'];
|
|
$this->city_id = $order_area['city'];
|
|
$this->district_id = $order_area['district'];
|
|
}else{
|
|
//省
|
|
if($user_area['province'] > 0){
|
|
$this->province_id = $user_area['province'];
|
|
setcookie('province', $user_area['province'], gmtime() + 3600 * 24 * 30);
|
|
$this->region_id = get_province_id_warehouse($this->province_id);
|
|
}else{
|
|
$sql = "select region_name from " .$this->ecs->table('region_warehouse'). " where regionId = '" .$province_info['region_id']. "'";
|
|
$warehouse_name = $this->db->getOne($sql);
|
|
|
|
$this->province_id = $province_info['region_id'];
|
|
$cangku_name = $warehouse_name;
|
|
$this->region_id = get_warehouse_name_id(0, $cangku_name);
|
|
}
|
|
//市
|
|
if($user_area['city'] > 0){
|
|
$this->city_id = $user_area['city'];
|
|
setcookie('city', $user_area['city'], gmtime() + 3600 * 24 * 30);
|
|
}else{
|
|
$this->city_id = $city_info[0]['region_id'];
|
|
}
|
|
//区
|
|
if($user_area['district'] > 0){
|
|
$this->district_id = $user_area['district'];
|
|
setcookie('district', $user_area['district'], gmtime() + 3600 * 24 * 30);
|
|
}else{
|
|
$this->district_id = $district_info[0]['region_id'];
|
|
}
|
|
}
|
|
|
|
$this->province_id = isset($_COOKIE['province']) ? $_COOKIE['province'] : $this->province_id;
|
|
|
|
$child_num = get_region_child_num($this->province_id);
|
|
if($child_num > 0){
|
|
$this->city_id = isset($_COOKIE['city']) ? $_COOKIE['city'] : $this->city_id;
|
|
}else{
|
|
$this->city_id = '';
|
|
}
|
|
|
|
$child_num = get_region_child_num($this->city_id);
|
|
if($child_num > 0){
|
|
$this->district_id = isset($_COOKIE['district']) ? $_COOKIE['district'] : $this->district_id;
|
|
}else{
|
|
$this->district_id = '';
|
|
}
|
|
|
|
$this->region_id = !isset($_COOKIE['region_id']) ? $this->region_id : $_COOKIE['region_id'];
|
|
$goods_warehouse = get_warehouse_goods_region($this->province_id); //查询用户选择的配送地址所属仓库
|
|
if($goods_warehouse){
|
|
$this->regionId = $goods_warehouse['region_id'];
|
|
if($_COOKIE['region_id'] && $_COOKIE['regionId']){
|
|
$gw = 0;
|
|
}else{
|
|
$gw = 1;
|
|
|
|
}
|
|
}
|
|
if($gw){
|
|
$this->region_id = $this->regionId;
|
|
setcookie('area_region', $this->region_id, gmtime() + 3600 * 24 * 30);
|
|
}
|
|
|
|
setcookie('goodsId', $this->goods_id, gmtime() + 3600 * 24 * 30);
|
|
|
|
$sellerInfo = get_seller_info_area();
|
|
if(empty($this->province_id)){
|
|
$this->province_id = $sellerInfo['province'];
|
|
$this->city_id = $sellerInfo['city'];
|
|
$this->district_id = 0;
|
|
|
|
setcookie('province', $this->province_id, gmtime() + 3600 * 24 * 30);
|
|
setcookie('city', $this->city_id, gmtime() + 3600 * 24 * 30);
|
|
setcookie('district', $this->district_id, gmtime() + 3600 * 24 * 30);
|
|
|
|
$this->region_id = get_warehouse_goods_region($this->province_id);
|
|
}
|
|
//ecmoban模板堂 --zhuo end 仓库
|
|
$this->area_info = get_area_info($this->province_id);
|
|
}
|
|
|
|
/**
|
|
* 数据迁移
|
|
*/
|
|
public function actionMigrate(){
|
|
\libraries\Migrate::init();
|
|
show_message('数据迁移成功', '返回首页', U('site/index/index'), 'success');
|
|
}
|
|
}
|
|
|