You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
146 lines
5.0 KiB
146 lines
5.0 KiB
<?php
|
|
namespace app\member\controller;
|
|
use think\Db;
|
|
use think\Validate;
|
|
|
|
class Activity extends Base{
|
|
/**
|
|
* 活动报名接口
|
|
* @return string
|
|
*/
|
|
public function detail(){
|
|
$id=input('id','','intval');
|
|
$token=request()->token();
|
|
$uid=session('mhid');
|
|
if(!$id)$this->error('缺少参数',"",['token'=>$token]);
|
|
|
|
$activity=db('activity')->where(['id'=>$id])->find();
|
|
$apply=$activity['apply']?json_decode($activity['apply'],true):[];
|
|
|
|
$start=$activity['start_date'];
|
|
$end=$activity['end_date'];
|
|
$cur=time();
|
|
$state=1;
|
|
if($end<$cur)$state=-1;
|
|
if($start>$cur)$state=0;
|
|
$activity['state']=$state;
|
|
if($state>0){
|
|
if(!$uid){
|
|
$this->error('请先登录',url('login/index',['jump'=>urlencode(url('activity/detail',['id'=>$id]))]));
|
|
return false;
|
|
}
|
|
}else{
|
|
$this->error('活动已结束');
|
|
}
|
|
if(count($apply)){
|
|
foreach ($apply as $k=>$row){
|
|
if($row['ftype']=='checkbox'||$row['ftype']=='select'||$row['ftype']=='radio'){
|
|
$apply[$k]['foptions']=explode("||",$row['foptions']);
|
|
}
|
|
}
|
|
}
|
|
echo $state;
|
|
die('111');
|
|
if(request()->isPost()){
|
|
$uid=session('mhid');
|
|
if(!$uid){
|
|
$this->error('请先登录',url('index'),['token'=>$token]);
|
|
return false;
|
|
}
|
|
if($state==0){
|
|
$this->error("活动未开始","",['token'=>$token]);
|
|
return false;
|
|
}
|
|
if($state==-1){
|
|
$this->error("活动已结束","",['token'=>$token]);
|
|
return false;
|
|
}
|
|
$rule=[];
|
|
$msg=['__token__'=>'令牌验证失败',];
|
|
|
|
$check=Db::name('activityapply')->where(['uid'=>$uid,'aid'=>$id])->count();
|
|
if($check){
|
|
$this->error("此活动您已提交过报名","",['token'=>$token]);
|
|
return false;
|
|
}
|
|
$data=[];
|
|
$data['uid']=$uid;
|
|
$data['aid']=$id;
|
|
if(count($apply)){
|
|
foreach ($apply as $k=>$row){
|
|
|
|
if(request()->isPost()){
|
|
$ftag=$row['ftag'];
|
|
if($row['frequire']){
|
|
$fmsg='必填';
|
|
switch ($row['ftype']){
|
|
case 'checkbox':
|
|
case 'select':
|
|
case 'radio':
|
|
$fmsg='必选';
|
|
break;
|
|
case 'file':
|
|
$fmsg='必上传';
|
|
break;
|
|
}
|
|
$msg[$ftag]=$row['fname'].$fmsg;
|
|
}
|
|
if(isset($_POST[$ftag])){
|
|
$data[$ftag]=input("post.$ftag");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$post=input("post.");
|
|
|
|
$validate = new Validate($rule,$msg);
|
|
$result = $validate->check($post);
|
|
if(!$result){
|
|
$this->error($validate->getError(),"",['token'=>$token]);
|
|
}
|
|
$data['create_time']=time();
|
|
$query=Db::name('activityapply')->insert($data);
|
|
if(!$query){
|
|
$this->error('提交失败',"",['token'=>$token]);
|
|
}else{
|
|
|
|
$notice_title='您好,您的活动报名('.$activity['title'].')已报名成功 ';
|
|
$notice='';
|
|
$sl_data=[
|
|
'notice_title'=>$notice_title,
|
|
'notice'=>$notice_title,
|
|
'user_id'=>$uid,
|
|
'apply_id'=>$id,
|
|
'create_id'=>$uid,
|
|
'create_type'=>1,
|
|
'create_time'=>time()
|
|
];
|
|
Db::name('activitynotice')->insert($sl_data);
|
|
|
|
$this->success('提交成功');
|
|
}
|
|
}
|
|
$this->assign('id',$id);
|
|
$this->assign('apply',$apply);
|
|
$this->assign('activity',$activity);
|
|
return $this->view->fetch();
|
|
}
|
|
/**
|
|
* 检查是否允许托管
|
|
* @return string
|
|
*/
|
|
public function check()
|
|
{
|
|
if(!session('mhid')) return json(['code'=>0,'msg'=>'未登录','url'=>url('Login/index',['jump'=>urlencode(url('activity/index'))])]);
|
|
return json(['code'=>1,'url'=>url('activity/index')]);
|
|
}
|
|
public function index(){
|
|
|
|
$list= Db::name('activity')->where(['status'=>1,'kind'=>1,'poster'=>['neq','']])->order('sort desc')->paginate(10);
|
|
$show = $list->render();
|
|
$this->assign("list",$list);
|
|
$this->assign("show",$show);
|
|
return $this->view->fetch();
|
|
}
|
|
}
|