|
|
|
@ -51,36 +51,57 @@ class EcloudController < ApplicationController
|
|
|
|
|
# ecordercode 唯一标志一个企业的订购关系
|
|
|
|
|
# params['opttype']:操作类型。0开通;1变更;2试用转商用;4再次开通
|
|
|
|
|
# 业务列表opttype: 0新增;1注销;2修改
|
|
|
|
|
# serviceparas: 但是由于企业版是按成员收费的,所以serviceparas里面会传成员数;个人版是包月计费的,serviceparas不会传成员数
|
|
|
|
|
def bs_new
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
ecloud_id = 0
|
|
|
|
|
if params['opttype'] == 0 # 开通企业/个人业务
|
|
|
|
|
ecloud = Ecloud.create!(eloud_params)
|
|
|
|
|
create_service(params['services'], ecloud_id, params['productcode'])
|
|
|
|
|
create_service(params['services'], ecloud.try(:id))
|
|
|
|
|
create_product_params(params['productparas'], ecloud.try(:id)) if params['productparas'].present?
|
|
|
|
|
# REDO为管理员添加一条记录
|
|
|
|
|
elsif params['opttype'] == 2 # 试用转商用 # 变更企业/个人业务
|
|
|
|
|
# 业务列表:注销业务(注销试用的套餐),另一个业务项的操作代码是:新增业务(开通商用的套餐)
|
|
|
|
|
# 需要通过产品服务编号和业务编码来区分哪个产品
|
|
|
|
|
ecloud = Ecloud.where(productcode: params['productcode'], trial: true).first
|
|
|
|
|
ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode'], productcode: params['productcode'], trial: true).first
|
|
|
|
|
|
|
|
|
|
# 注销试用的套餐
|
|
|
|
|
## 需要注销的套餐; 试用转商用是不会有批量操作的,所以可以使用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 = EcloudService.where(ecloud_id: ecloud.try(:id), code: des_service['code'], productcode: params['productcode']).first
|
|
|
|
|
ecloud.update_attribute(:trial, params['trial'])
|
|
|
|
|
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)
|
|
|
|
|
add_service = params['services'].select{|s| s['opttype'] == 0}
|
|
|
|
|
create_service(add_service, ecloud.try(:id))
|
|
|
|
|
|
|
|
|
|
elsif params['opttype'] == 1 # 业务变更
|
|
|
|
|
ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode'], productcode: params['productcode']).first
|
|
|
|
|
# 套餐变更
|
|
|
|
|
params['services'].each do |service|
|
|
|
|
|
|
|
|
|
|
# 新增业务
|
|
|
|
|
add_service = params['services'].select{|s| s['opttype'] == 0}
|
|
|
|
|
create_service(add_service, ecloud.try(:id)) if add_service.present?
|
|
|
|
|
|
|
|
|
|
# 如果有注销业务,注销业务
|
|
|
|
|
des_services = params['services'].select{|s| s['opttype'] == 1}
|
|
|
|
|
if des_services.present?
|
|
|
|
|
des_services.each do |ds|
|
|
|
|
|
esd = EcloudService.where(ecloud_id: ecloud.try(:id), code: ds['code']).first
|
|
|
|
|
esd.update_attributes!(opttype: ds['opttype'], begintime: ds['begintime'], endtime: ds['endtime'])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 变更业务
|
|
|
|
|
edt_services = params['services'].select{|s| s['opttype'] == 2}
|
|
|
|
|
if edt_services.present?
|
|
|
|
|
edt_services.each do |es|
|
|
|
|
|
ese = EcloudService.where(ecloud_id: ecloud.try(:id), code: es['code']).first
|
|
|
|
|
ese.update_attributes!(opttype: es['opttype'], begintime: es['begintime'], endtime: es['endtime'])
|
|
|
|
|
create_serviceparas es['serviceparas'].first, ese.id
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ecloud = Ecloud.where(bossorderid: params['bossorderid']).first
|
|
|
|
@ -91,8 +112,9 @@ class EcloudController < ApplicationController
|
|
|
|
|
# ecloud_id = ecloud.try(:id)
|
|
|
|
|
|
|
|
|
|
elsif params['opttype'] == 4 # 再次重复开通
|
|
|
|
|
REDO
|
|
|
|
|
ecloud = Ecloud.where(bossorderid: params['bossorderid']).first
|
|
|
|
|
ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode'], productcode: params['productcode']).first
|
|
|
|
|
create_service(params['services'], ecloud.try(:id))
|
|
|
|
|
create_product_params(params['productparas'], ecloud.try(:id)) if params['productparas'].present?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# # 业务列表
|
|
|
|
@ -277,10 +299,25 @@ class EcloudController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 新增套餐
|
|
|
|
|
def create_service services, ecloud_id, productcode
|
|
|
|
|
def create_service services, ecloud_id
|
|
|
|
|
services.each do |service|
|
|
|
|
|
EcloudService.create!(opttype: service['opttype'], code: service['code'], begintime: service['begintime'],
|
|
|
|
|
endtime: service['endtime'], ecloud_id: ecloud_id, productcode: productcode)
|
|
|
|
|
ese = EcloudService.create!(opttype: service['opttype'], code: service['code'], begintime: service['begintime'],
|
|
|
|
|
endtime: service['endtime'], ecloud_id: ecloud_id)
|
|
|
|
|
if service['serviceparas'].present?
|
|
|
|
|
create_serviceparas(service['serviceparas'].first, ese.id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_serviceparas params_serviceparas, ese_id
|
|
|
|
|
if params_serviceparas.present?
|
|
|
|
|
EcloudServieceServicepara.create(key: params_serviceparas['key'], value: params_serviceparas['value'], ecloud_service_id: ese_id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_product_params params, ecloud_id
|
|
|
|
|
params.each do |p|
|
|
|
|
|
EcloudProductpara.create(key: p['key'], value: p['value'], ecloud_id: ecloud_id)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|