Activity.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\mobile\controller;
  4. use think\facade\Request;
  5. use app\model\Employee;
  6. use app\model\Activity as ActivityModel;
  7. use app\model\ActivityMaterial;
  8. use app\model\ActivityCollor;
  9. use toolkits\Aec;
  10. class Activity extends Base
  11. {
  12. /**
  13. * 活动列表
  14. */
  15. public function list()
  16. {
  17. $where = [
  18. ['root_id','=',0],
  19. ['del','=',0],
  20. ['show','=',1]
  21. ];
  22. $list = ActivityModel::where($where)->order('id desc')->field('id,title,cover,address,introduce,start_date,end_date')->limit(2)->select()->toArray();
  23. if($list){
  24. foreach ($list as $key => $value) {
  25. $list[$key]['start_date'] = date('m月d日',strtotime($value['start_date']));
  26. $list[$key]['end_date'] = date('m月d日',strtotime($value['end_date']));
  27. $list[$key]['introduce'] = '';//简介
  28. $list[$key]['is_sign'] = 0;//是否报名
  29. }
  30. }
  31. return json(['code'=>0,'data'=>$list]);
  32. }
  33. /**
  34. * 活动页面 列表
  35. * 活动预告 活动进行中 活动已结束
  36. */
  37. public function getList()
  38. {
  39. $param = Request::only(['page'=>1,'limit'=>10,'keyword'=>'','type'=>0]);
  40. $where = [
  41. ['root_id','=',0],
  42. ['del','=',0],
  43. ['show','=',1]
  44. ];
  45. if($param['keyword']) $where[] = ['title','like','%'.$param['keyword'].'%'];
  46. $date = date('Y-m-d');
  47. if ($param['type']==1) {
  48. //直播预告
  49. $where[] = ['start_date','>',$date];
  50. }elseif ($param['type']==2) {
  51. //直播中
  52. $where[] = ['start_date','<=',$date];
  53. $where[] = ['end_date','>=',$date];
  54. }elseif ($param['type']==3) {
  55. //直播回放
  56. $where[] = ['end_date','<',$date];
  57. }
  58. $list = ActivityModel::where($where)->order('id desc')->field('id,title,cover,address,introduce,start_date,end_date')->page((int)$param['page'],(int)$param['limit'])->select()->toArray();
  59. $sign = ActivityCollor::where([['aid','in',array_column($list,'id')],['type','=',1],['employee_id','=',$this->employeeId]])->column('aid');
  60. $group = ActivityCollor::where([['aid','in',array_column($list,'id')],['type','=',1]])->group('aid')->column('count(*)','aid');
  61. if($list){
  62. foreach ($list as $key => $value) {
  63. $list[$key]['start_date'] = date('m月d日',strtotime($value['start_date']));
  64. $list[$key]['end_date'] = date('m月d日',strtotime($value['end_date']));
  65. $list[$key]['introduce'] = $value['introduce'] ?: '';//简介
  66. $list[$key]['is_sign'] = in_array($value['id'],$sign) ? 1 : 0;//是否报名
  67. $list[$key]['res'] = $value['start_date']>$date ? '预告' : ($value['end_date']<$date ? '已结束' : '活动进行中');
  68. $list[$key]['sign_count'] = isset($group[$value['id']]) ? $group[$value['id']] : 0;
  69. }
  70. }
  71. $count = ActivityModel::where($where)->count();
  72. return json(['code'=>0,'data'=>$list,'count'=>$count]);
  73. }
  74. /**
  75. * 活动详情
  76. */
  77. public function read($id)
  78. {
  79. $where = [
  80. ['root_id','=',0],
  81. ['id','=',$id]
  82. ];
  83. $info = ActivityModel::where($where)->order('id desc')->findOrEmpty();
  84. if(!$info->isEmpty()){
  85. //是否结束
  86. $info['is_end'] = date('Y-m-d')>$info['end_date'] ? 1 : 0;
  87. $info['start_date'] = date('m月d日',strtotime($info['start_date']));
  88. $info['end_date'] = date('m月d日',strtotime($info['end_date']));
  89. $info['sign_count'] = ActivityCollor::where([['aid','=',$id],['type','=',1]])->count();
  90. $info['is_collor'] = !ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',0]])->findOrEmpty()->isEmpty();
  91. $info['is_sign'] = ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',1]])->findOrEmpty()->isEmpty();
  92. //分享加密参数
  93. $str = '0#' . $this->employeeId . '#' . $id;
  94. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  95. $info['str'] = $aec->encrypt($str);
  96. }
  97. return json(['code'=>0,'data'=>$info]);
  98. }
  99. /**
  100. * 获取活动相册
  101. * type 0图 1视频
  102. */
  103. public function getAlbum()
  104. {
  105. $param = Request::only(['page'=>1,'limit'=>10,'id'=>0,'type'=>0]);
  106. $where = [
  107. ['root_id','=',0],
  108. ['aid','=',$param['id']],
  109. ['type','=',$param['type']]
  110. ];
  111. $list = ActivityMaterial::where($where)->field('id,url')->page((int)$param['page'],(int)$param['limit'])->order('id desc')->select()->toArray();
  112. return json(['code'=>0,'data'=>$list]);
  113. }
  114. /**
  115. * 收藏
  116. */
  117. public function activityCollor()
  118. {
  119. $id = input('id',0);
  120. $check = ActivityModel::where([['root_id','=',0],['id','=',$id]])->findOrEmpty();
  121. if($check->isEmpty()) return json(['code'=>1,'data'=>'收藏失败','msg'=>'收藏失败']);
  122. $res = ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',0]])->findOrEmpty();
  123. if ($res->isEmpty()) {
  124. ActivityCollor::insertGetId(['employee_id'=>$this->employeeId,'aid'=>$id,'addtime'=>time()]);
  125. return json(['code'=>0,'data'=>'收藏成功','msg'=>'收藏成功']);
  126. }else{
  127. ActivityCollor::where([['aid','=',$id],['employee_id','=',$this->employeeId],['type','=',0]])->delete();
  128. return json(['code'=>0,'data'=>'取消收藏','msg'=>'取消收藏']);
  129. }
  130. }
  131. /**
  132. * 报名
  133. */
  134. public function activitySign()
  135. {
  136. $id = input('id',0);
  137. $check = ActivityModel::where([['root_id','=',0],['id','=',$id]])->findOrEmpty();
  138. if($check->isEmpty()) return json(['code'=>1,'data'=>'报名失败','msg'=>'报名失败']);
  139. $res = ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',1]])->findOrEmpty();
  140. if ($res->isEmpty()) {
  141. ActivityCollor::insertGetId(['employee_id'=>$this->employeeId,'aid'=>$id,'addtime'=>time(),'type'=>1]);
  142. return json(['code'=>0,'data'=>'报名成功','msg'=>'报名成功']);
  143. }else{
  144. return json(['code'=>0,'data'=>'已报名','msg'=>'已报名']);
  145. }
  146. }
  147. /**
  148. * 课件学习完成人员列表
  149. */
  150. public function course()
  151. {
  152. $id = input('id',0);
  153. $check = ActivityModel::where([['root_id','=',0],['id','=',$id]])->findOrEmpty();
  154. if($check->isEmpty()) return json(['code'=>1,'data'=>'报名失败','msg'=>'报名失败']);
  155. $res = ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',1]])->findOrEmpty();
  156. if ($res->isEmpty()) {
  157. ActivityCollor::insertGetId(['employee_id'=>$this->employeeId,'aid'=>$id,'addtime'=>time(),'type'=>1]);
  158. return json(['code'=>0,'data'=>'报名成功','msg'=>'报名成功']);
  159. }else{
  160. return json(['code'=>0,'data'=>'已报名','msg'=>'已报名']);
  161. }
  162. }
  163. }