LinkService.php 998 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * 友链服务
  4. * @author wesmielr
  5. */
  6. namespace app\index\service;
  7. use think\Db;
  8. class LinkService
  9. {
  10. /**
  11. * 获取友链列表
  12. * @param $params 参数
  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 getList($params, $num=6, $field=''){
  21. $field = $field? $field : 'id,name,catname,url,image,target';
  22. return Db::name('link')->where(['status'=> 1])
  23. ->where(function($query) use($params){
  24. $catname = isset($params['catname'])? : '';
  25. if($catname){
  26. $query->where('catname', $catname);
  27. }
  28. })
  29. ->field($field)
  30. ->order('list_order')
  31. ->limit($num)
  32. ->select()
  33. ->toArray();
  34. }
  35. }