LaborReportController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\LaborReport;
  4. use App\UserWorkgroup;
  5. use Carbon\Carbon;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Gate;
  8. class LaborReportController extends Controller
  9. {
  10. //超15天精确查询抽离 cloumn前提:数据库字段名必须与request内字段名一致
  11. public function preciseQuery(string $column,Request $request,$laborReports){
  12. $today=Carbon::now()->subDays(15);
  13. $laborReportsTem=clone $laborReports;
  14. $laborReportsTem=$laborReportsTem->where($column,'like','%'.$request->input($column).'%')->where('created_at','>',$today->format('Y-m-d'));
  15. if($laborReportsTem->count()==0
  16. ||$laborReportsTem->first()[$column]==$request->input($column)){
  17. $laborReports=$laborReports->where($column,$request->input($column));
  18. }else{
  19. $laborReports=$laborReportsTem;
  20. }
  21. return $laborReports;
  22. }
  23. public function conditionQuery(Request $request,$laborReports){
  24. if ($request->input('enter_number')){
  25. $laborReports=$this->preciseQuery('enter_number',$request,$laborReports);
  26. }
  27. if ($request->input('name')){
  28. $laborReports=$this->preciseQuery('name',$request,$laborReports);
  29. }
  30. if ($request->input('created_at_start')){
  31. $created_at_start=$request->input('created_at_start')." 00:00:00";
  32. $laborReports=$laborReports->where('created_at','>=',$created_at_start);
  33. }
  34. if ($request->input('created_at_end')){
  35. $created_at_end=$request->input('created_at_end')." 23:59:59";
  36. $laborReports=$laborReports->where('created_at','<=',$created_at_end);
  37. }
  38. if ($request->input('mobile_phone')){
  39. $laborReports=$laborReports->where('mobile_phone',$request->input('mobile_phone'));
  40. }
  41. if ($request->input('mobile_phone')){
  42. $laborReports=$laborReports->where('mobile_phone',$request->input('mobile_phone'));
  43. }
  44. if ($request->input('identify_number')){
  45. $laborReports=$this->preciseQuery('identify_number',$request,$laborReports);
  46. }
  47. return $laborReports;
  48. }
  49. /**
  50. * Display a listing of the resource.
  51. *@param \Illuminate\Http\Request $request
  52. * @return \Illuminate\Http\Response
  53. * 临时工报表
  54. */
  55. public function index(Request $request)
  56. {
  57. if (!Gate::allows('人事管理-临时工报表 ')){return redirect(url('/')); }
  58. if ($request->input()){
  59. $laborReports=LaborReport::orderBy('id','DESC');
  60. $laborReports=$this->conditionQuery($request,$laborReports);
  61. $laborReports=$laborReports->paginate($request->input('paginate')?$request->input('paginate'):50);
  62. $userWorkGroups=UserWorkgroup::select('id','name')->get();
  63. return view('personnel.laborReport.index',['laborReports'=>$laborReports,'userWorkGroups'=>$userWorkGroups,'request'=>$request->input()]);
  64. }
  65. $laborReports=LaborReport::orderBy('id','DESC')->paginate(50);
  66. $userWorkGroups=UserWorkgroup::select('id','name')->get();
  67. return view('personnel/laborReport/index',['laborReports'=>$laborReports,'userWorkGroups'=>$userWorkGroups,]);
  68. }
  69. /**
  70. * Show the form for creating a new resource.
  71. *
  72. * @return \Illuminate\Http\Response
  73. */
  74. public function create()
  75. {
  76. //
  77. }
  78. /**
  79. * Store a newly created resource in storage.
  80. *
  81. * @param \Illuminate\Http\Request $request
  82. * @return \Illuminate\Http\Response
  83. */
  84. public function store(Request $request)
  85. {
  86. //
  87. }
  88. /**
  89. * Display the specified resource.
  90. *
  91. * @param \App\LaborReport $laborReport
  92. * @return \Illuminate\Http\Response
  93. */
  94. public function show(LaborReport $laborReport)
  95. {
  96. //
  97. }
  98. /**
  99. * Show the form for editing the specified resource.
  100. *
  101. * @param \App\LaborReport $laborReport
  102. * @return \Illuminate\Http\Response
  103. */
  104. public function edit(LaborReport $laborReport)
  105. {
  106. //
  107. }
  108. /**
  109. * Update the specified resource in storage.
  110. *
  111. * @param \Illuminate\Http\Request $request
  112. * @param \App\LaborReport $laborReport
  113. * @return \Illuminate\Http\Response
  114. */
  115. public function update(Request $request, LaborReport $laborReport)
  116. {
  117. //
  118. }
  119. /**
  120. * Remove the specified resource from storage.
  121. *
  122. * @param \App\LaborReport $laborReport
  123. * @return \Illuminate\Http\Response
  124. */
  125. public function destroy(LaborReport $laborReport)
  126. {
  127. //
  128. }
  129. }