|
@@ -0,0 +1,215 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller\zzz;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+class Huodong extends Api
|
|
|
+{
|
|
|
+ protected $noNeedLogin = ['typelist','duixianglist'];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+ //活动类型
|
|
|
+ public function typelist()
|
|
|
+ {
|
|
|
+ $list = Db::name('zzz_hdtype')->field('id, name')->select();
|
|
|
+
|
|
|
+ $this->success(1, $list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //邀约对象
|
|
|
+ public function duixianglist(){
|
|
|
+ $list = Db::name('zzz_hdyaoyue')->field('id, name')->select();
|
|
|
+
|
|
|
+ $this->success(1, $list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //发布活动
|
|
|
+ public function addone(){
|
|
|
+ $data = [
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'type_id' => input('type_id',0),
|
|
|
+ 'didian' => input('didian',''),
|
|
|
+ 'yaoyue' => input('yaoyue',''),
|
|
|
+ 'starttime' => input('starttime','','strtotime'),
|
|
|
+ 'endtime' => input('endtime','','strtotime'),
|
|
|
+ 'info' => input('info',''),
|
|
|
+ 'image' => input('image',''),
|
|
|
+ 'createtime' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $data['typename'] = Db::name('zzz_hdtype')->where('id',$data['type_id'])->value('name');
|
|
|
+
|
|
|
+ Db::name('zzz_huodong')->insertGetId($data);
|
|
|
+
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+
|
|
|
+ //活动列表
|
|
|
+ public function huodong_list(){
|
|
|
+ $type_id = input('type_id',0);
|
|
|
+ $where = [];
|
|
|
+
|
|
|
+ if(!empty($type_id)){
|
|
|
+ $where['hd.type_id'] = $type_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = Db::name('zzz_huodong')->alias('hd')
|
|
|
+ ->field('hd.*,user.avatar,user.nickname,user.gender')
|
|
|
+ ->join('user','hd.user_id = user.id','LEFT')
|
|
|
+ ->autopage()
|
|
|
+ ->order('hd.id desc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $list = list_domain_image($list,['image']);
|
|
|
+
|
|
|
+ if(!empty($list)){
|
|
|
+
|
|
|
+ //我参与的活动ids
|
|
|
+ $hd_ids = array_column($list,'id');
|
|
|
+ $my_join_log = Db::name('zzz_hd_joinlog')->where('user_id',$this->auth->id)->where('hd_id','IN',$hd_ids)->column('hd_id');
|
|
|
+
|
|
|
+ foreach($list as $key => &$val){
|
|
|
+ //是否已加入
|
|
|
+ $val['is_joined'] = 0;
|
|
|
+ if(in_array($val['id'],$my_join_log)){
|
|
|
+ $val['is_joined'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //显示时间
|
|
|
+ $val['showtime'] = get_last_time($val['createtime']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success(1, $list);
|
|
|
+ }
|
|
|
+ //活动详情
|
|
|
+ public function huodong_info(){
|
|
|
+ $id = input('id',0);
|
|
|
+
|
|
|
+ $info = Db::name('zzz_huodong')->alias('hd')
|
|
|
+ ->field('hd.*,user.avatar,user.nickname,user.gender')
|
|
|
+ ->join('user','hd.user_id = user.id','LEFT')
|
|
|
+ ->where('hd.id',$id)
|
|
|
+ ->find();
|
|
|
+
|
|
|
+ $info = info_domain_image($info,['image']);
|
|
|
+
|
|
|
+ //是否已加入
|
|
|
+ $info['is_joined'] = 0;
|
|
|
+ $my_join_log = Db::name('zzz_hd_joinlog')->where('user_id',$this->auth->id)->where('hd_id',$id)->find();
|
|
|
+ if($my_join_log){
|
|
|
+ $info['is_joined'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //显示时间
|
|
|
+ $info['showtime'] = get_last_time($info['createtime']);
|
|
|
+
|
|
|
+ $this->success(1, $info);
|
|
|
+ }
|
|
|
+ //活动报名
|
|
|
+ public function huodong_join(){
|
|
|
+ $id = input('id',0);
|
|
|
+
|
|
|
+ $my_join_log = Db::name('zzz_hd_joinlog')->where('user_id',$this->auth->id)->where('hd_id',$id)->find();
|
|
|
+ if($my_join_log){
|
|
|
+ $this->error('不能重复报名');
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'hd_id' => $id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'createtime' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ Db::name('zzz_hd_joinlog')->insertGetId($data);
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+ //我发起的
|
|
|
+ public function huodong_myfabu(){
|
|
|
+ $where = [];
|
|
|
+
|
|
|
+ $where['hd.user_id'] = $this->auth->id;
|
|
|
+
|
|
|
+ $list = Db::name('zzz_huodong')->alias('hd')
|
|
|
+ ->field('hd.*,user.avatar,user.nickname,user.gender')
|
|
|
+ ->join('user','hd.user_id = user.id','LEFT')
|
|
|
+ ->autopage()
|
|
|
+ ->order('hd.id desc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $list = list_domain_image($list,['image']);
|
|
|
+
|
|
|
+ if(!empty($list)){
|
|
|
+
|
|
|
+ //我参与的活动ids
|
|
|
+ $hd_ids = array_column($list,'id');
|
|
|
+ $my_join_log = Db::name('zzz_hd_joinlog')->where('user_id',$this->auth->id)->where('hd_id','IN',$hd_ids)->column('hd_id');
|
|
|
+
|
|
|
+ foreach($list as $key => &$val){
|
|
|
+ //是否已加入
|
|
|
+ $val['is_joined'] = 0;
|
|
|
+ if(in_array($val['id'],$my_join_log)){
|
|
|
+ $val['is_joined'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //显示时间
|
|
|
+ $val['showtime'] = get_last_time($val['createtime']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success(1, $list);
|
|
|
+ }
|
|
|
+ //我报名的
|
|
|
+ public function huodong_myjoin(){
|
|
|
+ $where = [];
|
|
|
+
|
|
|
+ $my_join_log = Db::name('zzz_hd_joinlog')->where('user_id',$this->auth->id)->column('hd_id');
|
|
|
+ $where['hd.id'] = ['IN',$my_join_log];
|
|
|
+
|
|
|
+ $list = Db::name('zzz_huodong')->alias('hd')
|
|
|
+ ->field('hd.*,user.avatar,user.nickname,user.gender')
|
|
|
+ ->join('user','hd.user_id = user.id','LEFT')
|
|
|
+ ->autopage()
|
|
|
+ ->order('hd.id desc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $list = list_domain_image($list,['image']);
|
|
|
+
|
|
|
+ if(!empty($list)){
|
|
|
+
|
|
|
+ foreach($list as $key => &$val){
|
|
|
+ $val['is_joined'] = 1;
|
|
|
+
|
|
|
+ //显示时间
|
|
|
+ $val['showtime'] = get_last_time($val['createtime']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success(1, $list);
|
|
|
+ }
|
|
|
+ //某活动的报名人员列表
|
|
|
+ public function huodong_joinuser(){
|
|
|
+ $id = input('id',0);
|
|
|
+
|
|
|
+ $list = Db::name('zzz_hd_joinlog')->alias('log')
|
|
|
+ ->field('log.*,user.avatar,user.nickname,user.gender')
|
|
|
+ ->where('hd_id',$id)->select();
|
|
|
+
|
|
|
+ $this->success(1, $list);
|
|
|
+ }
|
|
|
+ //取消报名
|
|
|
+ public function huodong_join_cancel(){
|
|
|
+ $id = input('id',0);
|
|
|
+ Db::name('zzz_hd_joinlog')
|
|
|
+ ->where('user_id',$this->auth->id)
|
|
|
+ ->where('hd_id',$id)->delete();
|
|
|
+
|
|
|
+ $this->success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|