<?php

namespace App\Servicess;

use App\Models\Pay\PayMerchant;
use App\Services\Pay;

class PayMerchantService
{
    /**
     * 查找微信支付配置信息
     */
    public static function findPayConfig(int $id)
    {
        $pay_merchant = PayMerchant::find($id);
        $pay_config = json_decode($pay_merchant->config_info);
        return [
            'appid'     => $pay_config->appid,
            'merchant_id'     => $pay_config->merchant_id,
            'key'    => $pay_config->key,
        ];
    }

    /**
     * 查找微信支付配置信息
     */
    public static function findAliPayConfig(int $id)
    {
        $pay_merchant = PayMerchant::find($id);
        $pay_config = json_decode($pay_merchant->config_info);
        return [
            'app_id'     => $pay_config->app_id,
            'ali_pub_key'     => $pay_config->ali_pub_key,
            'pri_key'    => $pay_config->pri_key,
        ];
    }

    /**
     * 根据ID查找
     * @param $id
     * @return mixed
     */
    public static function getPayMerchantSingle($id)
    {
        return  PayMerchant::find($id);
    }

    /**
     * 查找所有的支付渠道通道
     * @return mixed
     */
    public static function getPayMerchantSourceList()
    {
        $result = PayMerchant::select('source')->distinct();
        return $result;
    }
}
