<?php

namespace App\Http\Controllers\Api\V1;

use App\Models\BaseSettingsModel;
use App\Models\DreamInfoModel;
use App\Models\UserInfoModel;
use Illuminate\Http\Request;
use App\Services\Base\ErrorCode;
class IndexController extends Controller
{
    /**
     * @api {get} /api/index/hot 热门(hot)
     * @apiDescription 登陆(hot)
     * @apiGroup Index
     * @apiPermission none
     * @apiVersion 0.1.0
     * @apiParam {string}  phone   手机号码
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *     "state": true,
     *     "code": 0,
     *     "message": "",
     *     "data": {
     *         "verify_code": "1234"//该值调试时使用，sms调通后取消
     *     }
     * }
     * @apiErrorExample {json} Error-Response:
     * HTTP/1.1 400 Bad Request
     * {
     *     "state": false,
     *     "code": 1000,
     *     "message": "传入参数不正确",
     *     "data": null or []
     * }
     * 可能出现的错误代码：
     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
     */
    public function hot(Request $request)
    {
        $user = $this->getUser();
//获取轮播图
        $banner = BaseSettingsModel::where(['category' => 'banner'])->where(['status' => '1'])
            ->orderBy('sort')->limit('3')->get()->toArray();
//        关注的用户
       $other_user =  $user->UserCareUser;
//        获取其他用户信息 及梦想
        $dreams = DreamInfoModel::orderBy('created_at')->get();
        foreach ($dreams as $k => $dream) {
            $dream->dream_find_user =  $dream->dreamFindUser;
            $dream->dream_first_pic =  $dream->dreamImgsFirst;
        }
        return $this->api(compact('banner','other_user','dreams'));
    }
}
