LinkService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/11/7
  6. * Time: 17:17
  7. */
  8. namespace App\Services\Content;
  9. use App\Repositories\LinkRepository;
  10. use App\Repositories\LinkCategoryRepository;
  11. class LinkService
  12. {
  13. protected $linkRepository;
  14. protected $linkCategoryRepository;
  15. /**
  16. * LinkService constructor.
  17. * @param $linkRepository
  18. */
  19. public function __construct(LinkRepository $linkRepository, LinkCategoryRepository $linkCategoryRepository)
  20. {
  21. $this->linkRepository = $linkRepository;
  22. $this->linkCategoryRepository = $linkCategoryRepository;
  23. }
  24. public function getLinks($data)
  25. {
  26. $where = array();
  27. /*if (array_key_exists('subsite_id', $data)) {
  28. $where[] = array('subsite_id','=',$data['subsite_id']);
  29. }*/
  30. $where[] = array('is_display','=','1');
  31. $limit = $data['limit'];
  32. if ($data['type']=='1') {
  33. $where[] = array('link_logo','=','');
  34. } elseif ($data['type']=='2') {
  35. $where[] = array('link_logo','<>','');
  36. }
  37. if (array_key_exists('alias', $data)) {
  38. $alias = $data['alias'];
  39. //获取链接分类信息
  40. //$link_category = $this->linkCategoryRepository->getCategories(array('alias'=>$alias));
  41. $link_categories = $this->linkCategoryRepository->getCategories();
  42. $link_category = $link_categories[$alias][0];
  43. if ($link_category->toArray()) {
  44. $where[] = array('type_id','=',$link_category->id);
  45. }
  46. }
  47. $links = $this->linkRepository->getLinks($where, $limit);
  48. if ($data['type']=='2') {
  49. if ($links->toArray()) {
  50. foreach ($links as $k => $v) {
  51. //判断是本地图片还是链接图片
  52. if (preg_match('/^http/', $v->link_logo)) {
  53. $links[$k]->image_type = 'link';
  54. } else {
  55. $links[$k]->image_type = 'image';
  56. }
  57. }
  58. }
  59. }
  60. return $links;
  61. }
  62. }