diff --git a/application/common/model/Document.php b/application/common/model/Document.php index 4b8d80dd..d825321c 100644 --- a/application/common/model/Document.php +++ b/application/common/model/Document.php @@ -1,133 +1,143 @@ - -// +---------------------------------------------------------------------- - -namespace app\common\model; - -/** -* 设置模型 -*/ -class Document extends \think\model\Merge{ - - protected $fk = 'doc_id'; - //protected static $relationModel = array('document_article'); - - // 定义需要自动写入时间戳格式的字段 - protected $autoWriteTimestamp = array('create_time','update_time','deadline'); - - protected $auto = array('doc_id', 'title', 'description', 'update_time','deadline'); - protected $insert = array('uid', 'attach'=>0, 'view'=>0, 'comment'=>0, 'extend'=>0, 'create_time', 'status'); - - protected $type = array( - 'cover_id' => 'integer', - 'link_id' => 'integer', - 'level' => 'integer', - 'comment' => 'integer', - 'view' => 'integer', - ); - - protected function setUidAttr(){ - return session('user_auth.uid'); - } - - protected function setDocIdAttr(){ - return input('id','','intval,trim'); - } - - protected function setDeadlineAttr($value){ - return $value ? strtotime($value) : time(); - } - - protected function setCreateTimeAttr($value){ - return $value ? strtotime($value) : time(); - } - - /** - * 获取数据状态 - * @return integer 数据状态 - * @author huajie - */ - protected function setStatusAttr($value){ - $cate = input('post.category_id'); - $check = db('Category')->getFieldById($cate, 'check'); - if($check){ - $status = 2; - }else{ - $status = 1; - } - return $status; - } - - protected function getTagsAttr($value){ - if ($value) { - return explode(',', $value); - } - } - - public function extend($name){ - if (is_numeric($name)) { - $name = db('model')->where(array('id'=>$name))->value('name'); - } - self::$relationModel = array('document_' . $name); - return $this; - } - - public function change(){ - /* 获取数据对象 */ - $data = \think\Request::instance()->post(); - - if ($data !== false) { - /* 添加或新增基础内容 */ - if(empty($data['id'])){ //新增数据 - unset($data['id']); - $id = $this->validate('document.edit')->save($data); //添加基础内容 - - if(!$id){ - return false; - } - $data['id'] = $id; - } else { //更新数据 - $status = $this->validate('document.edit')->save($data, array('id'=>$data['id'])); //更新基础内容 - if(false === $status){ - return false; - } - } - return $data['id']; - }else{ - return false; - } - } - - public function del($map){ - return $this->where($map)->delete(); - } - - public function detail($id){ - $data = $this->get($id); - - return $data; - } - - public function recom($id, $field = '*', $limit = 10, $order = 'id desc'){ - $tag = $this->where(array('id'=>$id))->value('tags'); - $map = ''; - if ($tag) { - $tags = explode(',', $tag); - foreach ($tags as $item) { - $where[] = 'tags LIKE "%' . $item . '%"'; - } - $map = implode(' OR ', $where); - } - $list = $this->where($map)->field($field)->limit($limit)->order($order)->select(); - if (empty($list)) { - return $list; - }else{ - return $this->field($field)->limit($limit)->order($order)->select(); - } - } + +// +---------------------------------------------------------------------- + +namespace app\common\model; + +/** +* 设置模型 +*/ +class Document extends \think\model\Merge{ + + protected $fk = 'doc_id'; + //protected static $relationModel = array('document_article'); + + // 定义需要自动写入时间戳格式的字段 + protected $autoWriteTimestamp = array('create_time','update_time','deadline'); + + protected $auto = array('doc_id', 'title', 'description', 'update_time','deadline'); + protected $insert = array('uid', 'attach'=>0, 'view'=>0, 'comment'=>0, 'extend'=>0, 'create_time', 'status'); + + protected $type = array( + 'cover_id' => 'integer', + 'link_id' => 'integer', + 'level' => 'integer', + 'comment' => 'integer', + 'view' => 'integer', + ); + + protected function setUidAttr(){ + return session('user_auth.uid'); + } + + protected function setDocIdAttr(){ + return input('id','','intval,trim'); + } + + protected function setDeadlineAttr($value){ + return $value ? strtotime($value) : time(); + } + + protected function setCreateTimeAttr($value){ + return $value ? strtotime($value) : time(); + } + + /** + * 获取数据状态 + * @return integer 数据状态 + * @author huajie + */ + protected function setStatusAttr($value){ + $cate = input('post.category_id'); + $check = db('Category')->getFieldById($cate, 'check'); + if($check){ + $status = 2; + }else{ + $status = 1; + } + return $status; + } + + protected function getTagsAttr($value){ + if ($value) { + return explode(',', $value); + } + } + + public function extend($name){ + if (is_numeric($name)) { + $name = db('model')->where(array('id'=>$name))->value('name'); + } + self::$relationModel = array('document_' . $name); + return $this; + } + + public function change(){ + /* 获取数据对象 */ + $data = \think\Request::instance()->post(); + + if ($data !== false) { + //增加增加复选框 shu'zu数组保存 + foreach($data ad $key=>$val){ + if(is_array($val)){ + $data[$key] = implode(',', $val); + } + } + /* 添加或新增基础内容 */ + if(empty($data['id'])){ //新增数据 + unset($data['id']); + $id = $this->validate('document.edit')->save($data); //添加基础内容 + + if(!$id){ + return false; + } + $data['id'] = $id; + } else { //更新数据 + $status = $this->validate('document.edit')->save($data, array('id'=>$data['id'])); //更新基础内容 + if(false === $status){ + return false; + } + } + return $data['id']; + }else{ + return false; + } + } + + public function del($map){ + return $this->where($map)->delete(); + } + + public function detail($id){ + $data = $this->get($id); + $model_type = db('attribute')->where('model_id'=>$data['model_id'], 'type'=>array('in', 'checkbox'))->column('name'); + foreach($model_type as $val){ + $data->setAttr($val, explode(',', $data[$val])); + } + + return $data; + } + + public function recom($id, $field = '*', $limit = 10, $order = 'id desc'){ + $tag = $this->where(array('id'=>$id))->value('tags'); + $map = ''; + if ($tag) { + $tags = explode(',', $tag); + foreach ($tags as $item) { + $where[] = 'tags LIKE "%' . $item . '%"'; + } + $map = implode(' OR ', $where); + } + $list = $this->where($map)->field($field)->limit($limit)->order($order)->select(); + if (empty($list)) { + return $list; + }else{ + return $this->field($field)->limit($limit)->order($order)->select(); + } + } } \ No newline at end of file diff --git a/application/common/view/default/form/show.html b/application/common/view/default/form/show.html index e14be293..2f0eac19 100644 --- a/application/common/view/default/form/show.html +++ b/application/common/view/default/form/show.html @@ -1,59 +1,59 @@ -{switch name="type"} - {case value="readonly"} - - {/case} - {case value="num"} - - {/case} - {case value="decimal"} - - {/case} - {case value="text"} - - {/case} - {case value="password"} - - {/case} - {case value="textarea"} - - {/case} - {case value="select"} - - {/case} - {case value="bool"} - - {/case} - {case value="bind"} - - {/case} - {case value="checkbox"} - {php}$value = isset($value) ? $value : 1;{/php} - {volist name="option" id="item"} -
- - -
- {/volist} - {/case} - {case value="radio"} - {php}$value = isset($value) ? $value : 1;{/php} - {volist name="option" id="item"} -
- - -
- {/volist} - {/case} +{switch name="type"} + {case value="readonly"} + + {/case} + {case value="num"} + + {/case} + {case value="decimal"} + + {/case} + {case value="text"} + + {/case} + {case value="password"} + + {/case} + {case value="textarea"} + + {/case} + {case value="select"} + + {/case} + {case value="bool"} + + {/case} + {case value="bind"} + + {/case} + {case value="checkbox"} + {php}$value = isset($value) && is_array($value) ? $value : array();{/php} + {volist name="option" id="item"} +
+ + +
+ {/volist} + {/case} + {case value="radio"} + {php}$value = isset($value) ? $value : 1;{/php} + {volist name="option" id="item"} +
+ + +
+ {/volist} + {/case} {/switch} \ No newline at end of file diff --git a/application/common/widget/Form.php b/application/common/widget/Form.php index c89962a1..57461277 100644 --- a/application/common/widget/Form.php +++ b/application/common/widget/Form.php @@ -1,40 +1,40 @@ - -// +---------------------------------------------------------------------- - -namespace app\common\widget; - -/** - * 上传插件widget - * 用于动态调用分类信息 - */ -class Form { - - public function show($field, $info) { - $type = isset($field['type']) ? $field['type'] : 'text'; - //类型合并 - if (in_array($type, array('string'))) { - $type = 'text'; - } - if (in_array($type, array('picture'))) { - $type = 'image'; - } - $data = array( - 'type' => $type, - 'field' => isset($field['name']) ? $field['name'] : '', - 'value' => isset($info[$field['name']]) ? $info[$field['name']] : '', - 'size' => isset($field['size']) ? $field['size'] : 12, - 'option' => isset($field['option']) ? $field['option'] : '', - ); - $no_tem = array('readonly', 'text', 'password', 'textarea', 'select', 'bind', 'checkbox', 'radio', 'num', 'bool', 'decimal'); - $type = !in_array($type, $no_tem) ? $type : 'show'; - $view = new \think\View(); - $view->assign($data); - return $view->fetch('common@default/form/' . $type); - } + +// +---------------------------------------------------------------------- + +namespace app\common\widget; + +/** + * 上传插件widget + * 用于动态调用分类信息 + */ +class Form { + + public function show($field, $info) { + $type = isset($field['type']) ? $field['type'] : 'text'; + //类型合并 + if (in_array($type, array('string'))) { + $type = 'text'; + } + if (in_array($type, array('picture'))) { + $type = 'image'; + } + $data = array( + 'type' => $type, + 'field' => isset($field['name']) ? $field['name'] : '', + 'value' => isset($info[$field['name']]) ? $info[$field['name']] : '', + 'size' => isset($field['size']) ? $field['size'] : 12, + 'option' => isset($field['option']) ? $field['option'] : '', + ); + $no_tem = array('readonly', 'text', 'password','checkbox', 'textarea', 'select', 'bind', 'checkbox', 'radio', 'num', 'bool', 'decimal'); + $type = !in_array($type, $no_tem) ? $type : 'show'; + $view = new \think\View(); + $view->assign($data); + return $view->fetch('common@default/form/' . $type); + } } \ No newline at end of file diff --git a/guoyanhao.md b/guoyanhao.md new file mode 100644 index 00000000..e69de29b