|
|
@@ -13,7 +13,6 @@ use Illuminate\Support\Facades\Cache;
|
|
|
trait ServiceAppAop
|
|
|
{
|
|
|
|
|
|
- protected $modelClass=null;
|
|
|
|
|
|
/**
|
|
|
* 实例化一个service的入口,为了测试方便做出来的,这样测试时可以代入假的柱件替换service的实现
|
|
|
@@ -42,7 +41,7 @@ trait ServiceAppAop
|
|
|
*/
|
|
|
function get(array $kvPairs):?Collection{
|
|
|
return Cache::remember($this->cachingKey($kvPairs), config('cache.expirations.serviceAutoCache'), function ()use($kvPairs) {
|
|
|
- $query = $this->getModelClass()::query();
|
|
|
+ $query = ($this->modelClass)::query();
|
|
|
foreach ($kvPairs as $column => $value){
|
|
|
if (is_array($value))$query->whereIn($column,$value);
|
|
|
else $query->where($column,$value);
|
|
|
@@ -51,13 +50,6 @@ trait ServiceAppAop
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- protected function getModelClass(){
|
|
|
- if(!$this->modelClass){
|
|
|
- throw new FatalException(__CLASS__.': 没有为 service 设定 $modelClass 的模型类');
|
|
|
- }
|
|
|
- return $this->modelClass;
|
|
|
- }
|
|
|
-
|
|
|
protected function cachingKey(array $kvPairs): string
|
|
|
{
|
|
|
ksort($kvPairs);
|
|
|
@@ -73,7 +65,7 @@ trait ServiceAppAop
|
|
|
if($materialBox->isNotEmpty())
|
|
|
return $materialBox->first();
|
|
|
$this->clearCache($kvPairs);
|
|
|
- return $this->getModelClass()::query()->create($kvPairs);
|
|
|
+ return ($this->modelClass)::query()->create($kvPairs);
|
|
|
}
|
|
|
|
|
|
function firstOrCreate(array $kvPairs){
|