12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- // +----------------------------------------------------------------------
- // | Yzncms [ 御宅男工作室 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2018 http://yzncms.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
- // +----------------------------------------------------------------------
- // | Author: 御宅男 <530765310@qq.com>
- // +----------------------------------------------------------------------
-
- // +----------------------------------------------------------------------
- // | 表单模型
- // +----------------------------------------------------------------------
- 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'];
- }
- }
|