dever %!s(int64=7) %!d(string=hai) anos
pai
achega
ccb52797c7
Modificáronse 2 ficheiros con 33 adicións e 7 borrados
  1. 16 0
      database/code.php
  2. 17 7
      lib/Base.php

+ 16 - 0
database/code.php

@@ -1,6 +1,11 @@
 <?php
 
 $mobile = Dever::rule('mobile');
+$status = array
+(
+	1 => '未使用',
+	2 => '已使用',
+);
 
 return array
 (
@@ -73,6 +78,17 @@ return array
 			'modal'		=> '查看详情',
 		),
 
+		'status'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '状态',
+			'match' 	=> 'is_string',
+			//'update'	=> 'radio',
+			//'option'	=> $status,
+		),
+
 		'state'		=> array
 		(
 			'type' 		=> 'tinyint-1',

+ 17 - 7
lib/Base.php

@@ -70,15 +70,10 @@ class Base
         return $result;
     }
 
-    public function sendCode($skin, $mobile, $code = false)
+    public function sendCode($skin, $mobile)
     {
         $this->config($skin)->mobile($mobile);
 
-        if ($code) {
-            $save = Dever::session($this->config['key']);
-            return $mobile . '_' . $code == $save;
-        }
-
         $day = date('Ymd', time());
 
         # 检测当前手机号最新一次发送时间,不允许一分钟之内发送
@@ -113,13 +108,28 @@ class Base
         $insert['mobile'] = $mobile;
         $insert['day'] = $day;
         $insert['code'] = $code;
+        $insert['status'] = 1;
         $insert['result'] = Dever::json_encode($result);
         $id = Dever::db('sms/code')->insert($insert);
 
-        Dever::session($this->config['key'], $mobile . '_' . $code, $this->config['code_timeout']);
+        //Dever::session($this->config['key'], $mobile . '_' . $code, $this->config['code_timeout'], 'session');
 
         return $code;
     }
+
+    public function checkCode($skin, $mobile, $code)
+    {
+        if ($code) {
+            //$save = Dever::session($this->config['key'], false, 3600, 'session');
+            //return $mobile . '_' . $code == $save;
+            $save = Dever::db('sms/code')->one(array('mobile' => $mobile, 'status' => 1));
+            if ($code == $save) {
+                Dever::db('sms/code')->update(array('where_id' => $save['id'], 'status' => 2));
+                return true;
+            }
+        }
+        return false;
+    }
    
 
     private function replace($content, $param)