1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace myapp\code\core\Api\V1\controllers;
- use yii\web\Response;
- use Yii;
- use yii\filters\auth\QueryParamAuth;
- use yii\filters\auth\CompositeAuth;
- use yii\rest\ActiveController;
- use myapp\code\core\Api\V1\models\wish\WishOrder;
- use yii\data\ActiveDataProvider;
- use backend\models\core\Request;
- class WishorderController extends ActiveController
- {
- public $modelClass = '\Api\V1\models\wish\WishOrder';
- public function behaviors()
- {
- $behaviors = parent::behaviors();
- $behaviors['authenticator'] = [
- 'class' => CompositeAuth::className(),
- 'authMethods' => [
- # 下面是三种验证access_token方式
- //HttpBasicAuth::className(),
- //HttpBearerAuth::className(),
- # 这是GET参数验证的方式
- # http://10.10.10.252:600/user/index/index?access-token=xxxxxxxxxxxxxxxxxxxx
- QueryParamAuth::className(),
- ],
- ];
- #定义返回格式是:JSON
- $behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
- return $behaviors;
- }
- public function actionViewbydate($begin_datetime,$end_datetime){
- # 分页参数处理
- $numPerPage = Request::param('numPerPage');
- if(!$numPerPage || $numPerPage <1 || $numPerPage > 800 ){
- $numPerPage = 100;
- }else{
- $numPerPage = (int)$numPerPage;
- }
- # where条件处理
- $where = '';
- if($begin_datetime){
- $where .= " last_updated >= '".$begin_datetime."' ";
- }
- if($end_datetime){
- if($where){
- $where .= " AND last_updated < '".$end_datetime."' ";
- }else{
- $where .= " last_updated < '".$end_datetime."' ";
- }
- }
- //echo $where;exit;
- if(!$where){
- throw new \yii\web\HttpException(404, 'You Must Add Where Filter By DateTime');
- }
- $query = WishOrder::find()->where($where);
- if($query->count() <1){
- throw new \yii\web\HttpException(404, 'No entries found with this query string');
- }
- $provider = new ActiveDataProvider([
- 'query' => $query,
- 'pagination' => [
- 'pageSize' => $numPerPage,
- ],
- ]);
- return $provider;
- }
- }
|