You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.0 KiB

4 years ago
  1. <?php
  2. namespace Api\Controller;
  3. use Think\Controller;
  4. class AdminItemController extends BaseController {
  5. public function test()
  6. {
  7. $oss_setting = D("Options")->get("oss_setting");
  8. dump($oss_setting);
  9. }
  10. //获取所有项目列表
  11. public function getList(){
  12. $login_user = $this->checkLogin();
  13. $this->checkAdmin();
  14. $item_name = I("item_name");
  15. $page = I("page/d");
  16. $count = I("count/d");
  17. $username = I("username");
  18. $where = " is_del = 0 ";
  19. if ($item_name) {
  20. $item_name = \SQLite3::escapeString($item_name);
  21. $where .= " and item_name like '%{$item_name}%' ";
  22. }
  23. if ($username) {
  24. $username = \SQLite3::escapeString($username);
  25. $where .= " and username like '%{$username}%' ";
  26. }
  27. $items = D("Item")->where($where)->order(" addtime desc ")->page($page ,$count)->select();
  28. $total = D("Item")->where($where)->count();
  29. $item_members = D("ItemMember")->field("item_id , count(uid) as member_num")->group("item_id")->select();
  30. $return = array() ;
  31. $return['total'] = (int)$total ;
  32. if ($items) {
  33. foreach ($items as $key => &$value) {
  34. $value['addtime'] = date("Y-m-d H:i:s" , $value['addtime']);
  35. $value['member_num'] = $this->_get_member_num($item_members , $value['item_id']);
  36. }
  37. $return['items'] = $items ;
  38. $this->sendResult($return);
  39. }else{
  40. $this->sendResult(array());
  41. }
  42. }
  43. private function _get_member_num($item_members , $item_id){
  44. if ($item_members ) {
  45. foreach ($item_members as $key => $value) {
  46. if ($value['item_id'] == $item_id ) {
  47. return $value['member_num'] + 1 ;
  48. }
  49. }
  50. }
  51. return 1 ;
  52. }
  53. //删除项目
  54. public function deleteItem(){
  55. $login_user = $this->checkLogin();
  56. $this->checkAdmin();
  57. $item_id = I("item_id/d");
  58. $return = D("Item")->soft_delete_item($item_id);
  59. if (!$return) {
  60. $this->sendError(10101);
  61. }else{
  62. $this->sendResult($return);
  63. }
  64. }
  65. //转让项目
  66. public function attorn(){
  67. $login_user = $this->checkLogin();
  68. $this->checkAdmin();
  69. $username = I("username");
  70. $item_id = I("item_id/d");
  71. $item = D("Item")->where("item_id = '$item_id' ")->find();
  72. $member = D("User")->where(" username = '%s' ",array($username))->find();
  73. if (!$member) {
  74. $this->sendError(10209);
  75. return ;
  76. }
  77. $data['username'] = $member['username'] ;
  78. $data['uid'] = $member['uid'] ;
  79. $id = D("Item")->where(" item_id = '$item_id' ")->save($data);
  80. $return = D("Item")->where("item_id = '$item_id' ")->find();
  81. if (!$return) {
  82. $this->sendError(10101);
  83. return ;
  84. }
  85. $this->sendResult($return);
  86. }
  87. }