<?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;
use JPush\Model as M;
use JPush\JPushClient;

class MessagesController extends HomeController {

    const VERIFY_TYPE = 12;

    public function add($verify=''){

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

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

            if($data && $message->add()){
                //@sendWX(I("name"),"访客电话为: " . I("phone"));
				
				hook('messageSaveComplete', array('name'=>I('name'),'tel'=>I('phone'),'content'=>'content'));
				
                $this->success('留言成功!');
            }else{
                $this->error('留言失败!');
            }
        }

    }


    /* 验证码，用于登录和注册 */
    public function verify(){
        $verify = new \Think\Verify();
        $verify->codeSet = '123456789';
        $verify->length = 4;
        $verify->useCurve = false;
        $verify->entry(VERIFY_TYPE);
    }

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