dev_haigong
cxt 6 years ago
commit 08accb32db

@ -1,4 +1,16 @@
#encoding=utf-8 #encoding=utf-8
# 云启训练场EduCoder个人版 产品编码appId 9200108
# 产品名称 计费类型 套餐编码
# 云启训练场EduCoder个人版 固定包月 9200108001
# 固定包月 9200108002
# 固定包月 9200108003
# ---------------------------------------------------
# 产品名称 计费类型 套餐编码
# 云启训练场EduCoder院校版 包月+按license 9200109001
# 包月+按license 9200109002
# 云启训练场EduCoder院校版 产品编码appId 9200109
require 'net/http' require 'net/http'
require 'digest' require 'digest'
@ -6,6 +18,7 @@ class EcloudController < ApplicationController
skip_before_filter :verify_authenticity_token skip_before_filter :verify_authenticity_token
# before_filter :check_sign, only: [:ps_new, :ps_update, :bs_new, :bs_update] # before_filter :check_sign, only: [:ps_new, :ps_update, :bs_new, :bs_update]
before_filter :save_para
before_filter :user_setup before_filter :user_setup
# before_filter :require_login, only: [:authorize] # before_filter :require_login, only: [:authorize]
@ -33,21 +46,64 @@ class EcloudController < ApplicationController
end end
# 企业开通 # 企业/个人业务开通
# applyno 申请单号,唯一 # applyno 申请单号,唯一
# ecordercode 唯一标志一个企业的订购关系 # ecordercode 唯一标志一个企业的订购关系
# params['opttype']操作类型。0开通1变更2试用转商用4再次开通
def bs_new def bs_new
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
ecloud = Ecloud.create!(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'], ecloud_id = 0
trial: params['trial'], bossorderid: params['bossorderid'], custid: params['custid'], custtype: params['custtype'], if params['opttype'] == 0 # 开通企业/个人业务
custcode: params['custcode'], registersource: params['registersource'], custname: params['custname'], ecloud = Ecloud.create!(eloud_params)
userid: params['userid'], username: params['username'], useralias: params['useralias'], mobile: params['mobile'], ecloud_id = ecloud.try(:id)
email: params['email'], productcode: params['productcode'], begintime: params['begintime'], elsif params['opttype'] == 2 # 试用转商用 # 变更企业/个人业务
endtime: params['endtime']) ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode']).first
services = params['services'].first ecloud.update_attributes!(eloud_params)
EcloudService.create(opttype: services['opttype'], code: services['code'], begintime: services['begintime'], ecloud.ecloud_productparas.destroy
endtime: services['endtime'], ecloud_id: ecloud.try(:id)) 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: ""} render :json => {result: true, errmsg: ""}
rescue Exception => e rescue Exception => e
@ -58,11 +114,11 @@ class EcloudController < ApplicationController
end end
end end
# 企业更新 # 企业/个人业务变更、注销
def bs_update def bs_update
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin 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'], ecloud.update_attributes!(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'],
custid: params['custid'], custcode: params['custcode'], productcode: params['productcode'], custid: params['custid'], custcode: params['custcode'], productcode: params['productcode'],
operatime: params['operatime'], effecttime: params['effecttime']) operatime: params['operatime'], effecttime: params['effecttime'])
@ -79,17 +135,16 @@ class EcloudController < ApplicationController
end end
# 用户业务开通与变更接口 # 用户业务开通与变更接口
# 授权statu为1取消授权status为0
def ps_new def ps_new
begin begin
user_param = params['users'].first user_params = params['users']
# ecloud_user = EcloudUser.where(:custid => params['custid'], :userid => user_param['userid']).first user_params.each do |user_param|
# if ecloud_user.present?
# render :json => {code: 500, msg: "你已开通过该业务"}
# else
EcloudUser.create!(custid: params['custid'], opttype: user_param['opttype'], userid: user_param['userid'], EcloudUser.create!(custid: params['custid'], opttype: user_param['opttype'], userid: user_param['userid'],
username: user_param['username'], useralias: user_param['useralias'], username: user_param['username'], useralias: user_param['useralias'],
mobile: user_param['mobile'], email: user_param['email'], begintime: user_param['begintime'].to_s, mobile: user_param['mobile'], email: user_param['email'], begintime: user_param['begintime'].to_s,
endtime: user_param['endtime'].to_s, status: 1) endtime: user_param['endtime'].to_s, status: 1)
end
render :json => {success: true, errmsg: ""} render :json => {success: true, errmsg: ""}
# end # end
rescue Exception => e rescue Exception => e
@ -99,13 +154,15 @@ class EcloudController < ApplicationController
end end
# 用户业务状态变更 # 用户业务状态变更
# 授权statu为1取消授权status为0
def ps_update def ps_update
begin begin
ecloud = Ecloud.where(applyno: params['applyno']).first user_params = params['users']
user_param = params['users'].first user_params.each do |user_param|
ecloud_user = EcloudUser.where(userid: user_param['userid'], status: 1).first 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) ecloud_user.update_attributes(opttype: user_param['opttype'], userid: user_param['userid'], status: 0)
end
render :json => {success: true, errmsg: ""} render :json => {success: true, errmsg: ""}
# else # else
# render :json => {code: 404, msg: "企业ID不存在"} # render :json => {code: 404, msg: "企业ID不存在"}
@ -156,28 +213,30 @@ class EcloudController < ApplicationController
private private
def get(url) def get(url)
uri = URI(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 end
def post(url) def post(url)
uri = URI(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 end
def decode(s) def decode(s)
@ -189,6 +248,16 @@ class EcloudController < ApplicationController
end end
private 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 def check_sign
sign = sign(params['timestamp']) sign = sign(params['timestamp'])
if sign != params['sign'] if sign != params['sign']
@ -197,4 +266,8 @@ class EcloudController < ApplicationController
end end
end end
def save_para
EcloudLog.create(url: request.url, para_value: params, applyno: params['applyno'], custid: params['custid'], custcode: params['custcode'])
end
end end

@ -1,7 +1,11 @@
#encoding=utf-8
class Ecloud < ActiveRecord::Base class Ecloud < ActiveRecord::Base
attr_accessible :applyno, :begintime, :bossorderid, :custcode, :custid, :custname, :custtype, :ecordercode, :endtime, attr_accessible :applyno, :begintime, :bossorderid, :custcode, :custid, :custname, :custtype, :ecordercode, :endtime,
:mobile, :opttype, :productcode, :registersource, :string, :trial, :useralias, :userid, :username, :email, :mobile, :opttype, :productcode, :registersource, :string, :trial, :useralias, :userid, :username, :email,
:effecttime, :operatime :effecttime, :operatime
has_many :ecloud_services, :dependent => :destroy # 业务列表
has_many :ecloud_productparas, :dependent => :destroy # 开通参数列表
has_one :ecloud_user has_one :ecloud_user
has_one :ecloud_service
end end

@ -0,0 +1,3 @@
class EcloudLog < ActiveRecord::Base
attr_accessible :para_value, :url, :applyno, :custid, :custcode
end

@ -0,0 +1,4 @@
class EcloudProductpara < ActiveRecord::Base
attr_accessible :key, :value, :ecloud_id
belongs_to :ecloud
end

@ -1,3 +1,5 @@
class EcloudService < ActiveRecord::Base class EcloudService < ActiveRecord::Base
attr_accessible :begintime, :code, :endtime, :opttype, :ecloud_id, :packagecode, :bossorderid attr_accessible :begintime, :code, :endtime, :opttype, :ecloud_id, :packagecode, :bossorderid
belongs_to :ecloud
has_many :ecloud_serviece_serviceparas
end end

@ -0,0 +1,4 @@
class EcloudServieceServicepara < ActiveRecord::Base
attr_accessible :key, :value, :ecloud_service_id
belongs_to :ecloud_service
end

@ -51,23 +51,12 @@
</div> </div>
</div> </div>
</div> </div>
<!--精选实训-->
<div class="clearfix pt20 educontent pr pb20">
<div class="edu-txt-center">
<p class="color-dark edu-txt-center font-24" style="line-height: 30px">精选实训</p>
<p class="color-grey-cd font-12">SELECTED TRAINING</p>
</div>
<a href="<%= shixuns_path %>" class="moreitem">更多<i class="fa fa-angle-right ml5"></i></a>
<div class="square-list clearfix">
<%= render :partial => "shixuns/shixun_item", :locals => {:shixuns => @shixuns} %>
</div>
</div>
<!--实训路径--> <!--实训路径-->
<div class="clearfix pt20 educontent pr pb20 mb60"> <div class="clearfix pt20 educontent pr pb20 mb60">
<div class="edu-txt-center"> <div class="edu-txt-center">
<p class="color-dark edu-txt-center font-24" style="line-height: 30px">实训课程</p> <p class="color-dark edu-txt-center font-24" style="line-height: 30px">实训课程</p>
<p class="color-grey-cd font-12">TRAINING PATH</p> <p class="color-grey-cd font-12">TRAINING COURSE</p>
</div> </div>
<a href="<%= subjects_path() %>" class="moreitem">更多<i class="fa fa-angle-right ml5"></i></a> <a href="<%= subjects_path() %>" class="moreitem">更多<i class="fa fa-angle-right ml5"></i></a>
<div class="square-list clearfix"> <div class="square-list clearfix">
@ -77,6 +66,20 @@
<!--<a href="https://www.educoder.net/paths/4" target="_blank"><img src="/images/educoder/guagngao.png" width="100%"/></a>--> <!--<a href="https://www.educoder.net/paths/4" target="_blank"><img src="/images/educoder/guagngao.png" width="100%"/></a>-->
</div> </div>
<!--精选实训 改为 开发社区-->
<div class="clearfix pt20 educontent pr pb20">
<div class="edu-txt-center">
<p class="color-dark edu-txt-center font-24" style="line-height: 30px">开发社区</p>
<p class="color-grey-cd font-12">DEVELOPMENT COMMUNITY</p>
</div>
<a href="<%= shixuns_path %>" class="moreitem">更多<i class="fa fa-angle-right ml5"></i></a>
<div class="square-list clearfix">
<%= render :partial => "shixuns/shixun_item", :locals => {:shixuns => @shixuns} %>
</div>
</div>
<!--导师排行榜--> <!--导师排行榜-->
<div class="pt60 pb60 mb30 mentor-ranking"> <div class="pt60 pb60 mb30 mentor-ranking">
<div class="educontent"> <div class="educontent">

@ -0,0 +1,11 @@
class CreateEcloudProductpara < ActiveRecord::Migration
def change
create_table :ecloud_productparas do |t|
t.string :key
t.string :value
t.integer :ecloud_id
t.timestamps
end
end
end

@ -0,0 +1,11 @@
class CreateEcloudServieceServicepara < ActiveRecord::Migration
def change
create_table :ecloud_serviece_serviceparas do |t|
t.string :key
t.string :value
t.integer :ecloud_service_id
t.timestamps
end
end
end

@ -0,0 +1,13 @@
class CreateEcloudLogs < ActiveRecord::Migration
def change
create_table :ecloud_logs do |t|
t.string :url
t.string :applyno
t.integer :custid
t.string :custcode
t.string :para_value
t.timestamps
end
end
end

@ -0,0 +1,16 @@
class ChangeClo < ActiveRecord::Migration
def up
change_column :eclouds, :begintime, :bigint, :limit => 20
change_column :eclouds, :endtime, :bigint, :limit => 20
change_column :eclouds, :operatime, :bigint, :limit => 20
change_column :eclouds, :effecttime, :bigint, :limit => 20
change_column :ecloud_services, :endtime, :bigint, :limit => 20
change_column :ecloud_services, :begintime, :bigint, :limit => 20
change_column :ecloud_users, :begintime, :bigint, :limit => 20
change_column :ecloud_users, :endtime, :bigint, :limit => 20
change_column :ecloud_logs, :para_value, :longtext
end
def down
end
end

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :ecloud_log do
url "MyString"
params ""
end
end

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :ecloud_productpara, :class => 'EcloudProductparas' do
key "MyString"
value "MyString"
end
end

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :ecloud_serviece_servicepara, :class => 'EcloudServieceServicepara' do
key "MyString"
value "MyString"
end
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe EcloudLog, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe EcloudProductparas, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe EcloudServieceServicepara, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save