TeamController.php 4.9 KB
<?php
/**
 * Created by PhpStorm.
 * auther: sgj
 * Date: 2020/10/12
 * Time: 9:54
 */

namespace app\admin\controller;


use cmf\controller\AdminBaseController;

class TeamController extends AdminBaseController
{

    /**
     * 首页内容
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index(){
        $teamId=$this->getAdminTeamId();
        $param=$this->request->param();
        if ($teamId==0){
            $map=[];
        }else{
            $map['id']=$teamId;
        }

        $data= db('team')->where($map)->order('id desc')->paginate();
        $data->appends($param);
        $list=$data->items();
        $this->assign([
            'data'=>$list,
            'page'=>$data->render(),
        ]);
        $this->assign('teamId',$teamId);
        return $this->fetch();
    }

    /**
     * 申请列表
     */
    public function applylist(){
        $param=$this->request->param();
        $map['t.team_id']=$param['id'];
        $data= db('team_apply')
            ->field('t.*,v.name')
            ->alias('t')->join('volunteer v','v.user_id=t.user_id')
            ->where($map)
            ->order('t.id desc')
            ->paginate();
        $data->appends($param);
        $list=$data->items();
        $this->assign([
            'data'=>$list,
            'page'=>$data->render(),
        ]);
        return $this->fetch();
    }
    /**
     * 是否通过
     */
    public function pass(){
        $data=input();
        $update['status']=$data['status'];
        $info=db('team')->where('id',$data['id'])->update($update);
        if (!empty($info)){
            $this->success('操作成功!');
        }else{
            $this->error('操作失败');
        }
    }

    /**
     * 编辑
     */
    public function edit(){
        $id=input('id');
        $data=db('team')->where('id',$id)->find();

        $provincedb=db('position_province')->select()->toArray();
        foreach ($provincedb as $k=>$v){
            $province[$v['id']]['name']=$v['province_name'];
            $province[$v['id']]['id']=$v['id'];
        }
        $this->assign('data',$data);
        $this->assign('area',$province);
        return $this->fetch();
    }


    /**
     * 编辑提交
     */
    public function editPost(){
        $id=input('id');
        $data=input('');
        $info=db('team')->where('id',$data['id'])->update($data);
        $this->success('操作成功!');
    }


    /**
     * 申请通过
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function apply_pass(){
        $teamId=$this->getAdminTeamId();
        $data=input();
        $update['status']=$data['status'];
        $info=db('team_apply')->where('id',$data['id'])->find();
        db('team')->where('id',$info['team_id'])->setInc('people_num');
        $info=db('team_apply')->where('id',$data['id'])->update($update);

        if (!empty($info)){
            if ($data['status']==1){
                $action='审核通过';
            }else{
                $action='审核不同过';
            }
            if ($teamId>0){

                $this->addTeamLog($teamId,'团队',$action,$info);
            }

            $openid=db('third_party_user')->where('user_id',$info['user_id'])->value('openid');
            $volunteer=db('volunteer')->where('user_id',$info['user_id'])->find();

            $date=date('Y-m-d H:i');
            $data=[
                'phrase1' => ['value' =>"$volunteer[name] $action"],    //审核结果
                'thing2'=>['value'=>$info['name']],         //活动名称
                'thing4'=>['value'=>$action],                      //备注
                'date7'=>['value'=>$date]                        //审核时间
            ];
            $Info=sendSubMessage($data,$openid);

            $this->success('操作成功!');
        }else{
            $this->success('操作成功!');
        }
    }


    /**
     * 添加团队
     * @return mixed
     */
    public function addTeam(){
        $provincedb=db('position_province')->select()->toArray();
        foreach ($provincedb as $k=>$v){
            $province[$v['id']]['name']=$v['province_name'];
            $province[$v['id']]['id']=$v['id'];
        }

        $this->assign('area',$province);
        return $this->fetch();
    }

    /**
     * 提交信息
     */
    public function addPost(){
        $data=input('');
        $data['create_time']=time();
        $info=db('team')->insert($data);
       if (!empty($info)){
           $this->success('操作成功!');
       }
    }

    /**
     * 删除信息
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function delete(){
        $id=input('id');
        db('team')->where('id',$id)->delete();
        $this->success('操作成功!');
    }


}