<?php
/**
 * AJAX数据获取
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Mobile\Controller;
class AjaxController extends BaseController{
    public function index(){exit;}
    //发送验证短信
    public function sendsms(){
       	$postdata=I('param.');
        $backdata=D('Ajax')->sendsms($postdata);
        $this->ajaxReturn($backdata);
   }
   public function sendsms_email(){
        $backdata['status']=0;
		$email=I('post.email');
        if(empty($email)){
            $backdata['msg']='邮箱不能为空';
            $this->ajaxReturn($backdata);
        }
        $data['to']=$email;
        $data['verify_code']=$data['code']=randStr(4,'0123456789');
        $result=sendbytheme($data,'EMAIL_USER_EMAIL');
        if($result=='发送成功'){$backdata['status']=1;}else{$backdata['status']=0;}
        $backdata['msg']=$result;
        $this->ajaxReturn($backdata);
   }
   public function msg_sender(){//自动发送列表消息
        $map['is_send']=$map['is_success']=0;$mod=M('SmsLogs');
        $lists=$mod->where($map)->field('id,to,from,send_type,content,uid,title')->limit(5)->order('id')->select();
        foreach($lists as $v){
            $where=array();
            $where['id']=$v['id'];
            if($v['send_type']==1){
                $sendresult=dosendemail($v['to'],$v['from'],$v['title'], $v['content']);
                if($sendresult){
                    $data['is_success']='1';
                    $data['result']='发送成功';
                }else{
                    $data['is_success']='0';
                    $data['result']=$mail->ErrorInfo;
                }
            }else{
                $sendresult=dosendsms($v['to'],$v['title']);
                $data['is_success']=$sendresult['status'];
                $data['result']=$sendresult['msg'];
            }
            $data['is_send']=1;
            $data['sendtime']=NOW_TIME;
            $mod->where($where)->save($data);
        }
   }
   
   public function getarearegion(){//调取地理区域缓存
        $return['status'] = 0;$id = intval(I('post.id'));$level = intval(I('post.level'));
        if($level==1){
            $map=array();
            $map['status']=1;
            $map['pid']=1;
            $data=M('Area')->where($map)->field('id,pid,name')->cache(true)->select();
        
            $return['status'] = 1;
            $html = '';
            foreach($data as $k=>$v){
                if(!is_numeric($k))continue;
                $html.='<li onClick="intProvince(' . ($level+1) . ',' . $v['id'] . ');">' . $v['name'] . '</li>';
            }
            $datanames = D('Common/Area')->now_area_names();//改变地区信息mobile
            $return['datanames'] = 0;
            if($datanames)$return['datanames'] = $datanames;
            $return['data'] = $html;
            $this->ajaxReturn($return);
        }
        if($id<0)$this->ajaxReturn($return);
        $result = D('Common/Area')->change_areacache_mobile($id,$level);//改变地区信息mobile
        if($result)$this->ajaxReturn($result);
   }
   public function change_mobile_index_areacache(){//切换手机端首页城市
        $return['status'] = 0;$id = intval(I('post.id'));
        if($id<0)$this->ajaxReturn($return);
        $result = D('Common/Area')->change_mobile_index_areacache($id);//改变地区信息mobile index
        if($result)$this->ajaxReturn($result);
   }
   
}
?>