uid}")) { $tags = json_decode($json_tags, true); return $tags; } else { $datas = $this->get()->toArray(); $result = array(); $taged_1 = explode(',', $user->tag_1); $taged_2 = explode(',', $user->tag_2); $taged_3 = explode(',', $user->tag_3); $taged_4 = explode(',', $user->tag_4); foreach ($datas as $data) { if (!empty($data) && in_array($data['group'], [1, 2, 3, 4])) { $data['belong'] = 0; if (in_array($data['id'], ${"taged_{$data['group']}"})) { $data['belong'] = 1; } $result[$data['group']][$data['id']] = $data; } } Redis::set("charge_user_tag_{$user->uid}", json_encode($result)); return $result; } } // 刷新用户标签缓存 public function flushTagByUser(int $uid, array $data, $is_add = true) { if ($json_tags = Redis::get("charge_user_tag_{$uid}")) { $tags = json_decode($json_tags, true); if ($is_add) { $tags[$data['group']][$data['tag_id']]['belong'] = 1; } else { $tags[$data['group']][$data['tag_id']]['belong'] = 0; } Redis::set("charge_user_tag_{$uid}", json_encode($tags)); return $tags; } else { $user = UserModel::findOrFail($uid); $tags = $this->getAllTagByUser($user); return $tags; } } }