Team.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://demo.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  12. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\api\controller\Base;
  16. use think\Db;
  17. use think\Model;
  18. /**
  19. * @title 团队管理
  20. * @controller Team
  21. * @group base
  22. */
  23. class Team extends Base
  24. {
  25. function initialize()
  26. {
  27. $this->check_login();
  28. }
  29. /**
  30. * @title 更多排名/团队列表
  31. * @desc 更多排名/团队列表
  32. * @author QGF
  33. * @url /api/Team/team_list
  34. * @method GET
  35. * @tag 更多排名/团队列表
  36. * @param name:page type:int require:0 default:1 desc:页数(默认为1)
  37. * @param name:page_size type:int require:0 default:10 desc:每页数量(默认为10)
  38. * @return name:id type:int default:-- desc:团队ID
  39. * @return name:name type:string default:-- desc:团队名称
  40. * @return name:headimg type:string default:-- desc:团队头像地址
  41. * @return name:integral type:int default:-- desc:团队积分数量
  42. * @return name:people type:int default:-- desc:团队人数
  43. */
  44. public function team_list(){
  45. $page = input('page',1);
  46. $field = 'id,name,headimg,integral';
  47. $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();
  48. if($team_list){
  49. foreach ($team_list as &$value){
  50. //统计团队人数
  51. $value['people'] = Db::name('store_member')->where('team_id',$value['id'])->where('is_deleted',0)->where('status',1)->count('id');
  52. }
  53. }
  54. $this->success('获取成功',$team_list);
  55. }
  56. /**
  57. * @title 团队详情/我的团队
  58. * @desc 团队详情/我的团队
  59. * @author QGF
  60. * @url /api/Team/team_detail
  61. * @method GET
  62. * @tag 团队详情/我的团队
  63. * @param name:type type:int require:1 default:-- desc:接口类型(1:团队详情,2:我的团队)
  64. * @param name:team_id type:int require:0 default:-- desc:团队ID
  65. * @return name:headimg type:string default:-- desc:团队头像地址
  66. * @return name:name type:string default:-- desc:团队名称
  67. * @return name:integral type:int default:-- desc:团队积分数量
  68. * @return name:rank type:int default:-- desc:团队排名
  69. * @return name:team_member type:array default:-- desc:团队成员信息数组(id:成员ID,name:成员名称,headimg:成员头像,integral:成员获取的积分)
  70. * @return name:people type:int default:-- desc:团队人数
  71. * @return name:is_team_initiate type:int default:-- desc:是否是团队创建者(0:不是,1:是)
  72. */
  73. public function team_detail(){
  74. $uid = $this->uid;
  75. $type = input('type');
  76. if(empty($type)){
  77. $this->error('参数错误');
  78. }
  79. if($type == 1){
  80. $team_id = input('team_id');
  81. if(empty($team_id)){
  82. $this->error('参数错误');
  83. }
  84. }else{
  85. $field = 'team_id,is_team_initiate';
  86. $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
  87. if($user_info['is_team_initiate'] == 0){
  88. $this->error('你还没有自己的团队');
  89. }
  90. $team_id = $user_info['team_id'];
  91. }
  92. $team_info = Db::name('store_team')->field('user_id,headimg,name,integral')->where('id',$team_id)->where('is_deleted',0)->where('status',1)->find();
  93. if(empty($team_info)){
  94. $this->error('团队信息有误');
  95. }
  96. //查看团队排名
  97. $team_list = Db::name('store_team')->where('is_deleted',0)->where('status',1)->order('integral desc')->column('id');
  98. $team_info['rank'] = array_search($team_id, array_values($team_list))+1;
  99. //查看团队成员
  100. $team_member = Db::name('store_member')->field('id,name,headimg,integral')->where('team_id',$team_id)->where('is_deleted',0)->where('status',1)->select();
  101. $team_info['team_member'] = $team_member;
  102. $team_info['people'] = count($team_member);
  103. //是否是创建人
  104. $team_info['is_team_initiate'] = $team_info['user_id'] == $uid?1:0;
  105. unset($team_info['user_id']);
  106. $this->success('获取成功',$team_info);
  107. }
  108. /**
  109. * @title 申请列表
  110. * @desc 申请列表
  111. * @author QGF
  112. * @url /api/Team/apply_list
  113. * @method GET
  114. * @tag 申请列表
  115. * @return name:id type:int default:-- desc:申请记录ID
  116. * @return name:name type:string default:-- desc:申请人员名称
  117. * @return name:headimg type:string default:-- desc:申请人员头像地址
  118. * @return name:integral type:int default:-- desc:申请人员积分数量
  119. */
  120. public function apply_list(){
  121. $uid = $this->uid;
  122. $field = 'team_id,is_team_initiate';
  123. $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
  124. if($user_info['is_team_initiate'] == 0){
  125. $this->error('你还没有自己的团队');
  126. }
  127. $team_id = $user_info['team_id'];
  128. $apply_list = Db::name('store_team_apply')->field('id,user_id')->where('team_id',$team_id)->where('status',0)->select();
  129. if($apply_list){
  130. foreach ($apply_list as &$value){
  131. $member_info = Db::name('store_member')->field('name,headimg,integral')->where('id',$value['user_id'])->find();
  132. $value['name'] = $member_info['name'];
  133. $value['headimg'] = $member_info['headimg'];
  134. $value['integral'] = $member_info['integral'];
  135. unset($value['user_id']);
  136. }
  137. }
  138. $this->success('获取成功',$apply_list);
  139. }
  140. /**
  141. * @title 同意/拒绝
  142. * @desc 同意/拒绝申请加入团队
  143. * @author QGF
  144. * @url /api/Team/operate_apply
  145. * @method GET
  146. * @tag 申请列表
  147. * @param name:apply_id type:int require:1 default:-- desc:申请记录ID
  148. * @param name:type type:int require:1 default:-- desc:操作类型(1:同意,2:拒绝)
  149. */
  150. public function operate_apply(){
  151. $uid = $this->uid;
  152. $apply_id = input('apply_id');
  153. $type = input('type');
  154. if(empty($apply_id) || empty($type)){
  155. $this->error('参数错误');
  156. }
  157. $field = 'team_id,is_team_initiate';
  158. $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
  159. if($user_info['is_team_initiate'] == 0){
  160. $this->error('你还没有自己的团队');
  161. }
  162. $team_id = $user_info['team_id'];
  163. $apply_info = Db::name('store_team_apply')->field('id,user_id')->where('team_id',$team_id)->where('status',0)->where('id',$apply_id)->find();
  164. if(empty($apply_info)){
  165. $this->error('申请信息有误');
  166. }
  167. if($type == 1){
  168. $integral = Db::name('store_member')->where('id',$apply_info['user_id'])->value('integral');
  169. update_team_integral($integral,$team_id);
  170. Db::name('store_member')->where('id',$apply_info['user_id'])->update(array('team_id'=>$team_id));
  171. Db::name('store_team_apply')->where('id',$apply_id)->update(array('status'=>1));
  172. }else{
  173. Db::name('store_team_apply')->where('id',$apply_id)->update(array('status'=>2));
  174. }
  175. $this->success('操作成功');
  176. }
  177. /**
  178. * @title 成员详情
  179. * @desc 成员详情
  180. * @author QGF
  181. * @url /api/Team/team_member_detail
  182. * @method GET
  183. * @tag 成员详情
  184. * @param name:member_id type:int require:0 default:-- desc:成员ID
  185. * @return name:headimg type:string default:-- desc:成员头像地址
  186. * @return name:name type:string default:-- desc:成员名称
  187. * @return name:integral type:int default:-- desc:成员积分数量
  188. * @return name:manifesto type:string default:-- desc:成员宣言
  189. * @return name:photo type:string default:-- desc:成员个人照片地址
  190. * @return name:challenge_list type:array default:-- desc:成员挑战项目数组(title:标题,logo:图片地址,synopsis:简介,sign_info:挑战项目的签到信息(integral:获得积分数,image:签到图片(数组形式),thoughts:签到感想,create_at:签到时间))
  191. */
  192. public function team_member_detail(){
  193. $uid = $this->uid;
  194. $member_id = input('member_id');
  195. if(empty($member_id)){
  196. $this->error('参数错误');
  197. }
  198. $field = 'team_id,is_team_initiate';
  199. $user_info = Db::name('store_member')->field($field)->where('id',$uid)->find();
  200. if($user_info['is_team_initiate'] == 0){
  201. $this->error('你还没有自己的团队');
  202. }
  203. $member_info = Db::name('store_member')->field('headimg,name,team_id,integral,manifesto,photo')->where('id',$member_id)->find();
  204. if($member_info['team_id'] != $user_info['team_id']){
  205. $this->error('该成员不在你的团队');
  206. }
  207. //挑战的项目
  208. $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();
  209. if($challenge_list){
  210. foreach ($challenge_list as &$value){
  211. $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();
  212. $value['title'] = $task_info['title'];
  213. $value['logo'] = $task_info['logo'];
  214. $value['synopsis'] = $task_info['synopsis'];
  215. //该挑战项目签到的信息
  216. $sign_info = Db::name('store_sign_list')->field('integral,image,thoughts,create_at')->where('user_id',$member_id)->where('challenge_id',$value['id'])->select();
  217. if($sign_info){
  218. foreach ($sign_info as &$sign_value){
  219. $sign_value['image'] = image_path($sign_value['image']);
  220. }
  221. }
  222. $value['sign_info'] = $sign_info;
  223. unset($value['task_id']);
  224. unset($value['id']);
  225. }
  226. }
  227. $data = array(
  228. 'headimg' => $member_info['headimg'],
  229. 'name' => $member_info['name'],
  230. 'integral' => $member_info['integral'],
  231. 'manifesto' => $member_info['manifesto'],
  232. 'photo' => $member_info['photo'],
  233. 'challenge_list' => $challenge_list,
  234. );
  235. $this->success('获取成功',$data);
  236. }
  237. }