<?php
namespace hook\listeners\user;

use app\admin\model\UserNews;
use Symfony\Contracts\EventDispatcher\Event;

/**
 * 插入会员消息
 * Class CreateUserNewsListen
 * @package listeners\user
 */
class CreateUserNewsListen extends Event
{
    public $data;

    public function __construct(array $data)
    {
        $this->data = $data;
    }

    public function handle()
    {
        try {
            if(!isset($this->data['log_type']) || !isset($this->data['log_uid']) || !isset($this->data['log_content']))
            {
                throw new \Exception('缺少必要参数');
            }
            $insert = array(
                'log_type' => $this->data['log_type'],
                'log_uid' => $this->data['log_uid'],
                'log_content' => $this->data['log_content'],
                'log_create_time' => time()
            );
            UserNews::insertData($insert);
            return true;
        }catch (\Exception $exception){
            throw new \Exception($exception->getMessage(), $exception->getCode());
        }
    }

}
