0
0

Banner.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class Banner extends Base
  5. {
  6. protected $createTime = 'create_time';
  7. protected $updateTime = 'update_time';
  8. public function updates(){
  9. $data = request()->post();
  10. $result = validate('Banner')->check($data,[],'');
  11. if(true !== $result){
  12. $this->error = validate('Banner')->getError();
  13. return false;
  14. }
  15. $id = $data['id'];
  16. unset($data['id']);
  17. if($id > 0){
  18. $data['update_time'] = date('Y-m-d H:i:s');
  19. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  20. }else{
  21. $data['create_time'] = date('Y-m-d H:i:s');
  22. $ret = $this->allowField(true)->save($data);
  23. }
  24. if(!$ret){
  25. $this->error = '操作失败';
  26. return false;
  27. }
  28. return true;
  29. }
  30. public function getList($limit,$type=0){
  31. $lists = Db::name('banner')
  32. ->where('del',0)
  33. ->where('enable',1)
  34. ->where('type',$type)
  35. ->order('sort asc,id desc')
  36. ->field('id,title,path')
  37. ->limit($limit)
  38. ->select();
  39. return $lists?$lists:[];
  40. }
  41. }