Skip to content

Commit

Permalink
show customer order statistics.
Browse files Browse the repository at this point in the history
  • Loading branch information
saberma committed Jun 27, 2011
1 parent 4314034 commit 8c9a57d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 14 deletions.
3 changes: 2 additions & 1 deletion app/coffeescripts/admin_application.coffee
Expand Up @@ -14,7 +14,8 @@ App =
Customer:
Index:
Filter: {}
Show: {}
Show:
Order: {}
CustomerGroup:
Index: {}
Product:
Expand Down
1 change: 1 addition & 0 deletions app/coffeescripts/views/customers/show/index.coffee
Expand Up @@ -6,3 +6,4 @@ App.Views.Customer.Show.Index = Backbone.View.extend

render: ->
new App.Views.Customer.Show.Show model: @model
new App.Views.Customer.Show.Order.Index model: @model
13 changes: 13 additions & 0 deletions app/coffeescripts/views/customers/show/orders/index.coffee
@@ -0,0 +1,13 @@
App.Views.Customer.Show.Order.Index = Backbone.View.extend
el: '#show-customer-screen'

initialize: ->
self = this
@collection = new App.Collections.Orders @model.get('orders')
this.render()

render: ->
self = this
template = Handlebars.compile $('#customer-facts-item').html()
$('#customer-facts').html template @model.attributes
@collection.each (model) -> new App.Views.Customer.Show.Order.Show model: model
21 changes: 21 additions & 0 deletions app/coffeescripts/views/customers/show/orders/show.coffee
@@ -0,0 +1,21 @@
App.Views.Customer.Index.Filter.Show = Backbone.View.extend
className: 'filter-tag'

events:
"click .close-filter-tag": 'destroy' # 删除主过滤器

initialize: ->
self = this
_.bindAll this, 'render'
this.render()

# 删除过滤器
destroy: ->
@model.collection.remove @model
this.remove()
false

render: ->
template = Handlebars.compile $('#customer-search_filters-item').html()
$(@el).html template @model.attributes
$('#customer-search_filters').append @el
5 changes: 3 additions & 2 deletions app/controllers/customers_controller.rb
Expand Up @@ -58,9 +58,10 @@ class CustomersController < ApplicationController
expose(:customer_json) do
customer.to_json({
include: {
addresses: { methods: [:province_name, :city_name, :district_name] }
addresses: { methods: [:province_name, :city_name, :district_name] },
orders: {}
},
methods: [ :address, :status_name ],
methods: [ :address, :order, :status_name ],
except: [ :created_at, :updated_at ]
})
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/customer.rb
Expand Up @@ -14,6 +14,11 @@ def address
json['customer_address']
end

# 首次下单
def order
self.orders.where(status: [:paid, :pending, :authorized]).first.as_json['order']
end

def status_name
KeyValues::Customer::State.find_by_code(status).name
end
Expand Down
23 changes: 12 additions & 11 deletions app/views/customers/show.html.haml
@@ -1,5 +1,5 @@
=content_for :javascripts do
=javascript_include_tag 'models/customer', 'views/customers/show/index', 'views/customers/show/show'
=javascript_include_tag 'models/customer', 'models/order', 'collections/orders', 'views/customers/show/index', 'views/customers/show/show', 'models/order', 'views/customers/show/orders/index', 'views/customers/show/orders/show'

%h2#title
#action-links
Expand All @@ -22,16 +22,6 @@
.customer.col-8.last
#show-customer-screen
#customer-facts.box2(style="margin-top:20px;")
%ul
%li.first
%p.big ¥95.00
%span 消费金额
%li
%p.big 2
%span 订单数
%li.last
%p.big Jun 05
%span 首次下单
#orders
%table#order-table.ssb.data(cellpadding="0" cellspacing="0")
%tr
Expand Down Expand Up @@ -154,6 +144,17 @@
or
%a.close-lightbox(href="#") Cancel

%script(id="customer-facts-item" type="text/x-jquery-tmpl")
%ul
%li.first
%p.big {{{total_spent}}}
%span 消费金额
%li
%p.big {{{orders_count}}}
%span 订单数
%li.last
%p.big Jun 05
%span 首次下单
%script(id="customer-summary-item" type="text/x-jquery-tmpl")
%tbody
%tr.first
Expand Down

0 comments on commit 8c9a57d

Please sign in to comment.