You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.7 KiB
67 lines
1.7 KiB
5 years ago
|
<?php
|
||
|
/**
|
||
|
* Created by IntelliJ IDEA.
|
||
|
* User: luwei
|
||
|
* Date: 2017/6/14
|
||
|
* Time: 9:32
|
||
|
*/
|
||
|
|
||
|
namespace app\controllers;
|
||
|
|
||
|
use app\behaviors\BargainBehavior;
|
||
|
use app\behaviors\LotteryBehavior;
|
||
|
use app\behaviors\CouponBehavior;
|
||
|
use app\behaviors\OrderBehavior;
|
||
|
use app\behaviors\PintuanBehavior;
|
||
|
use app\behaviors\PluginBehavior;
|
||
|
use yii\web\Response;
|
||
|
use app\hejiang\ValidationErrorResponse;
|
||
|
|
||
|
class Controller extends \yii\web\Controller
|
||
|
{
|
||
|
public function behaviors()
|
||
|
{
|
||
|
return [
|
||
|
'order' => [
|
||
|
'class' => OrderBehavior::className(),
|
||
|
],
|
||
|
'coupon' => [
|
||
|
'class' => CouponBehavior::className(),
|
||
|
],
|
||
|
'pintuan' => [
|
||
|
'class' => PintuanBehavior::className(),
|
||
|
],
|
||
|
'bargain' => [
|
||
|
'class' => BargainBehavior::className(),
|
||
|
],
|
||
|
'lottery' => [
|
||
|
'class' => LotteryBehavior::className(),
|
||
|
],
|
||
|
'plugin' => [
|
||
|
'class' => PluginBehavior::className(),
|
||
|
],
|
||
|
];
|
||
|
}
|
||
|
|
||
|
public function init()
|
||
|
{
|
||
|
\Yii::$app->response->on(Response::EVENT_BEFORE_SEND, [$this, 'beforeSend']);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param \yii\base\Event $event
|
||
|
*/
|
||
|
public function beforeSend($event)
|
||
|
{
|
||
|
/* @var $response \yii\web\response */
|
||
|
$response = $event->sender;
|
||
|
/* @var $data \app\hejiang\ValidationErrorResponse */
|
||
|
$data = &$response->data;
|
||
|
|
||
|
if ($data instanceof ValidationErrorResponse) {
|
||
|
$response->format = Response::FORMAT_JSON;
|
||
|
$data = $data->raw;
|
||
|
}
|
||
|
}
|
||
|
}
|