pull/57/head
XingChao 2018-03-01 17:54:40 +08:00
parent ee93723d62
commit 92f055a934
2 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,60 @@
<?php
/**
* Created by PhpStorm.
* User: Windows 10
* Date: 2018-02-04
* Time: 10:41
*/
namespace app\api\controller;
use app\common\controller\Api;
class Raiders extends Api
{
public function _initialize()
{
parent::_initialize();
$this->model = model('raiders');
}
/**
* 读取产品信息
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags']);
// if ($this->request->isAjax())
// {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('pkey_name'))
{
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$total = $this->model
->where($where)
->order($sort, $order)
->count();
$list = $this->model
->where($where)
->order($sort, $order)
->limit($offset, $limit)
->select();
$result = array("total" => $total, "rows" => $list);
return json($result);
// $this->success('','',json(),$result);
// }
// return $this->view->fetch();
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace app\api\model;
use think\Model;
class Raiders extends Model
{
// 表名
protected $name = 'raiders';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
'create_time_text',
'update_time_text'
];
public function getCreateTimeTextAttr($value, $data)
{
$value = $value ? $value : $data['create_time'];
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getUpdateTimeTextAttr($value, $data)
{
$value = $value ? $value : $data['update_time'];
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setCreateTimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
protected function setUpdateTimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}
}