<?php

namespace App\Modules\WechatMaterial\Services;

use App\Jobs\ActionTrigger;
use GuzzleHttp\Client;
use Redis;

/**
 * 埋点类
 *
 */
class ActionService
{
    /**
     * 扔行为到队列中
     * @param int   $distribution_channel_id
     * @param array $base_param
     * @param array $extra_param
     */
    static function PushActionToQueue($params = [],$queue='{batch_wechat_material_action_trigger_list}')
    {
        try {
            $param                = [];
            $param['send_time']   = date("Y-m-d H:i:s");
            $param['ip']          = get_client_ip();
            $param['action_type']          = $params['action_type'];
            $param['data']        = $params;
            $send_data            = array(
                'send_time' => date("Y-m-d H:i:s"),
                'data'      => $param
            );
            \Log::info('PushActionToQueue_send_data:');
            \Log::info($send_data);
            $delay = 0;
            $job   = (new ActionTrigger($send_data))->onConnection('rabbitmq')->delay($delay)->onQueue($queue);
            dispatch($job);
        } catch (\Exception $e) {
            \Log::info('PushActionToQueue_ept:' . $e->getMessage());
        }
    }

}
