55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
namespace app\controller;
|
|
|
|
use support\Request;
|
|
|
|
use App\Utils\ApiResponse;
|
|
use App\model\Project;
|
|
use App\model\ProjectRegister;
|
|
use App\model\ProjectDetailed;
|
|
use App\dao\MessageDao;
|
|
class ProjectRegisterController
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* 报名函数
|
|
*/
|
|
public function signup(Request $request)
|
|
{
|
|
$user = $request->data;
|
|
$data = $request->post();
|
|
/**
|
|
* 通过中间件获取userid
|
|
*/
|
|
$userid=$user['id'];
|
|
$projectid=$data['projectid'];
|
|
$type=$data['type'];
|
|
$search_type=$type==1?'registerserve':'recruitingpersonnel';
|
|
$res=ProjectDetailed::where('projectid',$projectid)->first();
|
|
$Project=Project::where('id',$projectid)->first();
|
|
if(ProjectRegister::where('projectid',$projectid)->where('type','=',$type)->count()==$res->$search_type){
|
|
return ApiResponse::success(402,[],"当前报名人数已经满员");
|
|
}
|
|
|
|
/**
|
|
* 查询用户是否报名过
|
|
*/
|
|
$issignup=ProjectRegister::where('userid',$userid)->where('projectid',$projectid)->count();
|
|
if($issignup==0){
|
|
$ProjectRegister=new ProjectRegister();
|
|
$ProjectRegister->projectid=$projectid;
|
|
$ProjectRegister->type=$type;
|
|
$ProjectRegister->userid=$userid;
|
|
$ProjectRegister->save();
|
|
MessageDao::SendMessage($userid,"系统提醒","您已成功报名 $Project->title ");
|
|
return ApiResponse::success(200,[],"报名成功");
|
|
}
|
|
return ApiResponse::success(402,$issignup,"您已经报名过了");
|
|
}
|
|
|
|
|
|
} |