完成试用转商用接口调试

dev_shixuns
huang 6 years ago
parent 4c58e97d94
commit 8b62caf8a6

@ -50,6 +50,7 @@ class EcloudController < ApplicationController
# applyno 申请单号,唯一 # applyno 申请单号,唯一
# ecordercode 唯一标志一个企业的订购关系 # ecordercode 唯一标志一个企业的订购关系
# params['opttype']操作类型。0开通1变更2试用转商用4再次开通 # params['opttype']操作类型。0开通1变更2试用转商用4再次开通
# 业务列表opttype: 0新增1注销2修改
def bs_new def bs_new
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
@ -58,11 +59,23 @@ class EcloudController < ApplicationController
ecloud = Ecloud.create!(eloud_params) ecloud = Ecloud.create!(eloud_params)
ecloud_id = ecloud.try(:id) ecloud_id = ecloud.try(:id)
elsif params['opttype'] == 2 # 试用转商用 # 变更企业/个人业务 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.where(productcode: params['productcode'], trial: true).first
ecloud.ecloud_services.destroy
ecloud_id = ecloud.try(:id)
# 注销试用的套餐
## 需要注销的套餐; 试用转商用是不会有批量操作的所以可以使用first
des_service = params['services'].select{|s| s['opttype'] == 1}.first
esd = EcloudService.where(ecloud_id: ecloud.try(:id), code: des_service['code']).first
ecloud.update_attribute(:trial, false)
esd.update_attributes!(opttype: des_service['opttype'], begintime: des_service['begintime'], endtime: des_service['endtime'])
# 试用转商用是不会有批量操作的
# 新增业务
add_servide = params['services'].select{|s| s['opttype'] == 0}.first
create_service(add_servide, ecloud_id)
elsif params['opttype'] == 1 # 业务变更 elsif params['opttype'] == 1 # 业务变更
ecloud = Ecloud.where(bossorderid: params['bossorderid']).first ecloud = Ecloud.where(bossorderid: params['bossorderid']).first
ecloud.update_attributes!(eloud_params) ecloud.update_attributes!(eloud_params)
@ -76,34 +89,34 @@ class EcloudController < ApplicationController
ecloud = Ecloud.where(bossorderid: params['bossorderid']).first ecloud = Ecloud.where(bossorderid: params['bossorderid']).first
end end
# 业务列表 # # 业务列表
services = params['services'] # services = params['services']
if services.present? # if services.present?
services.each do |service| # services.each do |service|
es = EcloudService.create(opttype: service['opttype'], code: service['code'], begintime: service['begintime'], # es = EcloudService.create(opttype: service['opttype'], code: service['code'], begintime: service['begintime'],
endtime: service['endtime'], ecloud_id: ecloud_id) # endtime: service['endtime'], ecloud_id: ecloud_id)
if service['serviceparas'].present? # if service['serviceparas'].present?
service['serviceparas'].each do |servicepara| # service['serviceparas'].each do |servicepara|
EcloudServieceServicepara.create!(ecloud_service_id: es.id, key: servicepara['key'], value: servicepara['value']) # EcloudServieceServicepara.create!(ecloud_service_id: es.id, key: servicepara['key'], value: servicepara['value'])
end # end
end # end
end # end
end # end
# 应用开通参数 # # 应用开通参数
productparas = params['productparas'] # productparas = params['productparas']
if productparas.present? # if productparas.present?
productparas.each do |productpara| # productparas.each do |productpara|
EcloudProductpara.create!(key: productpara['key'], value: productpara['value'], ecloud_id: ecloud_id) # EcloudProductpara.create!(key: productpara['key'], value: productpara['value'], ecloud_id: ecloud_id)
end # end
end # end
#
# 非试用情况下,为管理员单独创建一条账号,企业账号 # # 非试用情况下,为管理员单独创建一条账号,企业账号
unless params['trial'] # unless params['trial']
EcloudUser.create!(ecloud_id: ecloud.try(:id), opttype: params['opttype'], userid: params['userid'], # EcloudUser.create!(ecloud_id: ecloud.try(:id), opttype: params['opttype'], userid: params['userid'],
username: params['username'], useralias: params['useralias'], # username: params['username'], useralias: params['useralias'],
mobile: params['mobile'], email: params['email']) # mobile: params['mobile'], email: params['email'])
end # end
render :json => {result: true, errmsg: ""} render :json => {result: true, errmsg: ""}
rescue Exception => e rescue Exception => e
@ -257,6 +270,11 @@ class EcloudController < ApplicationController
endtime: params['endtime']} endtime: params['endtime']}
end end
# 新增套餐
def create_service service, ecloud_id
EcloudService.create(opttype: service['opttype'], code: service['code'], begintime: service['begintime'],
endtime: service['endtime'], ecloud_id: ecloud_id)
end
def check_sign def check_sign
sign = sign(params['timestamp']) sign = sign(params['timestamp'])

Loading…
Cancel
Save