AdvertService.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * 广告
  4. * @author wesmielr
  5. */
  6. namespace app\index\service;
  7. use think\Db;
  8. class AdvertService
  9. {
  10. /**
  11. * 获取对应位置轮播列表
  12. * @param $slideId 广告位ID
  13. * @param int $num 获取数量
  14. * @param string $field 字段
  15. * @return array
  16. * @throws \think\db\exception\DataNotFoundException
  17. * @throws \think\db\exception\ModelNotFoundException
  18. * @throws \think\exception\DbException
  19. */
  20. public static function getListBySlide($slideId, $num=6, $field=''){
  21. $field = $field? $field : 'id,title,image,url,target';
  22. return Db::name('slide_item')->where(['status'=> 1])
  23. ->where(function($query) use ($slideId){
  24. if(is_array($slideId)){
  25. $query->whereIn('slide_id', $slideId);
  26. }else{
  27. $query->where('slide_id', $slideId);
  28. }
  29. })
  30. ->field($field)
  31. ->order('list_order')
  32. ->limit($num)
  33. ->select()
  34. ->toArray();
  35. }
  36. }