<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use Common\Api;

class ZhuangxiuController extends HomeController {

    const VERIFY_TYPE = 12;
    const SMS_VERIFY_TYPE = 99;

    public function addBaojiao($verify=''){

        if (IS_POST) {
            /* 检测验证码 */

            if(!check_verify($verify,VERIFY_TYPE) ){
                $this->error('验证码输入错误！');
            }

            $message = D('Messages');
            $data =  $message->create();

            if($data && $message->add()){
                $name =  I('name');
                $phone =  I('phone');
                $content = I('content');
                if(empty($content)){
                    $content = "电话:" .I('name');
                }
                hook('messageSaveComplete', array('name'=>$name,'content'=>$content,"phone"=>$phone));

                $this->success('留言成功!');
            }else{
                $this->error('留言失败!');
            }
        }

    }

    public function addBaojiaoSMS($verify=''){

        if (IS_POST) {
            /* 检测验证码 */

            $check = new \Think\Verify();
            $check->reset = false;
            $result = $check->check($verify,self::SMS_VERIFY_TYPE) ;

            if(!$result){
                $this->error('手机验证码输入错误！');
            }

            $message = D('Messages');
            $data =  $message->create();

            if($data && $message->add()){
                $name =  I('name');
                $phone =  I('phone');
                $content = I('content');
                if(empty($content)){
                    $content = "电话:" .I('name');
                }
                hook('messageSaveComplete', array('name'=>$name,'content'=>$content,"phone"=>$phone));

                $this->success('留言成功!');
            }else{
                $this->error('留言失败!');
            }
        }

    }
    public function addBaoxiu($verify=''){

        if (IS_POST) {
            /* 检测验证码 */

            if(!check_verify($verify,VERIFY_TYPE) ){
                $this->error('验证码输入错误！');
            }


            $Think = A('Home/Think');  //参数为需要调用的模块名
            $Think->add(10);

            /*
            $message = D('Baoxiu');
            $data =  $message->create();

            if($data && $message->add()){

                $this->success('报修成功!');
            }else{
                $this->error('报修失败!');
            }
            */
        }

    }
    public function baojiaqi(){
        $this->assign("title","在线报价器");
        $this->display('Html/baojiaqi');
    }

    /* 验证码，用于登录和注册 */
    public function verify(){
        $verify = new \Think\Verify();
        $verify->codeSet = '2345689';
        $verify->length = 4;
        $verify->useCurve = false;
        $verify->useNoise = false;
        //$verify->imageW = 77;
        //$verify->imageH = 24;

        $verify->entry(VERIFY_TYPE);
    }

    /**
     * 统计留言数量
     */
    public function tongji(){
        $map['status'] = 1;
        echo(C("BAOJIAQI_XUNIRENSHU") + D('Messages')->where($map)->count());
    }

}
