<?php
/**
 * 信息管理
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Admin\Controller;
class SmsController extends BaseController{
    public function _initialize() {
        parent::_initialize();
    }
    public function _before_index(){
        $sms =new \Common\Vendor\Sms;
        $this->sms_classname=$sms->sms_classname;
    } 
    public function _before_update(){
        if(empty($_POST['password']))unset($_POST['password']);
    }
	public function balance(){
		$id = I('id');
        $code=idtoname($id,'Sms','code');
        $smsclass = new \Common\Vendor\Sms($code);
        $result=$smsclass->balance();
        echo $result['msg'];
	}
    public function smssend(){
        $id = I('id');
        if(empty($id)){echo '参数错误';exit;}
        $info=idtoname($id,'SmsLogs','*','id',false);
        $data['updatetime']=NOW_TIME;
        $data['adminid']=UID;
        if($info['send_type']){
             $mail = new \Common\Vendor\PHPMailer\PHPMailer();
             $mail->CharSet    = 'UTF-8';$mail->IsSMTP();// 设th定ink使用SMTP服oao务
             $mail->SMTPAuth   = true;                  // 启用 SMTP 验证功能     
             $mail->Host       = C('EMAIL_SMTPHOST');  // SMTP 服务器
             $mail->Port       = C('EMAIL_SMTPPORT');  // SMTP服务器的端口号
             $mail->Username   = C('EMAIL_SMTPNAME');  // SMTP服务器用户名
             $mail->Password   = C('EMAIL_SMTPPASSWORD');  // SMTP服务器密码
             $mail->SetFrom(C('EMAIL_FAJIAN'), C('WEB_SITE_TITLE'));
             $mail->AddReplyTo(C('EMAIL_FAJIAN'), C('WEB_SITE_TITLE'));
             $mail->Subject    = $info['title'];
             $mail->MsgHTML($info['content']);
             $mail->AddAddress($info['to'], $info['from']);
             if($mail->Send()){
                $result=true;
                $data['is_success']='1';
                $data['result']='发送成功';
             }else{
                $result=$mail->ErrorInfo;
                $data['is_success']='0';
                $data['result']=$result;
             }
        }else{
            $sms =new \Common\Vendor\Sms;
            $smsdata['phone']=$info['to'];
            $smsdata['content']=$info['content'];
            $result=$sms->send($smsdata);
            $data['is_success']=$result['status'];
            $data['result']=$result['msg'];
        }
        M('SmsLogs')->where('id='.$id)->save($data);
        echo $data['result'];exit;
    }
}