<?php namespace app\controllers;
use PHPMailer\PHPMailer\PHPMailer;
use sc\Controller;
use sc\Helper;
class IndexController extends Controller
{
private $helper;
public function __construct($template = null)
{
parent::__construct($template);
$this->helper = new Helper();
$this->helper->pageNumberStyle = [
'tags' => [
'home' => '',
'last' => '',
'prev' => '«',
'next' => '»',
'jump' => ''
],
'class' => [
'normal' => '',
'active' => 'active',
'home' => '',
'last' => '',
'prev' => 'sc_pre',
'next' => 'sc_pre',
],
'length' => 5
];
}
/*导航下拉菜单产品*/
protected function getNavProTree($data, $clear = true)
{
if (!isset($prohtml)) {
static $prohtml = '';
}
foreach ($data as $datum) {
if ($datum['c_url'] != '') {
$url = $this->helper->url($datum['c_url']);
} else {
$url = $this->helper->url($datum['id']);
}
if (isset($datum['sub'])) {
$prohtml .= '<li><a href="' . $url . '">' . $datum['c_name'] . '</a><span></span><ul>';
$this->getNavProTree($datum['sub']);
$prohtml .= '</ul></li>';
} else {
$prohtml .= '<li><a href="' . $url . '">' . $datum['c_name'] . '</a></li>';
}
}
return $prohtml;
}
/*导航下拉菜单新闻*/
protected function getNavNewTree($data)
{
if (!isset($newhtml)) {
static $newhtml = '';
}
foreach ($data as $datum) {
if ($datum['c_url'] != '') {
$url = $this->helper->url('news/' . $datum['c_url']);
} else {
$url = $this->helper->url('news/' . $datum['id']);
}
if (isset($datum['sub'])) {
$newhtml .= '<li ><a href="' . $url . '">' . $datum['c_name'] . '</a><ul>';
$this->getNavNewTree($datum['sub']);
$newhtml .= '</ul></li>';
} else {
$newhtml .= '<li><a href="' . $url . '">' . $datum['c_name'] . '</a></li>';
}
}
return $newhtml;
}
/*产品页面的分类*/
protected function getProducts($data, $clear = true)
{
if (!isset($Prohtml)) {
static $Prohtml = '';
}
foreach ($data as $datum) {
if ($datum['c_url'] != '') {
$listurl = $this->helper->url($datum['c_url']);
} else {
$listurl = $this->helper->url($datum['id']);
}
if (isset($datum['sub'])) {
if($datum['pid']==1){
$Prohtml .= '<li><a href="'.$listurl.'"><span>'.$datum['c_name'].'</span><img src="'.$this->helper->to($datum['c_img']).'" alt=""></a><ul>';
}else{
$Prohtml .= '<li class="yj_xiala"> <span><a href="'.$listurl.'">'.$datum['c_name'].'</a><b class="yjt_xiala sc_p_jia"></b></span><ul>';
}
$this->getProducts($datum['sub']);
$Prohtml .= '</ul></li>';
} else {
if($datum['pid']==1){
$Prohtml .= '<li><a href="'.$listurl.'"><span>'.$datum['c_name'].'</span><img src="'.$this->helper->to($datum['c_img']).'" alt=""></a></li>';
}else{
$Prohtml .= '<li> <span><a href="'.$listurl.'">'.$datum['c_name'].'</a></span> </li>';
}
}
}
return $Prohtml;
}
/*新闻分类*/
/*产品页面的分类*/
protected function getNews($data, $clear = true)
{
if (!isset($NewsHtml)) {
static $NewsHtml = '';
}
foreach ($data as $datum) {
if ($datum['c_url'] != '') {
$listurl = $this->helper->url('news/'.$datum['c_url']);
} else {
$listurl = $this->helper->url('news/'.$datum['id']);
}
if (isset($datum['sub'])) {
$NewsHtml.='<li><i></i><a href="'.$listurl.'">'.$datum['c_name'].'</a><ul>';
$this->getNews($datum['sub']);
$NewsHtml .= '</ul></li>';
} else {
if($datum['pid']==2){
$NewsHtml.='<li><i></i><a href="'.$listurl.'">'.$datum['c_name'].'</a></li>';
}else{
$NewsHtml.='<li><a href="'.$listurl.'">'.$datum['c_name'].'</a></li>';
}
}
}
return $NewsHtml;
}
/*分类下所有产品*/
protected function getProduct($data)
{
if (!isset($Pid)) {
static $Pid = '';
}
foreach ($data as $value) {
if (isset($value['sub'])) {
$Pid .= $value['id'] . ',';
$this->getProduct($value['sub']);
} else {
$Pid .= $value['id'] . ',';
}
}
return $Pid;
}
//获取IP方法
function getRealIp()
{
$ip=false;
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
for ($i = 0; $i < count($ips); $i++) {
if (!eregi ("^(10│172.16│192.168).", $ips[$i])) {
$ip = $ips[$i];
break;
}
}
}
return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
}
/*共享参数*/
protected function GetAll($url = null)
{
$GetAll = array();
$NavigationHtml = '';//导航
$html = '';//小购物车
$id = '';//产品id
$cookieHtml='';//小购物车显示
$coinHtml = '';//货币设置
$coinhtml = '';//货币设置
$footerHtml = '';//尾部分类
$total_price = '';//总价格
$checkHtml = '';//支付路径
$CrumbHtml = '';//新闻详细页面包屑
$aboutlist = '';//about
$aboutlists='';//weibu about
$countryHtml = '';//国家下拉框
/*cookie名字切换*/
$GetAll['Name']='feng';
/*获取当前时间*/
$GetAll['time'] = date('Y-m-d H:i:s');
/*获取当前IP*/
$GetAll['ip'] = $this->getRealIp();
/*文字标签*/
$translates = $this->db->table('page')->find('p_tags')->where('p_lang=\'' . LANG . '\'')->one();
$translates = json_decode($translates['p_tags'], true);
$GetAll['translates'] = $translates;
/*导航*/
$NavigationOb = $this->db->table('nav')->find('n_name,n_url')->where('n_lang=\'' . LANG . '\' and n_sort!=0')->order('n_sort')->all();
$productlist = $this->helper->subTree($this->db->table('cate')->find('c_name,c_url,pid,id')->where('c_on=1 and c_lang=\'' . LANG . '\'')->order('c_sort')->all(), 1);
$newslist = $this->helper->subTree($this->db->table('cate')->find('c_name,c_url,pid,id')->where('c_on=1 and c_lang=\'' . LANG . '\'')->order('c_sort')->all(), 2);
/*产品下拉显示*/
$productlist = $this->getNavProTree($productlist);
/*新闻下拉显示*/
$newslist = $this->getNavNewTree($newslist);
if ($NavigationOb !== false) {
foreach ($Navigatio