userinfo; $SchoolCode = (new platformAuth())->interfaceRequest('getSchoolCode', []); $codes = array_column($SchoolCode['data'], 'code'); if (!$userinfo['is_developer']) { $org_ids =$this->userinfo['org_id']; $where = []; $where[] = ['type', 'IN', $codes]; if($org_ids!==1){ $where[] = ['org_id', 'IN', $org_ids]; } $list = Org::where($where)->field("org_id,name,type")->select(); } else { $list = Org::where('type', 'IN', $codes)->field("org_id,name,type")->select(); } return res(1, '获取成功', $list); } /** * Notes:预约人数统计 * User: zhang * Date: 2025/2/17 * Time: 19:58 */ public function orderNumCount() { $data = $this->request->param(); $where = []; $SchoolCode = (new platformAuth())->interfaceRequest('getSchoolCode', []); $codes = array_column($SchoolCode['data'], 'code'); $timeMode = 'Y-m-d H:i:s';//需要的时间格式 $x = []; $userinfo = $this->userinfo; if (empty($data['type'])) { $data['type'] = 1; } switch ($data['type']) { case 1: //近3天 $timeData = TimeHandle::getSrceenSE("", 1, $timeMode); $x = TimeHandle::getChartX($timeData['s'], $timeData['e'], 2)['x']; // 构造条件 $where[] = ['b.create_at', '>=', $timeData['s']]; $where[] = ['b.create_at', '<=', $timeData['e']]; break; case 2: //近7天 $timeData = TimeHandle::getSrceenSE("", 2, $timeMode); $x = TimeHandle::getChartX($timeData['s'], $timeData['e'], 2)['x']; // 构造条件 $where[] = ['b.create_at', '>=', $timeData['s']]; $where[] = ['b.create_at', '<=', $timeData['e']]; break; } if (!$userinfo['is_developer']) { $org_ids = UserRole::where('user_id', $this->userinfo['user_id'])->column("org_id"); $types = Org::where('org_id', 'IN', $org_ids)->field("org_id,name,type")->column("type"); //去重 $types = array_unique($types); $where[] = ['b.stage_code', 'IN', $types]; if (!in_array(1, $org_ids)) { $where[] = ['a.org_id', 'IN', $org_ids]; } } else { $where[] = ['b.stage_code', 'IN', $codes]; } if (!empty($data['org_id'])) { $where[] = ['a.org_id', '=', $data['org_id']]; } $list = JdfEnrollVolunteer::alias('a') ->join('jdf_enroll_students b', 'a.enroll_id=b.enroll_id') ->where($where) ->field('a.org_id,b.semester_date,b.create_at,b.stage_code,count(*) as value') ->group('DATE(b.create_at),b.stage_code')->select()->toArray(); // $list = EnrollStudents::where($where)->field('semester_date,stage_code,count(*) as value')->group('DATE(create_at),stage_code')->select()->toArray(); $arr_code = array_column($list, 'stage_code'); $arr_code = array_unique($arr_code); $typeList = OrgType::where('code', 'IN', $arr_code)->field("org_type_name as name,code")->select(); // 初始化数据数组,默认为0 $initialData = []; foreach ($x as $date) { foreach ($arr_code as $code) { if (!isset($initialData[$code])) { $initialData[$code] = []; } $initialData[$code][$date] = 0; // 初始化为0 } } // 遍历已有数据并填充 foreach ($list as $item) { $date = date('Y-m-d', strtotime($item['semester_date'])); $date = TimeHandle::beginToday(2, $date, 'd') . '号';// 将日期格式化为Y-m-d,与$x中的格式一致 $stageCode = $item['stage_code']; $value = $item['value']; $initialData[$stageCode][$date] = $value; // 填充已有数据 } // 转换数据格式,符合之前的返回结构 $typeData = []; foreach ($initialData as $stageCode => $dailyData) { $values = array_values($dailyData); // 将日期作为键的数组转换为值数组,保持顺序 $typeData[$stageCode] = $values; } return res(1, '获取成功', ['x' => $x, 'data' => $typeData, 'type' => $typeList]); } /** * Desc :预约性别统计 * User : zwq * Date : 2025-02-17 19:31 */ public function orderSexCount() { $org_id = input('org_id/d', 0); $where = []; $userinfo = $this->userinfo; if (!$userinfo['is_developer']) { $org_ids = UserRole::where('user_id', $userinfo['user_id'])->column("org_id"); if (!in_array(1, $org_ids)) {// 非集团 $where[] = ['a.org_id', 'IN', $org_ids]; } } if (!empty($org_id)) { $where[] = ['a.org_id', '=', $org_id]; } $list = JdfEnrollVolunteer::alias('a') ->join('jdf_enroll_students b', 'a.enroll_id=b.enroll_id') ->where($where) ->field('a.org_id,b.sex,count(*) as value') ->group('b.sex') ->select() ->toArray(); // $list = EnrollStudents::where($where)->field('sex,count(*) as value')->group('sex')->select()->toArray(); if ($list) { // 计算总人数 $total = array_sum(array_column($list, 'value')); foreach ($list as $k => &$v) { $list[$k]['name'] = $v['sex'] == 1 ? '男' : '女'; $v['percentage'] = round(($v['value'] / $total) * 100, 2); // 保留两位小数 } // 移除引用,因为我们在foreach中使用了引用 unset($v); } else { $list = []; } return res(1, '获取成功', $list); } }