Advert.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\system;
  4. use library\basic\BaseModel;
  5. use library\traits\JwtAuthModelTrait;
  6. use library\traits\ModelTrait;
  7. use think\Model;
  8. /**
  9. * @mixin \think\Model
  10. */
  11. class Advert extends BaseModel
  12. {
  13. use ModelTrait;
  14. use JwtAuthModelTrait;
  15. /**
  16. * 获取列表数据
  17. * @param $page
  18. * @param $where
  19. * @param $pageCount
  20. * @param $desc
  21. */
  22. public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = ''){
  23. $data = $this
  24. ->field("p.*,ap.cate_name,ap.json")
  25. ->alias("p")
  26. ->join("adver_page ap",'ap.id=p.page_id')
  27. ->when(!empty($where),function ($query) use($where){
  28. if(!empty($where['page_id'])) {
  29. $query->where('p.page_id',$where['page_id']);
  30. }
  31. if(!empty($where['title'])) {
  32. $query->wherelike('p.title','%' . $where['title'] . '%');
  33. }
  34. if(isset($where['sassid'])) {
  35. $query->where('p.sassid',$where['sassid']);
  36. }
  37. })
  38. ->order($desc)
  39. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  40. ->toArray();
  41. foreach ($data['data'] as $k=>$v) {
  42. $data['data'][$k]['time'] = date('Y-m-d',$v['time']);
  43. $data['data'][$k]['jsonAr'] = json_decode($v['data'],true);
  44. }
  45. //echo $this->getLastSql();
  46. return [$data['total'],$data['data']];
  47. }
  48. /**
  49. * 保存分类
  50. * @param $post
  51. * @return bool
  52. */
  53. public function savePage($post){
  54. if(!empty($post['id'])) {
  55. $this->where('id',$post['id'])->save($post);
  56. return true;
  57. } else {
  58. unset($post['id']);
  59. $post['time'] = time();
  60. $bool = $this->insert($post);
  61. return $bool;
  62. }
  63. }
  64. //
  65. }