|
@@ -4,9 +4,6 @@ namespace App\Models; |
|
@@ -4,9 +4,6 @@ namespace App\Models; |
|
4
|
|
4
|
|
|
5
|
use App\Helper\Common;
|
5
|
use App\Helper\Common;
|
|
6
|
use Illuminate\Database\Eloquent\Model;
|
6
|
use Illuminate\Database\Eloquent\Model;
|
|
7
|
-use Illuminate\Support\Facades\Cache;
|
|
|
|
8
|
-use Illuminate\Support\Facades\DB;
|
|
|
|
9
|
-
|
|
|
|
10
|
class Base extends Model
|
7
|
class Base extends Model
|
|
11
|
{
|
8
|
{
|
|
12
|
protected $table = '';
|
9
|
protected $table = '';
|
|
@@ -107,11 +104,22 @@ class Base extends Model |
|
@@ -107,11 +104,22 @@ class Base extends Model |
|
107
|
*/
|
104
|
*/
|
|
108
|
public function read($condition,$files = ['*'])
|
105
|
public function read($condition,$files = ['*'])
|
|
109
|
{
|
106
|
{
|
|
|
|
107
|
+ //读取缓存
|
|
|
|
108
|
+ $cache = config('cache.user_is_cache');
|
|
|
|
109
|
+ if(($cache['is_cache'] == true) && isset($condition['id'])){
|
|
|
|
110
|
+ $info = Common::get_user_cache($this->getTable(),$condition['id']);
|
|
|
|
111
|
+ if(!empty($info)){
|
|
|
|
112
|
+ return $info;
|
|
|
|
113
|
+ }
|
|
|
|
114
|
+ }
|
|
110
|
$query = $this->formatQuery($condition);
|
115
|
$query = $this->formatQuery($condition);
|
|
111
|
$info = $query->select($files)->first();
|
116
|
$info = $query->select($files)->first();
|
|
112
|
if (empty($info)) {
|
117
|
if (empty($info)) {
|
|
113
|
return false;
|
118
|
return false;
|
|
114
|
}
|
119
|
}
|
|
|
|
120
|
+ if(($cache['is_cache'] == true) && isset($condition['id'])){
|
|
|
|
121
|
+ Common::set_user_cache($info,$this->getTable(),$condition['id']);
|
|
|
|
122
|
+ }
|
|
115
|
$info = $info->toArray();
|
123
|
$info = $info->toArray();
|
|
116
|
return $info;
|
124
|
return $info;
|
|
117
|
}
|
125
|
}
|
|
@@ -136,6 +144,11 @@ class Base extends Model |
|
@@ -136,6 +144,11 @@ class Base extends Model |
|
136
|
$query = $this->formatQuery($condition);
|
144
|
$query = $this->formatQuery($condition);
|
|
137
|
$data['updated_at'] = date('Y-m-d H:i:s');
|
145
|
$data['updated_at'] = date('Y-m-d H:i:s');
|
|
138
|
$rs = $query->update($data);
|
146
|
$rs = $query->update($data);
|
|
|
|
147
|
+ //更新缓存
|
|
|
|
148
|
+ $cache = config('cache.user_is_cache');
|
|
|
|
149
|
+ if(($cache['is_cache'] == true) && isset($condition['id'])) {
|
|
|
|
150
|
+ Common::del_user_cache($this->getTable(), $condition['id']);
|
|
|
|
151
|
+ }
|
|
139
|
return $rs;
|
152
|
return $rs;
|
|
140
|
}
|
153
|
}
|
|
141
|
/**
|
154
|
/**
|
|
@@ -146,8 +159,7 @@ class Base extends Model |
|
@@ -146,8 +159,7 @@ class Base extends Model |
|
146
|
*/
|
159
|
*/
|
|
147
|
public function del($condition){
|
160
|
public function del($condition){
|
|
148
|
$query = $this->formatQuery($condition);
|
161
|
$query = $this->formatQuery($condition);
|
|
149
|
- $rs = $query->delete();
|
|
|
|
150
|
- return $rs;
|
162
|
+ return $query->delete();
|
|
151
|
}
|
163
|
}
|
|
152
|
/**
|
164
|
/**
|
|
153
|
* @name :参数处理查询
|
165
|
* @name :参数处理查询
|