request->isAjax) { $get = \Yii::$app->request->get(); $where = [ ['mall_id' => $this->mall_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]], ]; if (!empty($get['store_id'])) $where[] = ['store_id' => $get['store_id']]; $params = ['where' => $where, 'order' => 'id desc', 'with' => 'store']; $list = StoreClerkIncomeData::listPage($params); if ($list === false) return $this->error(StoreClerkIncomeData::getStaticError()); return $this->success('ok', $list); } return $this->render($this->action->id); } public function actionDetail() { if (Yii::$app->request->isAjax && Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $store_id=$params['store_id']; $res = Yii::$app->services->validate->validate($params, [ [['page', 'user_id','clerk_user_id'], 'integer'], [['user_name', 'e_coupon_name', 'check_user_name'], 'string'], [['usage_time'], 'safe'], ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $where = [ ['mall_id' => $this->mall_id], ['store_id' => $store_id], ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]], ]; if ($params['user_id']) { $where[] = ['=', 'user_id', (int)$params['user_id']]; } if ($params['clerk_user_id']) { $where[] = ['clerk_user_id'=>(int)$params['clerk_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]; } // 核销员 昵称、手机号 if ($params['check_user_name']) { $user_ids = User::find() ->orWhere(['like', 'nickname', "%" . $params['check_user_name'] . "%", false]) ->orWhere(['like', 'mobile', "%" . $params['check_user_name'] . "%", false]) ->select('id') ->asArray() ->column(); $where[] = ['in', 'clerk_user_id', $user_ids]; } if ($params['e_coupon_name']) { $where[] = ['like', 'e_coupon_name', "%" . $params['e_coupon_name'] . "%", false]; } // 使用时间 $start_time = strtotime($params['usage_time'][0] ?? 0); $end_time = strtotime($params['usage_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, 'order' => 'id desc']; $page_data = StoreClerkIncome::listPage($condition); $user_id_array1 = array_column($page_data['list'], 'user_id'); $user_id_array2 = array_column($page_data['list'], 'clerk_user_id'); $user_id_array3 = array_column($page_data['list'], 'proper_user_id'); $user_id_array = array_unique(array_filter(array_merge($user_id_array1, $user_id_array2, $user_id_array3))); $users = User::find() ->select('id,nickname,avatar_url,mobile') ->where(['>=', 'status', StatusEnum::DISABLED]) ->where(['mall_id' => $this->mall_id]) ->where(['in', 'id', $user_id_array]) ->asArray() ->all(); $users_data = array_column($users, null, 'id'); $page_data['list'] = is_array($page_data['list']) ? $page_data['list'] : []; foreach ($page_data['list'] as $index => $item) { $item['user'] = $users_data[$item['user_id']] ?? []; $item['clerk_user'] = $users_data[$item['clerk_user_id']] ?? []; $item['proper_user'] = $users_data[$item['proper_user_id']] ?? []; $page_data['list'][$index] = $item; } if ($page_data === false) return $this->error(StoreClerkIncome::getStaticError()); return $this->success('ok', compact('page_data')); } return $this->render($this->action->id); } public function actionGetTopData() { if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $get = \Yii::$app->request->get(); $store_id=$get['store_id']; $params=$get; $where[] = 'and'; $where[] = ['mall_id' => $this->mall_id]; $where[] = ['store_id' => $store_id]; $where[] = ['status' => StatusEnum::ENABLED]; if ($params['user_id']) { $where[] = ['=', 'user_id', (int)$params['user_id']]; } if ($params['clerk_user_id']) { $where[] = ['clerk_user_id'=>(int)$params['clerk_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]; } // 核销员 昵称、手机号 if ($params['check_user_name']) { $user_ids = User::find() ->orWhere(['like', 'nickname', "%" . $params['check_user_name'] . "%", false]) ->orWhere(['like', 'mobile', "%" . $params['check_user_name'] . "%", false]) ->select('id') ->asArray() ->column(); $where[] = ['in', 'clerk_user_id', $user_ids]; } if ($params['e_coupon_name']) { $where[] = ['like', 'e_coupon_name', "%" . $params['e_coupon_name'] . "%", false]; } // 使用时间 $start_time = strtotime($params['usage_time'][0] ?? 0); $end_time = strtotime($params['usage_time'][1] ?? 0); if ($start_time > 0 && $end_time > 0 && $end_time >= $start_time) { $where[] = ['>=', 'created_at', $start_time]; $where[] = ['<=', 'created_at', $end_time]; } $total_amount = StoreClerkIncome::find() ->where($where) ->sum('amount'); $total_amount = $total_amount ? $total_amount : 0; $total_income = StoreClerkIncome::find() ->where($where) ->sum('income'); $total_time = StoreClerkIncome::find() ->where($where) ->count(); $data = [ 'total_time'=>$total_time??0, 'total_amount' => $total_amount??0, 'total_income'=>$total_income??0, ]; return $this->success('获取成功', $data); } } } }