<?php

namespace App\Modules\Trade\Pay;

use App\Libs\Pay\PayFactory;
use App\Modules\Trade\Services\PayMerchantService;
use Log;

class WxOrderArousePay extends OrderArousePayAbstract
{
    public function arouse(array $data)
    {
        $pay_merchant_name = $data['pay_merchant_source'];
        $config = PayMerchantService::getPayConfigByNameStatic($pay_merchant_name);
        $pay = PayFactory::official($config);
        try {
            $payOrder = [
                'trade_type'     => $data['trade_type'], // 交易类型
                'trade_no'     => $data['trade_no'], // 订单号
                'price'        => $data['price'], // 订单金额，单位：分
                'body'             => '快应用 小说', // 订单描述
                'create_ip' => _getIp(), // 支付人的 IP
                'remark'            =>  $pay_merchant_name
            ];
            $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;
        }
    }
}
