<?php


namespace App\Http\logic\api;

use App\dao\Pay\AccountPayInfo;
use App\dao\Pay\PayController;
use App\Http\helper\CreateOrder;
use App\Http\helper\NumConfig;
use App\Services\PayConfig;

class AppleStorePayLogic extends BaseApiLogic
{
    public function pay_order($userId, $pay_amount,$productId, $userPhone, $userEmail, $userName, $GiftsID, $buyIP, $AdId, $eventType)
    {
        $dao = new AccountPayInfo();
        [$userPhone, $userName, $userEmail] = $dao->payInfo($userId);

        $pay_amount = (int)$pay_amount;

        // 礼包类型验证
        $PayVerify = new PayController();
        $pay_amount = $PayVerify->verify($userId, $GiftsID, $pay_amount);
        if ($PayVerify->verify($userId, $GiftsID, $pay_amount) === false) {
            $this->error = $PayVerify->getError();
            return false;
        }
        if ($pay_amount < 0) {
            $this->error = 'Payment error_4';
            return false;
        }

        $order_sn = CreateOrder::order_sn($userId);

        // 生成订单信息
        $logic = new OrderLogic();

        $amount = $pay_amount ;
        $logic->orderCreate(
            $order_sn,
            $amount,
            'AppleStore',
            $userId,
            $productId,
            $GiftsID,
            $AdId,
            $eventType
        );

        return [
            'code' => 0,
            'order_sn' => $order_sn,
        ];
    }
}
