From 03b67d1b4d4e9d8975d9309bea0bd18667a8ce8f Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 13 Mar 2019 20:28:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=A1=8C=E4=B8=BA=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/ecloud_controller.rb | 78 ++++++++++++------- app/models/ecloud_log.rb | 3 + .../20190313115011_create_ecloud_logs.rb | 13 ++++ db/migrate/20190313120249_change_clo.rb | 16 ++++ spec/factories/ecloud_logs.rb | 7 ++ spec/models/ecloud_log_spec.rb | 5 ++ 6 files changed, 93 insertions(+), 29 deletions(-) create mode 100644 app/models/ecloud_log.rb create mode 100644 db/migrate/20190313115011_create_ecloud_logs.rb create mode 100644 db/migrate/20190313120249_change_clo.rb create mode 100644 spec/factories/ecloud_logs.rb create mode 100644 spec/models/ecloud_log_spec.rb diff --git a/app/controllers/ecloud_controller.rb b/app/controllers/ecloud_controller.rb index 94470166..63c9ad27 100644 --- a/app/controllers/ecloud_controller.rb +++ b/app/controllers/ecloud_controller.rb @@ -18,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] @@ -45,44 +46,49 @@ 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'] - 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.try(:id)) - if service['serviceparas'].present? - service['serviceparas'].each do |servicepara| - EcloudServieceServicepara.create!(ecloud_service_id: es.id, key: servicepara['key'], value: servicepara['value']) + if params['opttype'] == 0 # 开通企业/个人业务 + ecloud = Ecloud.create!(eloud_params) + # 业务列表 + 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.try(: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 - end - # 应用开通参数 - productparas = params['productparas'] - if productparas.present? - productparas.each do |productpara| - EcloudProductpara.create!(key: productpara['key'], value: productpara['value'], ecloud_id: ecloud.try(:id)) + # 应用开通参数 + productparas = params['productparas'] + if productparas.present? + productparas.each do |productpara| + EcloudProductpara.create!(key: productpara['key'], value: productpara['value'], ecloud_id: ecloud.try(:id)) + end end - end - # 为管理员单独创建一条账号,企业账号 - 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']) + # 为管理员单独创建一条账号,企业账号 + 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']) + + elsif params['opttype'] == 1 # 变更企业/个人业务 + ecloud = Ecloud.where(custid: params['custid'], custcode: params['custcode']).first + ecloud.update_attributes!(eloud_params) + ecloud.ecloud_productparas.destroy + ecloud.ecloud_service.destroy + + end render :json => {result: true, errmsg: ""} rescue Exception => e @@ -93,11 +99,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']).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']) @@ -227,6 +233,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'] @@ -235,4 +251,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_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/db/migrate/20190313115011_create_ecloud_logs.rb b/db/migrate/20190313115011_create_ecloud_logs.rb new file mode 100644 index 00000000..c5a9f3a8 --- /dev/null +++ b/db/migrate/20190313115011_create_ecloud_logs.rb @@ -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 diff --git a/db/migrate/20190313120249_change_clo.rb b/db/migrate/20190313120249_change_clo.rb new file mode 100644 index 00000000..794aa56c --- /dev/null +++ b/db/migrate/20190313120249_change_clo.rb @@ -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 diff --git a/spec/factories/ecloud_logs.rb b/spec/factories/ecloud_logs.rb new file mode 100644 index 00000000..e442e25d --- /dev/null +++ b/spec/factories/ecloud_logs.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :ecloud_log do + url "MyString" +params "" + end + +end diff --git a/spec/models/ecloud_log_spec.rb b/spec/models/ecloud_log_spec.rb new file mode 100644 index 00000000..25126a65 --- /dev/null +++ b/spec/models/ecloud_log_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe EcloudLog, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end