PackageStatisticsService.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Services;
  3. use App\OrderPackage;
  4. use App\Services\common\QueryService;
  5. use Illuminate\Database\Eloquent\Builder;
  6. use Illuminate\Support\Facades\DB;
  7. Class PackageStatisticsService
  8. {
  9. /**
  10. * @param array $params
  11. * @return Builder
  12. */
  13. private function conditionQuery(array $params){
  14. $query = OrderPackage::query()->select(DB::raw('COUNT(owner_id) AS count'))
  15. ->whereNotNull('owner_id')
  16. ->whereNotNull('logistic_id')
  17. ->leftJoin('orders','order_packages.order_id','orders.id')
  18. ->leftJoin('owners','orders.owner_id','owners.id')
  19. ->selectRaw('owners.id owner_id,owners.name owner_name')
  20. ->leftJoin('logistics','orders.logistic_id','logistics.id')
  21. ->selectRaw('logistics.id logistic_id,logistics.name logistic_name');
  22. $columnQueryRules=[
  23. 'date_start' => ['alias' => 'created_at','startDate' => " 00:00:00"],
  24. 'date_end' => ['alias' => 'created_at','endDate' => " 23:59:59"],
  25. 'logistic_id' => ['multi' => ','],
  26. 'owner_id' => ['multi' => ','],
  27. ];
  28. $query = $query->groupBy(['owners.id','logistics.id']);
  29. return app(QueryService::class)->query($params,$query,$columnQueryRules);
  30. }
  31. public function get(array $params){
  32. return $this->conditionQuery($params)->get();
  33. }
  34. }