RedController.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace api\modules\v1\controllers;
  3. use common\models\ActivityReceive;
  4. use yii\rest\ActiveController;
  5. use common\library\Apireturn;
  6. use yii\helpers\ArrayHelper;
  7. use yii\filters\auth\QueryParamAuth;
  8. use yii;
  9. class RedController extends ActiveController
  10. {
  11. public $modelClass = 'common\models';
  12. const DISPLAY = 10;//显示条数
  13. public function behaviors()
  14. {
  15. return ArrayHelper::merge(parent::behaviors(), [
  16. 'authenticator' => [
  17. 'class' => QueryParamAuth::className(),
  18. 'tokenParam' => "token",//access-token修改为token
  19. 'optional' => [//不需要认证方法名 array
  20. ],
  21. ]
  22. ]);
  23. }
  24. /**
  25. * 红包记录
  26. * @return array
  27. */
  28. public function actionLog()
  29. {
  30. $page = Yii::$app->request->POST('page', 1);//分页页数
  31. $display = Yii::$app->request->POST('display', self::DISPLAY);//分页页数
  32. $mod = ActivityReceive::findBySql("SELECT a.amount,a.receive_at,b.title FROM {{%activity_receive}} AS a LEFT JOIN {{%building}} AS b ON a.source_id = b.id WHERE a.uid = :uid AND a.status = :status ORDER BY a.id desc LIMIT ". ($page - 1) * $display . "," . $display,[':uid'=>Yii::$app->user->id,':status'=>ActivityReceive::STATUS_YES]);
  33. $list = $mod->asArray()->all();
  34. $count = ActivityReceive::find()->where(['uid'=>Yii::$app->user->id,'status'=>ActivityReceive::STATUS_YES])->count();
  35. return Apireturn::sent(1,'success',200,array('count'=>$count,'list'=>$list));
  36. }
  37. }