| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Services;
- use App\OwnerAreaReport;
- use App\Services\common\QueryService;
- use Illuminate\Database\Eloquent\Builder;
- Class OwnerAreaReportService
- {
- /**
- * @param Builder $builder
- * @param array $params
- * @return Builder
- */
- private function query(Builder $builder, array $params)
- {
- $columnQueryRules = [
- 'counting_month_start' => ['alias' => 'counting_month', 'startDate' => '-01'],
- 'counting_month_end' => ['alias' => 'counting_month', 'endDate' => '-31'],
- 'owner_id' => ['multi' => ','],
- ];
- if ($params["customer_id"] ?? false){
- $builder->whereHas('owner',function ($query)use(&$params){
- /** @var Builder $query*/
- $query->where("customer_id",$params["customer_id"]);
- unset($params["customer_id"]);
- });
- }
- return app(QueryService::class)->query($params, $builder, $columnQueryRules);
- }
- public function paginate(array $params, array $withs = null)
- {
- $areas = OwnerAreaReport::query()->orderByDesc('id');
- if ($withs)$areas->with($withs);
- return $this->query($areas,$params)->paginate($params["paginate"] ?? 50);
- }
- public function update(array $params, array $values)
- {
- return $this->query(OwnerAreaReport::query(),$params)->update($values);
- }
- public function get(array $params, array $withs = null)
- {
- $query = OwnerAreaReport::query()->orderByDesc('id');
- if ($withs)$query->with($withs);
- return $this->query($query,$params)->get();
- }
- }
|