<?php

namespace app\common\listener\withdrawal;

use app\common\model\school\MessageConfig;
use app\common\model\User;

class WithdrawalHook
{

    // 体现打款审核提交
    public function userWithdrawalAuthNeedAfter(&$params)
    {
        ["userwithdrawalLog"=>$userwithdrawalLog] = $params;

        $user = User::where("id",$userwithdrawalLog["user_id"])->find();

        $mini_type = "user_auth";
        $to_id = $userwithdrawalLog["user_id"];
        $status ="system";
        $params=[
            "event"=>"user_withdrawal_auth_need_after",
            "withdrawal_log_id"=>$userwithdrawalLog["id"],
        ];

        $param = [
            "price" => $userwithdrawalLog['price'],
            "fee_price" => $userwithdrawalLog['fee_price'],
            "real_price" => $userwithdrawalLog['real_price'],
            "reason" => $userwithdrawalLog['reason'],


            "name" => $userwithdrawalLog['name'],
            "bank_name" => $userwithdrawalLog['bank_name'],
            "bank_user_name" => $userwithdrawalLog['bank_user_name'],
            "id_number" => $userwithdrawalLog['id_number'],

            "realname"=> $user["realname"] ,
            "nickname"=> $user["nickname"] ,
            "mobile"=> $user["mobile"] ,
        ];

        //发给用户
        (new MessageConfig)
            ->setTemplate($params["event"])
            ->setTemplateData($param)
            ->setToUid($to_id)
            ->setMessageStatus($status)
            ->setMessageMiniType($mini_type)
            ->setMessageParams($params)
            ->sendMessage();


    }

    // 体现打款审核通过后
    public function userWithdrawalAuthSuccessAfter(&$params)
    {
        ["userwithdrawalLog"=>$userwithdrawalLog] = $params;

        $user = User::where("id",$userwithdrawalLog["user_id"])->find();

        $mini_type = "user_auth";
        $to_id = $userwithdrawalLog["user_id"];
        $status ="system";
        $params=[
            "event"=>"user_withdrawal_auth_success_after",
            "withdrawal_log_id"=>$userwithdrawalLog["id"],
        ];

        $param = [
            "price" => $userwithdrawalLog['price'],
            "fee_price" => $userwithdrawalLog['fee_price'],
            "real_price" => $userwithdrawalLog['real_price'],
            "reason" => $userwithdrawalLog['reason'],


            "name" => $userwithdrawalLog['name'],
            "bank_name" => $userwithdrawalLog['bank_name'],
            "bank_user_name" => $userwithdrawalLog['bank_user_name'],
            "id_number" => $userwithdrawalLog['id_number'],

            "realname"=> $user["realname"] ,
            "nickname"=> $user["nickname"] ,
            "mobile"=> $user["mobile"] ,
        ];

        //发给用户
        (new MessageConfig)
            ->setTemplate($params["event"])
            ->setTemplateData($param)
            ->setToUid($to_id)
            ->setMessageStatus($status)
            ->setMessageMiniType($mini_type)
            ->setMessageParams($params)
            ->sendMessage();
    }

    // 体现打款审核失败后
    public function userWithdrawalAuthFailAfter(&$params)
    {
        ["userwithdrawalLog"=>$userwithdrawalLog] = $params;

        $user = User::where("id",$userwithdrawalLog["user_id"])->find();

        $mini_type = "user_auth";
        $to_id = $userwithdrawalLog["user_id"];
        $status ="system";
        $params=[
            "event"=>"user_withdrawal_auth_fail_after",
            "withdrawal_log_id"=>$userwithdrawalLog["id"],
        ];

        $param = [
            "price" => $userwithdrawalLog['price'],
            "fee_price" => $userwithdrawalLog['fee_price'],
            "real_price" => $userwithdrawalLog['real_price'],
            "reason" => $userwithdrawalLog['reason'],


            "name" => $userwithdrawalLog['name'],
            "bank_name" => $userwithdrawalLog['bank_name'],
            "bank_user_name" => $userwithdrawalLog['bank_user_name'],
            "id_number" => $userwithdrawalLog['id_number'],

            "realname"=> $user["realname"] ,
            "nickname"=> $user["nickname"] ,
            "mobile"=> $user["mobile"] ,
        ];

        //发给用户
        (new MessageConfig)
            ->setTemplate($params["event"])
            ->setTemplateData($param)
            ->setToUid($to_id)
            ->setMessageStatus($status)
            ->setMessageMiniType($mini_type)
            ->setMessageParams($params)
            ->sendMessage();
    }

    // 体现打款成功
    public function userWithdrawalSuccessAfter(&$params)
    {
        ["userwithdrawalLog"=>$userwithdrawalLog] = $params;

        $user = User::where("id",$userwithdrawalLog["user_id"])->find();

        $mini_type = "user_auth";
        $to_id = $userwithdrawalLog["user_id"];
        $status ="system";
        $params=[
            "event"=>"user_withdrawal_success_after",
            "withdrawal_log_id"=>$userwithdrawalLog["id"],
        ];

        $param = [
            "price" => $userwithdrawalLog['price'],
            "fee_price" => $userwithdrawalLog['fee_price'],
            "real_price" => $userwithdrawalLog['real_price'],
            "reason" => $userwithdrawalLog['reason'],


            "name" => $userwithdrawalLog['name'],
            "bank_name" => $userwithdrawalLog['bank_name'],
            "bank_user_name" => $userwithdrawalLog['bank_user_name'],
            "id_number" => $userwithdrawalLog['id_number'],

            "realname"=> $user["realname"] ,
            "nickname"=> $user["nickname"] ,
            "mobile"=> $user["mobile"] ,
        ];

        //发给用户
        (new MessageConfig)
            ->setTemplate($params["event"])
            ->setTemplateData($param)
            ->setToUid($to_id)
            ->setMessageStatus($status)
            ->setMessageMiniType($mini_type)
            ->setMessageParams($params)
            ->sendMessage();
    }

}