| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace addons\CloudStock\backend\controllers;
- use addons\CloudStock\common\models\CloudStockFillStatistics;
- use addons\CloudStock\common\models\CloudStockLevel;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- /**
- * Class PoolController
- * @package addons\DoubleCopy\backend\controllers
- */
- class FillStatisticsController extends BaseController
- {
- public $enableCsrfValidation = false;
- public function actionIndex()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax && $retuest->isGet) {
- // 检查提交的参数
- $get = $retuest->get();
- $res = Yii::$app->services->validate->validate($get, [
- [['page', 'limit', 'user_id', 'mobile'], 'integer'],
- [['start_at', 'end_at'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $level_map = CloudStockLevel::getMap($this->mall_id);
- // 获取等级
- $where = $list = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- !empty($get['user_id']) && $where[] = ['=', 'user_id', $get['user_id']];
- !empty($get['level']) && $where[] = ['=', 'level', $get['level']];
- if (!empty($get['mobile'])) {
- $user_id = User::find()->select('id')->where(['mall_id' => $this->mall_id, 'mobile' => $get['mobile'], 'status' => StatusEnum::ENABLED])->scalar() ?? 0;
- if (empty($user_id)) $this->success('获取成功', compact('list', 'level_map'));
- $where[] = ['=', 'user_id', $user_id];
- }
- if (!empty($get['start_at']) && !empty($get['end_at'])) {
- $where[] = ['between', 'created_at', strtotime($get['start_at']), strtotime($get['end_at'])];
- }
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $with = ['user'];
- $order = 'id desc,created_at desc';
- $params = array('where' => $where, 'order' => $order, 'with' => $with, 'limit' => $get['limit']);
- $list = CloudStockFillStatistics::listPage($params, false, true);
- if (empty($list)) return $this->error(CloudStockFillStatistics::getStaticError());
- return $this->success('获取成功', compact('list', 'level_map'));
- }
- return $this->render($this->action->id);
- }
- }
|