FillStatisticsController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace addons\CloudStock\backend\controllers;
  3. use addons\CloudStock\common\models\CloudStockFillStatistics;
  4. use addons\CloudStock\common\models\CloudStockLevel;
  5. use common\enums\StatusEnum;
  6. use common\models\user\User;
  7. use Yii;
  8. /**
  9. * Class PoolController
  10. * @package addons\DoubleCopy\backend\controllers
  11. */
  12. class FillStatisticsController extends BaseController
  13. {
  14. public $enableCsrfValidation = false;
  15. public function actionIndex()
  16. {
  17. $retuest = Yii::$app->request;
  18. if ($retuest->isAjax && $retuest->isGet) {
  19. // 检查提交的参数
  20. $get = $retuest->get();
  21. $res = Yii::$app->services->validate->validate($get, [
  22. [['page', 'limit', 'user_id', 'mobile'], 'integer'],
  23. [['start_at', 'end_at'], 'safe'],
  24. ]);
  25. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  26. $level_map = CloudStockLevel::getMap($this->mall_id);
  27. // 获取等级
  28. $where = $list = [];
  29. $where[] = ['=', 'mall_id', $this->mall_id];
  30. !empty($get['user_id']) && $where[] = ['=', 'user_id', $get['user_id']];
  31. !empty($get['level']) && $where[] = ['=', 'level', $get['level']];
  32. if (!empty($get['mobile'])) {
  33. $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id, 'mobile' => $get['mobile'], 'status' => StatusEnum::ENABLED])->scalar() ?? 0;
  34. if (empty($user_id)) $this->success('获取成功', compact('list', 'level_map'));
  35. $where[] = ['=', 'user_id', $user_id];
  36. }
  37. if (!empty($get['start_at']) && !empty($get['end_at'])) {
  38. $where[] = ['between', 'created_at', strtotime($get['start_at']), strtotime($get['end_at'])];
  39. }
  40. $where[] = ['=', 'status', StatusEnum::ENABLED];
  41. $with = ['user'];
  42. $order = 'id desc,created_at desc';
  43. $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => $get['limit']);
  44. $list = CloudStockFillStatistics::listPage($params, false, true);
  45. if (empty($list)) return $this->error(CloudStockFillStatistics::getStaticError());
  46. return $this->success('获取成功', compact('list', 'level_map'));
  47. }
  48. return $this->render($this->action->id);
  49. }
  50. }