Forráskód Böngészése

计量支付短信通知

后台、前端页面短信功能设置,手机号码验证
NoNZero 8 éve
szülő
commit
ce43f6f3c4

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 2 - 0
global/js/jquery.cookie.min.js


+ 1 - 0
index.php

@@ -5,6 +5,7 @@ include './protected/config/routes.conf.php';
 include './protected/config/db.conf.php';
 include './protected/config/acl.conf.php';
 include './protected/config/ver.conf.php';
+include './protected/config/sms.conf.php';
 #Just include this for production mode
 //include $config['BASE_PATH'].'deployment/deploy.php';
 include $config['BASE_PATH'] . 'Doo.php';

+ 14 - 0
protected/class/auth.php

@@ -67,6 +67,20 @@ class Auth
         return $_SESSION['uid'] = $uid;
     }
 
+    public function setVerifyMobile($array = array('mobile' => 0, 'code' => 0))
+    {
+        $_SESSION['verifymobile'] = $array;
+    }
+
+    public function getVerifyMobile()
+    {
+        if (isset($_SESSION['verifymobile']) && $_SESSION['verifymobile']) {
+            return $_SESSION['verifymobile'];
+        } else {
+            return FALSE;
+        }
+    }
+
     public function setUemail($uemail)
     {
         return $_SESSION['uemail'] = $uemail;

+ 51 - 34
protected/class/profile.php

@@ -2,53 +2,70 @@
 
 Doo::loadModel('uprofile');
 
-class Profile {
+class Profile
+{
 
     private $uprofile;
 
-    public function __construct() {
-	$this->uprofile = new Uprofile();
+    public function __construct()
+    {
+        $this->uprofile = new Uprofile();
     }
 
-    public function insertProfile($intp = array()) {
-	if (!isset($intp['userid']))
-	    return FALSE;
-	$this->uprofile->userid = filter_var($intp['userid'], FILTER_VALIDATE_INT);
-	$this->uprofile->name = filter_var($intp['realname'], FILTER_SANITIZE_STRING);
-	$this->uprofile->company = filter_var($intp['company'], FILTER_SANITIZE_STRING);
-	$this->uprofile->jobs = filter_var($intp['jobs'], FILTER_SANITIZE_STRING);
-	$this->uprofile->phone = filter_var($intp['phone'], FILTER_SANITIZE_STRING);
-	$this->uprofile->mobile = filter_var($intp['mobile'], FILTER_SANITIZE_STRING);
-	if (isset($intp['qq']))
-	    $this->uprofile->qq = filter_var($intp['qq'], FILTER_SANITIZE_STRING);
-	$this->uprofile->groups = 'vip';
-	return $this->uprofile->insert();
+    public function insertProfile($intp = array())
+    {
+        if (!isset($intp['userid']))
+            return FALSE;
+        $this->uprofile->userid = filter_var($intp['userid'], FILTER_VALIDATE_INT);
+        $this->uprofile->name = filter_var($intp['realname'], FILTER_SANITIZE_STRING);
+        $this->uprofile->company = filter_var($intp['company'], FILTER_SANITIZE_STRING);
+        $this->uprofile->jobs = filter_var($intp['jobs'], FILTER_SANITIZE_STRING);
+        $this->uprofile->phone = filter_var($intp['phone'], FILTER_SANITIZE_STRING);
+        $this->uprofile->mobile = filter_var($intp['mobile'], FILTER_SANITIZE_STRING);
+        if (isset($intp['qq']))
+            $this->uprofile->qq = filter_var($intp['qq'], FILTER_SANITIZE_STRING);
+        $this->uprofile->groups = 'vip';
+        return $this->uprofile->insert();
     }
 
-    public function getProWithUid($userid = 0) {
-	if (!isset($userid))
-	    return FALSE;
-	return $this->uprofile->getOne(array('where' => 'userid=?', 'param' => array($userid), 'asArray' => TRUE));
+    public function getProWithUid($userid = 0)
+    {
+        if (!isset($userid))
+            return FALSE;
+        return $this->uprofile->getOne(array('where' => 'userid=?', 'param' => array($userid), 'asArray' => TRUE));
     }
 
-    public function setAvatar($userid = 0, $avaurl) {
-	if (!isset($userid))
-	    return FALSE;
-	$this->uprofile->avatar = $avaurl;
-	return $this->uprofile->update(array('where' => 'userid=?', 'param' => array($userid)));
+    public function setAvatar($userid = 0, $avaurl)
+    {
+        if (!isset($userid))
+            return FALSE;
+        $this->uprofile->avatar = $avaurl;
+        return $this->uprofile->update(array('where' => 'userid=?', 'param' => array($userid)));
     }
 
-    public function upProfile($userid, $proArray) {
-	$this->uprofile->name = $proArray['name'];
-	$this->uprofile->company = $proArray['company'];
-	$this->uprofile->jobs = $proArray['jobs'];
-	$this->uprofile->phone = $proArray['phone'];
-	$this->uprofile->mobile = $proArray['mobile'];
-	if (isset($proArray['qq']) && $proArray['qq'])
-	    $this->uprofile->qq = $proArray['qq'];
-	return $this->uprofile->update(array('where' => 'userid=?', 'param' => array($userid)));
+    public function upProfile($userid, $proArray)
+    {
+        $this->uprofile->name = $proArray['name'];
+        $this->uprofile->company = $proArray['company'];
+        $this->uprofile->jobs = $proArray['jobs'];
+        $this->uprofile->phone = $proArray['phone'];
+        $this->uprofile->mobile = $proArray['mobile'];
+        if (isset($proArray['qq']) && $proArray['qq'])
+            $this->uprofile->qq = $proArray['qq'];
+        return $this->uprofile->update(array('where' => 'userid=?', 'param' => array($userid)));
     }
 
+    public function updateMobile($userid, $mobile)
+    {
+        $this->uprofile->mobile = $mobile;
+        $this->uprofile->isnotice = 1;
+        return $this->uprofile->update(array('where' => 'userid=?', 'param' => array($userid)));
+    }
+
+    public function checkMobile($number)
+    {
+        return $this->uprofile->count(array('where' => 'mobile=?', 'param' => array($number), 'asArray' => TRUE));
+    }
 }
 
 ?>

+ 83 - 0
protected/class/sms.php

@@ -0,0 +1,83 @@
+<?php
+
+class Sms
+{
+    private $api_url, $auth_key, $errorMsg;
+
+    function __construct($api_url, $auth_key)
+    {
+        $this->api_url = $api_url;
+        $this->auth_key = $auth_key;
+    }
+
+    /**
+     * 实现短信验证码接口
+     *
+     */
+    public function sendSms($mobile, $code)
+    {
+        $send = array(
+            'apikey' => $this->auth_key,
+            'mobile' => $mobile,
+            'text' => $code
+        );
+        $data = http_build_query($send);
+        $res = json_decode($this->_httpClient($this->api_url, $data));
+        $resArr = $this->objectToArray($res);
+        if (!empty($resArr) && $resArr["code"] == 0) {
+            return true;
+        } else {
+            if (empty($this->errorMsg)) $this->errorMsg = isset($resArr["msg"]) ? $resArr["msg"] : '未知错误';
+            return false;
+        }
+    }
+
+    //对象转数组,使用get_object_vars返回对象属性组成的数组
+    function objectToArray($array)
+    {
+        if (is_object($array)) {
+            $array = (array)$array;
+        }
+        if (is_array($array)) {
+            foreach ($array as $key => $value) {
+                $array[$key] = $this->objectToArray($value);
+            }
+        }
+        return $array;
+    }
+
+    /**
+     * POST方式访问短信接口
+     * @param string $data
+     * @return mixed
+     */
+    private function _httpClient($api_url, $data)
+    {
+        try {
+            $ch = curl_init();
+            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8', 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
+            curl_setopt($ch, CURLOPT_URL, $api_url);
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+            curl_setopt($ch, CURLOPT_POST, 1);
+            curl_setopt($ch, CURLOPT_TIMEOUT, 10);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
+            $res = curl_exec($ch);
+            curl_close($ch);
+            return $res;
+        } catch (Exception $e) {
+            $this->errorMsg = $e->getMessage();
+            return false;
+        }
+    }
+
+    /**
+     * POST方式访问短信接口
+     * @param string $data
+     * @return mixed
+     */
+    public function getErrors()
+    {
+        return $this->errorMsg;
+    }
+}

+ 2 - 0
protected/config/routes.conf.php

@@ -31,6 +31,8 @@ $route['get']['/sproject/:pid/section/measure'] = array('SProjectController', 'p
 $route['*']['/user/profile'] = array('UserController', 'index');
 $route['*']['/user/profile/sms'] = array('UserController', 'sms');
 $route['*']['/user/profile/sms/edit'] = array('UserController', 'smsEdit');
+$route['*']['/user/profile/check/mobile'] = array('UserController', 'checkMobile');
+$route['*']['/user/profile/sms/send/verify'] = array('UserController', 'smsSend');
 $route['*']['/user/avatar'] = array('UserController', 'avatar');
 $route['*']['/user/repasswd'] = array('UserController', 'repasswd');
 // Client API

+ 5 - 0
protected/config/sms.conf.php

@@ -0,0 +1,5 @@
+<?php
+$config['SMS_URL'] = 'http://sms.haotingyun.com/v2/sms/single_send.json';
+$config['SMS_AUTHKEY'] = 'fb5ef483e44b9556512a9febef376051';
+$config['SMS_TIPS'] = array('AUDIT_NOTICE' => '【纵横通行账号】您的验证码是', 'END_MSG' => ',15分钟内有效。');
+

+ 75 - 11
protected/controller/UserController.php

@@ -1,5 +1,5 @@
 <?php
-
+ini_set('display_errors', 1);
 Doo::loadClass('auth');
 Doo::loadClass('attfile');
 Doo::loadClass('profile');
@@ -9,6 +9,9 @@ Doo::loadClass('actmeasure');
 Doo::loadClass('numofperact');
 Doo::loadClass('user');
 Doo::loadClass('PasswordHash');
+Doo::loadClass('sms');
+Doo::loadModelAt('aconfig', 'admin');
+Doo::loadClass('measureauditact');
 
 /* * proDetail
  * MainController
@@ -20,7 +23,7 @@ Doo::loadClass('PasswordHash');
 class UserController extends DooController
 {
 
-    private $data, $auth, $attfile, $profile, $project, $contractact, $actmeasure, $numofperact, $user, $ph;
+    private $data, $auth, $attfile, $profile, $project, $contractact, $actmeasure, $numofperact, $user, $ph, $sms, $aconfig;
 
     public function beforeRun($resource, $action)
     {
@@ -40,6 +43,7 @@ class UserController extends DooController
 
     public function __construct()
     {
+        $this->data['numofchecking'] = null;
         $this->auth = new Auth();
         $this->attfile = new attFile();
         $this->profile = new Profile();
@@ -49,9 +53,22 @@ class UserController extends DooController
         $this->numofperact = new NumofperAct();
         $this->user = new User();
         $this->ph = new PasswordHash(8, FALSE);
+        $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_AUTHKEY);
+        $this->aconfig = new AConfig();
+        $this->measureauditact = new MeasureauditAct();
         $this->data['rootUrl'] = Doo::conf()->APP_URL;
         $this->data['currChannle'] = 'p';
         $this->data['user'] = $this->profile->getProWithUid($this->auth->getUid());
+        $mpidArray = $this->measureauditact->getAuditProject2($this->auth->getUid());
+        if (isset($mpidArray[0]['pid'])) {
+            foreach ($mpidArray as $key => $value) {
+                // 审批操作按照时间排序多标段
+                $this->data['numofchecking'] += $this->measureauditact->getCountMyChecking($value['pid'], $this->auth->getUid());
+            }
+        }
+        if ($this->data['numofchecking'] == 0) {
+            $this->data['numofchecking'] = null;
+        }
     }
 
     /**
@@ -62,7 +79,7 @@ class UserController extends DooController
     {
         $this->data['uprofile'] = $this->profile->getProWithUid($this->auth->getUid());
         $this->data['uprofile']['email'] = $this->auth->getUemail();
-        if (isset($_POST['name']) && isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['phone']) && isset($_POST['mobile'])) {
+        if (isset($_POST['name']) && isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['phone'])) {
             $this->profile->upProfile($this->auth->getUid(), $_POST);
             return DOO::conf()->APP_URL . 'user/profile';
         }
@@ -223,28 +240,77 @@ class UserController extends DooController
      */
     public function sms()
     {
-//        $this->data['uprofile'] = $this->profile->getProWithUid($this->auth->getUid());
+        if (isset($_POST['mobile']) && isset($_POST['verifycode'])) {
+            $vmArray = $this->auth->getVerifyMobile();
+            if (isset($vmArray) && $vmArray) {
+                if (md5($_POST['mobile'] . $_POST['verifycode']) == md5($vmArray['mobile'] . $vmArray['code'])) {
+                    $this->profile->updateMobile($this->auth->getUid(), $vmArray['mobile']);
+                    return Doo::conf()->APP_URL . 'user/profile/sms';
+                }
+            }
+        }
+        $this->data['uprofile'] = $this->profile->getProWithUid($this->auth->getUid());
+        $this->data['smsNoticeSwitch'] = $this->aconfig->getOne(array('select' => 'smsswitch', 'asArray' => TRUE))['smsswitch'];
+        $this->render('edit-profile-sms', $this->data, TRUE);
+    }
+
+    /**
+     *
+     * @return type
+     */
+    public function smsEdit()
+    {
+        if (isset($_POST['mobile']) && isset($_POST['verifycode'])) {
+            $vmArray = $this->auth->getVerifyMobile();
+            if (isset($vmArray) && $vmArray) {
+                if (md5($_POST['mobile'] . $_POST['verifycode']) == md5($vmArray['mobile'] . $vmArray['code'])) {
+                    $this->profile->updateMobile($this->auth->getUid(), $vmArray['mobile']);
+                    return Doo::conf()->APP_URL . 'user/profile/sms/edit';
+                }
+            }
+        }
+        $this->data['uprofile'] = $this->profile->getProWithUid($this->auth->getUid());
+        $this->render('edit-profile-sms-edit', $this->data, TRUE);
+    }
+
+    /**
+     *
+     * @return type
+     */
+    public function checkMobile()
+    {
 //        $this->data['uprofile']['email'] = $this->auth->getUemail();
 //        if (isset($_POST['name']) && isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['phone']) && isset($_POST['mobile'])) {
 //            $this->profile->upProfile($this->auth->getUid(), $_POST);
 //            return DOO::conf()->APP_URL . 'user/profile';
 //        }
-        $this->render('edit-profile-sms', $this->data, TRUE);
+        die(json_encode(array('mobile' => (int)$this->profile->checkMobile($_POST['mobile']))));
     }
 
     /**
      *
      * @return type
      */
-    public function smsEdit()
+    public function mobileVerify()
     {
-//        $this->data['uprofile'] = $this->profile->getProWithUid($this->auth->getUid());
 //        $this->data['uprofile']['email'] = $this->auth->getUemail();
 //        if (isset($_POST['name']) && isset($_POST['company']) && isset($_POST['jobs']) && isset($_POST['phone']) && isset($_POST['mobile'])) {
 //            $this->profile->upProfile($this->auth->getUid(), $_POST);
 //            return DOO::conf()->APP_URL . 'user/profile';
 //        }
-        $this->render('edit-profile-sms-edit', $this->data, TRUE);
+        die(json_encode(array('mobile' => (int)$this->profile->checkMobile($_POST['mobile']))));
+    }
+
+    /**
+     *
+     * @return type
+     */
+    public function smsSend()
+    {
+        $randNum = rand(1000, 9999);
+        $this->auth->setVerifyMobile(array('mobile' => $_POST['mobile'], 'code' => $randNum));
+        $res = $this->sms->sendSms($_POST['mobile'], Doo::conf()->SMS_TIPS['AUDIT_NOTICE'] . $randNum . Doo::conf()->SMS_TIPS['END_MSG']);
+        die(json_encode(array('verify' => $res)));
     }
 
 
@@ -453,9 +519,7 @@ class UserController extends DooController
 //	    closedir($handle);
 //	}
 //	$this->data['proArray'] = null;
-        $this->render('s-project
-
-	', $this->data);
+        $this->render('s-project', $this->data);
     }
 
 // ajax提取密码名称

+ 7 - 4
protected/model/uprofile.php

@@ -5,7 +5,8 @@ Doo::loadCore('db/DooModel');
 /**
  * 用户表
  */
-class Uprofile extends DooModel {
+class Uprofile extends DooModel
+{
 
     public $userid;
     public $name;
@@ -16,12 +17,14 @@ class Uprofile extends DooModel {
     public $qq;
     public $groups;
     public $avatar;
+    public $isnotice;
     public $_table = 'jl_user_profiles';
     public $_primarykey = 'userid';
-    public $_fields = array('userid', 'name', 'company', 'jobs', 'phone', 'mobile', 'qq', 'groups','avatar');
+    public $_fields = array('userid', 'name', 'company', 'jobs', 'phone', 'mobile', 'qq', 'groups', 'avatar', 'isnotice');
 
-    public function __construct() {
-	parent::setupModel(__CLASS__);
+    public function __construct()
+    {
+        parent::setupModel(__CLASS__);
     }
 
 }

+ 113 - 13
protected/view/edit-profile-sms-edit.html

@@ -10,6 +10,7 @@
     <script src={{rootUrl}}global/js/jquery-1.9.1.min.js></script>
     <script src={{rootUrl}}global/js/bootstrap.js></script>
     <script src={{rootUrl}}global/js/jl.js></script>
+    <script src={{rootUrl}}global/js/jquery.cookie.min.js></script>
 </head>
 <body>
 <!-- include "top" -->
@@ -29,33 +30,31 @@
                     <div class="control-group">
                         <label class="control-label" for="inputEmail">当前手机</label>
                         <div class="controls">
-                            <input type="text" placeholder="17875434567" disabled="">
+                            <input type="text" placeholder="{{uprofile.mobile}}" disabled="">
                         </div>
                     </div>
-                    <div class="control-group">
-                        <label class="control-label" for="inputEmail">新手机</label>
-                        <div class="controls">
-                            <input type="text" placeholder="输入您的新手机号码">
-                        </div>
-                    </div>
-                    <div class="control-group error">
+                    <div id="input_error" class="control-group">
                         <label class="control-label" for="inputEmail">新手机</label>
                         <div class="controls">
-                            <input type="text" placeholder="输入您的新手机号码"><span class="help-inline">手机号码已被使用</span>
+                            <input id="mobile" name="mobile" type="text" placeholder="输入您的新手机号码"><span id="help-inline"
+                                                                                                       class="help-inline hide"></span>
                         </div>
                     </div>
                     <div class="control-group">
                         <label class="control-label" for="inputEmail">短信校验码</label>
                         <div class="controls">
-                            <input type="text" placeholder="输入验证码" class="span2">
-                            <button class="btn">获取验证码</button>
-                            <button class="btn" disabled>重新获取 60s</button>
+                            <input type="text" id="verifycode" name="verifycode" placeholder="输入验证码" maxlength="11"
+                                   class="span2">
+                            <!--<button class="btn">获取验证码</button>-->
+                            <!--<button class="btn" disabled>重新获取 60s</button>-->
+                            <input type="button" class="btn" id="getting" value="获取验证码">
                         </div>
                     </div>
                     <div class="control-group">
                         <label class="control-label"></label>
                         <div class="controls">
-                            <a class="btn btn-primary" href="welcome - 1.html"><i class="icon-ok icon-white"></i>&nbsp;确定修改</a>
+                            <i class="icon-ok icon-white"></i><input type="button" id="addMobile"
+                                                                     class="btn btn-primary" value="确定修改"/>
                         </div>
                     </div>
                     </fieldset>
@@ -66,4 +65,105 @@
     </div>
 </div>
 <script type="text/javascript">autoFlashHeight();</script>
+<script type="text/javascript">
+    $(document).ready(function () {
+        $("#mobile").blur(function () {
+            $.ajax({
+                type: "POST",
+                dataType: "json",
+                cache: false,
+                data: {"mobile": $(this).val()},
+                url: "{{rootUrl}}user/profile/check/mobile",
+            }).done(function (data) {
+                if (data['mobile'] > 0) {
+                    $("#input_error").addClass('error');
+                    $("#help-inline").html('手机号码已被使用');
+                    $("#help-inline").show();
+                } else {
+                    $("#input_error").removeClass('error');
+                    $("#help-inline").hide();
+                }
+            });
+        });
+
+
+        /*仿刷新:检测是否存在cookie*/
+        if ($.cookie("sms")) {
+            var count = $.cookie("sms");
+            var btn = $('#getting');
+            btn.val('重新获取 ' + count + 's').attr('disabled', true).css('cursor', 'not-allowed');
+            var resend = setInterval(function () {
+                count--;
+                if (count > 0) {
+                    btn.val('重新获取 ' + count + 's').attr('disabled', true).css('cursor', 'not-allowed');
+                    $.cookie("sms", count, {path: '/', expires: (1 / 86400) * count});
+                } else {
+                    clearInterval(resend);
+                    btn.val("获取验证码").removeClass('disabled').removeAttr('disabled style');
+                }
+            }, 1000);
+        }
+
+        /*点击改变按钮状态,已经简略掉ajax发送短信验证的代码*/
+        $('#getting').click(function () {
+            var btn = $(this);
+            if ($("#mobile").val() == '') {
+                $("#input_error").addClass('error');
+                $("#help-inline").html('手机号码不能为空');
+                $("#help-inline").show();
+                return false;
+            }
+            $.ajax({
+                type: "POST",
+                dataType: "json",
+                cache: false,
+                data: {"mobile": $("#mobile").val()},
+                url: "{{rootUrl}}user/profile/check/mobile",
+            }).done(function (data) {
+                if (data['mobile'] > 0) {
+                    $("#input_error").addClass('error');
+                    $("#help-inline").html('手机号码已被使用');
+                    $("#help-inline").show();
+                    return false;
+                } else {
+                    $("#input_error").removeClass('error');
+                    $("#help-inline").hide();
+                    $.ajax({
+                        type: "POST",
+                        dataType: "json",
+                        cache: false,
+                        data: {"mobile": $("#mobile").val()},
+                        url: "{{rootUrl}}user/profile/sms/send/verify",
+                    }).done(function (data) {
+                    });
+                    var count = 60;
+                    var resend = setInterval(function () {
+                        count--;
+                        if (count > 0) {
+                            btn.val('重新获取 ' + count + 's');
+                            $.cookie("sms", count, {path: '/', expires: (1 / 86400) * count});
+                        } else {
+                            clearInterval(resend);
+                            btn.val("获取验证码").removeAttr('disabled style');
+                        }
+                    }, 1000);
+                    btn.attr('disabled', true).css('cursor', 'not-allowed');
+                }
+            });
+        });
+
+        /*点击改变按钮状态,已经简略掉ajax发送短信验证的代码*/
+        $('#addMobile').click(function () {
+            $.ajax({
+                type: "POST",
+                dataType: "json",
+                cache: false,
+                data: {"mobile": $("#mobile").val(), "verifycode": $("#verifycode").val()},
+                url: "{{rootUrl}}user/profile/sms/edit",
+            }).done(function (data) {
+                window.location.reload(true);
+            });
+        });
+    });
+</script>
 </body>

+ 125 - 18
protected/view/edit-profile-sms.html

@@ -10,6 +10,7 @@
     <script src={{rootUrl}}global/js/jquery-1.9.1.min.js></script>
     <script src={{rootUrl}}global/js/bootstrap.js></script>
     <script src={{rootUrl}}global/js/jl.js></script>
+    <script src={{rootUrl}}global/js/jquery.cookie.min.js></script>
 </head>
 <body>
 <!-- include "top" -->
@@ -26,42 +27,49 @@
             <div class="form">
                 <form class="form-horizontal">
                     <legend>短信通知</legend>
+                    <!-- if {{smsNoticeSwitch}} < 1 -->
+                    <!--管理员关闭功能-->
+                    <div class="alert alert-error">
+                        短信通知功能已被关闭。
+                    </div>
+                    <!--管理员关闭功能-->
+                    <!-- else -->
+                    <!-- if {{uprofile.isnotice}} < 1 -->
                     <!--初次使用-->
                     <div class="alert alert-info">
                         初次使用,请先添加用于接收通知的手机号码。
                     </div>
-                    <div class="control-group">
+                    <div id="input_error" class="control-group">
                         <label class="control-label" for="inputEmail">添加手机</label>
                         <div class="controls">
-                            <input type="text" placeholder="输入您的手机号码">
-                        </div>
-                    </div>
-                    <div class="control-group error">
-                        <label class="control-label" for="inputEmail">添加手机</label>
-                        <div class="controls">
-                            <input type="text" placeholder="输入您的新手机号码"><span class="help-inline">手机号码已被使用</span>
+                            <input id="mobile" name="mobile" type="text" placeholder="输入您的新手机号码"><span id="help-inline"
+                                                                                                       class="help-inline hide"></span>
                         </div>
                     </div>
                     <div class="control-group">
                         <label class="control-label" for="inputEmail">短信校验码</label>
                         <div class="controls">
-                            <input type="text" placeholder="输入验证码" class="span2">
-                            <button class="btn">获取验证码</button>
-                            <button class="btn" disabled>重新获取 60s</button>
+                            <input type="text" id="verifycode" name="verifycode" placeholder="输入验证码" maxlength="11"
+                                   class="span2">
+                            <!--<button class="btn">获取验证码</button>-->
+                            <!--<button class="btn" disabled>重新获取 60s</button>-->
+                            <input type="button" class="btn" id="getting" value="获取验证码">
                         </div>
                     </div>
                     <div class="control-group">
                         <label class="control-label"></label>
                         <div class="controls">
-                            <a class="btn btn-primary" href="welcome - 1.html"><i class="icon-ok icon-white"></i>&nbsp;确定添加</a>
+                            <i class="icon-ok icon-white"></i><input type="button" id="addMobile"
+                                                                     class="btn btn-primary" value="确定添加"/>
                         </div>
                     </div>
                     <!--初次使用-->
+                    <!-- else -->
                     <!--正常使用-->
                     <div class="control-group">
                         <label class="control-label" for="inputEmail">接收手机</label>
                         <div class="controls">
-                            <input type="text" value="15678987654" disabled="">&nbsp;<a
+                            <input type="text" value="{{uprofile.mobile}}" disabled="">&nbsp;<a
                                 href="{{rootUrl}}user/profile/sms/edit">修改手机</a>
                         </div>
                     </div>
@@ -74,11 +82,8 @@
                         </div>
                     </div>
                     <!--正常使用-->
-                    <!--管理员关闭功能-->
-                    <div class="alert alert-error">
-                        短信通知功能已被关闭。
-                    </div>
-                    <!--管理员关闭功能-->
+                    <!-- endif -->
+                    <!-- endif -->
                     </fieldset>
                 </form>
             </div>
@@ -87,4 +92,106 @@
     </div>
 </div>
 <script type="text/javascript">autoFlashHeight();</script>
+<script type="text/javascript">
+    $(document).ready(function () {
+        $("#mobile").blur(function () {
+            $.ajax({
+                type: "POST",
+                dataType: "json",
+                cache: false,
+                data: {"mobile": $(this).val()},
+                url: "{{rootUrl}}user/profile/check/mobile",
+            }).done(function (data) {
+                if (data['mobile'] > 0) {
+                    $("#input_error").addClass('error');
+                    $("#help-inline").html('手机号码已被使用');
+                    $("#help-inline").show();
+                } else {
+                    $("#input_error").removeClass('error');
+                    $("#help-inline").hide();
+                }
+            });
+        });
+
+
+        /*仿刷新:检测是否存在cookie*/
+        if ($.cookie("sms")) {
+            var count = $.cookie("sms");
+            var btn = $('#getting');
+            btn.val('重新获取 ' + count + 's').attr('disabled', true).css('cursor', 'not-allowed');
+            var resend = setInterval(function () {
+                count--;
+                if (count > 0) {
+                    btn.val('重新获取 ' + count + 's').attr('disabled', true).css('cursor', 'not-allowed');
+                    $.cookie("sms", count, {path: '/', expires: (1 / 86400) * count});
+                } else {
+                    clearInterval(resend);
+                    btn.val("获取验证码").removeClass('disabled').removeAttr('disabled style');
+                }
+            }, 1000);
+        }
+
+        /*点击改变按钮状态,已经简略掉ajax发送短信验证的代码*/
+        $('#getting').click(function () {
+            var btn = $(this);
+            if ($("#mobile").val() == '') {
+                $("#input_error").addClass('error');
+                $("#help-inline").html('手机号码不能为空');
+                $("#help-inline").show();
+                return false;
+            }
+            $.ajax({
+                type: "POST",
+                dataType: "json",
+                cache: false,
+                data: {"mobile": $("#mobile").val()},
+                url: "{{rootUrl}}user/profile/check/mobile",
+            }).done(function (data) {
+                if (data['mobile'] > 0) {
+                    $("#input_error").addClass('error');
+                    $("#help-inline").html('手机号码已被使用');
+                    $("#help-inline").show();
+                    return false;
+                } else {
+                    $("#input_error").removeClass('error');
+                    $("#help-inline").hide();
+                    $.ajax({
+                        type: "POST",
+                        dataType: "json",
+                        cache: false,
+                        data: {"mobile": $("#mobile").val()},
+                        url: "{{rootUrl}}user/profile/sms/send/verify",
+                    }).done(function (data) {
+                    });
+                    var count = 60;
+                    var resend = setInterval(function () {
+                        count--;
+                        if (count > 0) {
+                            btn.val('重新获取 ' + count + 's');
+                            $.cookie("sms", count, {path: '/', expires: (1 / 86400) * count});
+                        } else {
+                            clearInterval(resend);
+                            btn.val("获取验证码").removeAttr('disabled style');
+                        }
+                    }, 1000);
+                    btn.attr('disabled', true).css('cursor', 'not-allowed');
+                }
+            });
+        });
+
+        /*点击改变按钮状态,已经简略掉ajax发送短信验证的代码*/
+        $('#addMobile').click(function () {
+            $.ajax({
+                type: "POST",
+                dataType: "json",
+                cache: false,
+                data: {"mobile": $("#mobile").val(), "verifycode": $("#verifycode").val()},
+                url: "{{rootUrl}}user/profile/sms",
+            }).done(function (data) {
+//                window.location.href = "{{rootUrl}}user/profile/sms";
+                window.location.reload();
+            });
+        });
+    });
+</script>
 </body>

+ 1 - 1
protected/view/edit-profile.html

@@ -68,7 +68,7 @@
                             </div>
                             <div class="input-prepend">
                                 <span class="add-on">手机</span>
-                                <input type="text" name="mobile" value="{{uprofile.mobile}}" placeholder="输入11位手机号码"
+                                <input type="text" disabled="disabled" value="{{uprofile.mobile}}" placeholder="输入11位手机号码"
                                        class="span2">
                             </div>
                         </div>

+ 1 - 1
protected/view/top.html

@@ -6,7 +6,7 @@
             </button>
             <ul class="dropdown-menu">
                 <li><a href="{{rootUrl}}user/profile">个人信息</a></li>
-                <li><a href="{{rootUrl}}user/profile/sms/edit">短信通知</a></li>
+                <li><a href="{{rootUrl}}user/profile/sms">短信通知</a></li>
                 <li class="hide"><a href="#"><span data-icon="r" aria-hidden="true"></span>&nbsp;工作组</a></li>
                 <li class="hide"><a href="#"><span data-icon="B" aria-hidden="true"></span>&nbsp;我的任务</a></li>
                 <li class="divider"></li>

+ 2 - 1
短信提醒.sql

@@ -1 +1,2 @@
-ALTER TABLE  `jl_config` ADD  `smsswitch` TINYINT NOT NULL DEFAULT  '1';
+ALTER TABLE  `jl_config` ADD  `smsswitch` TINYINT NOT NULL DEFAULT  '1';
+ALTER TABLE  `jl_user_profiles` ADD  `isnotice` TINYINT NOT NULL DEFAULT  '0';