// +---------------------------------------------------------------------- // +---------------------------------------------------------------------- // | 表单模型 // +---------------------------------------------------------------------- namespace addons\formguide\model; use addons\formguide\library\Service; use think\Db; use think\Model; class Formguide extends Model { protected $name = 'ModelField'; protected $autoWriteTimestamp = false; //添加模型内容 public function addFormguideData($formid, $data) { //完整表名获取 $tablename = $this->getModelTableName($formid); $data['user_id'] = \app\member\service\User::instance()->id; $data['username'] = \app\member\service\User::instance()->username ?: '游客'; //处理数据 $data = Service::dealModelPostData($formid, $data); $data['create_time'] = request()->time(); $data['ip'] = request()->ip(); try { //主表 $id = Db::name($tablename)->insertGetId($data); } catch (\Exception $e) { throw new \Exception($e->getMessage()); } return $id; } /** * 根据模型ID,返回表名 * @param type $modelid * @return string */ protected function getModelTableName($modelid) { //读取模型配置 以后优化缓存形式 $model_cache = cache("Model"); //表名获取 return $model_cache[$modelid]['tablename']; } }