<?php
/**
 * Created by PhpStorm.
 * User: Mead
 * Date: 2019/2/25
 * Time: 11:24 AM
 */

namespace App\Http\Controllers;


use App\Good;
use App\Trace;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;

class TestController extends Controller
{
    public function index()
    {

        $t1 = microtime(true);

//        $traces = Trace::select(DB::raw('count(*) as trace_count, gid'))
//            ->groupBy('gid')->get()->toArray();
//        foreach ($traces as $trace) {
//            Good::where('id', $trace['gid'])->update([
//                'trace_count' => $trace['trace_count']
//            ]);
//        }
        $key = '10060113971430974376444296336187';
        $key = substr($key, 11);
        $trace = Trace::where('slug', $key)->firstOrFail();
        $t2 = microtime(true);
        $time = round($t2 - $t1, 3) . '秒';
        dd($time);
    }

    private function num_random($len = 16)
    {
        $num = '';
        for ($i = 0; $i < $len; $i++) {
            $num .= rand(0, 9);
        }
        return $num;
    }
}