|
|
|
@ -76,48 +76,59 @@ class ApplicationController < ActionController::Base
|
|
|
|
|
# 包月+按license 9200109002
|
|
|
|
|
|
|
|
|
|
# 云启训练场(EduCoder))院校版 产品编码(appId) 9200109
|
|
|
|
|
def ecloud_auth subject_id
|
|
|
|
|
# euser = EcloudUser.where("userid =? and opttype not in(3, 5)", User.current.id).first
|
|
|
|
|
# if euser.present? # 开通过业务
|
|
|
|
|
# # 获取用户的套餐信息
|
|
|
|
|
# e_service = euser.ecloud_services.where("opttype != 1")
|
|
|
|
|
# # 如果用户开通过服务
|
|
|
|
|
# if e_service.present?
|
|
|
|
|
# if e_service.count >1 # 说明有重复开通过业务
|
|
|
|
|
# else
|
|
|
|
|
# code = e_service.first.try(:code)
|
|
|
|
|
#
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
# else
|
|
|
|
|
# false # 没开通过服务,或者服务被禁用则不允许访问
|
|
|
|
|
# end
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# if e_service.count > 1 # 说明有重复订购过套餐
|
|
|
|
|
# else
|
|
|
|
|
# code = e_service.try(:code)
|
|
|
|
|
# end
|
|
|
|
|
# service_count = euser.ecloud_services.where("opttype != 1").try(:code)
|
|
|
|
|
#
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
# 如果不是Ecloud过来的用户,则不改变用户的使用状态及权限,按现有模式即可
|
|
|
|
|
def ecloud_auth
|
|
|
|
|
euser = EcloudUser.where("userid =? and opttype not in(3, 5)", User.current.id).first
|
|
|
|
|
|
|
|
|
|
if euser.present? # 开通过业务
|
|
|
|
|
# 获取用户的套餐信息
|
|
|
|
|
e_services = euser.ecloud_services.where("opttype != 1").order("ecloud_services.code desc")
|
|
|
|
|
# 如果用户开通过服务
|
|
|
|
|
if e_services.present?
|
|
|
|
|
if e_services.count > 1 # 说明有重复开通过业务
|
|
|
|
|
# 开通多业务的话,以最大的套餐排序,如果最大套餐还可以用,则直接返回true,如果最大套餐不能用,则轮询返回,直到找到可用的套餐
|
|
|
|
|
e_services.each do |e_service|
|
|
|
|
|
# 使用期限内套餐才有效
|
|
|
|
|
ecloud_services_auth(e_service.code, e_service.begintime, e_service.endtime)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
# 先看套餐,再看时间区间
|
|
|
|
|
e_service = e_services.first
|
|
|
|
|
ecloud_services_auth(e_service.code, e_service.begintime, e_service.endtime)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
false # 没开通过服务,或者服务被禁用则不允许访问
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 根据业务确定权限
|
|
|
|
|
def ecloud_services_auth code, subject_id
|
|
|
|
|
subject = Subject.find(subject_id)
|
|
|
|
|
subject_level = subject.subject_level_system.try(:level)
|
|
|
|
|
# case code
|
|
|
|
|
# when "9200108001"
|
|
|
|
|
# subject_level.to_i == 1 ? true : false
|
|
|
|
|
# when "9200108002"
|
|
|
|
|
#
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
|
def ecloud_services_auth code, begintime, endtime
|
|
|
|
|
# 如果当前实训不在实训课堂等级体系中,则不允许访问
|
|
|
|
|
subject_id = @shixun.stage_shixuns.map(&:subject_id)
|
|
|
|
|
if subject_id.blank?
|
|
|
|
|
render_403
|
|
|
|
|
end
|
|
|
|
|
subject_level = Subject.find(subject_id).subject_level_system.try(:level)
|
|
|
|
|
# 当前时间转毫秒
|
|
|
|
|
current_time = DateTime.now.strftime('%Q').to_i
|
|
|
|
|
if current_time - begintime > 0 && endtime - current_time > 0
|
|
|
|
|
case code
|
|
|
|
|
when "9200108001"
|
|
|
|
|
subject_level.to_i == 1 ? true : false
|
|
|
|
|
when "9200108002"
|
|
|
|
|
subject_level.to_i == 2 ? true : false
|
|
|
|
|
when "9200108003"
|
|
|
|
|
subject_level.to_i == 3 ? true : false
|
|
|
|
|
when "9200109001" # 企业用户
|
|
|
|
|
subject_level.to_i < 3 ? true : false
|
|
|
|
|
when "9200109002" # 企业用户
|
|
|
|
|
subject_level.to_i <= 3 ? true : false
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|