Browse Source

Attachment management
附件管理

star7th 5 years ago
parent
commit
aec3df8419

+ 394 - 0
server/Application/Api/Controller/AttachmentController.class.php

@@ -0,0 +1,394 @@
+<?php
+//附件/图片等等
+namespace Api\Controller;
+use Think\Controller;
+class AttachmentController extends BaseController {
+
+    public function index(){
+        
+        echo 'Attachment';
+       
+    }
+
+    //浏览附件
+    public function visitFile(){
+      $sign = I("sign");
+      $imageView2 = I("imageView2");
+      $d = D("UploadFile") ;
+      $ret = $d->where(" sign = '%s' ",array($sign))->find();
+      if ($ret) {
+            $beyond_the_quota = 0 ;
+            $days = ceil(( time() -$ret['addtime'])/86400);//自添加图片以来的天数
+            $adv_day_times = $ret['visit_times'] / $days  ; //平均每天的访问次数
+            $flow_rate = ( $ret['file_size'] * $ret['visit_times'] ) / $days ; //日均流量
+
+
+            //如果是apk文件且在微信浏览器中打开
+            if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false  && strpos($ret['real_url'] , '.apk') !== false ) {
+                header("Content-type: text/html; charset=utf-8"); 
+                echo "<head><title>温馨提示</title></head>";
+                echo "<br><h1>微信不支持直接下载,请点击右上角“---”在外部浏览器中打开</h1>";
+                return ;
+
+            }
+
+          $d->where(" sign = '%s' ",array($sign))->save(array("visit_times" => $ret['visit_times'] + 1  ,"last_visit_time"=>time()));
+            //记录用户流量
+            D("Attachment")->recordUserFlow($ret['uid'] , $ret['file_size']) ;
+
+            //$ret['cache_url'] = '' ; //把这个变量赋值为空,禁用掉cache_url;
+            if ($ret['cache_url']) {
+                $url = $ret['cache_url'] ;
+            }else{
+                $url = $ret['real_url']  ;
+            }
+
+        header("location:{$url}");
+      }else{
+        echo "www.showdoc.cc";
+      }
+    }
+
+    //上传图片
+    public function uploadImg(){
+        $login_user = $this->checkLogin();
+        $item_id = I("item_id/d") ? I("item_id/d") : 0 ;
+        $page_id = I("page_id/d") ? I("page_id/d") : 0 ;
+
+        
+        if ($_FILES['editormd-image-file']['name'] == 'blob') {
+            $_FILES['editormd-image-file']['name'] .= '.jpg';
+        }
+        
+        if (!$_FILES['editormd-image-file']) {
+           return false;
+        }
+        
+        if (strstr(strip_tags(strtolower($_FILES['editormd-image-file']['name'])), ".php") ) {
+            return false;
+        }
+
+        $oss_open = D("Options")->get("oss_open" ) ;
+        if ($oss_open) {
+            $uploadFile = $_FILES['editormd-image-file'] ;
+            $url = upload_oss($uploadFile);
+            if ($url) {
+                $sign = md5($url.time().rand()) ;
+                $insert = array(
+                "sign" => $sign,
+                "uid" => $login_user['uid'],
+                "item_id" => $item_id,
+                "page_id" => $page_id,
+                "display_name" => $uploadFile['name'],
+                "file_type" => $uploadFile['type'],
+                "file_size" => $uploadFile['size'],
+                "real_url" => $url,
+                "addtime" => time(),
+                );
+                $ret = D("UploadFile")->add($insert);
+                $url = get_domain().U("api/attachment/visitFile",array("sign" => $sign))."&showdoc=.jpg"; 
+                echo json_encode(array("url"=>$url,"success"=>1));
+            }
+            return ;
+        }
+
+        $upload = new \Think\Upload();// 实例化上传类
+        $upload->maxSize  = 1003145728 ;// 设置附件上传大小
+        $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
+        $upload->rootPath = './../Public/Uploads/';// 设置附件上传目录
+        $upload->savePath = '';// 设置附件上传子目录
+        $info = $upload->uploadOne($_FILES['editormd-image-file']) ;
+        if(!$info) {// 上传错误提示错误信息
+          $this->error($upload->getError());
+          return;
+        }else{// 上传成功 获取上传文件信息
+          $url = get_domain().__ROOT__.substr($upload->rootPath,1).$info['savepath'].$info['savename'] ;
+          $sign = md5($url.time().rand()) ;
+          $uploadFile = $_FILES['editormd-image-file'] ;
+          $insert = array(
+            "sign" => $sign,
+            "uid" => $login_user['uid'],
+            "item_id" => $item_id,
+            "page_id" => $page_id,
+            "display_name" => $uploadFile['name'],
+            "file_type" => $uploadFile['type'],
+            "file_size" => $uploadFile['size'],
+            "real_url" => $url,
+            "addtime" => time(),
+            );
+          $ret = D("UploadFile")->add($insert);
+          $url = get_domain().U("api/attachment/visitFile",array("sign" => $sign))."&showdoc=.jpg";
+          echo json_encode(array("url"=>$url,"success"=>1));
+        }
+
+    }
+
+    //页面的上传附件
+    public function pageAttachmentUpload(){
+        $login_user = $this->checkLogin();
+        $item_id = I("item_id/d") ? I("item_id/d") : 0 ;
+        $page_id = I("page_id/d") ? I("page_id/d") : 0 ;
+        $uploadFile = $_FILES['file'] ;
+ 
+        if (!$page_id) {
+            $this->sendError(10103,"请至少先保存一次页面内容");
+            return;
+        }
+        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
+            $this->sendError(10103);
+            return;
+        }
+        
+        if (!$uploadFile) {
+           return false;
+        }
+        
+        if (strstr(strip_tags(strtolower($uploadFile['name'])), ".php") ) {
+            return false;
+        }
+
+        $oss_open = D("Options")->get("oss_open" ) ;
+        if ($oss_open) {
+            $url = upload_oss($uploadFile);
+            if ($url) {
+                $sign = md5($url.time().rand()) ;
+                $insert = array(
+                "sign" => $sign,
+                "uid" => $login_user['uid'],
+                "item_id" => $item_id,
+                "page_id" => $page_id,
+                "display_name" => $uploadFile['name'],
+                "file_type" => $uploadFile['type'],
+                "file_size" => $uploadFile['size'],
+                "real_url" => $url,
+                "addtime" => time(),
+                );
+                $ret = D("UploadFile")->add($insert);
+                $url = get_domain().U("api/attachment/visitFile",array("sign" => $sign)); 
+                echo json_encode(array("url"=>$url,"success"=>1));
+            }
+            return ;
+        }
+
+        $upload = new \Think\Upload();// 实例化上传类
+        $upload->maxSize  = 4145728000 ;// 设置附件上传大小
+        $upload->rootPath = './../Public/Uploads/';// 设置附件上传目录
+        $upload->savePath = '';// 设置附件上传子目录
+        $info = $upload->uploadOne($uploadFile) ;
+        if(!$info) {// 上传错误提示错误信息
+          $this->error($upload->getError());
+          return;
+        }else{// 上传成功 获取上传文件信息
+          $url = get_domain().__ROOT__.substr($upload->rootPath,1).$info['savepath'].$info['savename'] ;
+          $sign = md5($url.time().rand()) ;
+          $insert = array(
+            "sign" => $sign,
+            "uid" => $login_user['uid'],
+            "item_id" => $item_id,
+            "page_id" => $page_id,
+            "display_name" => $uploadFile['name'],
+            "file_type" => $uploadFile['type'],
+            "file_size" => $uploadFile['size'],
+            "real_url" => $url,
+            "addtime" => time(),
+            );
+          $ret = D("UploadFile")->add($insert);
+          $url = get_domain().U("api/attachment/visitFile",array("sign" => $sign));
+          echo json_encode(array("url"=>$url,"success"=>1));
+        }
+
+    }
+    //页面的上传附件列表
+    public function pageAttachmentUploadList(){
+        $login_user = $this->checkLogin();
+        $item_id = I("item_id/d") ? I("item_id/d") : 0 ;
+        $page_id = I("page_id/d") ? I("page_id/d") : 0 ;
+        if (!$page_id) {
+            $this->sendError(10103,"请至少先保存一次页面内容");
+            return;
+        }
+        $return = array() ;
+        $files = D("UploadFile")->where("page_id = '$page_id' ")->order("addtime desc")->select();
+        if ($files) {
+            $item_id = $files[0]['item_id'] ;
+            if (!$this->checkItemVisit($login_user['uid'] , $item_id)) {
+                $this->sendError(10103);
+                return;
+            }
+            foreach ($files as $key => $value) {
+                $return[] = array(
+                    "file_id"=>$value['file_id'],
+                    "display_name"=>$value['display_name'],
+                    "url"=>get_domain().U("api/attachment/visitFile",array("sign" => $value['sign'])),
+                    "addtime"=> date("Y-m-d H:i:s" , $value['addtime'] ),
+                    );
+            }
+
+        }
+        $this->sendResult($return);
+
+    }
+
+    //删除页面中已上传文件
+    public function deletePageUploadFile(){
+        $login_user = $this->checkLogin();
+        $file_id = I("file_id/d") ? I("file_id/d") : 0 ;
+
+        $file = D("UploadFile")->where("file_id = '$file_id' ")->find();
+        $item_id = $file['item_id'] ;
+        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
+            $this->sendError(10103);
+            return;
+        }
+        $ret = D("Page")->deleteFile($file_id);
+        if ($ret) {
+            $this->sendResult(array());
+        }else{
+            $this->sendError(10101,"删除失败");
+        }
+    }
+
+    //获取全站的附件列表。给管理员查看附件用
+    public function getAllList(){
+        $login_user = $this->checkLogin();
+        $this->checkAdmin(); //重要,校验管理员身份
+        $page = I("page/d");
+        $count = I("count/d");
+        $attachment_type = I("attachment_type/d");
+        $display_name = I("display_name");
+        $username = I("username");
+        $return = array() ;
+        $where = ' 1 = 1 ';
+        if($attachment_type == 1 ){
+            $where .=" and file_type like '%image%' " ;
+        }
+        if($attachment_type == 2 ){
+            $where .=" and file_type not like '%image%' " ;
+        }
+        if($display_name){
+            $display_name =  \SQLite3::escapeString($display_name) ;
+            $where .=" and display_name  like '%{$display_name}%' " ;
+        }
+        if($username){
+            $username =  \SQLite3::escapeString($username) ;
+            $uid = D("User")->where(" username = '{$username}' ")->getField('uid') ;
+            $uid = $uid ? $uid  : -99 ;
+            $where .=" and uid  = '{$uid}' " ;
+        }
+        $files = D("UploadFile")->where($where)->order("addtime desc")->page($page ,$count)->select();
+        if ($files) {
+            foreach ($files as $key => $value) {
+                $username = '';
+                if($value['uid']){
+                    $username = D("User")->where(" uid = {$value['uid']} ")->getField('username') ;
+                }
+                $return['list'][] = array(
+                    "file_id"=>$value['file_id'],
+                    "username"=>$username,
+                    "uid"=>$value['uid'],
+                    "file_type"=>$value['file_type'],
+                    "visit_times"=>$value['visit_times'],
+                    "file_size"=>$value['file_size'],
+                    "item_id"=>$value['item_id'],
+                    "page_id"=>$value['page_id'],
+                    "file_size_m"=>round( $value['file_size']/(1024*1024),3),
+                    "display_name"=>$value['display_name']?$value['display_name']:'',
+                    "url"=>get_domain().U("api/attachment/visitFile",array("sign" => $value['sign'])),
+                    "addtime"=> date("Y-m-d H:i:s" , $value['addtime'] ),
+                    "last_visit_time"=> date("Y-m-d H:i:s" , $value['last_visit_time'] ),
+                    );
+            }
+
+        }
+        $return['total'] = D("UploadFile")->where($where)->count();
+        $used = D("UploadFile")->where($where)->getField('sum(file_size)');
+        $return['used'] = $used ;
+        $return['used_m'] = round( $used/(1024*1024),3) ;
+        $this->sendResult($return);
+    }
+
+    //删除附件
+    public function deleteAttachment(){
+        $login_user = $this->checkLogin();
+        $this->checkAdmin(); //重要,校验管理员身份
+        $file_id = I("file_id/d") ? I("file_id/d") : 0 ;
+
+        $file = D("UploadFile")->where("file_id = '$file_id' ")->find();
+
+        $ret = D("Page")->deleteFile($file_id);
+        if ($ret) {
+            $this->sendResult(array());
+        }else{
+            $this->sendError(10101,"删除失败");
+        }
+    }
+
+    //获取我的附件列表
+    public function getMyList(){
+        $login_user = $this->checkLogin();
+        $page = I("page/d");
+        $count = I("count/d");
+        $attachment_type = I("attachment_type/d");
+        $display_name = I("display_name");
+        $username = I("username");
+        $return = array() ;
+        $where = " uid  = '{$login_user[uid]}' ";
+        if($attachment_type == 1 ){
+            $where .=" and file_type like '%image%' " ;
+        }
+        if($attachment_type == 2 ){
+            $where .=" and file_type not like '%image%' " ;
+        }
+        if($display_name){
+            $display_name =  \SQLite3::escapeString($display_name) ;
+            $where .=" and display_name  like '%{$display_name}%' " ;
+        }
+        $files = D("UploadFile")->where($where)->order("addtime desc")->page($page ,$count)->select();
+        if ($files) {
+            foreach ($files as $key => $value) {
+                $username = '';
+                $return['list'][] = array(
+                    "file_id"=>$value['file_id'],
+                    "uid"=>$value['uid'],
+                    "file_type"=>$value['file_type'],
+                    "visit_times"=>$value['visit_times'],
+                    "file_size"=>$value['file_size'],
+                    "item_id"=>$value['item_id'],
+                    "page_id"=>$value['page_id'],
+                    "file_size_m"=>round( $value['file_size']/(1024*1024),3),
+                    "display_name"=>$value['display_name']?$value['display_name']:'',
+                    "url"=>get_domain().U("api/attachment/visitFile",array("sign" => $value['sign'])),
+                    "addtime"=> date("Y-m-d H:i:s" , $value['addtime'] ),
+                    "last_visit_time"=> date("Y-m-d H:i:s" , $value['last_visit_time'] ),
+                    );
+            }
+
+        }
+        $return['total'] = D("UploadFile")->where($where)->count();
+        $used = D("UploadFile")->where($where)->getField('sum(file_size)');
+        $return['used'] = $used ;
+        $return['used_m'] = round( $used/(1024*1024),3) ;
+        $used_flow =  D("Attachment")->getUserFlow($login_user['uid']) ; ; //该用户的本月使用流量
+        $return['used_flow_m'] = round( $used_flow/(1024*1024),3) ;
+
+        $this->sendResult($return);
+    }
+
+    //删除附件
+    public function deleteMyAttachment(){
+        $login_user = $this->checkLogin();
+        $file_id = I("file_id/d") ? I("file_id/d") : 0 ;
+
+        $file = D("UploadFile")->where("file_id = '$file_id' and uid ='$login_user[uid]' ")->find();
+
+        if($file){
+            $ret = D("Page")->deleteFile($file_id);
+            if ($ret) {
+                $this->sendResult(array());
+                return ;
+            }
+        }
+        $this->sendError(10101,"删除失败");
+    }
+
+}

+ 5 - 0
server/Application/Api/Controller/CommonController.class.php

@@ -95,5 +95,10 @@ class CommonController extends BaseController {
       $json = json_decode($file , 1 );
       $this->sendResult(array("version"=>$json['version']));
     }
+
+    //浏览附件
+    public function visitFile(){
+       R("Attachment/visitFile");
+    }
     
 }

+ 8 - 150
server/Application/Api/Controller/PageController.class.php

@@ -210,167 +210,25 @@ class PageController extends BaseController {
 
     //上传图片
     public function uploadImg(){
-        $login_user = $this->checkLogin();
-        $item_id = I("item_id/d") ? I("item_id/d") : 0 ;
-        $page_id = I("page_id/d") ? I("page_id/d") : 0 ;
-
-        
-        if ($_FILES['editormd-image-file']['name'] == 'blob') {
-            $_FILES['editormd-image-file']['name'] .= '.jpg';
-        }
-        
-        if (!$_FILES['editormd-image-file']) {
-           return false;
-        }
-        
-        if (strstr(strip_tags(strtolower($_FILES['editormd-image-file']['name'])), ".php") ) {
-            return false;
-        }
-
-        $oss_open = D("Options")->get("oss_open" ) ;
-        if ($oss_open) {
-            $uploadFile = $_FILES['editormd-image-file'] ;
-            $url = upload_oss($uploadFile);
-            if ($url) {
-                echo json_encode(array("url"=>$url,"success"=>1));
-            }
-            return ;
-        }
-
-        $upload = new \Think\Upload();// 实例化上传类
-        $upload->maxSize  = 1003145728 ;// 设置附件上传大小
-        $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
-        $upload->rootPath = './../Public/Uploads/';// 设置附件上传目录
-        $upload->savePath = '';// 设置附件上传子目录
-        $info = $upload->uploadOne($_FILES['editormd-image-file']) ;
-        if(!$info) {// 上传错误提示错误信息
-          $this->error($upload->getError());
-          return;
-        }else{// 上传成功 获取上传文件信息
-          $url = get_domain().__ROOT__.substr($upload->rootPath,1).$info['savepath'].$info['savename'] ;
-          echo json_encode(array("url"=>$url,"success"=>1));
-        }
-
+        //重定向控制器和方法
+        R("Attachment/uploadImg");
     }
 
     //上传附件
     public function upload(){
-        $login_user = $this->checkLogin();
-        $item_id = I("item_id/d") ? I("item_id/d") : 0 ;
-        $page_id = I("page_id/d") ? I("page_id/d") : 0 ;
-        $uploadFile = $_FILES['file'] ;
- 
-        if (!$page_id) {
-            $this->sendError(10103,"请至少先保存一次页面内容");
-            return;
-        }
-        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
-            $this->sendError(10103);
-            return;
-        }
-        
-        if (!$uploadFile) {
-           return false;
-        }
-        
-        if (strstr(strip_tags(strtolower($uploadFile['name'])), ".php") ) {
-            return false;
-        }
-
-        $oss_open = D("Options")->get("oss_open" ) ;
-        if ($oss_open) {
-            $url = upload_oss($uploadFile);
-            if ($url) {
-                $insert = array(
-                "uid" => $login_user['uid'],
-                "item_id" => $item_id,
-                "page_id" => $page_id,
-                "display_name" => $uploadFile['name'],
-                "file_type" => $uploadFile['type'],
-                "file_size" => $uploadFile['size'],
-                "real_url" => $url,
-                "addtime" => time(),
-                );
-                $ret = D("UploadFile")->add($insert);
-                echo json_encode(array("url"=>$url,"success"=>1));
-            }
-            return ;
-        }
-
-        $upload = new \Think\Upload();// 实例化上传类
-        $upload->maxSize  = 4145728000 ;// 设置附件上传大小
-        $upload->rootPath = './../Public/Uploads/';// 设置附件上传目录
-        $upload->savePath = '';// 设置附件上传子目录
-        $info = $upload->uploadOne($uploadFile) ;
-        if(!$info) {// 上传错误提示错误信息
-          $this->error($upload->getError());
-          return;
-        }else{// 上传成功 获取上传文件信息
-          $url = get_domain().__ROOT__.substr($upload->rootPath,1).$info['savepath'].$info['savename'] ;
-          $insert = array(
-            "uid" => $login_user['uid'],
-            "item_id" => $item_id,
-            "page_id" => $page_id,
-            "display_name" => $uploadFile['name'],
-            "file_type" => $uploadFile['type'],
-            "file_size" => $uploadFile['size'],
-            "real_url" => $url,
-            "addtime" => time(),
-            );
-          $ret = D("UploadFile")->add($insert);
-
-          echo json_encode(array("url"=>$url,"success"=>1));
-        }
-
+        //重定向控制器和方法
+        R("Attachment/pageAttachmentUpload");
     }
 
     public function uploadList(){
-        $login_user = $this->checkLogin();
-        $item_id = I("item_id/d") ? I("item_id/d") : 0 ;
-        $page_id = I("page_id/d") ? I("page_id/d") : 0 ;
-        if (!$page_id) {
-            $this->sendError(10103,"请至少先保存一次页面内容");
-            return;
-        }
-        $return = array() ;
-        $files = D("UploadFile")->where("page_id = '$page_id' ")->order("addtime desc")->select();
-        if ($files) {
-            $item_id = $files[0]['item_id'] ;
-            if (!$this->checkItemVisit($login_user['uid'] , $item_id)) {
-                $this->sendError(10103);
-                return;
-            }
-            foreach ($files as $key => $value) {
-                $return[] = array(
-                    "file_id"=>$value['file_id'],
-                    "display_name"=>$value['display_name'],
-                    "url"=>$value['real_url'],
-                    "addtime"=> date("Y-m-d H:i:s" , $value['addtime'] ),
-                    );
-            }
-
-        }
-        $this->sendResult($return);
-
+        //重定向控制器和方法
+        R("Attachment/pageAttachmentUploadList");
     }
 
     //删除已上传文件
     public function deleteUploadFile(){
-        $login_user = $this->checkLogin();
-        $file_id = I("file_id/d") ? I("file_id/d") : 0 ;
-
-        $file = D("UploadFile")->where("file_id = '$file_id' ")->find();
-        $item_id = $file['item_id'] ;
-        if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
-            $this->sendError(10103);
-            return;
-        }
-        $ret = D("Page")->deleteFile($file_id);
-        if ($ret) {
-            $this->sendResult(array());
-        }else{
-            $this->sendError(10101,"删除失败");
-        }
+        //重定向控制器和方法
+        R("Attachment/deletePageUploadFile");
     }
 
 

+ 8 - 0
server/Application/Api/Controller/UpdateController.class.php

@@ -274,6 +274,14 @@ class UpdateController extends BaseController {
             )";
         D("User")->execute($sql);
 
+        //创建file_flow表
+        $sql = "CREATE TABLE IF NOT EXISTS `file_flow` (
+            `id`  INTEGER PRIMARY KEY ,
+            `uid` int(11) NOT NULL DEFAULT '0',
+            `used` int(11) NOT NULL DEFAULT '0',
+            `date_month` CHAR(2000) NOT NULL DEFAULT ''
+            )";
+        D("User")->execute($sql);
 
         return true ;
     }

+ 52 - 0
server/Application/Api/Model/AttachmentModel.class.php

@@ -0,0 +1,52 @@
+<?php
+namespace Api\Model;
+use Api\Model\BaseModel;
+/**
+ * 
+ * @author star7th      
+ */
+class AttachmentModel extends BaseModel {
+
+	Protected $autoCheckFields = false;  //一定要关闭字段缓存,不然会报找不到表的错误
+
+	//获取某个用户的当前已使用附件流量
+	public function getUserFlow($uid){
+		$month = Date("Y-m") ;
+		$file_flow = D("FileFlow")->where(" uid = '%s'  and date_month = '$month' " , array($uid))->find() ;
+		if($file_flow){
+			return intval($file_flow['used']) ;
+		}else{
+			D("FileFlow")->add(array(
+				"uid" => $uid ,
+				"used" => 0  ,
+				"date_month" => $month ,
+
+			));
+			return 0 ;
+		}
+	}
+
+	//记录某个用户流量
+	public function recordUserFlow($uid , $file_size){
+		$month = Date("Y-m") ;
+		$used = $this->getUserFlow($uid) ;
+		return D("FileFlow")->where(" uid = '%s'  and date_month = '$month' " , array($uid))->save(array(
+			"used" => $used + intval($file_size) 
+		));
+	}
+
+	public function deleteFile($file_id){
+
+		$file = D("UploadFile")->where("file_id = '$file_id' ")->find();
+		$real_url = $file['real_url'] ;
+		$array = explode("/Public/Uploads/", $real_url) ;
+		$file_path = "../Public/Uploads/".$array[1] ;
+		if (file_exists($file_path)) {
+			@unlink($file_path);
+		}
+		D("UploadFile")->where(" file_id = '$file_id' ")->delete();
+		return true ;
+
+	}
+
+}

+ 1 - 9
server/Application/Api/Model/PageModel.class.php

@@ -148,15 +148,7 @@ class PageModel extends BaseModel {
    }
 
    public function deleteFile($file_id){
-      $file = D("UploadFile")->where("file_id = '$file_id' ")->find();
-      $real_url = $file['real_url'] ;
-      $array = explode("/Public/Uploads/", $real_url) ;
-      $file_path = "../Public/Uploads/".$array[1] ;
-      if (file_exists($file_path)) {
-        unlink($file_path);
-      }
-      D("UploadFile")->where(" file_id = '$file_id' ")->delete();
-      return true ;
+        return D("Attachment")->deleteFile($file_id) ;
     }
 
 }

+ 5 - 0
web_src/.prettierrc.json

@@ -0,0 +1,5 @@
+{
+    "singleQuote": true,
+    "trailingComma": "es6",
+    "semi": false
+}

+ 8 - 1
web_src/src/components/admin/Index.vue

@@ -23,6 +23,10 @@
               <i class="el-icon-tickets"></i>
               <span slot="title">{{$t('item_manage')}}</span>
             </el-menu-item>
+            <el-menu-item index="5">
+              <i class="el-icon-tickets"></i>
+              <span slot="title">{{$t('attachment_manage')}}</span>
+            </el-menu-item>
             <el-menu-item index="3">
               <i class="el-icon-tickets"></i>
               <span slot="title">{{$t('web_setting')}}</span>
@@ -34,6 +38,7 @@
             <User v-if="open_menu_index == 1 "></User>
             <Item v-if="open_menu_index == 2 "></Item>
             <Setting v-if="open_menu_index == 3 "></Setting>
+            <Attachment v-if="open_menu_index == 5 "></Attachment>
           </el-main>
           <el-footer>
             <!-- something -->
@@ -113,6 +118,7 @@ body > .el-container {
 import Item from '@/components/admin/item/Index'
 import User from '@/components/admin/user/Index'
 import Setting from '@/components/admin/setting/Index'
+import Attachment from '@/components/admin/attachment/Index'
 
 export default {
   data() {
@@ -123,7 +129,8 @@ export default {
   components: {
     Item,
     User,
-    Setting
+    Setting,
+    Attachment
   },
   methods: {
     select_menu(index, indexPath) {

+ 121 - 0
web_src/src/components/admin/attachment/Index.vue

@@ -0,0 +1,121 @@
+<template>
+  <div class="hello">
+    <el-form :inline="true" class="demo-form-inline">
+      <el-form-item label>
+        <el-input v-model="display_name" :placeholder="$t('display_name')"></el-input>
+      </el-form-item>
+      <el-form-item label>
+        <el-select v-model="attachment_type" placeholder>
+          <el-option :label="$t('all_attachment_type')" value="-1"></el-option>
+          <el-option :label="$t('image')" value="1"></el-option>
+          <el-option :label="$t('general_attachment')" value="2"></el-option>
+        </el-select>
+      </el-form-item>
+      <el-form-item label>
+        <el-input v-model="username" :placeholder="$t('uploader')"></el-input>
+      </el-form-item>
+      <el-form-item>
+        <el-button @click="onSubmit">{{$t('search')}}</el-button>
+      </el-form-item>
+    </el-form>
+    <P>累计已使用 {{used}}M 空间</P>
+    <el-table :data="dataList" style="width: 100%">
+      <el-table-column prop="file_id" :label="$t('file_id')"></el-table-column>
+      <el-table-column prop="display_name" :label="$t('display_name')"></el-table-column>
+      <el-table-column prop="file_type" :label="$t('file_type')" width="140"></el-table-column>
+      <el-table-column prop="file_size_m" :label="$t('file_size_m')" width="140"></el-table-column>
+      <el-table-column prop="visit_times" :label="$t('visit_times')"></el-table-column>
+      <el-table-column prop="username" :label="$t('uploader')"></el-table-column>
+      <el-table-column prop="addtime" :label="$t('add_time')" width="160"></el-table-column>
+      <el-table-column prop :label="operation">
+        <template slot-scope="scope">
+          <el-button @click="visit(scope.row)" type="text" size="small">{{$t('visit')}}</el-button>
+          <el-button @click="delete_row(scope.row)" type="text" size="small">{{$t('delete')}}</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+
+    <div class="block">
+      <span class="demonstration"></span>
+      <el-pagination
+        @current-change="handleCurrentChange"
+        :page-size="count"
+        layout="total, prev, pager, next"
+        :total="total"
+      ></el-pagination>
+    </div>
+  </div>
+</template>
+
+<style scoped>
+</style>
+
+<script>
+export default {
+  data() {
+    return {
+      page: 1,
+      count: 7,
+      display_name: '',
+      username: '',
+      dataList: [],
+      total: 0,
+      positive_type: '1',
+      attachment_type: '-1',
+      used: 0
+    }
+  },
+  methods: {
+    getList() {
+      this.request('/api/attachment/getAllList', {
+        page: this.page,
+        count: this.count,
+        attachment_type: this.attachment_type,
+        display_name: this.display_name,
+        username: this.username
+      }).then(data => {
+        var json = data.data
+        this.dataList = json.list
+        this.total = parseInt(json.total)
+        this.used = json.used_m
+      })
+    },
+    // 跳转到项目
+    jump_to_item(row) {
+      let url = '/' + row.item_id
+      window.open(url)
+    },
+    handleCurrentChange(currentPage) {
+      this.page = currentPage
+      this.getList()
+    },
+    onSubmit() {
+      this.page = 1
+      this.getList()
+    },
+    visit(row) {
+      window.open(row.url)
+    },
+    delete_row(row) {
+      this.$confirm(this.$t('confirm_delete'), ' ', {
+        confirmButtonText: this.$t('confirm'),
+        cancelButtonText: this.$t('cancel'),
+        type: 'warning'
+      }).then(() => {
+        this.request('/api/attachment/deleteAttachment', {
+          file_id: row.file_id
+        }).then(data => {
+          this.$message.success(this.$t('op_success'))
+          this.getList()
+        })
+      })
+    }
+  },
+  mounted() {
+    this.getList()
+  },
+  beforeDestroy() {
+    this.$message.closeAll()
+  }
+}
+</script>

+ 149 - 0
web_src/src/components/attachment/Index.vue

@@ -0,0 +1,149 @@
+<template>
+  <div class="hello">
+    <Header></Header>
+
+    <el-container>
+      <el-card class="hor-center-card">
+        <el-button type="text" @click="goback" class="goback-btn">
+          <i class="el-icon-back"></i>
+        </el-button>
+        <el-form :inline="true" class="demo-form-inline">
+          <el-form-item label>
+            <el-input v-model="display_name" :placeholder="$t('display_name')"></el-input>
+          </el-form-item>
+          <el-form-item label>
+            <el-select v-model="attachment_type" placeholder>
+              <el-option :label="$t('all_attachment_type')" value="-1"></el-option>
+              <el-option :label="$t('image')" value="1"></el-option>
+              <el-option :label="$t('general_attachment')" value="2"></el-option>
+            </el-select>
+          </el-form-item>
+          <el-form-item>
+            <el-button @click="onSubmit">{{$t('search')}}</el-button>
+          </el-form-item>
+        </el-form>
+        <P>{{$t('accumulated_used_sapce')}} {{used}}M , {{$t('month_flow')}} {{used_flow}}M</P>
+        <el-table :data="dataList" style="width: 100%">
+          <el-table-column prop="file_id" :label="$t('file_id')"></el-table-column>
+          <el-table-column prop="display_name" :label="$t('display_name')"></el-table-column>
+          <el-table-column prop="file_type" :label="$t('file_type')" width="160"></el-table-column>
+          <el-table-column prop="file_size_m" :label="$t('file_size_m')" width="160"></el-table-column>
+          <el-table-column prop="visit_times" :label="$t('visit_times')"></el-table-column>
+          <el-table-column prop="addtime" :label="$t('add_time')" width="160"></el-table-column>
+          <el-table-column prop :label="operation">
+            <template slot-scope="scope">
+              <el-button @click="visit(scope.row)" type="text" size="small">{{$t('visit')}}</el-button>
+              <el-button @click="delete_row(scope.row)" type="text" size="small">{{$t('delete')}}</el-button>
+            </template>
+          </el-table-column>
+        </el-table>
+
+        <div class="block">
+          <span class="demonstration"></span>
+          <el-pagination
+            @current-change="handleCurrentChange"
+            :page-size="count"
+            layout="total, prev, pager, next"
+            :total="total"
+          ></el-pagination>
+        </div>
+      </el-card>
+    </el-container>
+
+    <Footer></Footer>
+  </div>
+</template>
+
+<script>
+export default {
+  name: '',
+  components: {},
+  data() {
+    return {
+      page: 1,
+      count: 6,
+      display_name: '',
+      username: '',
+      dataList: [],
+      total: 0,
+      positive_type: '1',
+      attachment_type: '-1',
+      used: 0,
+      used_flow: 0
+    }
+  },
+  methods: {
+    getList() {
+      this.request('/api/attachment/getMyList', {
+        page: this.page,
+        count: this.count,
+        attachment_type: this.attachment_type,
+        display_name: this.display_name,
+        username: this.username
+      }).then(data => {
+        var json = data.data
+        this.dataList = json.list
+        this.total = parseInt(json.total)
+        this.used = json.used_m
+        this.used_flow = json.used_flow_m
+      })
+    },
+    // 跳转到项目
+    jump_to_item(row) {
+      let url = '/' + row.item_id
+      window.open(url)
+    },
+    handleCurrentChange(currentPage) {
+      this.page = currentPage
+      this.getList()
+    },
+    onSubmit() {
+      this.page = 1
+      this.getList()
+    },
+    visit(row) {
+      window.open(row.url)
+    },
+    delete_row(row) {
+      this.$confirm(this.$t('confirm_delete'), ' ', {
+        confirmButtonText: this.$t('confirm'),
+        cancelButtonText: this.$t('cancel'),
+        type: 'warning'
+      }).then(() => {
+        this.request('/api/attachment/deleteMyAttachment', {
+          file_id: row.file_id
+        }).then(data => {
+          this.$message.success(this.$t('op_success'))
+          this.getList()
+        })
+      })
+    },
+    goback() {
+      this.$router.push({ path: '/item/index' })
+    }
+  },
+
+  mounted() {
+    this.getList()
+  },
+  beforeDestroy() {}
+}
+</script>
+
+<!-- Add "scoped" attribute to limit CSS to this component only -->
+<style scoped>
+.hor-center-card a {
+  font-size: 12px;
+}
+
+.hor-center-card {
+  width: 1000px;
+}
+
+.goback-btn {
+  font-size: 18px;
+  margin-right: 800px;
+  margin-bottom: 5px;
+}
+
+</style>

+ 3 - 0
web_src/src/components/item/Index.vue

@@ -66,6 +66,9 @@
                 <el-dropdown-item>
                   <router-link to="/user/setting">{{$t("Logged")}}:{{username}}</router-link>
                 </el-dropdown-item>
+                <el-dropdown-item>
+                  <router-link to="/attachment/index">{{$t("my_attachment")}}</router-link>
+                </el-dropdown-item>
                 <el-dropdown-item :command="logout">{{$t("logout")}}</el-dropdown-item>
               </el-dropdown-menu>
             </el-dropdown>

+ 6 - 0
web_src/src/router/index.js

@@ -21,6 +21,7 @@ import Admin from '@/components/admin/Index'
 import Team from '@/components/team/Index'
 import TeamMember from '@/components/team/Member'
 import TeamItem from '@/components/team/Item'
+import Attachment from '@/components/attachment/Index'
 
 Vue.use(Router)
 
@@ -135,6 +136,11 @@ export default new Router({
       path: '/team/item/:team_id',
       name: 'TeamItem',
       component: TeamItem
+    },
+    {
+      path: '/attachment/index',
+      name: 'Attachment',
+      component: Attachment
     }
   ]
 })

+ 11 - 0
web_src/static/css/common.css

@@ -27,6 +27,17 @@ a {
   box-sizing: border-box;
 }
 
+/* 水平居中的卡片 */
+.hor-center-card {
+  width: 700px;
+  margin: 20px auto;
+  padding-top: 0px;
+  padding-left: 15px;
+  padding-right: 15px;
+  padding-bottom: 0px;
+  box-sizing: border-box;
+}
+
 .pull-right {
   float: right;
 }

+ 17 - 1
web_src/static/lang/en.js

@@ -373,5 +373,21 @@ exports.default = {
   update_pwd_tips: 'Password, leave blank if not changed',
 
   import_excel: 'You can choose to import excel file',
-  table: 'table'
+  table: 'table',
+
+  attachment_manage: 'Attachment',
+  op_success: 'success',
+  display_name: 'display name',
+  all_attachment_type: 'all type',
+  image: 'image',
+  general_attachment: 'general attachment',
+  uploader: 'uploader',
+  file_id: 'file id',
+  file_type: 'type',
+  file_size_m: 'size/mb',
+  visit: 'visit',
+  visit_times: 'visit times',
+  my_attachment: 'My attachment',
+  accumulated_used_sapce: 'Accumulated used space',
+  month_flow: 'Traffic has been used this month'
 }

+ 17 - 1
web_src/static/lang/zh-CN.js

@@ -364,5 +364,21 @@ exports.default = {
   update_pwd_tips: '密码,不修改则留空',
 
   import_excel: '你可以选择Excel文件导入',
-  table: '表格'
+  table: '表格',
+
+  attachment_manage: '附件管理',
+  op_success: '操作成功',
+  display_name: '展示名字',
+  all_attachment_type: '全部附件类型',
+  image: '图片',
+  general_attachment: '普通附件',
+  uploader: '上传者',
+  file_id: '文件id',
+  file_type: '文件类型',
+  file_size_m: '文件大小/mb',
+  visit: '查看',
+  visit_times: '访问次数',
+  my_attachment: '我的附件',
+  accumulated_used_sapce: '累计已使用空间',
+  month_flow: '本月已使用流量'
 }