diff --git a/application/admin/controller/Form.php b/application/admin/controller/Form.php index d74e06fb..335482ba 100644 --- a/application/admin/controller/Form.php +++ b/application/admin/controller/Form.php @@ -102,8 +102,52 @@ class Form extends Admin { * @DateTime 2017-06-30 * @return html 页面 */ - public function lists() { - return $this->fetch(); + public function lists($form_id = '') { + $form = $this->model->where('id', $form_id)->find(); + + $list = M($form['name'], 'form')->order('id desc')->paginate(25); + + $data = array( + 'form_id' => $form_id, + 'list' => $list, + 'page' => $list->render() + ); + $this->assign($data); + $this->setMeta('数据列表'); + return $this->fetch('list_'.$form['name']); + } + + public function detail($form_id = '', $id = ''){ + $form = $this->model->where('id', $form_id)->find(); + + $info = M($form['name'], 'form')->where('id', $id)->find(); + + $data = array( + 'info' => $info + ); + $this->assign($data); + $this->setMeta('数据详情'); + return $this->fetch('detail_'.$form['name']); + } + + //数据导出 + public function outxls($form_id = '') { + $form = $this->model->where('id', $form_id)->find(); + + $attr = $this->Fattr->where('form_id', $form_id)->where('is_show', 1)->select(); + foreach ($attr as $key => $value) { + $title[$value['name']] = $value['title']; + } + + $data[] = $title; + $res = M($form['name'], 'form')->order('id desc')->select(); + + foreach ($res as $key => $value) { + $data[] = $value; + } + + $out = new \com\Outxls($data, date('Y-m-d')); + $out->out(); } public function attr($form_id = '') { @@ -187,7 +231,6 @@ class Form extends Admin { } } - protected function getField(){ return array( array('name' => 'id', 'title' => 'id', 'help' => '', 'type' => 'hidden'), diff --git a/application/common/model/BaseModel.php b/application/common/model/BaseModel.php index 6c8174ef..2957eff7 100644 --- a/application/common/model/BaseModel.php +++ b/application/common/model/BaseModel.php @@ -34,13 +34,21 @@ class BaseModel { protected $attrDb = 'Attribute'; public function __construct($name) { - $this->db = db($name); + if ($this->attrDb == 'FormAttr') { + $this->db = db('Form'.ucfirst($name)); + }else{ + $this->db = db($name); + } } public function save($data, $where = array()) { $this->data = $data; $rule = $msg = array(); - $attr = db($this->attrDb)->where('model_id', $data['model_id'])->select(); + if ($this->attrDb == 'FormAttr') { + $attr = db($this->attrDb)->where('form_id', $data['form_id'])->select(); + }else{ + $attr = db($this->attrDb)->where('model_id', $data['model_id'])->select(); + } foreach ($attr as $key => $value) { if ($value['is_must'] == 1) { $rule[$value['name']] = "require"; @@ -249,6 +257,28 @@ class BaseModel { } return $value; } + + + /** + * 获取对象原始数据 如果不存在指定字段返回false + * @access public + * @param string $name 字段名 留空获取全部 + * @return mixed + * @throws InvalidArgumentException + */ + public function getData($name = null) + { + if (is_null($name)) { + return $this->data; + } elseif (array_key_exists($name, $this->data)) { + return $this->data[$name]; + } elseif (array_key_exists($name, $this->relation)) { + return $this->relation[$name]; + } else { + throw new InvalidArgumentException('property not exists:' . $this->class . '->' . $name); + } + } + public function __call($method, $args) { return call_user_func_array([$this->db, $method], $args); } diff --git a/application/common/model/DiyForm.php b/application/common/model/DiyForm.php index 4f82c568..180087ae 100644 --- a/application/common/model/DiyForm.php +++ b/application/common/model/DiyForm.php @@ -13,5 +13,6 @@ namespace app\common\model; * 自定义表单模型 */ class DiyForm extends BaseModel{ - + + protected $attrDb = 'FormAttr'; } \ No newline at end of file diff --git a/application/common/model/FormAttr.php b/application/common/model/FormAttr.php index ae30c4a4..34760f19 100644 --- a/application/common/model/FormAttr.php +++ b/application/common/model/FormAttr.php @@ -37,7 +37,7 @@ class FormAttr extends Base{ return $db->columField('form_' . strtolower($name), $attr)->query(); } }); - self::beforeUpdate(function($data){dump($data); + self::beforeUpdate(function($data){ $attr = $data->toArray(); $attr['action'] = 'CHANGE'; $attr['oldname'] = db('FormAttr')->where('id', $attr['id'])->value('name');