-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGridCacheService.php
More file actions
39 lines (33 loc) · 1.03 KB
/
Copy pathGridCacheService.php
File metadata and controls
39 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace Andruby\DeepAdmin\Services;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
/**
* @method static GridCacheService instance()
*
* Class ActivityConfigService
* @package App\Api\Services
*/
class GridCacheService
{
public static function __callStatic($method, $params): GridCacheService
{
return new self();
}
public function get_cache_value($model, $key, $where_field_value, $where_field, $value_field, $is_delete = 0)
{
$value = Cache::get($key);
if (empty($value)) {
if(!($model instanceof Model)){
$model = $model::query();
}
if ($is_delete) {
$model = $model->withTrashed(); // 查询已删除数据
}
$value = $model->where($where_field, $where_field_value)->value($value_field);
$value = $value ? $value : '';
Cache::put($key, $value, config('deep_admin.GRID_RELATED_DATA_CACHE_EXPIRE_TIME'));
}
return $value;
}
}