renderError('模板id不能为空'); $where = ['id' => $diyformid, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']]; $diyFrom = pdo_get(PDO_NAME . 'diyform' , $where , ['id','info'],'','create_time desc',1); if (!$diyFrom) $this->renderError('未设置报名表单'); $diyFromInfo = json_decode(base64_decode($diyFrom['info']) , true); $data = [ 'diyform' => $diyFromInfo //页面的配置信息 ]; $this->renderSuccess('数据返回成功',$data); } /** * 保存填写模板数据 */ public function saveDiyForm() { global $_W, $_GPC; try { $mid = $_W['mid']; $diyformid = $_GPC['diyformid']; $form_data = $_GPC['form_data']; $template_type = $_GPC['template_type']; $activities_id = $_GPC['activities_id']; $enroll_data = []; if (empty($diyformid) || !is_numeric($diyformid)) throw new Exception('表单id不能为空'); if (empty($form_data)) throw new Exception('表单数据不能为空'); if (empty($template_type)) throw new Exception('模板类型不能为空'); if (!in_array($template_type,array_keys(FormTemplate::$template_type))) throw new Exception('模板类型数据错误'); if (empty($activities_id) || !is_numeric($activities_id)) throw new Exception('活动id不能为空'); $activitiesData = FormTemplate::getTemplateTableData($template_type,$activities_id); if (empty($activitiesData)) throw new Exception('该活动不存在'); $query = pdo_get(PDO_NAME . 'member_enroll',['template_type' => $template_type,'mid' => $mid,'activities_id' => $activities_id],'id'); if ($query) throw new Exception('已报名该活动'); $diyFormInfo = html_entity_decode($form_data); $diyFormInfo = json_decode($diyFormInfo,true); foreach ($diyFormInfo as $info) { if ($info['is_required'] == '1') { if (empty($info['data'])) throw new Exception($info['title'] . " 为必填项"); } $info['data'] = FormTemplate::serializeTitle($info['data'],$info['id']); $enroll_data[] = [ 'name' => $info['title'], 'value' => $info['data'], 'filed_id' => $info['id'] ]; } if (empty($enroll_data)) throw new Exception('请填写至少一项'); $diyform = pdo_get(PDO_NAME . 'diyform',['id' => $diyformid],'info'); if (empty($diyform)) throw new Exception('表单id错误'); $diyFormInfo = $diyform['info']; // 开启事务 pdo_begin(); $insert = [ 'uniacid' => $_W['uniacid'], 'mid' => $mid, 'diyformid' => $diyformid, 'form_data' => $diyFormInfo, 'template_type' => $template_type, 'activities_id' => $activities_id, 'create_time' => date("Y-m-d H:i:s",time()) ]; $insertRes = pdo_insert(PDO_NAME . 'member_enroll',$insert); if (!$insertRes) { pdo_rollback(); throw new Exception('报名失败'); } $enroll_id = pdo_insertid(); $createRes = MemberEnrollData::create($enroll_data,$enroll_id); if (!$createRes) { pdo_rollback(); throw new Exception('报名失败'); } pdo_commit(); $this->renderSuccess('报名成功'); } catch (Exception $e) { $this->renderError($e->getMessage()); } } /** * 取消报名 */ public function cancelEnroll() { global $_W, $_GPC; $mid = $_W['mid']; $enroll_id = $_GPC['enroll_id']; if (empty($enroll_id)) $this->renderError('enroll_id is null'); $query = pdo_get(PDO_NAME . 'member_enroll',['id' => $enroll_id, 'mid' => $mid]); if (!$query) $this->renderError('报名信息不存在'); pdo_delete(PDO_NAME . 'member_enroll',$enroll_id); $this->renderSuccess('已取消'); } /** * 报名列表 */ public function getUserEnrollList() { global $_W, $_GPC; $mid = $_W['mid']; } }