getData($redis_on_name); if(empty($invite_code_id)){ $invite_info = InviteCode::where('status', 0)->select(['id','code'])->first(); RedisDataServer::creatServer()->setData($redis_on_name,$invite_info->{'id'},'str',1800,false); }else{ ++$invite_code_id; RedisDataServer::creatServer()->setData($redis_on_name,$invite_code_id,'str',1800,false); $invite_info = InviteCode::where('id','>',$invite_code_id)->where('status', 0)->select(['id','code'])->first(); } $invite_info->update(['status'=>1]); return $invite_info->{'code'}; } /** * 预生成编码 */ function setInviteCode() { if (file_exists(public_path('code/data-with-code-cache.json'))) { $json = file_get_contents(public_path('code/data-with-code-cache.json')); $json = json_decode($json, true); } else { $json = []; } for ($i = 1; $i <= 50000; ++$i) { $invite_code = ''; $is_ok = true; while ($is_ok) { $invite_code = rand(10000000, 99999999); if (!in_array($invite_code, $json)) { $is_ok = false; $json[] = $invite_code; } } InviteCode::create(['code' => $invite_code, 'status' => 0]); } file_put_contents(public_path('code/data-with-code-cache.json'), json_encode($json)); } }