diff --git a/app/controllers/ecloud_controller.rb b/app/controllers/ecloud_controller.rb index 9af476cf..216df8df 100644 --- a/app/controllers/ecloud_controller.rb +++ b/app/controllers/ecloud_controller.rb @@ -1,4 +1,16 @@ #encoding=utf-8 +# 云启训练场(EduCoder)个人版 产品编码(appId) 9200108 +# 产品名称 计费类型 套餐编码 +# 云启训练场(EduCoder)个人版 固定包月 9200108001 +# 固定包月 9200108002 +# 固定包月 9200108003 +# --------------------------------------------------- +# 产品名称 计费类型 套餐编码 +# 云启训练场(EduCoder))院校版 包月+按license 9200109001 +# 包月+按license 9200109002 + +# 云启训练场(EduCoder))院校版 产品编码(appId) 9200109 + require 'net/http' require 'digest' @@ -6,6 +18,7 @@ class EcloudController < ApplicationController skip_before_filter :verify_authenticity_token # before_filter :check_sign, only: [:ps_new, :ps_update, :bs_new, :bs_update] + before_filter :save_para before_filter :user_setup # before_filter :require_login, only: [:authorize] @@ -33,21 +46,64 @@ class EcloudController < ApplicationController end - # 企业开通 + # 企业/个人业务开通 # applyno 申请单号,唯一 # ecordercode 唯一标志一个企业的订购关系 + # params['opttype']:操作类型。0开通;1变更;2试用转商用;4再次开通 def bs_new ActiveRecord::Base.transaction do begin - ecloud = Ecloud.create!(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'], - trial: params['trial'], bossorderid: params['bossorderid'], custid: params['custid'], custtype: params['custtype'], - custcode: params['custcode'], registersource: params['registersource'], custname: params['custname'], - userid: params['userid'], username: params['username'], useralias: params['useralias'], mobile: params['mobile'], - email: params['email'], productcode: params['productcode'], begintime: params['begintime'], - endtime: params['endtime']) - services = params['services'].first - EcloudService.create(opttype: services['opttype'], code: services['code'], begintime: services['begintime'], - endtime: services['endtime'], ecloud_id: ecloud.try(:id)) + ecloud_id = 0 + if params['opttype'] == 0 # 开通企业/个人业务 + ecloud = Ecloud.create!(eloud_params) + ecloud_id = ecloud.try(:id) + elsif params['opttype'] == 2 # 试用转商用 # 变更企业/个人业务 + ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode']).first + ecloud.update_attributes!(eloud_params) + ecloud.ecloud_productparas.destroy + ecloud.ecloud_services.destroy + ecloud_id = ecloud.try(:id) + elsif params['opttype'] == 1 # 业务变更 + ecloud = Ecloud.where(bossorderid: params['bossorderid']).first + ecloud.update_attributes!(eloud_params) + ecloud.ecloud_productparas.destroy + ecloud.ecloud_services.destroy + + ecloud_id = ecloud.try(:id) + + elsif params['opttype'] == 4 # 再次重复开通 + REDO + ecloud = Ecloud.where(bossorderid: params['bossorderid']).first + end + + # 业务列表 + services = params['services'] + if services.present? + services.each do |service| + es = EcloudService.create(opttype: service['opttype'], code: service['code'], begintime: service['begintime'], + endtime: service['endtime'], ecloud_id: ecloud_id) + if service['serviceparas'].present? + service['serviceparas'].each do |servicepara| + EcloudServieceServicepara.create!(ecloud_service_id: es.id, key: servicepara['key'], value: servicepara['value']) + end + end + end + end + + # 应用开通参数 + productparas = params['productparas'] + if productparas.present? + productparas.each do |productpara| + EcloudProductpara.create!(key: productpara['key'], value: productpara['value'], ecloud_id: ecloud_id) + end + end + + # 非试用情况下,为管理员单独创建一条账号,企业账号 + unless params['trial'] + EcloudUser.create!(ecloud_id: ecloud.try(:id), opttype: params['opttype'], userid: params['userid'], + username: params['username'], useralias: params['useralias'], + mobile: params['mobile'], email: params['email']) + end render :json => {result: true, errmsg: ""} rescue Exception => e @@ -58,11 +114,11 @@ class EcloudController < ApplicationController end end - # 企业更新 + # 企业/个人业务变更、注销 def bs_update ActiveRecord::Base.transaction do begin - ecloud = Ecloud.where(applyno: params['applyno']).first + ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode']).first ecloud.update_attributes!(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'], custid: params['custid'], custcode: params['custcode'], productcode: params['productcode'], operatime: params['operatime'], effecttime: params['effecttime']) @@ -79,17 +135,16 @@ class EcloudController < ApplicationController end # 用户业务开通与变更接口 + # 授权statu为1,取消授权status为0 def ps_new begin - user_param = params['users'].first - # ecloud_user = EcloudUser.where(:custid => params['custid'], :userid => user_param['userid']).first - # if ecloud_user.present? - # render :json => {code: 500, msg: "你已开通过该业务"} - # else - EcloudUser.create!(custid: params['custid'], opttype: user_param['opttype'], userid: user_param['userid'], - username: user_param['username'], useralias: user_param['useralias'], - mobile: user_param['mobile'], email: user_param['email'], begintime: user_param['begintime'].to_s, - endtime: user_param['endtime'].to_s, status: 1) + user_params = params['users'] + user_params.each do |user_param| + EcloudUser.create!(custid: params['custid'], opttype: user_param['opttype'], userid: user_param['userid'], + username: user_param['username'], useralias: user_param['useralias'], + mobile: user_param['mobile'], email: user_param['email'], begintime: user_param['begintime'].to_s, + endtime: user_param['endtime'].to_s, status: 1) + end render :json => {success: true, errmsg: ""} # end rescue Exception => e @@ -99,13 +154,15 @@ class EcloudController < ApplicationController end # 用户业务状态变更 + # 授权statu为1,取消授权status为0 def ps_update begin - ecloud = Ecloud.where(applyno: params['applyno']).first - user_param = params['users'].first - ecloud_user = EcloudUser.where(userid: user_param['userid'], status: 1).first + user_params = params['users'] + user_params.each do |user_param| + ecloud_user = EcloudUser.where(userid: user_param['userid'], status: 1).first + ecloud_user.update_attributes(opttype: user_param['opttype'], userid: user_param['userid'], status: 0) + end - ecloud_user.update_attributes(opttype: user_param['opttype'], userid: user_param['userid'], status: 0) render :json => {success: true, errmsg: ""} # else # render :json => {code: 404, msg: "企业ID不存在"} @@ -156,28 +213,30 @@ class EcloudController < ApplicationController private def get(url) uri = URI(url) - res = Net::HTTP.start(uri.host, uri.port, use_ssl: url.start_with?('https')) do |http| - req = Net::HTTP::Get.new(uri) - #req['Content-Type'] = 'application/json' - # The body needs to be a JSON string, use whatever you know to parse Hash to JSON - #req.body = {a: 1}.to_json - http.request(req) - end - res.body + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = url.start_with?('https') + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + request = Net::HTTP::Get.new(uri.request_uri) + request['Content-Type'] = 'application/json' + request['Accept'] = 'application/json' + response = http.request(request) + + response.body end def post(url) uri = URI(url) - res = Net::HTTP.start(uri.host, uri.port, use_ssl: url.start_with?('https')) do |http| - req = Net::HTTP::Post.new(uri) - #req['Content-Type'] = 'application/json' - # The body needs to be a JSON string, use whatever you know to parse Hash to JSON - #req.body = {a: 1}.to_json - http.request(req) - end - res.body + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = url.start_with?('https') + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + request = Net::HTTP::Post.new(uri.request_uri) + request['Content-Type'] = 'application/json' + request['Accept'] = 'application/json' + response = http.request(request) + + response.body end def decode(s) @@ -189,6 +248,16 @@ class EcloudController < ApplicationController end private + def eloud_params + return {applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'], + trial: params['trial'], bossorderid: params['bossorderid'], custid: params['custid'], custtype: params['custtype'], + custcode: params['custcode'], registersource: params['registersource'], custname: params['custname'], + userid: params['userid'], username: params['username'], useralias: params['useralias'], mobile: params['mobile'], + email: params['email'], productcode: params['productcode'], begintime: params['begintime'], + endtime: params['endtime']} + end + + def check_sign sign = sign(params['timestamp']) if sign != params['sign'] @@ -197,4 +266,8 @@ class EcloudController < ApplicationController end end + def save_para + EcloudLog.create(url: request.url, para_value: params, applyno: params['applyno'], custid: params['custid'], custcode: params['custcode']) + end + end diff --git a/app/models/ecloud.rb b/app/models/ecloud.rb index fc23d00a..293948f3 100644 --- a/app/models/ecloud.rb +++ b/app/models/ecloud.rb @@ -1,7 +1,11 @@ +#encoding=utf-8 class Ecloud < ActiveRecord::Base attr_accessible :applyno, :begintime, :bossorderid, :custcode, :custid, :custname, :custtype, :ecordercode, :endtime, :mobile, :opttype, :productcode, :registersource, :string, :trial, :useralias, :userid, :username, :email, :effecttime, :operatime + + has_many :ecloud_services, :dependent => :destroy # 业务列表 + has_many :ecloud_productparas, :dependent => :destroy # 开通参数列表 + has_one :ecloud_user - has_one :ecloud_service end diff --git a/app/models/ecloud_log.rb b/app/models/ecloud_log.rb new file mode 100644 index 00000000..4e187aa5 --- /dev/null +++ b/app/models/ecloud_log.rb @@ -0,0 +1,3 @@ +class EcloudLog < ActiveRecord::Base + attr_accessible :para_value, :url, :applyno, :custid, :custcode +end diff --git a/app/models/ecloud_productpara.rb b/app/models/ecloud_productpara.rb new file mode 100644 index 00000000..ec1b94bc --- /dev/null +++ b/app/models/ecloud_productpara.rb @@ -0,0 +1,4 @@ +class EcloudProductpara < ActiveRecord::Base + attr_accessible :key, :value, :ecloud_id + belongs_to :ecloud +end diff --git a/app/models/ecloud_service.rb b/app/models/ecloud_service.rb index 596ad684..4a388ed4 100644 --- a/app/models/ecloud_service.rb +++ b/app/models/ecloud_service.rb @@ -1,3 +1,5 @@ class EcloudService < ActiveRecord::Base attr_accessible :begintime, :code, :endtime, :opttype, :ecloud_id, :packagecode, :bossorderid + belongs_to :ecloud + has_many :ecloud_serviece_serviceparas end diff --git a/app/models/ecloud_serviece_servicepara.rb b/app/models/ecloud_serviece_servicepara.rb new file mode 100644 index 00000000..91bb0a0d --- /dev/null +++ b/app/models/ecloud_serviece_servicepara.rb @@ -0,0 +1,4 @@ +class EcloudServieceServicepara < ActiveRecord::Base + attr_accessible :key, :value, :ecloud_service_id + belongs_to :ecloud_service +end diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index f9a52452..f7a6dbc4 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -51,23 +51,12 @@ - -
精选实训
-SELECTED TRAINING
-实训课程
-TRAINING PATH
+TRAINING COURSE
开发社区
+DEVELOPMENT COMMUNITY
+