<?php
/**
 * Created by PhpStorm
 * DateTime: 2022/11/5 0:31.
 *
 * @description
 */

namespace App\Http\Controllers\V1\Share;

use App\Http\Controllers\V1\Controller;
use App\Models\UserShare;
use Dingo\Api\Http\Request;
use Illuminate\Http\JsonResponse;

class OrderController extends Controller
{
    public function lists(Request $request): JsonResponse
    {
        $limit  = $request->input('limit', 10);
        $page   = $request->input('page', 1);
        $offset = ($page - 1) * 10;
        $user   = \user();

        $lists = UserShare::with([
            'vipOrder:id,user_id,combo_id,pay_id,status,created_at',
            'vipOrder.user:id,nickname,avatar',
            'vipOrder.combo:id,name,price',
            'rechargeOrder:id,user_id,combo_id,price,gold,pay_id,status,created_at',
            'rechargeOrder.user:id,nickname,avatar',
            'rechargeOrder.combo:id,name,price',
        ])->where('user_id', $user->id)
            ->limit($limit)
            ->offset($offset)
            ->get();

        /* @var UserShare $list */
        foreach ($lists as $list) {
            $list->order     = $list;
            $list->type_name = $list->order_type;
            unset($list->vipOrder, $list->rechargeOrder);
        }

        return $this->success($lists);
    }
}
