WaybillService.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Services;
  3. use App\Services\common\QueryService;
  4. use App\Waybill;
  5. use Illuminate\Http\Request;
  6. Class WaybillService
  7. {
  8. private function conditionQuery(Request $request){
  9. $waybills = Waybill::with(['owner','wmsCommodities','waybillAuditLogs' => function ($query) {
  10. return $query->with('user');
  11. }])->selectRaw('waybills.* ,waybill_on_tops.id top_id ,waybill_on_tops.remark,waybill_on_tops.updated_at top_update')
  12. ->leftJoin('waybill_on_tops','waybill_on_tops.waybill_id','=','waybills.id')
  13. ->whereNull('waybill_on_tops.deleted_at')
  14. ->orderBy('waybill_on_tops.updated_at','desc')
  15. ->orderBy('waybills.id','desc');
  16. $columnQueryRules=[
  17. 'waybill_number' => ['timeLimit' => 15],
  18. 'carrier_bill' => ['timeLimit' => 15],
  19. 'owner_id' => ['multi' => ','],
  20. 'wms_bill_number' => ['timeLimit' => 15],
  21. 'origination' => ['timeLimit' => 15],
  22. 'destination' => ['timeLimit' => 15],
  23. 'created_at_start' => ['alias' => 'created_at' , 'startDate' => ' 00:00:00'],
  24. 'created_at_end' => ['alias' => 'created_at' , 'endDate' => ' 23:59:59'],
  25. 'uriType' => ['alias' => 'type']
  26. ];
  27. $waybills = app(QueryService::class)->query($request,$waybills,$columnQueryRules,"waybills");
  28. return $waybills;
  29. }
  30. public function paginate(Request $request){
  31. $waybills = $this->conditionQuery($request);
  32. return $waybills->paginate($request->paginate ?? 50);
  33. }
  34. public function get(Request $request){
  35. $waybills = $this->conditionQuery($request);
  36. return $waybills->get();
  37. }
  38. public function some(Request $request){
  39. return $waybills = Waybill::with(['owner'])->selectRaw('waybills.* ,waybill_on_tops.id top_id ,waybill_on_tops.remark,waybill_on_tops.updated_at top_update')
  40. ->leftJoin('waybill_on_tops','waybill_on_tops.waybill_id','=','waybills.id')
  41. ->whereNull('waybill_on_tops.deleted_at')
  42. ->orderBy('waybill_on_tops.updated_at','desc')
  43. ->orderBy('waybills.id','desc')
  44. ->whereIn('id',explode(',',$request->data))
  45. ->get();
  46. }
  47. }