Skip to content
Browse files

add free plan, #406.

  • Loading branch information...
1 parent 2ce7812 commit 49a64415c7faba119f49932f72b36c84d18458cf @saberma saberma committed Feb 21, 2012
View
2 app/models/consumption.rb
@@ -17,7 +17,7 @@ def pay!
self.status = true
self.save
base = shop.deadline.future? ? shop.deadline : Date.today
- shop.deadline = base.advance(months: self.quantity)
+ shop.deadline = base.advance(years: self.quantity)
shop.plan = self.plan_type.code
shop.save
end
View
18 app/models/key_values.rb
@@ -178,21 +178,15 @@ class Service < KeyValues::Base # 支付接口
module Plan
class Type < KeyValues::Base
- UNLIMIT_SKU = 65535
- UNLIMIT_STORAGE = 65535
self.data = [
- {id: 1 ,name:'旗舰版' , code: 'unlimited' , skus: UNLIMIT_SKU , storage: UNLIMIT_STORAGE, price: 2998},
- {id: 2 ,name:'企业版' , code: 'business' , skus: 10000 , storage: 1000 , price: 898 },
- {id: 3 ,name:'专业版' , code: 'professional', skus: 2500 , storage: 500 , price: 498 },
- {id: 4 ,name:'基础版' , code: 'basic' , skus: 100 , storage: 100 , price: 298 },
+ {id: 1 ,name:'旗舰版' , code: 'unlimited' , skus: 1000 , storage: 1000, price: 9988 },
+ {id: 2 ,name:'企业版' , code: 'business' , skus: 500 , storage: 500 , price: 5988 },
+ {id: 3 ,name:'专业版' , code: 'professional' , skus: 100 , storage: 100 , price: 2988 },
+ {id: 4 ,name:'免费版' , code: 'free' , skus: 50 , storage: 50 , price: 0 }
]
- def skus_name
- skus == UNLIMIT_SKU ? '不限' : skus
- end
-
- def storage_name
- storage == UNLIMIT_STORAGE ? '不限' : storage
+ def free?
+ self.code == 'free'
end
end
end
View
8 app/models/shop.rb
@@ -76,8 +76,8 @@ def plan_type
KeyValues::Plan::Type.find_by_code(self.plan)
end
- def plan_unlimited?
- self.plan == 'unlimited'
+ def plan_free?
+ self.plan == 'free'
end
def storage # 已占用的容量(如要支持windows可修改为循环获取目录大小)
@@ -87,7 +87,7 @@ def storage # 已占用的容量(如要支持windows可修改为循环获取目
end
def available?
- !self.deadline.past?
+ self.deadline.nil? or !self.deadline.past?
end
def storage_idle? # 存在剩余空间
@@ -165,7 +165,7 @@ def storage_cache_key
protected
def init_valid_date
- self.deadline = Date.today.advance months: 1
+ self.deadline = Date.today.advance months: 1 unless self.plan_free?
end
def init_currency
View
37 app/views/admin/account/_about.html.haml
@@ -2,31 +2,30 @@
%tr
%td.r 您的商店URL地址:
%td=link_to show_shop_url,show_shop_url
- - unless shop.plan_unlimited?
+ %tr
+ %td.r SKUs使用量:
+ %td
+ %div{:style => "width:140px"}
+ .progress-container{:style => "margin-top:7px"}
+ .progress-bar{:style => "width: #{skus_size*100/current_plan_type.skus}%; "}
+ %span.note{:style => ""}==剩余#{current_plan_type.skus - skus_size}
+ %tr#disk-management
+ %td.r 剩余使用空间:
+ %td(title="数值会被缓存5分钟")
+ %div(style="width:170px")
+ .progress-container(style="margin-top:7px")
+ .progress-bar(style="width: #{storages_size*100/current_plan_type.storage}%; ")
+ %span.note==剩余#{current_plan_type.storage - storages_size} MB
+ -#
%tr
- %td.r SKUs使用量:
+ %td &nbsp;
%td
- %div{:style => "width:140px"}
- .progress-container{:style => "margin-top:7px"}
- .progress-bar{:style => "width: #{skus_size*100/current_plan_type.skus}%; "}
- %span.note{:style => ""}==剩余#{current_plan_type.skus - skus_size}
- %tr#disk-management
- %td.r 剩余使用空间:
- %td(title="数值会被缓存5分钟")
- %div(style="width:170px")
- .progress-container(style="margin-top:7px")
- .progress-bar(style="width: #{storages_size*100/current_plan_type.storage}%; ")
- %span.note==剩余#{current_plan_type.storage - storages_size} MB
- -#
- %tr
- %td &nbsp;
- %td
- %a.icon.uploaded-files{:href => "/admin/files"} 显示上传的文件
+ %a.icon.uploaded-files{:href => "/admin/files"} 显示上传的文件
%tr
%td.r 商店注册时间
%td=I18n.l shop.created_at,format: :serial
%td.r 账户截止时间:
- %td=I18n.l shop.deadline, format: :long
+ %td=shop.plan_free? ? '不限' : I18n.l(shop.deadline, format: :long)
%tr
%td.r 账户状态:
%td{:colspan => "3"}=shop.available? ? '已生效' : '禁止访问'
View
14 app/views/admin/account/_plans.html.haml
@@ -2,12 +2,12 @@
%table.data2{:cellspacing => "0"}
%tr
%th 方案
- %th{:style => "text-align: center"} 费用(元/)
+ %th{:style => "text-align: center"} 费用(元/)
%th{:style => "text-align: center"} 最多商品款式数量
%th{:style => "text-align: center"} 存储空间(M)
-#%th{:style => "text-align: center"} 商品打折促销
- %th{:style => "text-align: center"} SSL
%th{:style => "text-align: center"} 绑定域名
+ %th{:style => "text-align: center"} SSL
%th{:style => "text-align: center"} 统计
-plan_types.each do |plan_type|
-flag = shop.plan == plan_type.code
@@ -20,12 +20,12 @@
%br/
-if flag
=raw(high_color('当前帐户已过期')) unless shop.available?
- =link_to '续费', pay_plan_account_index_path
+ =link_to '续费', pay_plan_account_index_path unless plan_type.free?
-else
- =link_to w('upgrade'), change_plan_account_index_path(code: plan_type.code)
+ =link_to w('upgrade'), change_plan_account_index_path(code: plan_type.code) unless plan_type.free?
%td=plan_type.price
- %td=plan_type.skus_name
- %td=plan_type.storage_name
- %td=image_tag 'admin/icons/check2.gif'
+ %td=plan_type.skus
+ %td=plan_type.storage
+ %td=image_tag 'admin/icons/check2.gif' unless plan_type.free?
%td=image_tag 'admin/icons/check2.gif'
%td=image_tag 'admin/icons/check2.gif'
View
8 app/views/admin/account/change_plan.html.haml
@@ -7,13 +7,13 @@
%p.sb
%strong 请您确认你想要升级您的ShopQi账户:
%p.sb
- ==您将升级您的账户到 #{raw high_color plan_type.name} 方案,此方案单价为#{raw high_color plan_type.price}元/
+ ==您将升级您的账户到 #{raw high_color plan_type.name} 方案,此方案单价为#{raw high_color plan_type.price}元/
%p.sb
- 默认支付为12个月,您可以选择支付
+ 默认支付为1年,您可以选择支付
%p.sb
- =f.select :quantity, options_for_select((1..24).map{|c|[c,c]}, 12)
+ =f.select :quantity, options_for_select((1..5).map{|c|[c,c]}, 1)
=hidden_field_tag :code, params[:code]
- 个月
+
%p.sb
方案将在您支付成功后生效!点确认则进入确认付款页面!
.actions
View
4 app/views/admin/account/confirm_pay_plan.html.haml
@@ -3,8 +3,8 @@
.status
%p 确认账户方案续费
.ppb
- %p.sb==您当前使用的是 #{raw high_color shop.plan_type.name} 方案,此方案单价为#{raw high_color shop.plan_type.price}元/
- %p.sb==您将支付 #{raw high_color @consumption.quantity} 个月,总价为 #{raw high_color @consumption.total_price}
+ %p.sb==您当前使用的是 #{raw high_color shop.plan_type.name} 方案,此方案单价为#{raw high_color shop.plan_type.price}元/
+ %p.sb==您将支付 #{raw high_color @consumption.quantity} ,总价为 #{raw high_color @consumption.total_price}
%p.sb 目前,暂支持 #{raw high_color '支付宝'} 方式支付
- payment_service_for @consumption.token, AlipayConfig['account'], :service => :alipay, :html => { :id => 'payment-form', :method => :get } do |service|
- service.total_fee @consumption.total_price
View
4 app/views/admin/account/confirm_plan.html.haml
@@ -6,9 +6,9 @@
%p.sb
%strong 请您确认你想要升级您的ShopQi账户:
%p.sb
- ==您将升级您的账户到 #{raw high_color plan_type.name} 方案,此方案单价为#{raw high_color plan_type.price}元/
+ ==您将升级您的账户到 #{raw high_color plan_type.name} 方案,此方案单价为#{raw high_color plan_type.price}元/
%p.sb
- ==您将支付 #{raw high_color @consumption.quantity} 个月,总价为 #{raw high_color @consumption.total_price}
+ ==您将支付 #{raw high_color @consumption.quantity} ,总价为 #{raw high_color @consumption.total_price}
%p.sb 方案将在您支付成功后生效!暂支持 #{raw high_color '支付宝'} 方式支付
- payment_service_for @consumption.token, AlipayConfig['account'], :service => :alipay, :html => { :id => 'payment-form', :method => :get } do |service|
- service.total_fee @consumption.total_price
View
8 app/views/admin/account/pay_plan.html.haml
@@ -4,11 +4,11 @@
%p 账户方案续费
=form_for :consumption, url: confirm_pay_plan_account_index_path do |f|
.ppb
- %p.sb==您当前使用的是 #{raw high_color shop.plan_type.name} 方案,此方案单价为#{raw high_color shop.plan_type.price}元/
- %p.sb 默认支付为12个月,您可以选择支付
+ %p.sb==您当前使用的是 #{raw high_color shop.plan_type.name} 方案,此方案单价为#{raw high_color shop.plan_type.price}元/
+ %p.sb 默认支付为1年,您可以选择支付
%p.sb
- =f.select :quantity, options_for_select((1..24).map{|c|[c,c]}, 12)
- 个月
+ =f.select :quantity, options_for_select((1..5).map{|c|[c,c]}, 1)
+
%p.sb 点击确认按钮,将进入确认付款页面。
.actions
=f.submit '确认',class: 'btn'
View
78 app/views/admin/domains/_index.html.haml
@@ -0,0 +1,78 @@
+.section
+ %h3 域名管理
+ %p.note
+ 这些是您的商店当前使用的域名.
+ = succeed "." do
+ =link_to '了解如何在ShopQi设置您的域名', "#{wiki_url_with_port}/DNS"
+ %table#domains.standard-table.domainlisting(cellpadding="0" cellspacing="0")
+ %thead
+ %tr
+ %th(scope="col") 域名
+ %th(scope="col") 备案号
+ %th.c(scope="col" style="text-align: center" width="100px") DNS绑定至商店
+ %th(colspan="2" scope="col" width="140px") &nbsp;
+ %tbody.items
+ %tbody
+ %tr#add-domain-link
+ %td.action-link(colspan="5")
+ %a(href="#")
+ %span.plus +
+ 新增一个您已经拥有的域名
+ #add-domain.group(style="display:none;")
+ #errorExplanation.errorExplanation(style="display:none;")
+ %h2 保存时发生1个错误
+ %ul
+ %li 域名 不能为空
+ %form(action="/admin/domains" method="post")
+ .group-fields
+ .instructions
+ %p
+ %strong 请在下方输入您的域名
+ %p
+ http://
+ %input#domain_host(name="domain[host]" size="32" type="text")
+ .instructions
+ %p
+ %strong 请输入域名备案号(备案号无效的话,此域名将无法被访问)
+ %p
+ %input#domain_record(name="domain[record]" size="32" type="text")
+ / instructions
+ / .group-fields
+ .group-actions
+ %input.btn(name="commit" type="submit" value="绑定此域名")
+ 或者
+ %a.cancel(href="#") 取消
+ / .group-actions
+ / .group
+-#=render 'buy'
+
+%script(id="domain-item" type="text/x-handlebars-template")
+ %td(class="{{#if primary}}primary{{/if}}")
+ %span.note http://
+ %span
+ %a.host(href="http://{{{host}}}") {{{host}}}
+ %td.record {{{record}}}
+ %td.c
+ %span.dns-check=image_tag 'spinner.gif'
+ %td(style="text-align: left; padding: 10px")
+ {{#if primary}}
+ %p(style="margin: 0 0 7px")
+ %strong 主域名
+ %p#force-domain(style="margin: 0")
+ %small
+ {{#if force_domain}}
+ %input#shop_force_domain(name="shop[force_domain]" type="checkbox" value="1" checked="checked")
+ {{else}}
+ %input#shop_force_domain(name="shop[force_domain]" type="checkbox" value="1")
+ {{/if}}
+ %label(for="shop_force_domain" style="font-weight: normal") 总是重定向顾客到这里?
+ {{else}}
+ %small
+ %a.btn(href="#") 作为主域名
+ {{/if}}
+ %td.deletions
+ {{#unless is_myshopqi}}
+ %a.del(href='#')=image_tag 'admin/icons/trash.gif', alt: '删除'
+ {{/unless}}
+%script(id="dns-wiki-item" type="text/x-handlebars-template")
+ %a(href="#{wiki_url_with_port}/DNS#CNAME_Status" target="_blank") 失败
View
85 app/views/admin/domains/index.html.haml
@@ -4,84 +4,13 @@
#action-links
%ul
.pgroup.st.domain-page(style="margin-bottom: 5px")
- .section
- %h3 域名管理
- %p.note
- 这些是您的商店当前使用的域名.
- = succeed "." do
- =link_to '了解如何在ShopQi设置您的域名', "#{wiki_url_with_port}/DNS"
- %table#domains.standard-table.domainlisting(cellpadding="0" cellspacing="0")
- %thead
- %tr
- %th(scope="col") 域名
- %th(scope="col") 备案号
- %th.c(scope="col" style="text-align: center" width="100px") DNS绑定至商店
- %th(colspan="2" scope="col" width="140px") &nbsp;
- %tbody.items
- %tbody
- %tr#add-domain-link
- %td.action-link(colspan="5")
- %a(href="#")
- %span.plus +
- 新增一个您已经拥有的域名
- #add-domain.group(style="display:none;")
- #errorExplanation.errorExplanation(style="display:none;")
- %h2 保存时发生1个错误
- %ul
- %li 域名 不能为空
- %form(action="/admin/domains" method="post")
- .group-fields
- .instructions
- %p
- %strong 请在下方输入您的域名
- %p
- http://
- %input#domain_host(name="domain[host]" size="32" type="text")
- .instructions
- %p
- %strong 请输入域名备案号(备案号无效的话,此域名将无法被访问)
- %p
- %input#domain_record(name="domain[record]" size="32" type="text")
- / instructions
- / .group-fields
- .group-actions
- %input.btn(name="commit" type="submit" value="绑定此域名")
- 或者
- %a.cancel(href="#") 取消
- / .group-actions
- / .group
--#=render 'buy'
-
-%script(id="domain-item" type="text/x-handlebars-template")
- %td(class="{{#if primary}}primary{{/if}}")
- %span.note http://
- %span
- %a.host(href="http://{{{host}}}") {{{host}}}
- %td.record {{{record}}}
- %td.c
- %span.dns-check=image_tag 'spinner.gif'
- %td(style="text-align: left; padding: 10px")
- {{#if primary}}
- %p(style="margin: 0 0 7px")
- %strong 主域名
- %p#force-domain(style="margin: 0")
- %small
- {{#if force_domain}}
- %input#shop_force_domain(name="shop[force_domain]" type="checkbox" value="1" checked="checked")
- {{else}}
- %input#shop_force_domain(name="shop[force_domain]" type="checkbox" value="1")
- {{/if}}
- %label(for="shop_force_domain" style="font-weight: normal") 总是重定向顾客到这里?
- {{else}}
- %small
- %a.btn(href="#") 作为主域名
- {{/if}}
- %td.deletions
- {{#unless is_myshopqi}}
- %a.del(href='#')=image_tag 'admin/icons/trash.gif', alt: '删除'
- {{/unless}}
-%script(id="dns-wiki-item" type="text/x-handlebars-template")
- %a(href="#{wiki_url_with_port}/DNS#CNAME_Status" target="_blank") 失败
+ -if shop.plan_free?
+ %p
+ 免费版无法绑定顶级域名,使用此功能前请先
+ =link_to '升级版本', account_index_path
+ 。
+ -else
+ =render "index"
:javascript
App.domains = new App.Collections.Domains(#{shop_domains_json});
View
24 db/migrate/20120219015553_change_basic_plan_to_free.rb
@@ -0,0 +1,24 @@
+class ChangeBasicPlanToFree < ActiveRecord::Migration
+
+ def up # 406
+ Shop.all.each do |shop|
+ shop.update_attributes! plan: 'free', deadline: nil if shop.plan == 'basic'
+ if shop.plan = 'basic'
+ shop.plan = 'free'
+ shop.deadline = nil
+ shop.save
+ end
+ end
+ end
+
+ def down
+ Shop.all.each do |shop|
+ if shop.plan = 'free'
+ shop.plan = 'basic'
+ shop.deadline = 1.month.since
+ shop.save
+ end
+ end
+ end
+
+end
View
2 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120206135658) do
+ActiveRecord::Schema.define(:version => 20120219015553) do
create_table "active_admin_comments", :force => true do |t|
t.integer "resource_id", :null => false
View
10 spec/controllers/admin/account_controller_spec.rb
@@ -60,7 +60,7 @@
context '#notify' do # 支付宝从后台发送通过
- let(:consumption) { Factory(:consumption, shop: shop) }
+ let(:consumption) { Factory(:consumption, shop: shop) } # 支付两年
before do
controller.stub!(:valid?) { true } # 向支付宝校验notification的合法性
@@ -82,7 +82,7 @@
post :notify, attrs.merge(sign_type: 'md5', sign: sign(attrs, AlipayConfig['key']))
response.body.should eql 'success'
consumption.reload.status.should be_true
- shop.reload.deadline.should eql Date.today.advance(months: 3) # 三个月后到期
+ shop.reload.deadline.should eql Date.today.advance(years: 2, months: 1) # 两年一个月后到期
end
end
@@ -99,7 +99,7 @@
post :notify, attrs.merge(sign_type: 'md5', sign: sign(attrs, AlipayConfig['key']))
response.body.should eql 'success'
consumption.reload.status.should be_true
- shop.reload.deadline.should eql Date.today.advance(months: 2) # 二个月后到期
+ shop.reload.deadline.should eql Date.today.advance(years: 2) # 二年后到期
end
end
@@ -153,7 +153,7 @@
get :done, attrs.merge(sign_type: 'md5', sign: sign(attrs, AlipayConfig['key']))
response.should be_redirect
consumption.reload.status.should be_true
- shop.reload.deadline.should eql Date.today.advance(months: 3) # 三个月后到期
+ shop.reload.deadline.should eql Date.today.advance(years: 2, months: 1) # 兩年一个月后到期
end
end
@@ -169,7 +169,7 @@
get :done, attrs.merge(sign_type: 'md5', sign: sign(attrs, AlipayConfig['key']))
response.should be_redirect
consumption.reload.status.should be_true
- shop.reload.deadline.should eql Date.today.advance(months: 2) # 二个月后到期
+ shop.reload.deadline.should eql Date.today.advance(years: 2) # 二年后到期
end
end
View
28 spec/controllers/admin/domains_controller_spec.rb
@@ -1,5 +1,33 @@
+#encoding: utf-8
require 'spec_helper'
describe Admin::DomainsController do
+ let(:user) { Factory(:user) }
+
+ let(:shop) { user.shop }
+
+ before :each do
+ request.host = "#{shop.primary_domain.host}"
+ sign_in(user)
+ end
+
+ context 'shop use free plan' do # 免费
+
+ render_views
+
+ before do
+ shop.plan = 'free'
+ shop.deadline = nil
+ shop.save
+ end
+
+ it 'should not use domain' do # 无法绑定域名
+ get :index
+ response.body.should include '免费版无法绑定顶级域名'
+ response.body.should_not include '域名管理'
+ end
+
+ end
+
end
View
2 spec/factories/consumptions.rb
@@ -3,7 +3,7 @@
FactoryGirl.define do
factory :consumption do
- plan_type_id KeyValues::Plan::Type.where(name: '基础版').first.id
+ plan_type_id KeyValues::Plan::Type.where(name: '专业版').first.id
quantity 2
end
end
View
17 spec/models/shop_spec.rb
@@ -43,6 +43,23 @@
shop.storage_idle?.should be_true
end
+ context 'paid' do # 收费版本
+
+ it 'should init deadline' do # 有截止时间
+ shop.deadline.should_not be_nil
+ end
+
+ end
+
+
+ context 'free' do # 免费版本
+
+ it 'should not init deadline' do # 没有截止时间
+ shop.deadline.should be_nil
+ end
+
+ end
+
end
end
View
2 spec/models/user_spec.rb
@@ -16,7 +16,7 @@
address: "311",
zip_code: "518057",
phone: "13928458888",
- plan: "basic"
+ plan: "professional"
},
name: "马海波",
email: "mahb45@gmail.com",
View
4 spec/requests/shopqi/registrations_spec.rb
@@ -19,7 +19,7 @@
before(:each) do
theme_dark
theme_slate
- visit '/services/signup/new/basic'
+ visit '/services/signup/new/professional'
end
describe "signup" do
@@ -54,7 +54,7 @@
local_ip.each do |ip|
Rails.cache.write("registered_#{ip}", true, expires_in: 24.hours) # 避免重复注册
end
- visit '/services/signup/new/basic'
+ visit '/services/signup/new/professional'
end
after(:each) do

0 comments on commit 49a6441

Please sign in to comment.
Something went wrong with that request. Please try again.