123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- declare(strict_types=1);
- namespace app\mobile\controller;
- use think\facade\Request;
- use app\model\Employee;
- use app\model\Activity as ActivityModel;
- use app\model\ActivityMaterial;
- use app\model\ActivityCollor;
- use toolkits\Aec;
- class Activity extends Base
- {
- /**
- * 活动列表
- */
- public function list()
- {
- $where = [
- ['root_id','=',0],
- ['del','=',0],
- ['show','=',1]
- ];
- $list = ActivityModel::where($where)->order('id desc')->field('id,title,cover,address,introduce,start_date,end_date')->limit(2)->select()->toArray();
- if($list){
- foreach ($list as $key => $value) {
- $list[$key]['start_date'] = date('m月d日',strtotime($value['start_date']));
- $list[$key]['end_date'] = date('m月d日',strtotime($value['end_date']));
- $list[$key]['introduce'] = '';//简介
- $list[$key]['is_sign'] = 0;//是否报名
- }
- }
- return json(['code'=>0,'data'=>$list]);
- }
- /**
- * 活动页面 列表
- * 活动预告 活动进行中 活动已结束
- */
- public function getList()
- {
- $param = Request::only(['page'=>1,'limit'=>10,'keyword'=>'','type'=>0]);
- $where = [
- ['root_id','=',0],
- ['del','=',0],
- ['show','=',1]
- ];
- if($param['keyword']) $where[] = ['title','like','%'.$param['keyword'].'%'];
- $date = date('Y-m-d');
- if ($param['type']==1) {
- //直播预告
- $where[] = ['start_date','>',$date];
- }elseif ($param['type']==2) {
- //直播中
- $where[] = ['start_date','<=',$date];
- $where[] = ['end_date','>=',$date];
- }elseif ($param['type']==3) {
- //直播回放
- $where[] = ['end_date','<',$date];
- }
- $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();
- $sign = ActivityCollor::where([['aid','in',array_column($list,'id')],['type','=',1],['employee_id','=',$this->employeeId]])->column('aid');
- $group = ActivityCollor::where([['aid','in',array_column($list,'id')],['type','=',1]])->group('aid')->column('count(*)','aid');
- if($list){
- foreach ($list as $key => $value) {
- $list[$key]['start_date'] = date('m月d日',strtotime($value['start_date']));
- $list[$key]['end_date'] = date('m月d日',strtotime($value['end_date']));
- $list[$key]['introduce'] = $value['introduce'] ?: '';//简介
- $list[$key]['is_sign'] = in_array($value['id'],$sign) ? 1 : 0;//是否报名
- $list[$key]['res'] = $value['start_date']>$date ? '预告' : ($value['end_date']<$date ? '已结束' : '活动进行中');
- $list[$key]['sign_count'] = isset($group[$value['id']]) ? $group[$value['id']] : 0;
- }
- }
- $count = ActivityModel::where($where)->count();
- return json(['code'=>0,'data'=>$list,'count'=>$count]);
- }
- /**
- * 活动详情
- */
- public function read($id)
- {
- $where = [
- ['root_id','=',0],
- ['id','=',$id]
- ];
- $info = ActivityModel::where($where)->order('id desc')->findOrEmpty();
- if(!$info->isEmpty()){
- //是否结束
- $info['is_end'] = date('Y-m-d')>$info['end_date'] ? 1 : 0;
- $info['start_date'] = date('m月d日',strtotime($info['start_date']));
- $info['end_date'] = date('m月d日',strtotime($info['end_date']));
- $info['sign_count'] = ActivityCollor::where([['aid','=',$id],['type','=',1]])->count();
- $info['is_collor'] = !ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',0]])->findOrEmpty()->isEmpty();
- $info['is_sign'] = ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',1]])->findOrEmpty()->isEmpty();
- //分享加密参数
- $str = '0#' . $this->employeeId . '#' . $id;
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- $info['str'] = $aec->encrypt($str);
- }
- return json(['code'=>0,'data'=>$info]);
- }
- /**
- * 获取活动相册
- * type 0图 1视频
- */
- public function getAlbum()
- {
- $param = Request::only(['page'=>1,'limit'=>10,'id'=>0,'type'=>0]);
- $where = [
- ['root_id','=',0],
- ['aid','=',$param['id']],
- ['type','=',$param['type']]
- ];
- $list = ActivityMaterial::where($where)->field('id,url')->page((int)$param['page'],(int)$param['limit'])->order('id desc')->select()->toArray();
- return json(['code'=>0,'data'=>$list]);
- }
- /**
- * 收藏
- */
- public function activityCollor()
- {
- $id = input('id',0);
- $check = ActivityModel::where([['root_id','=',0],['id','=',$id]])->findOrEmpty();
- if($check->isEmpty()) return json(['code'=>1,'data'=>'收藏失败','msg'=>'收藏失败']);
- $res = ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',0]])->findOrEmpty();
- if ($res->isEmpty()) {
- ActivityCollor::insertGetId(['employee_id'=>$this->employeeId,'aid'=>$id,'addtime'=>time()]);
- return json(['code'=>0,'data'=>'收藏成功','msg'=>'收藏成功']);
- }else{
- ActivityCollor::where([['aid','=',$id],['employee_id','=',$this->employeeId],['type','=',0]])->delete();
- return json(['code'=>0,'data'=>'取消收藏','msg'=>'取消收藏']);
- }
- }
- /**
- * 报名
- */
- public function activitySign()
- {
- $id = input('id',0);
- $check = ActivityModel::where([['root_id','=',0],['id','=',$id]])->findOrEmpty();
- if($check->isEmpty()) return json(['code'=>1,'data'=>'报名失败','msg'=>'报名失败']);
- $res = ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',1]])->findOrEmpty();
- if ($res->isEmpty()) {
- ActivityCollor::insertGetId(['employee_id'=>$this->employeeId,'aid'=>$id,'addtime'=>time(),'type'=>1]);
- return json(['code'=>0,'data'=>'报名成功','msg'=>'报名成功']);
- }else{
- return json(['code'=>0,'data'=>'已报名','msg'=>'已报名']);
- }
- }
- /**
- * 课件学习完成人员列表
- */
- public function course()
- {
- $id = input('id',0);
- $check = ActivityModel::where([['root_id','=',0],['id','=',$id]])->findOrEmpty();
- if($check->isEmpty()) return json(['code'=>1,'data'=>'报名失败','msg'=>'报名失败']);
- $res = ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',1]])->findOrEmpty();
- if ($res->isEmpty()) {
- ActivityCollor::insertGetId(['employee_id'=>$this->employeeId,'aid'=>$id,'addtime'=>time(),'type'=>1]);
- return json(['code'=>0,'data'=>'报名成功','msg'=>'报名成功']);
- }else{
- return json(['code'=>0,'data'=>'已报名','msg'=>'已报名']);
- }
- }
- }
|