public static function getAll($wechatId) { $users = []; $all = self::where(['user_openid.is_delete' => 0])->get(); if ($all) { foreach ($all as $item) { $typeCode = UserType::getCode($item['user_type_id']); if ($typeCode == self::TYPE_MANAGER && $item['user_id']) { $model = ActivityManager::getManager($wechatId, $item['open_id']); if ($model) { $users[$model['open_id']] = ['open_id' => $model['open_id'], 'type' => $model['code'], 'id' => $model['id'], 'name' => $model['name'], 'mobile' => $model['mobile'], 'time_out' => (int) $model['activity_timeout'] * 60 * 60]; } } else { if ($typeCode == self::TYPE_DOCTOR && $item['user_id']) { $model = Doctor::getDoctor($wechatId, $item['open_id']); if ($model) { $users[$model['open_id']] = ['open_id' => $model['open_id'], 'type' => $model['code'], 'id' => $model['id'], 'name' => $model['name'], 'mobile' => $model['mobile']]; } } else { $users[$item['open_id']] = ['open_id' => $item['open_id'], 'type' => '', 'id' => '', 'name' => '', 'mobile' => '']; } } } } return $users; }
private static function update($app, $openId) { $key = 'user-cache-' . $app['id']; if (Cache::has($key)) { $type = UserOpenid::getUserTypeCode($app['id'], $openId); $cache = json_decode(base64_decode(Cache::get($key)), true); if (self::get($app, $openId)) { //先删除 unset($cache[$openId]); //重新获取 $item = null; if ($type == UserOpenid::TYPE_DOCTOR) { $model = Doctor::getDoctor($app['id'], $openId); if ($model) { $item = ['open_id' => $model['open_id'], 'type' => $model['code'], 'id' => $model['id'], 'name' => $model['name'], 'mobile' => $model['mobile']]; $cache[$openId] = $item; } } if ($type == UserOpenid::TYPE_MANAGER) { $model = ActivityManager::getManager($app['id'], $openId); if ($model) { $item = ['open_id' => $model['open_id'], 'type' => $model['code'], 'id' => $model['id'], 'name' => $model['name'], 'mobile' => $model['mobile'], 'time_out' => (int) $model['activity_timeout'] * 60 * 60]; $cache[$openId] = $item; } } //更新 if ($item) { Cache::forget($key); $value = base64_encode(json_encode($cache)); Cache::forever($key, $value); return true; } } } return false; }