request->isAjax && Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['page', 'user_id'], 'integer'], [['profit_time'], 'safe'], [['user_name'], 'string'], ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = [ ['=', 'mall_id', $this->mall_id], ['>=', 'status', StatusEnum::DISABLED], ]; if ($params['user_id']) { $where[] = ['=', 'user_id', (int)$params['user_id']]; } // 昵称、手机号 if ($params['user_name']) { $user_ids = User::find() ->orWhere(['like', 'nickname', "%" . $params['user_name'] . "%", false]) ->orWhere(['like', 'mobile', "%" . $params['user_name'] . "%", false]) ->select('id') ->asArray() ->column(); $where[] = ['in', 'user_id', $user_ids]; } // 收益时间 $start_time = strtotime($params['profit_time'][0] ?? 0); $end_time = strtotime($params['profit_time'][1] ?? 0); if ($start_time > 0 && $end_time > 0 && $end_time >= $start_time) { $where[] = ['>=', 'created_at', $start_time]; $where[] = ['<=', 'created_at', $end_time]; } $condition = ['where' => $where, 'with' => ['user'], 'order' => 'id desc']; $page_data = ElectronCouponApprovalIncomeLog::listPage($condition, false, true); $page_data['list'] = is_array($page_data['list']) ? $page_data['list'] : []; // 关联电子券 $coupon_id_array = array_unique(array_filter(array_column($page_data['list'], 'e_coupon_id'))); $e_coupon = ElectronCoupon::find() ->select('id,name,is_proper') ->where(['>=', 'status', StatusEnum::DISABLED]) ->where(['mall_id' => $this->mall_id]) ->where(['in', 'id', $coupon_id_array]) ->asArray() ->all(); $coupon_name_data = array_column($e_coupon, null, 'id'); foreach ($page_data['list'] as $index => $item) { // 电子券名称 $item['coupon'] = $coupon_name_data[$item['e_coupon_id']] ?? ''; $page_data['list'][$index] = $item; } $this->success('获取成功', compact('page_data')); } else { return $this->render('index'); } } }