NewsController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace api\modules\v1\controllers;
  3. use common\models\Information;
  4. use common\models\Notice;
  5. use yii\rest\ActiveController;
  6. use common\library\Apireturn;
  7. use yii\helpers\ArrayHelper;
  8. use yii\filters\auth\QueryParamAuth;
  9. use yii;
  10. class NewsController extends ActiveController
  11. {
  12. public $modelClass = 'common\models';
  13. const DISPLAY = 10;//显示条数
  14. public function behaviors()
  15. {
  16. return ArrayHelper::merge(parent::behaviors(), [
  17. 'authenticator' => [
  18. 'class' => QueryParamAuth::className(),
  19. 'tokenParam' => "token",//access-token修改为token
  20. 'optional' => [//不需要认证方法名 array
  21. 'new-first','new-first2'
  22. ],
  23. ]
  24. ]);
  25. }
  26. /**
  27. * 最新一条
  28. */
  29. public function actionNewFirst()
  30. {
  31. $time = time();
  32. $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 ]);
  33. //$datas = Notice::find()->select("{{%notice}}.sid,{{%information}}.title")->joinWith('information')->where(['{{%notice}}.status'=>Notice::STATUS_ACTIVE,'{{%information}}.type'=>Information::INFORMATION ]);
  34. $datas = $datas->andwhere(['<' , 'a.release_time' , $time]);
  35. $datas = $datas->andwhere(['>' , 'a.over_time' , $time]);
  36. $datas = $datas->orderBy('a.updated_at DESC')->asArray()->one();
  37. return Apireturn::sent(1,'success',200,$datas);
  38. }
  39. }