Browse Source

团队管理

star7th 7 years ago
parent
commit
0999833d2d

BIN
Sqlite/showdoc.db.php


+ 74 - 0
server/Application/Api/Controller/TeamController.class.php

@@ -0,0 +1,74 @@
+<?php
+namespace Api\Controller;
+use Think\Controller;
+/*
+    团队管理
+ */
+class TeamController extends BaseController {
+
+    //添加和编辑
+    public function save(){
+        $login_user = $this->checkLogin();
+
+        $team_name = I("team_name");
+        $id = I("id/d");
+
+        if ($id) {
+            
+            D("Team")->where(" id = '$id' ")->save(array("team_name"=>$team_name));
+
+        }else{
+            $data['username'] = $login_user['username'] ;
+            $data['uid'] = $login_user['uid'] ;
+            $data['team_name'] = $team_name ;
+            $data['addtime'] = time() ;
+            $id = D("Team")->add($data);  
+        }
+
+        $return = D("Team")->where(" id = '$id' ")->find();
+
+        if (!$return) {
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+        }
+
+        $this->sendResult($return);
+        
+    }
+
+    //获取列表
+    public function getList(){
+        $login_user = $this->checkLogin();
+        if ($login_user['uid'] > 0 ) {
+            $ret = D("Team")->where(" uid = '$login_user[uid]' ")->order(" addtime desc  ")->select();
+        }
+        if ($ret) {
+            foreach ($ret as $key => &$value) {
+                $value['addtime'] = date("Y-m-d H:i:s" , $value['addtime']);
+            }
+           $this->sendResult($ret);
+        }else{
+            $this->sendResult(array());
+        }
+    }
+
+    //删除
+    public function delete(){
+        $id = I("id/d")? I("id/d") : 0;
+        $login_user = $this->checkLogin();
+        if ($id && $login_user['uid']) {
+            $ret = D("Team")->where(" id = '$id' and uid = '$login_user[uid]'")->delete();
+        }
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+
+
+
+}

+ 118 - 0
server/Application/Api/Controller/TeamItemController.class.php

@@ -0,0 +1,118 @@
+<?php
+namespace Api\Controller;
+use Think\Controller;
+/*
+    团队和项目的绑定关系
+ */
+class TeamItemController extends BaseController {
+
+    //添加和编辑
+    public function save(){
+        $login_user = $this->checkLogin();
+        $uid = $login_user['uid'] ;
+
+        $item_id = I("item_id/d");
+        $team_id = I("team_id/d");
+
+        if(!$this->checkItemCreator($uid , $item_id)){
+            $this->sendError(10303);
+            return ;
+        }
+
+        $teamInfo = D("Team")->where(" id = '$team_id' and uid = '$login_user[uid]' ")->find();
+        if (!$teamInfo) {
+            $this->sendError(10209,"无此团队或者你无管理此团队的权限");
+            return ;
+        } 
+
+
+        $data = array() ;
+        $data['item_id'] = $item_id ;
+        $data['team_id'] = $team_id ;
+        $data['addtime'] = time() ;
+        $id = D("TeamItem")->add($data);
+
+        //获取该团队的所有成员并加入项目
+        $teamMembers = D("TeamMember")->where("  team_id = '$team_id' ")->select() ;
+        if ($teamMembers) {
+            foreach ($teamMembers as $key => $value) {
+                $data= array(
+                    "team_id"=>$team_id,
+                    "member_uid"=>$value['member_uid'],
+                    "member_username"=>$value['member_username'],
+                    "item_id"=>$item_id,
+                    "member_group_id"=>1, //默认添加的权限为1,即编辑权限
+                    "addtime"=>time()
+                );
+                D("TeamItemMember")->add($data);
+            }
+        }
+
+
+        $return = D("TeamItem")->where(" id = '$id' ")->find();
+
+        if (!$return) {
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+        }
+
+        $this->sendResult($return);
+        
+    }
+
+    //获取列表
+    public function getList(){
+        $login_user = $this->checkLogin();
+        $uid = $login_user['uid'] ;
+
+        $item_id = I("item_id/d");
+
+        if(!$this->checkItemCreator($uid , $item_id)){
+            $this->sendError(10303);
+            return ;
+        }
+
+        $sql  = "select team.*,team_item.team_id , team_item.id as id from team left join team_item on team.id = team_item.team_id where team_item.item_id = '$item_id' ";
+        $ret = D("TeamItem")->query($sql);
+
+        if ($ret) {
+            foreach ($ret as $key => &$value) {
+                $value['addtime'] = date("Y-m-d H:i:s" , $value['addtime']);
+            }
+           $this->sendResult($ret);
+        }else{
+            $this->sendResult(array());
+        }
+    }
+
+    //删除
+    public function delete(){
+        $login_user = $this->checkLogin();
+        $uid = $login_user['uid'] ;
+
+        $id = I("id/d")? I("id/d") : 0;
+        $teamItemInfo = D("TeamItem")->where(" id = '$id'  ")->find();
+        $item_id = $teamItemInfo['item_id'] ;
+        $team_id = $teamItemInfo['team_id'] ;
+
+        if(!$this->checkItemCreator($uid , $item_id)){
+            $this->sendError(10303);
+            return ;
+        }
+
+        $ret = D("TeamItemMember")->where(" item_id = '$item_id' and team_id = '$team_id' ")->delete();
+        $ret = D("TeamItem")->where(" id = '$id' ")->delete();
+
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+
+
+
+}

+ 67 - 0
server/Application/Api/Controller/TeamItemMemberController.class.php

@@ -0,0 +1,67 @@
+<?php
+namespace Api\Controller;
+use Think\Controller;
+/*
+    成员组和项目绑定后,每个人的绑定情况
+ */
+class TeamItemMemberController extends BaseController {
+
+    //添加和编辑
+    //由于初始添加成员的时候就已经有了记录,所以本方法是编辑
+    public function save(){
+        $login_user = $this->checkLogin();
+        $uid = $login_user['uid'] ;
+
+        $id = I("id/d");
+        $member_group_id = I("member_group_id/d");
+
+        $teamItemMemberInfo = D("TeamItemMember")->where(" id = '$id'  ")->find();
+        $item_id = $teamItemMemberInfo['item_id'] ;
+        $team_id = $teamItemMemberInfo['team_id'] ;
+
+
+        if(!$this->checkItemCreator($uid , $item_id)){
+            $this->sendError(10303);
+            return ;
+        }
+
+        $teamInfo = D("Team")->where(" id = '$team_id' and uid = '$login_user[uid]' ")->find();
+        if (!$teamInfo) {
+            $this->sendError(10209,"无此团队或者你无管理此团队的权限");
+            return ;
+        } 
+
+        $return = D("TeamItemMember")->where(" id = '$id' ")->save(array("member_group_id"=>$member_group_id));
+
+        $this->sendResult($return);
+        
+    }
+
+    //获取列表
+    public function getList(){
+        $login_user = $this->checkLogin();
+        $uid = $login_user['uid'] ;
+
+        $item_id = I("item_id/d");
+        $team_id = I("team_id/d");
+
+        if(!$this->checkItemCreator($uid , $item_id)){
+            $this->sendError(10303);
+            return ;
+        }
+
+        $ret = D("TeamItemMember")->where(" item_id = '$item_id'  and team_id = '$team_id' ")->select();
+
+        if ($ret) {
+            foreach ($ret as $key => &$value) {
+                $value['addtime'] = date("Y-m-d H:i:s" , $value['addtime']);
+            }
+           $this->sendResult($ret);
+        }else{
+            $this->sendResult(array());
+        }
+    }
+
+
+
+}

+ 111 - 0
server/Application/Api/Controller/TeamMemberController.class.php

@@ -0,0 +1,111 @@
+<?php
+namespace Api\Controller;
+use Think\Controller;
+/*
+    团队成员管理
+ */
+class TeamMemberController extends BaseController {
+
+    //添加和编辑
+    public function save(){
+        $login_user = $this->checkLogin();
+
+        $member_username = I("member_username");
+        $team_id = I("team_id/d");
+
+        $teamInfo = D("Team")->where(" id = '$team_id' and uid = '$login_user[uid]' ")->find();
+        if (!$teamInfo) {
+            $this->sendError(10209,"无此团队或者你无管理此团队的权限");
+            return ;
+        } 
+
+        $memberInfo = D("User")->where(" username = '%s' ",array($member_username,$member_username))->find();
+        if (!$memberInfo) {
+            $this->sendError(10209);
+            return ;
+        }
+
+        $data['team_id'] = $team_id ;
+        $data['member_uid'] = $memberInfo['uid'] ;
+        $data['member_username'] = $memberInfo['username'] ;
+        $data['addtime'] = time() ;
+        $id = D("TeamMember")->add($data);  
+
+        //检查该团队已经加入了哪些项目
+        $teamItems = D("TeamItem")->where("  team_id = '$team_id' ")->select() ;
+        if ($teamItems) {
+            foreach ($teamItems as $key => $value) {
+                $data= array(
+                    "team_id"=>$team_id,
+                    "member_uid"=>$memberInfo['uid'],
+                    "member_username"=>$memberInfo['username'],
+                    "item_id"=>$value['item_id'],
+                    "member_group_id"=>1, //默认添加的权限为1,即编辑权限
+                    "addtime"=>time()
+                );
+                D("TeamItemMember")->add($data);
+            }
+        }
+        $return = D("TeamMember")->where(" id = '$id' ")->find();
+
+        if (!$return) {
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+        }
+
+        $this->sendResult($return);
+        
+    }
+
+    //获取列表
+    public function getList(){
+        $login_user = $this->checkLogin();
+        $team_id = I("team_id/d");
+
+        $teamInfo = D("Team")->where(" id = '$team_id' and uid = '$login_user[uid]' ")->find();
+        if (!$teamInfo) {
+            $this->sendError(102099,"无此团队或者你无管理此团队的权限");
+            return ;
+        }
+
+        if ($login_user['uid'] > 0 ) {
+            $ret = D("TeamMember")->where(" team_id = '$team_id' ")->order(" addtime desc  ")->select();
+        }
+        if ($ret) {
+            foreach ($ret as $key => &$value) {
+                $value['addtime'] = date("Y-m-d H:i:s" , $value['addtime']);
+            }
+           $this->sendResult($ret);
+        }else{
+            $this->sendResult(array());
+        }
+    }
+
+    //删除
+    public function delete(){
+        $login_user = $this->checkLogin();
+        $id = I("id/d")? I("id/d") : 0;
+        $teamMemberInfo = D("TeamMember")->where(" id = '$id'  ")->find();
+        $team_id = $teamMemberInfo['team_id'] ;
+        $teamInfo = D("Team")->where(" id = '$team_id' and uid = '$login_user[uid]' ")->find();
+        if (!$teamInfo) {
+            $this->sendError(102099,"无此团队或者你无管理此团队的权限");
+            return ;
+        }
+        $ret = D("TeamItemMember")->where(" member_uid = '$teamMemberInfo[member_uid]' and  team_id = '$team_id' ")->delete();
+        $ret = D("TeamMember")->where(" id = '$id' ")->delete();
+        
+
+        if ($ret) {
+           $this->sendResult($ret);
+        }else{
+            $return['error_code'] = 10103 ;
+            $return['error_message'] = 'request  fail' ;
+            $this->sendResult($return);
+        }
+    }
+
+
+
+
+}

+ 46 - 0
server/Application/Home/Controller/UpdateController.class.php

@@ -138,6 +138,52 @@ class UpdateController extends BaseController {
                 D("ItemMember")->execute($sql);
         }
 
+        //创建team表
+        $sql = "CREATE TABLE IF NOT EXISTS `team` (
+        `id`  INTEGER PRIMARY KEY ,
+        `team_name` CHAR(200) NOT NULL DEFAULT '',
+        `uid` int(11) NOT NULL DEFAULT '0' ,
+        `username` CHAR(200) NOT NULL DEFAULT '',
+        `addtime` int(11) NOT NULL DEFAULT '0' ,
+        `last_update_time` int(11) NOT NULL DEFAULT '0' 
+        )";
+        D("User")->execute($sql);
+
+        //创建team_item表
+        $sql = "CREATE TABLE IF NOT EXISTS `team_item` (
+        `id`  INTEGER PRIMARY KEY ,
+        `team_id` int(11) NOT NULL DEFAULT '0' ,
+        `item_id` int(11) NOT NULL DEFAULT '0' ,
+        `addtime` int(11) NOT NULL DEFAULT '0' ,
+        `last_update_time` int(11) NOT NULL DEFAULT '0' 
+        )";
+        D("User")->execute($sql);
+
+        //创建team_item_member表
+        $sql = "CREATE TABLE IF NOT EXISTS `team_item_member` (
+        `id`  INTEGER PRIMARY KEY ,
+        `team_id` int(11) NOT NULL DEFAULT '0' ,
+        `item_id` int(11) NOT NULL DEFAULT '0' ,
+        `member_group_id` int(11) NOT NULL DEFAULT '0' ,
+        `member_uid` int(11) NOT NULL DEFAULT '0' ,
+        `member_username` CHAR(200) NOT NULL DEFAULT '',
+        `addtime` int(11) NOT NULL DEFAULT '0' ,
+        `last_update_time` int(11) NOT NULL DEFAULT '0' 
+        )";
+        D("User")->execute($sql);
+
+        //创建team_member表
+        $sql = "CREATE TABLE IF NOT EXISTS `team_member` (
+        `id`  INTEGER PRIMARY KEY ,
+        `team_id` int(11) NOT NULL DEFAULT '0' ,
+        `member_uid` int(11) NOT NULL DEFAULT '0' ,
+        `member_username` CHAR(200) NOT NULL DEFAULT '',
+        `addtime` int(11) NOT NULL DEFAULT '0' ,
+        `last_update_time` int(11) NOT NULL DEFAULT '0' 
+        )";
+        D("User")->execute($sql);
+
+
 
         echo "OK!\n";
     }