<?php
namespace backend\controllers;

use common\pay\PayForm;
use Yii;

class PayController extends BaseController
{
    /**
     * 支付
     * @return \yii\web\Response
     */
    public function actionOutpay()
    {
        $model = new PayForm();
        $data = Yii::$app->getRequest()->post();
        $model->setAttributes($data);
        if ($model->outPay()) {
            $result['type'] = 'html';
            $result['html'] = $model->getOutPayResult();
            return $this->outJson(1, $result, 'OK');
        } else {
            return $this->outJson(0, [], $model->getErrors());
        }
    }

    /**
     * 异步回调
     * @return \yii\web\Response
     */
    public function actionNotify()
    {
        $model = new PayForm();
        $data = Yii::$app->getRequest()->post();
        if ($model->handleNotify($data)) {
            return $this->outJson(1, $model->getOutNotifyResult());
        } else {
            return $this->outJson(0, $model->getOutNotifyResult());
        }
    }

    /**
     * 同步回调
     * @return \yii\web\Response
     */
    public function actionReturn()
    {
        $model = new PayForm();
        $data = Yii::$app->getRequest()->post();
        if ($model->handleReturn($data)) {
            return $this->outJson(1, $model->getOutReturnResult());
        } else {
            return $this->outJson(0, $model->getOutReturnResult());
        }
    }
}