Person.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace app\run\controller;
use app\common\controller\Frontend;
use think\Db;
use think\exception\ValidateException;
use think\Request;
class Person extends Frontend
{
protected $noNeedLogin = [''];
protected $noNeedRight = '*';
protected $layout = '';
public $model = null;
protected $modelValidate = true;
protected $modelSceneValidate = true;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\reservoir\run\Person;
}
public function index()
{
$duty = input('get.duty');
$list = $this->model->order('createtime', 'desc')->where('duty','like','%'.$duty.'%')->paginate($this->limit, false, [
'query' => Request::instance()->param(),//不丢失已存在的url参数
]);
$page = $list->render();
$this->assign('list', $list);
$this->assign('page', $page);
return $this->view->fetch();
}
public function add(){
$params = input('post.params/a');
try {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException(true)->validate($validate);
$params['createtime'] = strtotime($params['createtime']);
if($params['id']){
$result = $this->model->allowField(true)->save($params,['id'=>$params['id']]);
}
else{
$result = $this->model->allowField(true)->save($params);
}
} catch (ValidateException $e) {
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
}
}
public function getinfo($id){
$info = $this->model->get($id);
$info->createtime_text = date('Y-m-d',$info->createtime);
$this->success('','',$info);
}
public function del($id){
$dairy = $this->model->get($id);
$result = $dairy->delete();
if($result){
$this->success();
}
else{
$this->error('删除失败');
}
}
}