瀏覽代碼

消息和系统消息转移

lizhen_gitee 1 年之前
父節點
當前提交
2c39c62f97
共有 3 個文件被更改,包括 83 次插入141 次删除
  1. 0 140
      application/api/controller/Index.php
  2. 82 0
      application/api/controller/Message.php
  3. 1 1
      application/common/library/Auth.php

+ 0 - 140
application/api/controller/Index.php

@@ -46,111 +46,9 @@ class Index extends Api
 //        return $newid;
 //    }
 
-    /**
-     * 获取用户协议等
-     */
-    public function getWebsiteInfo() {
-        $params = $this->request->request("params"); //内容
-
-        echo "<html><body>";
-        echo config("site.".$params);
-        echo "</body></html>";exit;
-    }
-
-    /**
-     * 获取用户协议等 小程序
-     */
-    public function getWebsiteInfoForMini() {
-        $params = $this->request->request("params"); //内容
-        $res = config("site.".$params);
-
-        $this->success("获取成功!",$res);
-    }
-
-    /**
-     * 联系我们
-     */
-    public function contactus() {
-        $list = \app\common\model\Config::where(["group"=>"basic","name"=>["in",["email","mobile"]]])->select();
-        $data = [];
-        foreach($list as $k => $v) {
-            $v["name"] == "email" && $data["email"] = $v["value"];
-            $v["name"] == "mobile" && $data["mobile"] = $v["value"];
-        }
-        $this->success("获取成功!",$data);
-    }
-
-    /*
-     * 获取系统消息列表
-     */
-    public function getMessageSys() {
-        $page = $this->request->request('page',1); // 分页
-        $pageNum = $this->request->request('pageNum',10); // 分页
-        // 分页搜索构建
-        $pageStart = ($page-1)*$pageNum;
-
-        $flag = $this->request->request("flag",1,"intval"); //标识:1=只取一条,0=全部
-        $type = $this->request->request("type",1);
-        $obj = Db::name('message_sys')->where('type',$type)->order("id","desc")->limit($pageStart,$pageNum);
-        if($flag == 1) {
-            $list = $obj->find();
-            $list || $list = [];
-            $list && $list["createtime"] = $this->get_last_time($list["createtime"]);
-        } else {
-            $list = $obj->select();
-            if($list) foreach($list as $k => &$v) {
-                $v["createtime"] = $this->get_last_time($v["createtime"]);
-            }
-        }
-
-        $this->success("获取成功!",$list);
-
-    }
-
-    /*
-     * 获取个人消息列表
-     */
-    public function getMessage() {
-        $page = $this->request->request('page',1); // 分页
-        $pageNum = $this->request->request('pageNum',10); // 分页
-        // 分页搜索构建
-        $pageStart = ($page-1)*$pageNum;
 
-        $flag = $this->request->request("flag",1,"intval"); //标识:1=只取一条,0=全部
-        $user_id = $this->auth->id;
-
-        $obj = \app\common\model\Message::where(["user_id"=>$user_id])->order("createtime","desc")->limit($pageStart,$pageNum);
-        if($flag == 1) {
-            $list = $obj->find();
-            $list || $list = [];
-            $list && $list["createtime"] = $this->get_last_time($list["createtime"]);
-        } else {
-            $list = $obj->select();
-            if($list) foreach($list as $k => &$v) {
-                $v["createtime"] = $this->get_last_time($v["createtime"]);
-            }
-        }
 
-        $this->success("获取成功!",$list);
 
-    }
-
-    /**
-     * 删除个人消息
-     */
-    public function delMessage() {
-        $id = $this->request->request("id",0,"intval"); //消息ID
-        if($id <= 0) {
-            $this->error("参数传入错误!");
-        }
-        $res = \app\common\model\Message::where(["id"=>$id,"user_id"=>$this->auth->id])->delete();
-
-        if($res) {
-            $this->success("删除成功!");
-        } else {
-            $this->error("删除失败!");
-        }
-    }
 
     /**
      * 获取主播魅力值排行
@@ -587,45 +485,7 @@ class Index extends Api
         $this->success("获取成功!",["switch"=>config("site.switch")]);
     }
 
-    /**
-     * 评论时间转换
-     * @param null $time
-     * @return false|string
-     */
-    private function get_last_time($time = NULL) {
-        $text = '';
-        $time = $time === NULL || $time > time() ? time() : intval($time);
-        $t = time() - $time; //时间差 (秒)
-        $y = date('Y', $time)-date('Y', time());//是否跨年
-        switch($t){
-            case $t == 0:
-                $text = '刚刚';
-                break;
-            case $t < 60:
-                $text = $t . '秒前'; // 一分钟内
-                break;
-            case $t < 60 * 60:
-                $text = floor($t / 60) . '分钟前'; //一小时内
-                break;
-            case $t < 60 * 60 * 24:
-                $text = floor($t / (60 * 60)) . '小时前'; // 一天内
-                break;
-            case $t < 60 * 60 * 24 * 3:
-                $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
-                break;
-            case $t < 60 * 60 * 24 * 30:
-                $text = date('m月d日 H:i', $time); //一个月内
-                break;
-            case $t < 60 * 60 * 24 * 365&&$y==0:
-                $text = date('m月d日', $time); //一年内
-                break;
-            default:
-                $text = date('Y年m月d日', $time); //一年以前
-                break;
-        }
 
-        return $text;
-    }
 
 
 

+ 82 - 0
application/api/controller/Message.php

@@ -0,0 +1,82 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+/**
+ * 消息
+ */
+class Message extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+        /*
+     * 获取系统消息列表
+     */
+    public function getMessageSys() {
+
+        $flag = input("flag",1,"intval"); //标识:1=只取一条,0=全部
+        $type = input("type",1);
+        $obj = Db::name('message_sys')->where('type',$type)->order("id","desc")->autopage();
+        if($flag == 1) {
+            $list = $obj->find();
+            $list || $list = [];
+            $list && $list["createtime"] = get_last_time($list["createtime"]);
+        } else {
+            $list = $obj->select();
+            if($list) foreach($list as $k => &$v) {
+                $v["createtime"] = get_last_time($v["createtime"]);
+            }
+        }
+
+        $this->success("获取成功!",$list);
+
+    }
+
+    /*
+     * 获取个人消息列表
+     */
+    public function getMessage() {
+
+
+        $flag = $this->request->request("flag",1,"intval"); //标识:1=只取一条,0=全部
+        $user_id = $this->auth->id;
+
+        $obj = Db::name('message')->where(["user_id"=>$user_id])->order("createtime","desc")->autopage();
+        if($flag == 1) {
+            $list = $obj->find();
+            $list || $list = [];
+            $list && $list["createtime"] = get_last_time($list["createtime"]);
+        } else {
+            $list = $obj->select();
+            if($list) foreach($list as $k => &$v) {
+                $v["createtime"] = get_last_time($v["createtime"]);
+            }
+        }
+
+        $this->success("获取成功!",$list);
+
+    }
+
+    /**
+     * 删除个人消息
+     */
+    public function delMessage() {
+        $id = $this->request->request("id",0,"intval"); //消息ID
+        if($id <= 0) {
+            $this->error("参数传入错误!");
+        }
+        $res = \app\common\model\Message::where(["id"=>$id,"user_id"=>$this->auth->id])->delete();
+
+        if($res) {
+            $this->success("删除成功!");
+        } else {
+            $this->error("删除失败!");
+        }
+    }
+
+
+
+}

+ 1 - 1
application/common/library/Auth.php

@@ -204,7 +204,7 @@ class Auth
         }
         //https://bansheng-1304213176.cos.ap-guangzhou.myqcloud.com/
         $params = array_merge($data, [
-            'nickname' => "K歌_" . $data["u_id"],
+            'nickname' => get_rand_nick_name() . $data["u_id"],
 //            'salt'     => Random::alnum(),
             'joinip'    => $ip,
             'logintime' => $time,