Maatwebsite/Laravel Excel查询结果与下载的XLS不同
我查询了过去5天的出勤情况,包括员工Id、姓名、日期以及登录和注销时间 如果我在MySql中运行查询,它会返回正确的日期,但当我使用Maatwebsite/Laravel excel时,它似乎缺少一些记录 我试着做了一些研究,但我找不到一种方法来确定是什么导致了它Maatwebsite/Laravel Excel查询结果与下载的XLS不同,laravel,cron,laravel-query-builder,maatwebsite-excel,Laravel,Cron,Laravel Query Builder,Maatwebsite Excel,我查询了过去5天的出勤情况,包括员工Id、姓名、日期以及登录和注销时间 如果我在MySql中运行查询,它会返回正确的日期,但当我使用Maatwebsite/Laravel excel时,它似乎缺少一些记录 我试着做了一些研究,但我找不到一种方法来确定是什么导致了它 return $user = DB::table('users AS u') ->join('user_attendance AS a', function($join) { $join-&g
return $user = DB::table('users AS u')
->join('user_attendance AS a', function($join)
{
$join->on('u.user_id', '=', 'a.user_id')
->whereBetween('a.server_time', ["2019-10-01 00:00:00", "2019-10-15 23:59:59"]);
})
->select('u.user_id', 'u.username',
DB::raw(
'min(case when a.action = "IN" then date(a.server_time) end) `Date`,
min(case when a.action = "IN" then time(a.server_time) end) `IN`,
min(case when a.action = "OUT" then time(a.server_time) end) `OUT`'
)
)
->groupBy('u.user_id', 'u.username', DB::raw('Date(a.server_time)'))
->orderBy('u.user_id')
->orderBy(DB::raw('Date(a.server_time)'))
->get();
如果我运行如下所示的查询,结果将是Mysql
| EmployeeId | EmployeeName | Date | IN | OUT |
------------------------------------------------------------------
| 400442 | Pooh | 2019-10-02 | 08:49:02 | 18:08:00 |
| 400442 | Pooh | 2019-10-07 | 08:29:22 | 18:08:35 |
| 400442 | Pooh | 2019-10-09 | 08:36:41 | 23:28:52 |
| 400442 | Pooh | 2019-10-10 | 08:20:15 | 21:40:12 |
| 400442 | Pooh | 2019-10-15 | 08:47:13 | 20:57:05 |
------------------------------------------------------------------
但是,当我使用MaatWebsite/Laravel Excel在Laravel中运行代码时,它会返回不完整的日期。
这是我的密码
AutomailerController.php
namespace App\Http\Controllers;
use App\Exports\UsersExport;
use Maatwebsite\Excel\Facades\Excel;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use DB;
class AutomailerController extends Controller
{
use Exportable;
public function export()
{
return Excel::download(new UserLogs, 'users.xlsx');
}
}
这是我的UserLogs.php
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use DB;
class UsersExport implements FromCollection
{
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
return $user = DB::table('users AS u')
->join('user_attendance AS a', function($join)
{
$join->on('u.user_id', '=', 'a.user_id')
->whereBetween('a.server_time', ["2019-10-01 00:00:00", "2019-10-15 23:59:59"]);
})
->select('u.user_id', 'u.username',
DB::raw(
'min(case when a.action = "IN" then date(a.server_time) end) `Date`,
min(case when a.action = "IN" then time(a.server_time) end) `IN`,
min(case when a.action = "OUT" then time(a.server_time) end) `OUT`'
)
)
->groupBy('u.user_id', 'u.username', DB::raw('Date(a.server_time)'))
->orderBy('u.user_id')
->orderBy(DB::raw('Date(a.server_time)'))
->get();
}
}
当我在Mysql上运行它时,我希望它的结果是相同的
后端是否发生了我错过的事情
谢谢。文档上说don'y put get,可能就是这个错误。
| EmployeeId | EmployeeName | Date | IN | OUT |
------------------------------------------------------------------
| 400442 | Pooh | | | 22:28:52 |
| 400442 | Pooh | 2019-10-10 | 08:20:15 | 21:40:12 |
------------------------------------------------------------------