<?php

namespace App\Listeners;

use App\Events\WithdrawalsApplyEvent;
use App\Events\WithdrawalsCompleteEvent;
use App\Jobs\SendTemplateNotice;
use App\Models\FinancialStaff;
use App\Models\Partner;
use App\Models\Wechat;

class SendApplyOfWithdrawalsNotifyToFinanceListener
{
    public function __construct()
    {
    }

    public function handle(WithdrawalsApplyEvent $event): void
    {
        // 获取提现记录和用户信息
        $withdrawal = $event->withdrawal;

        //给财务人员发消息
        FinancialStaff::query()
            ->where('is_lock',0)
            ->get()
            ->each(function ($financial_staff) use ($withdrawal) {

                $param = [
                    'touser'=>$financial_staff->open_id,
                    'template_id'=>config('wechat.tpls.withdrawal_notice_to_finance'),
                    'data'=>[
                        'keyword1'=>['value'=>$withdrawal->serviceUser->name],
                        'keyword2'=>['value'=>$withdrawal->amount."元"],
                        "keyword3"=>['value'=>date('Y-m-d H:i:s')],
                    ]
                ];
                SendTemplateNotice::dispatch($param);
            });
    }
}
