MaterialBoxService.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Services;
  3. use App\MaterialBox;
  4. use Illuminate\Support\Collection;
  5. use Illuminate\Support\Facades\Cache;
  6. use App\Traits\ServiceAppAop;
  7. class MaterialBoxService
  8. {
  9. use ServiceAppAop;
  10. protected $modelClass=MaterialBox::class;
  11. // function get(array $kvPairs):?Collection{
  12. // return Cache::remember($this->cachingKey($kvPairs), config('cache.expirations.rarelyChange'), function ()use($kvPairs) {
  13. // $query = MaterialBox::query();
  14. // foreach ($kvPairs as $column => $value){
  15. // if (is_array($value))$query->whereIn($column,$value);
  16. // else $query->where($column,$value);
  17. // }
  18. // return $query->get();
  19. // });
  20. // }
  21. //
  22. // protected function cachingKey(array $kvPairs){
  23. // ksort($kvPairs);
  24. // return 'MaterialBox_'.md5(json_encode($kvPairs));
  25. // }
  26. //
  27. // protected function clearCache(array $kvPairs){
  28. // Cache::forget($this->cachingKey($kvPairs));
  29. // }
  30. //
  31. // function create(array $kvPairs){
  32. // $materialBox=$this->get($kvPairs);
  33. // if($materialBox->isNotEmpty())
  34. // return $materialBox->first();
  35. // $this->clearCache($kvPairs);
  36. // return MaterialBox::query()->create($kvPairs);
  37. // }
  38. //
  39. // function firstOrCreate(array $kvPairs){
  40. // $materialBox=$this->get($kvPairs);
  41. // if($materialBox->isNotEmpty())
  42. // return $materialBox->first();
  43. // $this->clearCache($kvPairs);
  44. // return $this->create($kvPairs);
  45. // }
  46. }