You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							85 lines
						
					
					
						
							2.4 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							85 lines
						
					
					
						
							2.4 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								namespace App\Http\Controllers\Api;
							 | 
						|
								use App\Http\Controllers\Controller;
							 | 
						|
								use App\Models\Channel;
							 | 
						|
								use App\Models\Notice;
							 | 
						|
								use App\Models\AgentProduct;
							 | 
						|
								use App\Models\Advertising;
							 | 
						|
								use App\Models\UserChannel;
							 | 
						|
								use Illuminate\Support\Facades\Storage;
							 | 
						|
								
							 | 
						|
								/**
							 | 
						|
								 * 小程序首页
							 | 
						|
								 * Class IndexController
							 | 
						|
								 * @package App\Http\Controllers\Api
							 | 
						|
								 */
							 | 
						|
								class IndexController extends Controller
							 | 
						|
								{
							 | 
						|
								    // 首页数据大杂烩
							 | 
						|
								    public function index()
							 | 
						|
								    {
							 | 
						|
										$img_prefix = Storage::disk('public')->url('');
							 | 
						|
								
							 | 
						|
										# 轮播图
							 | 
						|
								        $slide = Advertising::where(['agent_id' => $this->agent_id, 'status' => 1, 'display' => 0])
							 | 
						|
											->orderBy('sort')->orderBy('id', 'DESC')->limit(10)
							 | 
						|
											->get(['title', 'picture', 'type', 'url']);
							 | 
						|
								        if (!$slide->isEmpty()) {
							 | 
						|
											foreach ($slide as &$v) {
							 | 
						|
												$v->picture = $img_prefix . $v->picture;
							 | 
						|
											}
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
								        # 公告
							 | 
						|
								        $notice = Notice::where('agent_id', $this->agent_id)->status()->limit(10)
							 | 
						|
											->orderBy('sort')->orderBy('id', 'desc')->get(['id', 'title']);
							 | 
						|
								
							 | 
						|
								        # 我的频道
							 | 
						|
										$my_channels = [];
							 | 
						|
										if ($this->user_id) {
							 | 
						|
											$channel_ids = UserChannel::where('user_id', $this->user_id)->value('channels') ?? [];
							 | 
						|
											$my_channels = Channel::where('agent_id', $this->agent_id)
							 | 
						|
												->whereIn('id', $channel_ids)
							 | 
						|
												->get(['id', 'name', 'icon']);
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										if ($my_channels && !$my_channels->isEmpty()) {
							 | 
						|
											foreach ($my_channels as &$v) {
							 | 
						|
												$v->icon = $img_prefix . $v->icon;
							 | 
						|
											}
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
								        # 专题列表
							 | 
						|
										$special = Advertising::where(['agent_id' => $this->agent_id, 'display' => 1])
							 | 
						|
											->orderBy('sort')->orderBy('id', 'desc')->limit(6)
							 | 
						|
											->get(['title', 'picture', 'type', 'url']);
							 | 
						|
										if (!$special->isEmpty()) {
							 | 
						|
											foreach ($special as $k=>&$v) {
							 | 
						|
												$v->picture = $img_prefix . $v->picture;
							 | 
						|
											}
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
								        # 人气爆款
							 | 
						|
								        $hots = AgentProduct::list($this->agent_id)
							 | 
						|
											->orderBy('sale', 'desc')->orderBy('id', 'desc')
							 | 
						|
											->limit(6)->get();
							 | 
						|
										if (!$hots->isEmpty()) {
							 | 
						|
											foreach ($hots as &$v) {
							 | 
						|
												if (!empty($v->pictures) && is_array($v->pictures)) {
							 | 
						|
													$v->pictures = array_map(function($item) use ($img_prefix) {
							 | 
						|
														return strpos($item, $img_prefix) === false ? $img_prefix . $item : $item;
							 | 
						|
													}, $v->pictures);
							 | 
						|
												}
							 | 
						|
											}
							 | 
						|
										}
							 | 
						|
								
							 | 
						|
										return $this->success([
							 | 
						|
								            'slide' => $slide,
							 | 
						|
								            'notice' => $notice,
							 | 
						|
								            'my_channels' => $my_channels,
							 | 
						|
								            'special' => $special,
							 | 
						|
								            'hots' => $hots,
							 | 
						|
								        ]);
							 | 
						|
								    }
							 | 
						|
								}
							 |