You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pgfqe6ch8/lib/tasks/users.rake

129 lines
5.3 KiB

6 years ago
#encoding=utf-8
desc "新建100个测试玩家"
task :add_test_users => :environment do
class UserRakeService
include ApplicationHelper
# 注册完/绑定邮箱 后完善资料
def user_info(user, params)
@user = user
lg = @user.login
@pref = @user.pref
@se = @user.extensions
# 已授权的用户修改单位名称,需要重新授权
if @se.school_id != params[:occupation].to_i && @user.certification == 1
@user.certification = 0
apply_user = ApplyAction.where(:user_id => @user.id, :container_type => "TrialAuthorization")
apply_user.update_all(:status => 2) unless apply_user.blank?
end
@user.lastname = params[:lastname]
@user.firstname = ""
@user.show_realname = params[:hide_realname] ? 0 : 1
@user.nickname = params[:hide_realname] ? params[:nickname] : params[:lastname]
@user.pref.attributes = params[:pref]
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
@user.mail = params[:mail]
@se.school_id = params[:occupation]
@se.department_id = params[:department_id]
@se.gender = params[:sex]
# @se.location = params[:province] if params[:province]
# @se.location_city = params[:city] if params[:city]
@se.identity = params[:identity].to_i if params[:identity]
if @se.identity == 0
@se.technical_title = params[:te_technical_title] if params[:te_technical_title]
@se.student_id = nil
elsif @se.identity == 1
@se.student_id = params[:no] if params[:no]
@se.technical_title = nil
elsif @se.identity == 2
@se.technical_title = params[:pro_technical_title] if params[:pro_technical_title]
@se.student_id = nil
end
# @se.brief_introduction = params[:brief_introduction]
if @user.save && @se.save
reward_grade(@user, @user.id, 'Account', 500)
if @user.certification != 1
school_ids = School.where(:auto_users_trial => 1).map(&:id)
# 授权单位中的老师,学生自动授权,且创建试用授权记录
if !@se.school.nil? && school_ids.include?(@se.school_id)
@user.update_attributes(:certification => 1)
apply_action = ApplyAction.where(:user_id => @user.id, :container_type => "TrialAuthorization", :status => 0).first
if apply_action.present?
apply_action.update_attributes(:status => 1, :noticed => 1)
else
ApplyAction.create(:user_id => @user.id, :container_type => "TrialAuthorization", :status => 1, :noticed => 1)
end
# 授权的教师加入示例课堂
join_ex_course(@user) if @se.identity == 0
end
end
@user.pref.save
set_language_if_valid @user.language
first_update = Grade.where(:user_id => @user.id, :container_id => @user.id, :container_type => 'Account').first
if @user.certification == 1 || (Time.now.to_i - first_update.created_at.to_i) < 86400
if @user.certification != 1 && !@user.user_day_certifications.first.present? # 更新字段是为了在user页面弹框提示
@user.update_attributes(:certification => 3)
UserDayCertification.create(:user_id => @user.id, :status => 1)
end
end
return
else
@user.login = lg
end
end
end
(1..1000).each do |i|
no = sprintf("%04d", i)
phone = "1560731#{no}"
us = UsersService.new
user = us.register phone: phone, password: 'edu12345678'
l = "赵,钱,孙,李,周,吴,郑,王,冯,陈,褚,卫,蒋,沈,韩,杨,朱,秦,尤,许,何,吕,施,张,孔,曹,严,华,金,魏,陶,姜,黄".split(",")
f = "爱童,安妮,若婷,安煜,博,雷,梅,静,士红,大龙,冰波,慧娟,梅,婧婧,军,淋,真,维,涛,程程,
,,,,,,,,,,,,,,,,访,,,绿,,
,,访,,,,,,,,,,,,访,,,,,,,
,,,,,,,,,,,,,,,,,,绿,,,
,,,,,,,,,,访,,绿,,,,,,,,,
,,绿,,,,,,,,,,,,,,,,,,,
,绿,,,,,,,,,绿,,,,,,,,,,
,,,,,,,,,,,,,,,,,".split(",")
lastname = l[rand(l.length)] + f[rand(f.length)]
edit_params = {
lastname: lastname,
nickname: '',
sex: 0,
mail: "educoder#{no}@qq.com",
identity: 1,
te_technical_title: 0,
pro_technical_title: 0,
no: phone,
school: '国防科技大学',
occupation: 117,
is_test: true
}
UserRakeService.new.user_info(user, edit_params)
user.update_attributes!(authentication:1, professional_certification: 1)
end
end