模块表单入库插入方法

2024-01-26 11:28 小编

一、表结构

1、主表:dr_1_模块目录_form_表单名称

固定字段介绍

id    自增
uid    作者id
author 作者账号名
cid    模块内容id
catid    模块的栏目id
title    标题主题
inputtime    入库时间
inputip    入库IP地址
status    审核值,1通过,0待审
displayorder 排序值
tableid 对应的附表id

2、附表:dr_1_模块目录_form_表单名称_data_0,0是标号,数据达到一定量时自动增加附表分表

固定字段介绍

id    自增
uid    作者id
cid    模块内容id
catid    模块的栏目id


二、插入方法

$data = [];

$data['title'] = '标题测试';

$data['status'] = 1;

$data['catid'] = 1; // 栏目id

$data['cid'] = 1; // 内容id

$data['uid'] = (int)$this->member['uid'];

$data['author'] = $this->member['username'];

$data['inputip'] = \Phpcmf\Service::L('input')->ip_address();

$data['inputtime'] = SYS_TIME;

$data['tableid'] = 0;

$data['displayorder'] = 0;

// 插入主表

$rt = \Phpcmf\Service::M()->table_site("模块目录_form_表单名称")->insert($data);

if (!$rt['code']) {

    exit("插入失败:".$rt['code']);

}


//$data['tableid'] = 1;

//\Phpcmf\Service::M()->table_site("模块目录_form_表单名称")->update($data['id'], ['tableid' => $data['tableid']]);


$data2 = [];

$data2['id'] = $rt['code'];

$data2['uid'] = (int)$this->member['uid'];

$data2['catid'] = 1; // 栏目id

$data2['cid'] = 1; // 内容id

// 插入附表

$rt = \Phpcmf\Service::M()->table_site("模块目录_form_表单名称_data_".$data['tableid'])->insert($data2);

if (!$rt['code']) {

    // 删除主表

    \Phpcmf\Service::M()->table_site("模块目录_form_表单名称")->delete($data['id']);

    exit("插入失败:".$rt['code']);

}

// 更新表单数量到模块内容主表

$total = \Phpcmf\Service::M()->table_site('模块目录_form_表单名称')->where('status', 1)->where('cid', $data['cid'])->counts();

\Phpcmf\Service::M()->table_site('模块目录')->update($data['cid'], [

    '表单名称_total' => $total,

]);


在线咨询 拨打电话

电话

13363039260

微信二维码

微信二维码