Merge pull request !3 from 微笑涩涩的/master

This commit is contained in:
2016-09-14 13:33:02 +08:00
4 changed files with 239 additions and 229 deletions

View File

@@ -1,133 +1,143 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ] // | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved. // | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn> // | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\common\model; namespace app\common\model;
/** /**
* 设置模型 * 设置模型
*/ */
class Document extends \think\model\Merge{ class Document extends \think\model\Merge{
protected $fk = 'doc_id'; protected $fk = 'doc_id';
//protected static $relationModel = array('document_article'); //protected static $relationModel = array('document_article');
// 定义需要自动写入时间戳格式的字段 // 定义需要自动写入时间戳格式的字段
protected $autoWriteTimestamp = array('create_time','update_time','deadline'); protected $autoWriteTimestamp = array('create_time','update_time','deadline');
protected $auto = array('doc_id', 'title', 'description', '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 $insert = array('uid', 'attach'=>0, 'view'=>0, 'comment'=>0, 'extend'=>0, 'create_time', 'status');
protected $type = array( protected $type = array(
'cover_id' => 'integer', 'cover_id' => 'integer',
'link_id' => 'integer', 'link_id' => 'integer',
'level' => 'integer', 'level' => 'integer',
'comment' => 'integer', 'comment' => 'integer',
'view' => 'integer', 'view' => 'integer',
); );
protected function setUidAttr(){ protected function setUidAttr(){
return session('user_auth.uid'); return session('user_auth.uid');
} }
protected function setDocIdAttr(){ protected function setDocIdAttr(){
return input('id','','intval,trim'); return input('id','','intval,trim');
} }
protected function setDeadlineAttr($value){ protected function setDeadlineAttr($value){
return $value ? strtotime($value) : time(); return $value ? strtotime($value) : time();
} }
protected function setCreateTimeAttr($value){ protected function setCreateTimeAttr($value){
return $value ? strtotime($value) : time(); return $value ? strtotime($value) : time();
} }
/** /**
* 获取数据状态 * 获取数据状态
* @return integer 数据状态 * @return integer 数据状态
* @author huajie <banhuajie@163.com> * @author huajie <banhuajie@163.com>
*/ */
protected function setStatusAttr($value){ protected function setStatusAttr($value){
$cate = input('post.category_id'); $cate = input('post.category_id');
$check = db('Category')->getFieldById($cate, 'check'); $check = db('Category')->getFieldById($cate, 'check');
if($check){ if($check){
$status = 2; $status = 2;
}else{ }else{
$status = 1; $status = 1;
} }
return $status; return $status;
} }
protected function getTagsAttr($value){ protected function getTagsAttr($value){
if ($value) { if ($value) {
return explode(',', $value); return explode(',', $value);
} }
} }
public function extend($name){ public function extend($name){
if (is_numeric($name)) { if (is_numeric($name)) {
$name = db('model')->where(array('id'=>$name))->value('name'); $name = db('model')->where(array('id'=>$name))->value('name');
} }
self::$relationModel = array('document_' . $name); self::$relationModel = array('document_' . $name);
return $this; return $this;
} }
public function change(){ public function change(){
/* 获取数据对象 */ /* 获取数据对象 */
$data = \think\Request::instance()->post(); $data = \think\Request::instance()->post();
if ($data !== false) { if ($data !== false) {
/* 添加或新增基础内容 */ //增加增加复选框 shu'zu数组保存
if(empty($data['id'])){ //新增数据 foreach($data ad $key=>$val){
unset($data['id']); if(is_array($val)){
$id = $this->validate('document.edit')->save($data); //添加基础内容 $data[$key] = implode(',', $val);
}
if(!$id){ }
return false; /* 添加或新增基础内容 */
} if(empty($data['id'])){ //新增数据
$data['id'] = $id; unset($data['id']);
} else { //更新数据 $id = $this->validate('document.edit')->save($data); //添加基础内容
$status = $this->validate('document.edit')->save($data, array('id'=>$data['id'])); //更新基础内容
if(false === $status){ if(!$id){
return false; return false;
} }
} $data['id'] = $id;
return $data['id']; } else { //更新数据
}else{ $status = $this->validate('document.edit')->save($data, array('id'=>$data['id'])); //更新基础内容
return false; if(false === $status){
} return false;
} }
}
public function del($map){ return $data['id'];
return $this->where($map)->delete(); }else{
} return false;
}
public function detail($id){ }
$data = $this->get($id);
public function del($map){
return $data; return $this->where($map)->delete();
} }
public function recom($id, $field = '*', $limit = 10, $order = 'id desc'){ public function detail($id){
$tag = $this->where(array('id'=>$id))->value('tags'); $data = $this->get($id);
$map = ''; $model_type = db('attribute')->where('model_id'=>$data['model_id'], 'type'=>array('in', 'checkbox'))->column('name');
if ($tag) { foreach($model_type as $val){
$tags = explode(',', $tag); $data->setAttr($val, explode(',', $data[$val]));
foreach ($tags as $item) { }
$where[] = 'tags LIKE "%' . $item . '%"';
} return $data;
$map = implode(' OR ', $where); }
}
$list = $this->where($map)->field($field)->limit($limit)->order($order)->select(); public function recom($id, $field = '*', $limit = 10, $order = 'id desc'){
if (empty($list)) { $tag = $this->where(array('id'=>$id))->value('tags');
return $list; $map = '';
}else{ if ($tag) {
return $this->field($field)->limit($limit)->order($order)->select(); $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();
}
}
} }

View File

@@ -1,59 +1,59 @@
{switch name="type"} {switch name="type"}
{case value="readonly"} {case value="readonly"}
<input type="text" class="form-control" name="{$field}" id="{$field}" value="{$value}" autocomplete="false" readonly> <input type="text" class="form-control" name="{$field}" id="{$field}" value="{$value}" autocomplete="false" readonly>
{/case} {/case}
{case value="num"} {case value="num"}
<input type="text" style="width: auto;" class="form-control" name="{$field}" id="{$field}" autocomplete="false" value="{$value}"> <input type="text" style="width: auto;" class="form-control" name="{$field}" id="{$field}" autocomplete="false" value="{$value}">
{/case} {/case}
{case value="decimal"} {case value="decimal"}
<input type="text" style="width: auto;" class="form-control" name="{$field}" id="{$field}" autocomplete="false" value="{$value}"> <input type="text" style="width: auto;" class="form-control" name="{$field}" id="{$field}" autocomplete="false" value="{$value}">
{/case} {/case}
{case value="text"} {case value="text"}
<input type="text" class="form-control" name="{$field}" id="{$field}" autocomplete="false" value="{$value}"> <input type="text" class="form-control" name="{$field}" id="{$field}" autocomplete="false" value="{$value}">
{/case} {/case}
{case value="password"} {case value="password"}
<input type="password" class="form-control" name="{$field}" id="{$field}" autocomplete="false" value="{$value}"> <input type="password" class="form-control" name="{$field}" id="{$field}" autocomplete="false" value="{$value}">
{/case} {/case}
{case value="textarea"} {case value="textarea"}
<textarea class="form-control" name="{$field}" id="{$field}">{$value}</textarea> <textarea class="form-control" name="{$field}" id="{$field}">{$value}</textarea>
{/case} {/case}
{case value="select"} {case value="select"}
<select class="form-control" name="{$field}" id="{$field}" style="width:auto;"> <select class="form-control" name="{$field}" id="{$field}" style="width:auto;">
{volist name="option" id="item"} {volist name="option" id="item"}
<option value="{$key}" {if condition="$key eq $value"}selected{/if}>{$item}</option> <option value="{$key}" {if condition="$key eq $value"}selected{/if}>{$item}</option>
{/volist} {/volist}
</select> </select>
{/case} {/case}
{case value="bool"} {case value="bool"}
<select class="form-control" name="{$field}" id="{$field}" style="width:auto;"> <select class="form-control" name="{$field}" id="{$field}" style="width:auto;">
{volist name="option" id="item"} {volist name="option" id="item"}
<option value="{$key}" {if condition="$key eq $value"}selected{/if}>{$item}</option> <option value="{$key}" {if condition="$key eq $value"}selected{/if}>{$item}</option>
{/volist} {/volist}
</select> </select>
{/case} {/case}
{case value="bind"} {case value="bind"}
<select class="form-control" name="{$field}" id="{$field}" style="width:auto;"> <select class="form-control" name="{$field}" id="{$field}" style="width:auto;">
{volist name="option" id="item"} {volist name="option" id="item"}
<option value="{$key}" {if condition="$key eq $value"}selected{/if}>{$item}</option> <option value="{$key}" {if condition="$key eq $value"}selected{/if}>{$item}</option>
{/volist} {/volist}
</select> </select>
{/case} {/case}
{case value="checkbox"} {case value="checkbox"}
{php}$value = isset($value) ? $value : 1;{/php} {php}$value = isset($value) && is_array($value) ? $value : array();{/php}
{volist name="option" id="item"} {volist name="option" id="item"}
<div class="checkbox-nice checkbox-inline"> <div class="checkbox-nice checkbox-inline">
<input type="checkbox" name="{$field}[]" id="{$field}-{$key}" value="{$key}" {if $key == $value}checked{/if}/> <input type="checkbox" name="{$field}[]" id="{$field}-{$key}" value="{$key}" {if in_array($key, $value)}checked{/if}/>
<label for="{$field}-{$key}">{$item}</label> <label for="{$field}-{$key}">{$item}</label>
</div> </div>
{/volist} {/volist}
{/case} {/case}
{case value="radio"} {case value="radio"}
{php}$value = isset($value) ? $value : 1;{/php} {php}$value = isset($value) ? $value : 1;{/php}
{volist name="option" id="item"} {volist name="option" id="item"}
<div class="radio radio-nice radio-inline"> <div class="radio radio-nice radio-inline">
<input type="radio" name="{$field}" id="{$field}-{$key}" value="{$key}" {if condition="$key eq $value"}checked{/if}/> <input type="radio" name="{$field}" id="{$field}-{$key}" value="{$key}" {if condition="$key eq $value"}checked{/if}/>
<label for="{$field}-{$key}">{$item}</label> <label for="{$field}-{$key}">{$item}</label>
</div> </div>
{/volist} {/volist}
{/case} {/case}
{/switch} {/switch}

View File

@@ -1,40 +1,40 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ] // | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved. // | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn> // | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\common\widget; namespace app\common\widget;
/** /**
* 上传插件widget * 上传插件widget
* 用于动态调用分类信息 * 用于动态调用分类信息
*/ */
class Form { class Form {
public function show($field, $info) { public function show($field, $info) {
$type = isset($field['type']) ? $field['type'] : 'text'; $type = isset($field['type']) ? $field['type'] : 'text';
//类型合并 //类型合并
if (in_array($type, array('string'))) { if (in_array($type, array('string'))) {
$type = 'text'; $type = 'text';
} }
if (in_array($type, array('picture'))) { if (in_array($type, array('picture'))) {
$type = 'image'; $type = 'image';
} }
$data = array( $data = array(
'type' => $type, 'type' => $type,
'field' => isset($field['name']) ? $field['name'] : '', 'field' => isset($field['name']) ? $field['name'] : '',
'value' => isset($info[$field['name']]) ? $info[$field['name']] : '', 'value' => isset($info[$field['name']]) ? $info[$field['name']] : '',
'size' => isset($field['size']) ? $field['size'] : 12, 'size' => isset($field['size']) ? $field['size'] : 12,
'option' => isset($field['option']) ? $field['option'] : '', 'option' => isset($field['option']) ? $field['option'] : '',
); );
$no_tem = array('readonly', 'text', 'password', 'textarea', 'select', 'bind', 'checkbox', 'radio', 'num', 'bool', 'decimal'); $no_tem = array('readonly', 'text', 'password','checkbox', 'textarea', 'select', 'bind', 'checkbox', 'radio', 'num', 'bool', 'decimal');
$type = !in_array($type, $no_tem) ? $type : 'show'; $type = !in_array($type, $no_tem) ? $type : 'show';
$view = new \think\View(); $view = new \think\View();
$view->assign($data); $view->assign($data);
return $view->fetch('common@default/form/' . $type); return $view->fetch('common@default/form/' . $type);
} }
} }

0
guoyanhao.md Normal file
View File