123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\api\controller;
- use app\api\controller\Base;
- use think\Db;
- use think\Model;
- /**
- * @title 团队管理
- * @controller Team
- * @group base
- */
- class Team extends Base
- {
- function initialize()
- {
- $this->check_login();
- }
- /**
- * @title 更多排名/团队列表
- * @desc 更多排名/团队列表
- * @author QGF
- * @url /api/Team/team_list
- * @method GET
- * @tag 更多排名/团队列表
- * @param name:page type:int require:0 default:1 desc:页数(默认为1)
- * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
- * @return name:id type:int default:-- desc:团队ID
- * @return name:name type:string default:-- desc:团队名称
- * @return name:headimg type:string default:-- desc:团队头像地址
- * @return name:integral type:int default:-- desc:团队积分数量
- * @return name:people type:int default:-- desc:团队人数
- */
- public function team_list(){
- $page = input('page',1);
- $field = 'id,name,headimg,integral';
- $team_list = Db::name('store_team')->field($field)->where('user_id','<>',13)->where('is_deleted',0)->where('status',1)->order('integral desc')->page($page,200)->select();
- if($team_list){
- foreach ($team_list as &$value){
- //统计团队人数
- $value['people'] = Db::name('store_member')->where('team_id',$value['id'])->where('is_deleted',0)->where('status',1)->count('id');
- }
- }
- $this->success('获取成功',$team_list);
- }
- /**
- * @title 团队详情/我的团队
- * @desc 团队详情/我的团队
- * @author QGF
- * @url /api/Team/team_detail
- * @method GET
- * @tag 团队详情/我的团队
- * @param name:type type:int require:1 default:-- desc:接口类型(1:团队详情,2:我的团队)
- * @param name:team_id type:int require:0 default:-- desc:团队ID
- * @return name:headimg type:string default:-- desc:团队头像地址
- * @return name:name type:string default:-- desc:团队名称
- * @return name:integral type:int default:-- desc:团队积分数量
- * @return name:rank type:int default:-- desc:团队排名
- * @return name:team_member type:array default:-- desc:团队成员信息数组(id:成员ID,name:成员名称,headimg:成员头像,integral:成员获取的积分)
- * @return name:people type:int default:-- desc:团队人数
- * @return name:is_team_initiate type:int default:-- desc:是否是团队创建者(0:不是,1:是)
- */
- public function team_detail(){
- $uid = $this->uid;
- $type = input('type');
- if(empty($type)){
- $this->error('参数错误');
- }
- if($type == 1){
- $team_id = input('team_id');
- if(empty($team_id)){
- $this->error('参数错误');
- }
- }else{
- $field = 'team_id,is_team_initiate';
- $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
- if($user_info['is_team_initiate'] == 0){
- $this->error('你还没有自己的团队');
- }
- $team_id = $user_info['team_id'];
- }
- $team_info = Db::name('store_team')->field('user_id,headimg,name,integral')->where('id',$team_id)->where('is_deleted',0)->where('status',1)->find();
- if(empty($team_info)){
- $this->error('团队信息有误');
- }
- //查看团队排名
- $team_list = Db::name('store_team')->where('is_deleted',0)->where('status',1)->order('integral desc')->column('id');
- $team_info['rank'] = array_search($team_id, array_values($team_list))+1;
- //查看团队成员
- $team_member = Db::name('store_member')->field('id,name,headimg,integral')->where('team_id',$team_id)->where('is_deleted',0)->where('status',1)->select();
- $team_info['team_member'] = $team_member;
- $team_info['people'] = count($team_member);
- //是否是创建人
- $team_info['is_team_initiate'] = $team_info['user_id'] == $uid?1:0;
- unset($team_info['user_id']);
- $this->success('获取成功',$team_info);
- }
- /**
- * @title 申请列表
- * @desc 申请列表
- * @author QGF
- * @url /api/Team/apply_list
- * @method GET
- * @tag 申请列表
- * @return name:id type:int default:-- desc:申请记录ID
- * @return name:name type:string default:-- desc:申请人员名称
- * @return name:headimg type:string default:-- desc:申请人员头像地址
- * @return name:integral type:int default:-- desc:申请人员积分数量
- */
- public function apply_list(){
- $uid = $this->uid;
- $field = 'team_id,is_team_initiate';
- $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
- if($user_info['is_team_initiate'] == 0){
- $this->error('你还没有自己的团队');
- }
- $team_id = $user_info['team_id'];
- $apply_list = Db::name('store_team_apply')->field('id,user_id')->where('team_id',$team_id)->where('status',0)->select();
- if($apply_list){
- foreach ($apply_list as &$value){
- $member_info = Db::name('store_member')->field('name,headimg,integral')->where('id',$value['user_id'])->find();
- $value['name'] = $member_info['name'];
- $value['headimg'] = $member_info['headimg'];
- $value['integral'] = $member_info['integral'];
- unset($value['user_id']);
- }
- }
- $this->success('获取成功',$apply_list);
- }
- /**
- * @title 同意/拒绝
- * @desc 同意/拒绝申请加入团队
- * @author QGF
- * @url /api/Team/operate_apply
- * @method GET
- * @tag 申请列表
- * @param name:apply_id type:int require:1 default:-- desc:申请记录ID
- * @param name:type type:int require:1 default:-- desc:操作类型(1:同意,2:拒绝)
- */
- public function operate_apply(){
- $uid = $this->uid;
- $apply_id = input('apply_id');
- $type = input('type');
- if(empty($apply_id) || empty($type)){
- $this->error('参数错误');
- }
- $field = 'team_id,is_team_initiate';
- $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
- if($user_info['is_team_initiate'] == 0){
- $this->error('你还没有自己的团队');
- }
- $team_id = $user_info['team_id'];
- $apply_info = Db::name('store_team_apply')->field('id,user_id')->where('team_id',$team_id)->where('status',0)->where('id',$apply_id)->find();
- if(empty($apply_info)){
- $this->error('申请信息有误');
- }
- if($type == 1){
- $integral = Db::name('store_member')->where('id',$apply_info['user_id'])->value('integral');
- update_team_integral($integral,$team_id);
- Db::name('store_member')->where('id',$apply_info['user_id'])->update(array('team_id'=>$team_id));
- Db::name('store_team_apply')->where('id',$apply_id)->update(array('status'=>1));
- }else{
- Db::name('store_team_apply')->where('id',$apply_id)->update(array('status'=>2));
- }
- $this->success('操作成功');
- }
- /**
- * @title 成员详情
- * @desc 成员详情
- * @author QGF
- * @url /api/Team/team_member_detail
- * @method GET
- * @tag 成员详情
- * @param name:member_id type:int require:0 default:-- desc:成员ID
- * @return name:headimg type:string default:-- desc:成员头像地址
- * @return name:name type:string default:-- desc:成员名称
- * @return name:integral type:int default:-- desc:成员积分数量
- * @return name:manifesto type:string default:-- desc:成员宣言
- * @return name:photo type:string default:-- desc:成员个人照片地址
- * @return name:challenge_list type:array default:-- desc:成员挑战项目数组(title:标题,logo:图片地址,synopsis:简介,sign_info:挑战项目的签到信息(integral:获得积分数,image:签到图片(数组形式),thoughts:签到感想,create_at:签到时间))
- */
- public function team_member_detail(){
- $uid = $this->uid;
- $member_id = input('member_id');
- if(empty($member_id)){
- $this->error('参数错误');
- }
- $field = 'team_id,is_team_initiate';
- $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
- if($user_info['is_team_initiate'] == 0){
- $this->error('你还没有自己的团队');
- }
- $member_info = Db::name('store_member')->field('headimg,name,team_id,integral,manifesto,photo')->where('id',$member_id)->find();
- if($member_info['team_id'] != $user_info['team_id']){
- $this->error('该成员不在你的团队');
- }
- //挑战的项目
- $challenge_list = Db::name('store_challenge')->field('id,task_id')->where('user_id',$member_id)->where('is_deleted',0)->where('status',1)->order('id desc')->select();
- if($challenge_list){
- foreach ($challenge_list as &$value){
- $task_info = Db::name('store_environmental_task')->field('title,logo,synopsis,integral')->where('id',$value['task_id'])->where('is_deleted',0)->where('status',1)->find();
- $value['title'] = $task_info['title'];
- $value['logo'] = $task_info['logo'];
- $value['synopsis'] = $task_info['synopsis'];
- //该挑战项目签到的信息
- $sign_info = Db::name('store_sign_list')->field('integral,image,thoughts,create_at')->where('user_id',$member_id)->where('challenge_id',$value['id'])->select();
- if($sign_info){
- foreach ($sign_info as &$sign_value){
- $sign_value['image'] = image_path($sign_value['image']);
- }
- }
- $value['sign_info'] = $sign_info;
- unset($value['task_id']);
- unset($value['id']);
- }
- }
- $data = array(
- 'headimg' => $member_info['headimg'],
- 'name' => $member_info['name'],
- 'integral' => $member_info['integral'],
- 'manifesto' => $member_info['manifesto'],
- 'photo' => $member_info['photo'],
- 'challenge_list' => $challenge_list,
- );
- $this->success('获取成功',$data);
- }
- }
|