merchant_id = $merchant->id; $app->app_id = $this->generateAppId(); $app->app_key = StringHelper::getRandomString(32); $app->status = App::STATUS_ACTIVE; $app->save(); return $app; } private function generateAppId() { $now = time(); $key = RedisKey::getGenerateAppIdKey($now); $expireAt = strtotime(date('Y-m-d 23:59:59', $now)) + 1; $incrId = Redis::incr($key); $incrId = '' . $incrId; Redis::expireAt($key, $expireAt); $padLength = 8 - strlen($incrId); $incrId = str_pad($incrId, $padLength, '0', STR_PAD_LEFT); return date('Ymd', $now) . $incrId; } }