<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;

class AfEvent implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $data;

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

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Log::channel('adjustEvent')->info('enter:'.json_encode($this->data));
        if (empty($this->data)) return;
//        return;
        // 接收数据
        [$UserID, $payAmt, $AdId, $eventType] = $this->data;

        if (empty($eventType)) $eventType = 2;

        Log::info('接收数据' . \GuzzleHttp\json_encode($this->data));
        // 执行AF事件
        $dao = new \App\dao\af\AfEvent();
        $dao->pay($AdId, $UserID, $eventType);
        $dao->paySum($AdId, $UserID, $payAmt, $eventType);
        $dao->payCount($AdId, $UserID, $eventType);
//        $dao->recordKwaiRecharge($UserID, $payAmt);
//        $dao->recordGoogleRecharge($UserID, $payAmt);
    }
}
