|
|
@@ -13,44 +13,41 @@ use App\Traits\ServiceAppAop;
|
|
|
class MaterialBoxService
|
|
|
{
|
|
|
use ServiceAppAop;
|
|
|
- function getModelClass(): string
|
|
|
- {
|
|
|
- return MaterialBox::class;
|
|
|
- }
|
|
|
-
|
|
|
- function get(array $kvPairs):?Collection{
|
|
|
- return Cache::remember($this->cachingKey($kvPairs), config('cache.expirations.rarelyChange'), function ()use($kvPairs) {
|
|
|
- $query = MaterialBox::query();
|
|
|
- foreach ($kvPairs as $column => $value){
|
|
|
- if (is_array($value))$query->whereIn($column,$value);
|
|
|
- else $query->where($column,$value);
|
|
|
- }
|
|
|
- return $query->get();
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- protected function cachingKey(array $kvPairs){
|
|
|
- ksort($kvPairs);
|
|
|
- return 'MaterialBox_'.md5(json_encode($kvPairs));
|
|
|
- }
|
|
|
-
|
|
|
- protected function clearCache(array $kvPairs){
|
|
|
- Cache::forget($this->cachingKey($kvPairs));
|
|
|
- }
|
|
|
-
|
|
|
- function create(array $kvPairs){
|
|
|
- $materialBox=$this->get($kvPairs);
|
|
|
- if($materialBox->isNotEmpty())
|
|
|
- return $materialBox->first();
|
|
|
- $this->clearCache($kvPairs);
|
|
|
- return MaterialBox::query()->create($kvPairs);
|
|
|
- }
|
|
|
-
|
|
|
- function firstOrCreate(array $kvPairs){
|
|
|
- $materialBox=$this->get($kvPairs);
|
|
|
- if($materialBox->isNotEmpty())
|
|
|
- return $materialBox->first();
|
|
|
- $this->clearCache($kvPairs);
|
|
|
- return $this->create($kvPairs);
|
|
|
- }
|
|
|
+ protected $modelClass=MaterialBox::class;
|
|
|
+
|
|
|
+// function get(array $kvPairs):?Collection{
|
|
|
+// return Cache::remember($this->cachingKey($kvPairs), config('cache.expirations.rarelyChange'), function ()use($kvPairs) {
|
|
|
+// $query = MaterialBox::query();
|
|
|
+// foreach ($kvPairs as $column => $value){
|
|
|
+// if (is_array($value))$query->whereIn($column,$value);
|
|
|
+// else $query->where($column,$value);
|
|
|
+// }
|
|
|
+// return $query->get();
|
|
|
+// });
|
|
|
+// }
|
|
|
+//
|
|
|
+// protected function cachingKey(array $kvPairs){
|
|
|
+// ksort($kvPairs);
|
|
|
+// return 'MaterialBox_'.md5(json_encode($kvPairs));
|
|
|
+// }
|
|
|
+//
|
|
|
+// protected function clearCache(array $kvPairs){
|
|
|
+// Cache::forget($this->cachingKey($kvPairs));
|
|
|
+// }
|
|
|
+//
|
|
|
+// function create(array $kvPairs){
|
|
|
+// $materialBox=$this->get($kvPairs);
|
|
|
+// if($materialBox->isNotEmpty())
|
|
|
+// return $materialBox->first();
|
|
|
+// $this->clearCache($kvPairs);
|
|
|
+// return MaterialBox::query()->create($kvPairs);
|
|
|
+// }
|
|
|
+//
|
|
|
+// function firstOrCreate(array $kvPairs){
|
|
|
+// $materialBox=$this->get($kvPairs);
|
|
|
+// if($materialBox->isNotEmpty())
|
|
|
+// return $materialBox->first();
|
|
|
+// $this->clearCache($kvPairs);
|
|
|
+// return $this->create($kvPairs);
|
|
|
+// }
|
|
|
}
|