| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace Modules\AgentApi\Controllers;
- use App\Constants\CommonConstant;
- use App\Repositories\AgentRepository;
- use App\Repositories\ChannelRepository;
- use App\Repositories\Criterias\OrderLimitCriteria;
- use App\Repositories\Criterias\ShareUrlsPagesCriteria;
- use App\Repositories\ShareUrlsRepository;
- use Modules\AgentApi\Responses\ShareUrlsResponse;
- class ShareUrlController extends BaseController
- {
- /**
- * 分享列表
- *
- * @param AgentRepository $agentRepo
- * @return ShareUrlsResponse
- */
- public function lists(AgentRepository $agentRepo)
- {
- $accountInfo = $this->getCurrentAgent();
- /**
- * 获取代理应用uid
- * @var AgentRepository $agentRepo
- */
- $agentRepo = app(AgentRepository::class);
- $appUidData = $agentRepo->findBy('uid', $accountInfo['uid'], ['own_app_uids']);
- $appUids = explode(',', $appUidData->own_app_uids);
- /**
- * 获取渠道app
- * @var ChannelRepository $channRepo
- */
- $channRepo = app(ChannelRepository::class);
- $channData = $channRepo->agentChannel($accountInfo['uid'], $appUids);
- /**
- * 获取获取分享url
- * @var ShareUrlsRepository $sharRepo
- */
- $sharRepo = app(ShareUrlsRepository::class);
- $sharData = $sharRepo->findAllBy('status', 1, ['mom_app_uid', 'title', 'url', 'cover','sort'])->toArray();
- $i = 0;
- $res = [];
- foreach ($appUids as $key => $uid) {
- foreach ($sharData as $sharVal) {
- if ($sharVal['mom_app_uid'] == $uid && isset($channData[$uid]['uid'])) {
- $res[$key][$i]['mom_app_uid'] = $uid;
- $res[$key][$i]['url'] = $sharVal['url'];
- $res[$key][$i]['cover'] = $sharVal['cover'];
- $res[$key][$i]['title'] = $sharVal['title'];
- $res[$key][$i]['sort'] = $sharVal['sort'];
- $res[$key][$i]['channel_uid'] = $channData[$uid]['uid'];
- $i++;
- }
- }
- $i = 0;
- }
- return new ShareUrlsResponse(array_values($res));
- }
- }
|