12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class Banner extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'img' => input('img','','trim'),
- 'type' => input('type/d','0'),
- 'enable' => input('enable/d',0),
- 'sort' => input('sort/d',0)
- ];
- $logdata = json_encode($data);
- $result = validate('Banner')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('Banner')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- if($id > 0){
- $content = '修改轮播图';
- }else{
- $content = '添加轮播图';
- }
- model('ActionLog')->add(18,$content,0,$logdata);
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info->toArray();
- }
- public function lists($page,$size,$type,$title){
- $map[] = ['del','=',0];
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- if(in_array($type,[0,1])){
- $map[] = ['type','=',$type];
- }
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('sort asc,id asc')
- ->select();
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists->toArray():[]
- ];
- return $data;
- }
- public function del($id){
- $ret = $this->where('id',$id)->delete();
- if(!$ret){
- HelpHander::error('删除失败');
- }
- $logdata = json_encode(['id' => $id]);
- model('ActionLog')->add(18,'删除轮播图',0,$logdata);
- return true;
- }
- }
|