Example #1
0
 /**
  * 删除群
  * @param int $id 群组ID
  */
 public function destroy($id = NULL)
 {
     if ($this->get_method() != 'POST') {
         $this->send_response(405, NULL, '请求的方法不存在');
     } elseif (empty($id)) {
         $this->send_response(400, NULL, '400401:群ID为空');
     }
     $groupInfo = $this->model->getGroupInfo($id);
     if (!$groupInfo) {
         $this->send_response(400, NULL, '400402:群不存在');
     }
     $grade = $this->model->getMemberGrade($id, $this->user_id);
     if ($grade < Kohana::config('group.grade.master')) {
         $this->send_response(400, NULL, '400413:非群主,无权限删除群');
     }
     $memberList = $this->model->getGroupAllMember($id);
     $result = $this->model->delete($id);
     if ($result) {
         $feedModel = Feed_Model::instance();
         $userModel = User_Model::instance();
         $content = '您加入的群"' . $groupInfo['gname'] . '"已解散';
         foreach ($memberList as $value) {
             $feedModel->deleteItem($id, 32, $value['uid']);
             $userModel->present_mo_notice(Kohana::config('uap.xiaomo'), $value['uid'], $content);
         }
         $this->send_response(200);
     }
     $this->send_response(400, NULL, '删除群失败');
 }