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.
129 lines
5.3 KiB
129 lines
5.3 KiB
#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 |