Browse Source

信息表单收集提交表单优化

master
wanghongjun 2 years ago
parent
commit
d56282f0c8
  1. 25
      addons/weliam_smartcity/api/Enroll.php
  2. 28
      addons/weliam_smartcity/core/model/MemberEnrollData.mod.php

25
addons/weliam_smartcity/api/Enroll.php

@ -44,13 +44,21 @@ class EnrollModuleUniapp extends Uniapp
$form_data = $_GPC['form_data'];
$template_type = $_GPC['template_type'];
$activities_id = $_GPC['activities_id'];
$enroll_data = $_GPC['enroll_data'];
if (empty($diyformid) || !is_numeric($diyformid)) throw new Exception('表单id不能为空');
if (empty($form_data)) throw new Exception('表单数据不能为空');
if (empty($enroll_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不能为空');
$enroll_data = json_decode(html_entity_decode($enroll_data),true);
foreach ($enroll_data as $item) {
if (!isset($item['name'])) throw new Exception('表单填写数据字段不能为空');
if (!isset($item['value'])) throw new Exception('表单填写数据值不能为空');
}
$activitiesData = FormTemplate::getTemplateTableData($template_type,$activities_id);
if (empty($activitiesData)) throw new Exception('该活动不存在');
@ -60,6 +68,8 @@ class EnrollModuleUniapp extends Uniapp
$diyFormInfo = html_entity_decode($form_data);
$diyFormInfo = base64_encode($diyFormInfo);
// 开启事务
pdo_begin();
$insert = [
'uniacid' => $_W['uniacid'],
'mid' => $mid,
@ -70,8 +80,21 @@ class EnrollModuleUniapp extends Uniapp
'create_time' => date("Y-m-d H:i:s",time())
];
pdo_insert(PDO_NAME . 'member_enroll',$insert);
$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());

28
addons/weliam_smartcity/core/model/MemberEnrollData.mod.php

@ -0,0 +1,28 @@
<?php
defined('IN_IA') or exit('Access Denied');
class MemberEnrollData
{
/**
* 添加
* @param $data
* @param $enroll_id
* @return bool
*/
public static function create($data,$enroll_id)
{
foreach ($data as $value) {
$insert = [
'enroll_id' => $enroll_id,
'filed_key' => $value['name'],
'field_value' => $value['value'],
];
$result = pdo_insert(PDO_NAME . 'member_enroll_data',$insert);
if (!$result) return false;
}
return true;
}
}
Loading…
Cancel
Save