diff --git a/app/controllers/ecloud_controller.rb b/app/controllers/ecloud_controller.rb index bd0170f9..8e120b9b 100644 --- a/app/controllers/ecloud_controller.rb +++ b/app/controllers/ecloud_controller.rb @@ -5,6 +5,7 @@ require 'digest' class EcloudController < ApplicationController skip_before_filter :verify_authenticity_token + before_filter check_sign before_filter :user_setup before_filter :require_login, only: [:authorize] @@ -35,31 +36,44 @@ class EcloudController < ApplicationController # 企业开通 # ecordercode 唯一标志一个企业的订购关系 def bs_new - begin - ecloud = Ecloud.create!(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'], - trial: params['trial'], bossorderid: params['bossorderid'], custid: params['custid'], - 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']) - EcloudService.create(opttype: params['services']['opttype'], code: params['services']['code'], begintime: params['services']['begintime'], - endtime: params['services']['endtime'], ecloud_id: ecloud.try(:id)) - - render :json => {result: true, errmsg: ""} - rescue Exception => e - logger.error(e.message) - render :json => {code: 500, msg: "#{e.message}"} + 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'].first + EcloudService.create(opttype: services['opttype'], code: services['code'], begintime: services['begintime'], + endtime: services['endtime'], ecloud_id: ecloud.try(:id)) + + render :json => {result: true, errmsg: ""} + rescue Exception => e + logger.error(e.message) + render :json => {code: 500, msg: "#{e.message}"} + raise ActiveRecord::Rollback + end end end # 企业更新 def bs_update - ecloud = Ecloud.where(custid: params['custid']).first - ecloud.update_attribute(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'], - custid: params['custid'], custcode: params['custcode'], productcode: params['productcode'], - operatime: params['operatime'], effecttime: params['effecttime']) - ecloud.ecloud_services.update_attributes(packagecode: params['services']['packagecode'], bossorderid: params['services']['bossorderid']) - + ActiveRecord::Base.transaction do + begin + ecloud = Ecloud.where(custid: params['custid']).first + ecloud.update_attribute(applyno: params['applyno'], ecordercode: params['ecordercode'], opttype: params['opttype'], + custid: params['custid'], custcode: params['custcode'], productcode: params['productcode'], + operatime: params['operatime'], effecttime: params['effecttime']) + services = params['ervices'].first + ecloud.ecloud_services.update_attributes(packagecode: services['packagecode'], bossorderid: services['bossorderid']) + + rescue Exception => e + logger.error(e.message) + render :json => {code: 500, msg: "#{e.message}"} + raise ActiveRecord::Rollback + end + end end # 用户业务开通接口 @@ -168,7 +182,10 @@ class EcloudController < ApplicationController end private - def ecloudeuser_params - {} + def check_sign + public_key = '1022' + secret_key = '2112037a-6d7a-432b-9081-feb1153d8668' + timestamp = params['timestamp'] + end end diff --git a/app/controllers/oauth_controller.rb b/app/controllers/oauth_controller.rb index bcc12856..54f15c43 100644 --- a/app/controllers/oauth_controller.rb +++ b/app/controllers/oauth_controller.rb @@ -1,6 +1,6 @@ #encoding: utf-8 class OauthController < ApplicationController - + require include ApplicationHelper before_filter :user_setup diff --git a/app/models/ecloud_service.rb b/app/models/ecloud_service.rb index cc227eb1..596ad684 100644 --- a/app/models/ecloud_service.rb +++ b/app/models/ecloud_service.rb @@ -1,3 +1,3 @@ class EcloudService < ActiveRecord::Base - attr_accessible :begintime, :code, :endtime, :opttype + attr_accessible :begintime, :code, :endtime, :opttype, :ecloud_id, :packagecode, :bossorderid end