From 2e0c9faf47a4acaf59ac331dd2447bdc4bf24d71 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 14 Mar 2019 10:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=B8=9A=E5=8A=A1=E6=96=B0?= =?UTF-8?q?=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ecloud_controller.rb | 28 ++++++++++++------- app/models/ecloud_service.rb | 2 +- ...21743_add_productcode_to_ucloud_service.rb | 5 ++++ 3 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20190314021743_add_productcode_to_ucloud_service.rb diff --git a/app/controllers/ecloud_controller.rb b/app/controllers/ecloud_controller.rb index 572d1817..2e8266cd 100644 --- a/app/controllers/ecloud_controller.rb +++ b/app/controllers/ecloud_controller.rb @@ -57,13 +57,12 @@ class EcloudController < ApplicationController ecloud_id = 0 if params['opttype'] == 0 # 开通企业/个人业务 ecloud = Ecloud.create!(eloud_params) - ecloud_id = ecloud.try(:id) + create_service(params['services'], ecloud_id, params['productcode']) elsif params['opttype'] == 2 # 试用转商用 # 变更企业/个人业务 # 业务列表:注销业务(注销试用的套餐),另一个业务项的操作代码是:新增业务(开通商用的套餐) # 需要通过产品服务编号和业务编码来区分哪个产品 ecloud = Ecloud.where(productcode: params['productcode'], trial: true).first - # 注销试用的套餐 ## 需要注销的套餐; 试用转商用是不会有批量操作的,所以可以使用first des_service = params['services'].select{|s| s['opttype'] == 1}.first @@ -77,12 +76,19 @@ class EcloudController < ApplicationController create_service(add_servide, ecloud_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 + # 套餐变更 + params['services'].each do |service| + + end - ecloud_id = ecloud.try(:id) + + + # 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 @@ -271,9 +277,11 @@ class EcloudController < ApplicationController 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) + def create_service services, ecloud_id, productcode + services.each do |service| + EcloudService.create!(opttype: service['opttype'], code: service['code'], begintime: service['begintime'], + endtime: service['endtime'], ecloud_id: ecloud_id, productcode: productcode) + end end def check_sign diff --git a/app/models/ecloud_service.rb b/app/models/ecloud_service.rb index 4a388ed4..018e170d 100644 --- a/app/models/ecloud_service.rb +++ b/app/models/ecloud_service.rb @@ -1,5 +1,5 @@ class EcloudService < ActiveRecord::Base - attr_accessible :begintime, :code, :endtime, :opttype, :ecloud_id, :packagecode, :bossorderid + attr_accessible :begintime, :code, :endtime, :opttype, :ecloud_id, :packagecode, :bossorderid, :productcode belongs_to :ecloud has_many :ecloud_serviece_serviceparas end diff --git a/db/migrate/20190314021743_add_productcode_to_ucloud_service.rb b/db/migrate/20190314021743_add_productcode_to_ucloud_service.rb new file mode 100644 index 00000000..a0ae6188 --- /dev/null +++ b/db/migrate/20190314021743_add_productcode_to_ucloud_service.rb @@ -0,0 +1,5 @@ +class AddProductcodeToUcloudService < ActiveRecord::Migration + def change + add_column :ecloud_services, :productcode, :string + end +end