WishorderController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace myapp\code\core\Api\V1\controllers;
  3. use yii\web\Response;
  4. use Yii;
  5. use yii\filters\auth\QueryParamAuth;
  6. use yii\filters\auth\CompositeAuth;
  7. use yii\rest\ActiveController;
  8. use myapp\code\core\Api\V1\models\wish\WishOrder;
  9. use yii\data\ActiveDataProvider;
  10. use backend\models\core\Request;
  11. class WishorderController extends ActiveController
  12. {
  13. public $modelClass = '\Api\V1\models\wish\WishOrder';
  14. public function behaviors()
  15. {
  16. $behaviors = parent::behaviors();
  17. $behaviors['authenticator'] = [
  18. 'class' => CompositeAuth::className(),
  19. 'authMethods' => [
  20. # 下面是三种验证access_token方式
  21. //HttpBasicAuth::className(),
  22. //HttpBearerAuth::className(),
  23. # 这是GET参数验证的方式
  24. # http://10.10.10.252:600/user/index/index?access-token=xxxxxxxxxxxxxxxxxxxx
  25. QueryParamAuth::className(),
  26. ],
  27. ];
  28. #定义返回格式是:JSON
  29. $behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  30. return $behaviors;
  31. }
  32. public function actionViewbydate($begin_datetime,$end_datetime){
  33. # 分页参数处理
  34. $numPerPage = Request::param('numPerPage');
  35. if(!$numPerPage || $numPerPage <1 || $numPerPage > 800 ){
  36. $numPerPage = 100;
  37. }else{
  38. $numPerPage = (int)$numPerPage;
  39. }
  40. # where条件处理
  41. $where = '';
  42. if($begin_datetime){
  43. $where .= " last_updated >= '".$begin_datetime."' ";
  44. }
  45. if($end_datetime){
  46. if($where){
  47. $where .= " AND last_updated < '".$end_datetime."' ";
  48. }else{
  49. $where .= " last_updated < '".$end_datetime."' ";
  50. }
  51. }
  52. //echo $where;exit;
  53. if(!$where){
  54. throw new \yii\web\HttpException(404, 'You Must Add Where Filter By DateTime');
  55. }
  56. $query = WishOrder::find()->where($where);
  57. if($query->count() <1){
  58. throw new \yii\web\HttpException(404, 'No entries found with this query string');
  59. }
  60. $provider = new ActiveDataProvider([
  61. 'query' => $query,
  62. 'pagination' => [
  63. 'pageSize' => $numPerPage,
  64. ],
  65. ]);
  66. return $provider;
  67. }
  68. }