12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class LeaderShip extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'content' =>input('content','','trim'),
- 'enable' =>input('enable',1),
- ];
- $result = validate('LeaderShip')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('LeaderShip')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $data['update_time'] = date("Y-m-d H:i:s");
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date("Y-m-d H:i:s");
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info->toArray();
- }
- public function del($id){
- $ret = $this->where('id',$id)->update(['del'=>1]);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function lists($page,$size,$content){
- $map[] = ['enable','=',1];
- $map[] = ['del','=',0];
- if($content){
- $map[] = ['content','like','%'.$content.'%'];
- }
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists->toArray():[]
- ];
- return $data;
- }
- public function all(){
- $lists = $this
- ->where(['enable'=>1,'del'=>0])
- ->order('id desc')
- ->select();
- return $lists?$lists->toArray():[];
- }
- }
|