ShareUrlController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Modules\AgentApi\Controllers;
  3. use App\Constants\CommonConstant;
  4. use App\Repositories\AgentRepository;
  5. use App\Repositories\ChannelRepository;
  6. use App\Repositories\Criterias\OrderLimitCriteria;
  7. use App\Repositories\Criterias\ShareUrlsPagesCriteria;
  8. use App\Repositories\ShareUrlsRepository;
  9. use Modules\AgentApi\Responses\ShareUrlsResponse;
  10. class ShareUrlController extends BaseController
  11. {
  12. /**
  13. * 分享列表
  14. *
  15. * @param AgentRepository $agentRepo
  16. * @return ShareUrlsResponse
  17. */
  18. public function lists(AgentRepository $agentRepo)
  19. {
  20. $accountInfo = $this->getCurrentAgent();
  21. /**
  22. * 获取代理应用uid
  23. * @var AgentRepository $agentRepo
  24. */
  25. $agentRepo = app(AgentRepository::class);
  26. $appUidData = $agentRepo->findBy('uid', $accountInfo['uid'], ['own_app_uids']);
  27. $appUids = explode(',', $appUidData->own_app_uids);
  28. /**
  29. * 获取渠道app
  30. * @var ChannelRepository $channRepo
  31. */
  32. $channRepo = app(ChannelRepository::class);
  33. $channData = $channRepo->agentChannel($accountInfo['uid'], $appUids);
  34. /**
  35. * 获取获取分享url
  36. * @var ShareUrlsRepository $sharRepo
  37. */
  38. $sharRepo = app(ShareUrlsRepository::class);
  39. $sharData = $sharRepo->findAllBy('status', 1, ['mom_app_uid', 'title', 'url', 'cover','sort'])->toArray();
  40. $i = 0;
  41. $res = [];
  42. foreach ($appUids as $key => $uid) {
  43. foreach ($sharData as $sharVal) {
  44. if ($sharVal['mom_app_uid'] == $uid && isset($channData[$uid]['uid'])) {
  45. $res[$key][$i]['mom_app_uid'] = $uid;
  46. $res[$key][$i]['url'] = $sharVal['url'];
  47. $res[$key][$i]['cover'] = $sharVal['cover'];
  48. $res[$key][$i]['title'] = $sharVal['title'];
  49. $res[$key][$i]['sort'] = $sharVal['sort'];
  50. $res[$key][$i]['channel_uid'] = $channData[$uid]['uid'];
  51. $i++;
  52. }
  53. }
  54. $i = 0;
  55. }
  56. return new ShareUrlsResponse(array_values($res));
  57. }
  58. }