GroupController.php 6.3 KB
<?php
/**
 * Created by PhpStorm.
 * auther: sgj
 * Date: 2019/1/5
 * Time: 9:34
 */

namespace app\admin\controller;


use app\admin\model\UserModel;
use app\portal\model\GroupModel;
use cmf\controller\AdminBaseController;

/**
 * Class GroupController
 * @package app\admin\controller
 * @adminMenuRoot(
 *     'name'   => '圈子管理',
 *     'action' => 'default',
 *     'parent' => '',
 *     'display'=> true,
 *     'order'  => 10000,
 *     'icon'   => '',
 *     'remark' => ''
 * )
 */
class GroupController extends AdminBaseController
{

    protected $GroupModel;
    protected $OfficeModel;


    public function __construct(GroupModel $GroupModel)
    {
        parent::__construct();
        $this->GroupModel = $GroupModel;
    }
    /**
     *圈子列表
     * @adminMenu(
     *     'name'   => '圈子列表',
     *     'parent' => 'default',
     *     'display'=> true,
     *	   'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '密码修改',
     *     'param'  => ''
     * )
     */
    public function index(){
        $group=$this->GroupModel->getAllGroup()->toArray();
        //dump($group);
        $this->assign('group',$group);
        return $this->fetch();
    }
    /**
     *添加圈子
     * @adminMenu(
     *     'name'   => '添加圈子',
     *     'parent' => 'default',
     *     'display'=> false,
     *	   'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '',
     *     'param'  => ''
     * )
     */
    public function groupAdd(){


        return $this->fetch();
    }

    public function groupDel(){
        $map['id']=input('id');
        $update['delete_time']=time();
        $result=$this->GroupModel->where($map)->Update($update);
        if ($result){
            $this->success('删除成功!');
        }else{
            $this->error('操作失败!');
        }
    }

    public function groupEdit(){
        $id=input('id');
        if (empty($id)){
            $this->error('缺少相应参数!');
        }
        $group=$this->GroupModel->getGroup($id);
        $User=new \app\user\model\UserModel();
        if(!empty($group['owner'])){
            $user=$User->getUserBase($group['owner'])->toArray();
            $group['owner_name']=$user['user_login'];
        }
        $this->assign('group',$group);
        return $this->fetch();
    }

    public function groupArticle(){
        $group_id=input('id');
        $article=$this->GroupModel->getArticleList($group_id);
        $this->assign('article',$article);
        $this->assign('group_id',$group_id);
        return $this->fetch();
    }
    /**
     * 编辑群信息
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function editGroupPost(){
        $update=input();
        unset($update['id']);
        $map['id']=input('id');
        $result=db('group')->where($map)->update($update);
        if ($result){
            $this->success('编辑成功');
        }
        $this->error('编辑失败');
    }

    /**
     * 添加群信息
     */
    public function addGroupPost(){
        $data=input();
        $data['addtime']=time();
        if (empty($data['name'])){
            $this->error('名称不能为空');
        }
        $result=db('group')->insert($data);
        if ($result){
            $this->success('添加成功');
        }
        $this->error('添加失败');
    }
    /**
     *群内人员信息
     */
    public function groupPeople(){
        $Group=$this->GroupModel;
        $group=$Group->getGroup(input('id'));
        $map['g.delete_time']=null;
        $map['g.group_id']=input('id');
        $list=db('group_user')
            ->alias('g')
            ->field('g.id as gid,u.*')
            ->where($map)
            ->join('user u','g.user_id=u.id')
            ->paginate('20');
        $page = $list->render();
        $this->assign('group', $group);
        $this->assign('list', $list);
        $this->assign('page', $page);
        return $this->fetch();
    }

    /**
     * 拉黑用户
     */
    public function banUser(){
        $map['id']=input('id');
        $result=db('group_user')->where($map)->delete();
        if ($result==1){
            $this->success('删除用户!');
        }else{
            $this->error('删除失败!');
        }
    }

    public function groupPeopleAdd(){

        $user_id=explode(',',input('user_id'));

        foreach ($user_id as $k=>$v){
            $insert[$k]['user_id']=$v;
            $insert[$k]['group_id']=input('group_id');
            $insert[$k]['addtime']=time();
        }

        db('group_user')->insertAll($insert);
      $this->success();
    }

   public function groupArticleDelete(){
        $map['post_id']=input('id');
        $map['group_id']=input('group_id');
        $result=db('portal_group_post')->where($map)->delete();
        if ($result==1){
            $this->success('操作成功!');
        }else{
            $this->error('操作失败!');
        }
    }

    /**
     * @return mixed
     */
    public function groupInfo(){
        $map['g.group_id']=input('id');
        $map['g.delete_time']=null;
        $list=db('group_text')
            ->field('g.*,u.user_login,u.avatar')
            ->alias('g')
            ->join('user u','g.user_id=u.id')
            ->where($map)
            ->paginate('20');
        $info=$list->items();

        foreach ($info as $k=>$v){
            $info[$k]['more']=json_decode($v['more'],true);

        }

        $page = $list->render();
        $this->assign('list', $info);
        $this->assign('page', $page);
        return $this->fetch();
    }

    public function commentinfo(){
        $map['g.id']=input('id');
        $list=db('friend_comment')
            ->field('g.*,u.user_login,u.avatar')
            ->alias('g')
            ->join('user u','g.user_id=u.id')
            ->where($map)
            ->paginate('20');
        $info=$list->items();
        $page = $list->render();
        $this->assign('list', $info);
        $this->assign('page', $page);
        return $this->fetch();
    }

    public function commentDelete(){
        $map['id']=input('');
        $result=db('friend_comment')->where($map)->delete();
        if ($result==1){
            $this->success('删除成功!');
        }else{
            $this->error('删除失败!');
        }
    }


}