fixed import_user.xlsx,num

This commit is contained in:
xxq250 2025-05-07 08:54:03 +08:00
parent c59a92f00f
commit 9cb4c214c0
2 changed files with 5 additions and 1 deletions

View File

@ -3,13 +3,16 @@ namespace :import_user do
task done: :environment do
doc = SimpleXlsxReader.open("#{Rails.root}/public/import_user.xlsx")
data = doc.sheets.first.rows
num = 0
data.each_with_index do |row, index|
next if index == 0
begin
puts "index=====#{index}, mail: #{row[0]} phone: #{row[1]}"
user = User.find_by(mail: row[0])
user = User.find_by(phone: row[1]) unless user.present?
unless user.present?
if user.present?
num += 1
else
username = generate_user_login('p')
email = row[0]
email = "#{username}@example.org" if email.blank?
@ -35,6 +38,7 @@ namespace :import_user do
puts "import_user batch error: #{row[5]} username: #{row[0]}, #{e.message}"
end
end
puts "import_user user.present?: #{num}"
end
# 生成邀请码

Binary file not shown.