123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace api\modules\v1\controllers;
- use common\models\Information;
- use common\models\Notice;
- use yii\rest\ActiveController;
- use common\library\Apireturn;
- use yii\helpers\ArrayHelper;
- use yii\filters\auth\QueryParamAuth;
- use yii;
- class NewsController extends ActiveController
- {
- public $modelClass = 'common\models';
- const DISPLAY = 10;//显示条数
- public function behaviors()
- {
- return ArrayHelper::merge(parent::behaviors(), [
- 'authenticator' => [
- 'class' => QueryParamAuth::className(),
- 'tokenParam' => "token",//access-token修改为token
- 'optional' => [//不需要认证方法名 array
- 'new-first','new-first2'
- ],
- ]
- ]);
- }
- /**
- * 最新一条
- */
- public function actionNewFirst()
- {
- $time = time();
- $datas = Notice::find()->from("{{%notice}} a")->select("b.id,b.title")->leftJoin("{{%information}} b","a.sid = b.id")->where(['a.status'=>Notice::STATUS_ACTIVE,'b.type'=>Information::INFORMATION ]);
- //$datas = Notice::find()->select("{{%notice}}.sid,{{%information}}.title")->joinWith('information')->where(['{{%notice}}.status'=>Notice::STATUS_ACTIVE,'{{%information}}.type'=>Information::INFORMATION ]);
- $datas = $datas->andwhere(['<' , 'a.release_time' , $time]);
- $datas = $datas->andwhere(['>' , 'a.over_time' , $time]);
- $datas = $datas->orderBy('a.updated_at DESC')->asArray()->one();
- return Apireturn::sent(1,'success',200,$datas);
- }
- }
|