select(DB::raw('COUNT(*) AS count')) ->whereIn('order_packages.owner_id',app("OwnerService")->getQuery()) ->whereNotNull('logistic_id') ->leftJoin('orders','order_packages.order_id','orders.id') ->selectRaw('orders.owner_id,logistic_id'); if ($params["logistic_id"] ?? false){ $logistics = explode(",",$params["logistic_id"]); $query->whereIn("logistic_id",$logistics); unset($params["logistic_id"]); } $columnQueryRules=[ 'created_at_start' => ['alias' => 'weighed_at','startDate' => ":00"], 'created_at_end' => ['alias' => 'weighed_at','endDate' => ":59"], 'owner_id' => ['multi' => ','], ]; $query = $query->groupBy('order_packages.owner_id','logistic_id'); return app(QueryService::class)->query($params,$query,$columnQueryRules,'order_packages'); } public function get(array $params){ return $this->conditionQuery($params)->get(); } public function getPackageStatistic(array $params) { $query = $this->conditionQuery($params); return DB::table(DB::raw("({$query->sql()}) AS p"))->selectRaw('p.*') ->leftJoin('owners','p.owner_id','owners.id') ->selectRaw('owners.name owner_name') ->leftJoin('logistics','p.logistic_id','logistics.id') ->selectRaw('logistics.name logistic_name') ->get(); } }