| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace App\Http\Controllers;
- use App\LaborReport;
- use App\UserWorkgroup;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Gate;
- class LaborReportController extends Controller
- {
- //超15天精确查询抽离 cloumn前提:数据库字段名必须与request内字段名一致
- public function preciseQuery(string $column,Request $request,$laborReports){
- $today=Carbon::now()->subDays(15);
- $laborReportsTem=clone $laborReports;
- $laborReportsTem=$laborReportsTem->where($column,'like','%'.$request->input($column).'%')->where('created_at','>',$today->format('Y-m-d'));
- if($laborReportsTem->count()==0
- ||$laborReportsTem->first()[$column]==$request->input($column)){
- $laborReports=$laborReports->where($column,$request->input($column));
- }else{
- $laborReports=$laborReportsTem;
- }
- return $laborReports;
- }
- public function conditionQuery(Request $request,$laborReports){
- if ($request->input('enter_number')){
- $laborReports=$this->preciseQuery('enter_number',$request,$laborReports);
- }
- if ($request->input('name')){
- $laborReports=$this->preciseQuery('name',$request,$laborReports);
- }
- if ($request->input('created_at_start')){
- $created_at_start=$request->input('created_at_start')." 00:00:00";
- $laborReports=$laborReports->where('created_at','>=',$created_at_start);
- }
- if ($request->input('created_at_end')){
- $created_at_end=$request->input('created_at_end')." 23:59:59";
- $laborReports=$laborReports->where('created_at','<=',$created_at_end);
- }
- if ($request->input('mobile_phone')){
- $laborReports=$laborReports->where('mobile_phone',$request->input('mobile_phone'));
- }
- if ($request->input('mobile_phone')){
- $laborReports=$laborReports->where('mobile_phone',$request->input('mobile_phone'));
- }
- if ($request->input('identify_number')){
- $laborReports=$this->preciseQuery('identify_number',$request,$laborReports);
- }
- return $laborReports;
- }
- /**
- * Display a listing of the resource.
- *@param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- * 临时工报表
- */
- public function index(Request $request)
- {
- if (!Gate::allows('人事管理-临时工报表 ')){return redirect(url('/')); }
- if ($request->input()){
- $laborReports=LaborReport::orderBy('id','DESC');
- $laborReports=$this->conditionQuery($request,$laborReports);
- $laborReports=$laborReports->paginate($request->input('paginate')?$request->input('paginate'):50);
- $userWorkGroups=UserWorkgroup::select('id','name')->get();
- return view('personnel.laborReport.index',['laborReports'=>$laborReports,'userWorkGroups'=>$userWorkGroups,'request'=>$request->input()]);
- }
- $laborReports=LaborReport::orderBy('id','DESC')->paginate(50);
- $userWorkGroups=UserWorkgroup::select('id','name')->get();
- return view('personnel/laborReport/index',['laborReports'=>$laborReports,'userWorkGroups'=>$userWorkGroups,]);
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- //
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- //
- }
- /**
- * Display the specified resource.
- *
- * @param \App\LaborReport $laborReport
- * @return \Illuminate\Http\Response
- */
- public function show(LaborReport $laborReport)
- {
- //
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param \App\LaborReport $laborReport
- * @return \Illuminate\Http\Response
- */
- public function edit(LaborReport $laborReport)
- {
- //
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param \App\LaborReport $laborReport
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, LaborReport $laborReport)
- {
- //
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param \App\LaborReport $laborReport
- * @return \Illuminate\Http\Response
- */
- public function destroy(LaborReport $laborReport)
- {
- //
- }
- }
|