<?php
// +-----------------------------------------------------------------------------------
// | Software: [ThinkPHP framework]
// | Version: V4.0
// | Site: http://www.czreg.com
// +-----------------------------------------------------------------------------------
// | Author: 飘叶 <cds425@163.com>
// | Copyright (c) 2012-2014, http://www.czreg.com All Rights Reserved.
// | time:2014.10.26
// | explain:首页
// +-----------------------------------------------------------------------------------
namespace Home\Controller;
use Think\Controller;
class IndexController extends PublicController {
    public function index(){
        $this->mainstyle = 1;
        //幻灯片输出
        $this->flash = M('Flash')->order('id desc')->limit(5)->select();
        // 公司信息输出 
        $this->my = M('Case')->order('id desc')->where('hot=1 and type=1')->find();
        //广告输出
        $this->ad = M('Ad')->order('id desc')->where(array('title'=>1))->order('position asc')->select();
        //最热产品输出
        //$this->hotpro = M('Pro')->field('id,title,img,lable,money,readnum')->where(array('hot'=>1))->order('id desc')->limit(4)->select();
        //最新新闻输出
        $newscls = M('News_cls')->where('ind=1')->order('id asc')->limit(C('INDEXNEWSCLS'))->select();
        $this->newscls = $newscls;//新闻分类
        //每类新闻最新新闻显示
        foreach ($newscls as $key=>$newscls) {
            $news[$key] = M('News')->field('id,title,timeline')->where(array('type'=>$newscls['id']))->order('id desc')->limit(C('INDEXNEWS'))->select();
        }
        $this->news = $news;
        //最新产品输出 
        $this->newpro  = M('Pro')->where(array('hot'=>1))->field('id,title,img,lable,money,readnum')->order('id desc')->limit(C('INDEXPRO'))->select();
        //友链输出
        $this->link = M('Link')->order('id desc')->limit(8)->select();
    	$this->show();
    }

    public function check_name(){
        $con['username']=I('param');
        if(!preg_match("/^(13|15|18|14|17)\d{9}$/",$con['username'])){      
            exit("手机号码格式不正确");
        } 
        $list = M('User')->where($con)->find();
        if(count($list)>0){
            echo "用户名已存在";
        }else{
            echo "y";
        }
    }

    public function quwx(){
    	$id = strtoupper(I('id'));
    	$list = M('wx')->where(array('wxno'=>$id))->find();
    	if($list['id']!=''){
    		$this->list = $list;
	        $this->log  = M('wxlog')->where(array('wxid'=>$list['id']))->order('id asc')->select();
	        $this->wxtype=C('WXTYPE');//维修类型输出
    	}
        $this->show();
    }

    public function ueupimg(){
        $config = $this->configset;//网站配置输出 
        if($config['upimg']==1){
            //使用七牛存储图片
            $setting=C('UPLOAD_SITEIMG_QINIU');
            $Upload = new \Think\Upload($setting);
            $info = $Upload->uploadOne($_FILES['upfile']);
        }else{
            //本地图片处理
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =  524288 ;// 设置附件上传大小    
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型    
            $upload->savePath  =     ''; // 设置附件上传目录
            $info   =   $upload->uploadOne($_FILES['upfile']);
        } 
        if(!$info) {
        // 上传错误提示错误信息  
            $this->error($upload->getError());    
        }else{
        // 上传成功
            $data = array(
                'originalName' =>$info['name'],//原图片名
                'state'        =>'SUCCESS',
                'type'         =>".".$info['ext'],
                'size'         =>$info['size'],
             ); 
            if($config['upimg']==1){
                $data['url']   = $config['imgurl'].$info['name'];
                $data['name']  = $info['name'];//现在的图片名
            }else{
                $data['url']   ="/Uploads/".$info['savepath'].$info['savename'];
                $data['name']  ="/Uploads/".$info['savepath'].$info['savename'];//现在的图片名
            }
            $this->ajaxReturn($data);
        }
    }
}