当前位置: 首页 > 工具软件 > php-concat > 使用案例 >

group_concat 加CONCAT的用法

高自怡
2023-12-01
 /**
     * @api-请假:导出月份数据 
     * @param-string|year|值|N|{"value":""}
     * @param-string|month|值|N|{"value":""}
     */
    public function exportMonth(Request $request)
    {
        $this->validate(
            $request,
            [
                'year' => 'required',
                'month' => 'required',
            ]
        );
        $year = $request->input('year');
        $month = $request->input('month');
        $schoolId = $request['_user']['school_id'];
        $list = \DB::table('smart_school_teacher_leave AS leave')
            ->leftjoin('smart_school_teacher_leave_times', 'leave.id', 'smart_school_teacher_leave_times.teacher_leave_id')
            ->leftjoin('smart_school_teacher_users', 'leave.applicant', 'smart_school_teacher_users.id')
            ->leftjoin('smart_school_teacher_leave_categories', 'leave.category_id', 'smart_school_teacher_leave_categories.id')
            ->selectRaw(
                'leave.created_at,
            smart_school_teacher_users.name AS teacher_name,
            leave.approval_number,
            smart_school_teacher_leave_categories.name AS categoriy_name,
            CONCAT(leave.start_date," ",leave.end_date),
             group_concat(CONCAT(smart_school_teacher_leave_times.leave_date," ",CASE
			WHEN smart_school_teacher_leave_times.type = 1 THEN
			"全天" ELSE CONCAT(
			CASE
			WHEN smart_school_teacher_leave_times.one_time_up IS NOT NULL
			THEN CONCAT(smart_school_teacher_leave_times.one_time_up,",") ELSE "" END ,
					CASE
			WHEN smart_school_teacher_leave_times.one_time_down IS NOT NULL
			THEN CONCAT(smart_school_teacher_leave_times.one_time_down,",") ELSE "" END ,
					CASE
			WHEN smart_school_teacher_leave_times.two_time_up  IS NOT NULL
			THEN CONCAT(smart_school_teacher_leave_times.two_time_up,",") 	ELSE "" END ,
					CASE
			WHEN smart_school_teacher_leave_times.two_time_down  IS NOT NULL
			THEN CONCAT(smart_school_teacher_leave_times.two_time_down,",") ELSE "" END ,
				CASE
			WHEN smart_school_teacher_leave_times.three_time_up  IS NOT NULL
			THEN 	CONCAT(smart_school_teacher_leave_times.three_time_up,",")  ELSE "" END ,
					CASE
			WHEN smart_school_teacher_leave_times.three_time_down  IS NOT NULL
			THEN smart_school_teacher_leave_times.three_time_down ELSE "" END )
            	END )order by smart_school_teacher_leave_times.leave_date),
            leave.description,
            leave.picture,
             CONCAT(CASE WHEN leave.status = 1 THEN "待审批" WHEN leave.status = 2 THEN "通过"  WHEN leave.status = 2 THEN "拒绝" ELSE "撤销" END),
            leave.approval_comments,
            leave.updated_at'
            )
            ->whereYear('leave.created_at', $year)
            ->whereMonth('leave.created_at', $month)
            ->where('leave.school_id', $schoolId)
            ->groupBy('smart_school_teacher_leave_times.teacher_leave_id')
            ->orderBy('smart_school_teacher_leave_times.leave_date')->get()->toArray();
        foreach ($list as &$item) {
            $item->approval_number = "\t" . $item->approval_number;
            $item = array_values($this->object_array($item));
        }

        $tableName = '教师请假数据导出' . $month;
        $columns = [['提交时间', '请假人', '审批编号', '请假类型', '请假日期', '请假时段', '请假事由', '图片地址', '审批状态', '审批意见', '审批时间']];

        export_method($tableName, $columns, $list);
    }

concat()函数

group_concat()函数

 类似资料: