SysAdModel.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Ad\Models;
  3. use App\Models\BaseModel;
  4. class SysAdModel extends BaseModel
  5. {
  6. protected $table = 'sys_ad';
  7. /**
  8. * 检查 名称是否唯一
  9. * */
  10. public function checkPosition($positionId,$id=0){
  11. $where=[];
  12. if(!empty($id)){
  13. $where[]=['id', '<>', $id];
  14. }
  15. $where[]=['status', '<', 2];
  16. $where[]=['position_id', '=', trim($positionId)];
  17. return $this->checkFieldUnique('position_id',$where);
  18. }
  19. /**
  20. * 获取广告列表
  21. * */
  22. public function getAdList($params){
  23. list($pageSize, $page, $skip) = $this->getPaginatorParams($params);
  24. $where=[];
  25. if(isset($params['status'])){
  26. $where[]=['a.status','=',$params['status']];
  27. }else{
  28. $where[]=['a.status','<',2];
  29. }
  30. $query= $this->newInstance()->alias('a')
  31. ->leftJoin('sys_ad_position as b', 'a.position_id', '=', 'b.id')
  32. ->where($where);
  33. $totalCount = $query->count();
  34. $list= $query->skip($skip)
  35. ->limit($pageSize)
  36. ->selectRaw('a.*,b.number,b.route_path_key,b.ad_key')
  37. ->orderBy('id')
  38. ->get();
  39. if(!empty($list)){
  40. $list=$list->toArray();
  41. }else{
  42. $list=[];
  43. }
  44. $result = $this->buildPaginator($list, $skip, $page, $pageSize, $totalCount);
  45. return $result;
  46. }
  47. }