<?php

namespace App\Http\logic\api;

use App\Models\Order;
use App\Services\PayMent;
use Illuminate\Support\Facades\DB;

class PayRechargeLogic extends BaseApiLogic
{

    public function orderList($user_id, $pageSize)
    {
        $where[] = ['user_id', $user_id];
        $where[] = ['pay_status', 1];


        $cacheTime = 60 * rand(1, 2);
//        $list = cache()->remember($user_id . '_order_list', $cacheTime, function () use ($where, $pageSize) {
//
//            return Order::where($where)
//                ->orderBy('finished_at', 'desc')
//                ->selectRaw('amount,payment_code,order_sn as payment_sn,finished_at,created_at,pay_status')
//                ->paginate(15,['*'],'page',1);
//        });

        $list = Order::where($where)
            ->orderBy('finished_at', 'desc')
            ->selectRaw('amount,payment_code,order_sn as payment_sn,finished_at,created_at,pay_status')
            ->paginate(15,['*'],'page',1);

        foreach ($list as &$val) {
            $val->amount = number_format($val->amount, 2, '.', '');
        }


        return $list;
    }
}
