<?php

namespace App\Modules\Trade\Pay;

use App\Libs\Pay\PayFactory;
use App\Modules\Trade\Services\PayMerchantService;
use Exception;
use Illuminate\Support\Facades\Log;

class WxOrderArousePay extends OrderArousePayAbstract
{
    public function arouse(array $data)
    {
        $pay_merchant_id = (int) $data['pay_merchant_id'];
        $config = PayMerchantService::findPayConfig($pay_merchant_id);
        $pay = PayFactory::official($config);
        try {
            $payOrder = [
                'trade_type'     => $data['trade_type'], // 交易类型
                'trade_no'     => $data['trade_no'], // 订单号
                'price'        => $data['price'], // 订单金额，单位：分
                'body'             => $this->getSubjectName($data['distribution_channel_id']), // 订单描述
                'create_ip' => _getIp(), // 支付人的 IP
                'remark'            =>  $pay_merchant_id
            ];
            $result = $pay->send($payOrder);
            if ($result) {
                return $result;
            } else {
                Log::error("创建微信订单失败: " . json_encode($result));
                return false;
            }
        } catch (Exception $e) {
            Log::error("创建微信订单失败: " . $e->getMessage());
            return false;
        }
    }
}
