25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

98 satır
2.9 KiB

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