OwnerFeeDetailService.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Services;
  3. use App\OwnerFeeDetail;
  4. use App\Services\common\QueryService;
  5. use Illuminate\Database\Eloquent\Builder;
  6. use App\Traits\ServiceAppAop;
  7. class OwnerFeeDetailService
  8. {
  9. use ServiceAppAop;
  10. protected $modelClass=OwnerFeeDetail::class;
  11. /**
  12. * @param Builder $builder
  13. * @param array $params
  14. * @return Builder
  15. */
  16. private function query(Builder $builder, array $params)
  17. {
  18. $builder->whereIn("owner_id",app("OwnerService")->getIdArr());
  19. $columnQueryRules = [
  20. 'worked_at_start' => ['alias' => 'worked_at', 'startDate' => ''],
  21. 'worked_at_end' => ['alias' => 'worked_at', 'endDate' => ''],
  22. 'owners' => ['alias' => 'owner_id','multi' => ','],
  23. 'id' => ['multi' => ','],
  24. 'operation_bill' => ['batch' => ''],
  25. 'logistic_bill' => ['batch' => ''],
  26. ];
  27. if ($params["customer_id"] ?? false){
  28. $builder->whereHas('owner',function ($query)use(&$params){
  29. /** @var Builder $query*/
  30. $query->where("customer_id",$params["customer_id"]);
  31. unset($params["customer_id"]);
  32. });
  33. }
  34. return app(QueryService::class)->query($params, $builder, $columnQueryRules, 'owner_fee_details');
  35. }
  36. public function paginate(array $params, array $withs = null)
  37. {
  38. $areas = OwnerFeeDetail::query()->orderByDesc('id');
  39. if ($withs)$areas->with($withs);
  40. return $this->query($areas,$params)->paginate($params["paginate"] ?? 50);
  41. }
  42. public function getSql($params)
  43. {
  44. $query = $this->query(OwnerFeeDetail::query()->orderByDesc('id'),$params);
  45. $query->selectRaw("owner_fee_details.*,(work_fee+logistic_fee) total");
  46. $query->leftJoin("owners","owner_fee_details.owner_id","owners.id")
  47. ->selectRaw("owners.name owner_name")
  48. ->leftJoin("customers","owners.customer_id","customers.id")
  49. ->selectRaw("customers.name customer_name")
  50. ->leftJoin("shops","owner_fee_details.shop_id","shops.id")
  51. ->selectRaw("shops.name shop_name")
  52. ->leftJoin("logistics","owner_fee_details.logistic_id","logistics.id")
  53. ->selectRaw("logistics.name logistic_name");
  54. return $query->sql();
  55. }
  56. public function create(array $params)
  57. {
  58. return OwnerFeeDetail::query()->create($params);
  59. }
  60. public function first(array $params)
  61. {
  62. $query = OwnerFeeDetail::query();
  63. foreach ($params as $column=>$param){
  64. if (is_array($param))$query->whereIn($column,$param);
  65. else $query->where($column,$param);
  66. }
  67. return $query->first();
  68. }
  69. public function updateFind(OwnerFeeDetail $detail, array $values)
  70. {
  71. return $detail->update($values);
  72. }
  73. }