<?php

namespace App\Jobs;

use App\Consts\SysConsts;
use App\Modules\User\Models\QappUserAddDestop;
use GuzzleHttp\Client;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

/**
 * 用户加桌
 */
class UserAddDeskJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $uid;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(int $uid)
    {
        $this->uid = $uid;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $exists = QappUserAddDestop::where('uid', $this->uid)->exists();
        if ($exists) {
            return;
        }
        $client = new Client();
        $params = [
            'uid' => $this->uid,
            'source' => 'wdy'
        ];
        $params['sign'] = _sign($params, SysConsts::TIKTOK_KEY);
        $url = 'https://newtrackapi.zhuishuyun.com/api/qappuser/addDesk';
        $response =  $client->post($url, ['form_params' => $params])->getBody()->getContents();
        myLog('user_add_desk')->info($response);
    }
}
