<?php

use App\Base\Base;
use App\Exception\custom\GoodsException;
use \Validate\GoodsTccValidate;
use \App\Services\tcc\Tcc2Service;


class TccController extends Base
{
    /**
     * 下单商品 tcc try
     * @throws GoodsException
     * @throws \App\Exception\custom\ParamException
     */
    public function place_an_order_tryAction()
    {
        (new GoodsTccValidate())->validate();

        $res = Tcc2Service::placeAnOrderTry($this->params["keys"], $this->params["tid"]);
        if ($res) {
            $this->success();
        } else {
            throw new GoodsException(["cus" => 27]);
        }
    }

    /**
     * 下单商品 tcc confirm
     * @throws \App\Exception\custom\ParamException
     * @throws \App\Exception\custom\ParamException
     */
    public function place_an_order_confirmAction()
    {
        (new GoodsTccValidate())->validate();

        $res = Tcc2Service::placeAnOrderConfirm($this->params["keys"], $this->params["tid"]);
        if ($res) {
            $this->success();
        } else {
            throw new GoodsException(["cus" => 27]);
        }
    }

    /**
     * 下单商品 cancel
     * @throws \App\Exception\custom\ParamException
     * @throws \App\Exception\custom\ParamException
     */
    public function place_an_order_cancelAction()
    {
        (new GoodsTccValidate())->validate();

        $res = Tcc2Service::placeAnOrderCancel($this->params["keys"], $this->params["tid"]);
        if ($res) {
            $this->success();
        } else {
            throw new GoodsException(["cus" => 27]);
        }
    }

    /**
     * 取消订单单 商品tcc confirm
     */
    public function cancel_order_confirmAction()
    {
        $res = Tcc2Service::cancelConfirm($this->params["keys"]);
        if ($res) {
            $this->success();
        } else {
            throw new GoodsException(["cus" => 27]);
        }
    }
}