<?php
namespace App\Models\order\mysql;

use Api\PhpUtils\Mysql\MysqlBase;
use App\Exception\custom\PayException;

class PayOrder extends MysqlBase
{
    const TABLE_NAME = 'pay_order';
    const CONFIG_INDEX = 'pay';

    /**
     * @param $order_id
     * @param $pay_order
     * @return array
     */
    public static function get_valid_order($order_id, $pay_order) {

        self::beginTransaction();
        try{
            $order = self::getMaster('*', ['order_id'=>$order_id]);
            if(empty($order)) {
                $cnt = self::insert($pay_order, ['rowCount'=>true]);
                if($cnt) {
                    $order = $pay_order;
                }
            }

            self::commit();

        }catch (\PDOException $e) {
            self::rollback();
        }

        return $order;
    }
}
