初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller\app\activity;
|
||||
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
/**
|
||||
* 线下活动-表单
|
||||
*/
|
||||
class Form extends Api
|
||||
{
|
||||
|
||||
protected $noNeedLogin = [];
|
||||
// 无需鉴权的接口,*表示全部
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\api\model\app\activity\Form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 提交表单
|
||||
* @return void
|
||||
*/
|
||||
public function submit(){
|
||||
$activityId = input('activity_id');
|
||||
|
||||
$activityDetail =\app\api\model\app\activity\Activity::getActivityDetail($activityId);
|
||||
|
||||
if(!$activityDetail){
|
||||
$this->error("获取活动信息失败");
|
||||
}
|
||||
|
||||
if(!$activityDetail['apply_status']){
|
||||
$this->error("当前活动暂时无法报名,请刷新后重试");
|
||||
}
|
||||
|
||||
|
||||
$fromField = $this->model->getFromField($activityId);
|
||||
|
||||
if(!$fromField){
|
||||
$this->error("获取表单数据失败,请刷新后重试");
|
||||
}
|
||||
|
||||
$form = input('form/a',[]);
|
||||
|
||||
$ids = [];
|
||||
|
||||
//判断手机号是否重复
|
||||
//判断手机号是否已经报名过了
|
||||
|
||||
|
||||
foreach ($form as $index => $item) {
|
||||
|
||||
if (count($fromField) != count($item)) {
|
||||
$this->error("请完善表单信息后提交");
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ($form as $key => $option) {
|
||||
if($item[1] == $option[1] && $index != $key){
|
||||
$this->error("手机号码不能重复");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$isApply = $this->model
|
||||
->alias('form')
|
||||
->join(\app\api\model\app\activity\UserTicket::getTable() . ' ut','ut.apply_info_id = form.id')
|
||||
->where([
|
||||
'form.uniacid'=>UNIACID,
|
||||
'form.activity_id'=>$activityId,
|
||||
'form.mobile'=>$item[1],
|
||||
'ut.status'=>['in',[0,1]]
|
||||
])->find();
|
||||
|
||||
if($isApply){
|
||||
$this->error("手机号码{$item[1]}已经报过名了");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach ($form as $item){
|
||||
|
||||
$parseForm = $this->parseForm($fromField,$item);
|
||||
|
||||
$ids[] = $this->model->insertGetId([
|
||||
'uniacid'=>UNIACID,
|
||||
'user_id'=>$this->auth->id,
|
||||
'activity_id'=>$activityId,
|
||||
'name'=>$item[0],
|
||||
'mobile'=>$item[1],
|
||||
'other'=>json_encode($parseForm),
|
||||
'createtime'=>time()
|
||||
]);
|
||||
}
|
||||
|
||||
$this->success("提交成功",$ids);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 格式化表单
|
||||
* @param $formField
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function parseForm($formField,$data){
|
||||
$list = [];
|
||||
foreach ($formField as $index => $item){
|
||||
$list[] = [$item['name'],$data[$index]];
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取报名信息
|
||||
* @return void
|
||||
*/
|
||||
public function getApplyForm(){
|
||||
$activityId = input('activity_id');
|
||||
$fromField = $this->model->getFromField($activityId);
|
||||
|
||||
if(!$fromField){
|
||||
$this->error("获取报名信息失败");
|
||||
}
|
||||
|
||||
$this->success("获取成功",$fromField);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user