<?php
/** App登录控制器
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaoq <xiaoq@570035208.com>
 */

namespace Pad\Controller;
class AjaxController extends BaseController {
	public function _initialize(){
        parent::_initialize ();
    }
	/**
	 * 发信息
	 */
	public function sendsms(){
		$param=I('param.');
		$model=D("Common/Ajax");
		$param['unverify'] = 1;
		$result=$model->sendsms($param);
		//转化为app返回数据统一格式
		if($result['status']!=1){
			$result['status']=3;
			$this->ajaxReturn($result);
		}
		$this->ajaxReturn($result);
	}
	/**
	 * 上传图片
	 */
    public function upload(){
        $upload = new \Think\Upload(); // 实例化上传类
        $upload->maxSize = C('UPLOAD_MAXSIZE')*1024*1024; // 设置附件上传大小
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
        $upload->rootPath = C('UPLOAD_PATH'); // 设置附件上传根目录
        $upload->savePath = 'image/'; // 设置附件上传（子）目录
        // 采用GUID序列命名
        $upload->saveName = md5();
        // 上传文件
        $info = $upload->upload();
        if (!$info) {// 上传错误提示错误信息
            $res['status'] =3;
            $res['msg'] =$upload->getError();
            $this->ajaxReturn($res);
        } else {// 上传成功
            $imgurl=str_exists($info['pic']['filename'],'http')?$info['pic']['filename']: __ROOT__.'/'.$info['pic']['filename'];
            //$imgurl=__ROOT__.'/'.$upload->rootPath. $info["pic"]["savepath"] . $info["pic"]["savename"];
            $res['status'] =1;
            $res['data'] =$imgurl;
            $this->ajaxReturn($res);
        }
        
    }

    /**
	 * 获取网站配置参数
	 */
    public function getconfig(){
        $return['status'] = 1;
        $return['data']['CONTENT_SEARCH'] = C('CONTENT_SEARCH')?explode(',',C('CONTENT_SEARCH')):'';//热门搜索关键字
        $return['data']['WEB_SITE_PHONE'] = C('WEB_SITE_PHONE');//客服电话
        $return['data']['WEB_SITE_QQ'] = C('WEB_SITE_QQ');//客服QQ
        //自定义添加
        $this->ajaxReturn($return);
    }
	/**
	 * 省市县数据
	 */
    public function linkage(){
        $return['status'] = 3;
        $id = I('param.id',0);
        $type = 0;
        $data = array();
        if(!$id)$type = 1;
        $data = get_arearegion_cache($type);
        if($id>0){$result['area'] = $data[$id];}
        if($data){
           $return['status'] = 1;
           $return['data'] = ($id>0)?$result:$data; 
        }else{
            $return['msg'] = '数据获取错误';
        }
        $this->ajaxReturn($return);
    }
    /**
    *外链
    */
    public function url_navtype(){
        $url_navtype = geturlrules(3);
        $return['status'] = 1;
        $return['url'] = $url_navtype;
        $this->ajaxReturn($return);
    }
    // 商户logo
    public function logo(){
        $shop_id = I('get.shop_id');
        $map = array();
        $map['id'] = $shop_id;
        $data = M('Shops')->where($map)->field('thumb,name')->find();
        if($data){            
            $return['status'] = 1;
            $return['data'] = $data;
        }else{
            $return['status'] = 3;
        }
        $this->ajaxReturn($return);
    }
}