Jonlin %!s(int64=6) %!d(string=hai) anos
pai
achega
7e8dbdc960
Modificáronse 1 ficheiros con 87 adicións e 14 borrados
  1. 87 14
      application/index/controller/User.php

+ 87 - 14
application/index/controller/User.php

@@ -80,17 +80,21 @@ class User extends Controller
     {
 
         if(request()->isPost()){
-            $name = input("param.name/s");
+            $account_id = input("param.account_id/s");
+            $nick_name = input("param.nick_name/s");
             $email = input("param.email/s");
-            $content = input("param.content/s");
             $phone = input("param.phone/s");
-            $qq = input("param.qq/s");
-            $wechat = input("param.wechat/s");
+            $content = input("param.content/s");
+            $account_ip = $_SERVER["REMOTE_ADDR"];
+            //获得访问者浏览器
+            $browse = $this->browse_info();
+            //获得访客操作系统
+            $system = $this->get_os();
 
             $image = input("param.file/s");
 
-            if(empty($name)){
-                return json(['code' => -1, 'data' => '', 'msg' => '用户名称不能为空']);
+            if(empty($account_id)){
+                return json(['code' => -1, 'data' => '', 'msg' => '用户id不能为空']);
             }
 
 //            if(empty($email)){
@@ -109,28 +113,43 @@ class User extends Controller
                 return json(['code' => -5, 'data' => '', 'msg' => '内容不能为空']);
             }
 
-            if(empty($phone)){
-                return json(['code' => -6, 'data' => '', 'msg' => '电话不能为空']);
-            }
+//            if(empty($phone)){
+//                return json(['code' => -6, 'data' => '', 'msg' => '电话不能为空']);
+//            }
 
 //            if(empty($image)){
 //                return json(['code' => -7, 'data' => '', 'msg' => '附件不能为空']);
 //            }
 
             $param = [
-                'name' => $name,
-                'email' => $email,
+                'account_id' => $account_id,
                 'content' => $content,
+                'account_ip' => $account_ip,
+                'browse' => $browse,
+                'system' => $system,
                 'image' => $image,
-                'phone' => $phone,
-                'qq' => $qq,
-                'wechat' => $wechat,
                 'message_status' => 0,
                 'add_time' => time()
             ];
+            $info = array();
+            if(!empty($nick_name)){
+                $param['nick_name'] = $nick_name;
+                $info['nick_name'] = $nick_name;
+            }
+            if(!empty($email)){
+                $param['email'] = $email;
+                $info['account_email'] = $email;
+            }
+            if(!empty($phone)){
+                $param['phone'] = $phone;
+                $info['account_phone'] = $phone;
+            }
 
             try{
                 db('accountsmessage')->insertGetId($param);
+                if(!empty($info)){
+                    db('accounts')->where('id',$account_id)->update($info);
+                }
             }catch(\Exception $e){
                 return json(['code' => -1, 'data' => '', 'msg' => $e->getMessage()]);
             }
@@ -175,4 +194,58 @@ class User extends Controller
         }
     }
 
+
+    /**
+     * 获得访客操作系统
+     * @return string
+     */
+    public static function get_os(){
+        if (!empty($_SESSION['userAgent'])) {
+            $os = $_SESSION['userAgent'];
+            if (preg_match('/win/i', $os)) {
+                $os = 'Windows';
+            } else if (preg_match('/mac/i', $os)) {
+                $os = 'MAC';
+            } else if (preg_match('/linux/i', $os)) {
+                $os = 'Linux';
+            } else if (preg_match('/unix/i', $os)) {
+                $os = 'Unix';
+            } else if (preg_match('/bsd/i', $os)) {
+                $os = 'BSD';
+            } else {
+                $os = 'Other';
+            }
+            return $os;
+        } else {
+            return 'unknow';
+        }
+    }
+
+    /**
+     * 获得访问者浏览器
+     * @return string
+     */
+    public static function browse_info(){
+        if (!empty($_SESSION['userAgent'])) {
+            $br = $_SESSION['userAgent'];
+            if (preg_match('/MSIE/i', $br)) {
+                $br = 'MSIE';
+            } else if (preg_match('/Firefox/i', $br)) {
+                $br = 'Firefox';
+            } else if (preg_match('/Chrome/i', $br)) {
+                $br = 'Chrome';
+            } else if (preg_match('/Safari/i', $br)) {
+                $br = 'Safari';
+            } else if (preg_match('/Opera/i', $br)) {
+                $br = 'Opera';
+            } else {
+                $br = 'Other';
+            }
+            return $br;
+        } else {
+            return 'unknow';
+        }
+    }
+
+
 }