Skip to content

Commit

Permalink
bank deposit user view and admin list
Browse files Browse the repository at this point in the history
  • Loading branch information
hpyhacking committed Mar 31, 2014
1 parent 2e6b99f commit d0921e5
Show file tree
Hide file tree
Showing 24 changed files with 170 additions and 27 deletions.
44 changes: 44 additions & 0 deletions app/controllers/admin/deposits_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Admin
class DepositsController < BaseController
def index
@admin_deposits_grid = Admin::DepositsGrid.new \
params[:admin_deposits_grid]
@assets = @admin_deposits_grid.assets.page(params[:page]).per(10)
end

def show
@deposit = Deposit.find(params[:id])
end

def update
@deposit = Deposit.find(params[:id])

ActiveRecord::Base.transaction do
if @deposit.update_attributes(destroy_params) \
&& @deposit.accept!
redirect_to admin_deposits_path, notice: t('.notice')
else
redirect_to admin_deposit_path(@deposit), alert: t('.alert')
end
end
end

def destroy
@deposit = Deposit.find(params[:id])

ActiveRecord::Base.transaction do
if @deposit.update_attributes(destroy_params) \
&& @deposit.reject!
redirect_to admin_deposits_path, notice: t('.notice')
else
redirect_to admin_deposit_path(@deposit), alert: t('.alert')
end
end
end

def destroy_params
params.require(:deposit).permit(:memo)
end
end
end

2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def auth_admin!
end

def is_admin?
current_user.admin?
current_user && current_user.admin?
end

private
Expand Down
12 changes: 2 additions & 10 deletions app/controllers/private/deposits/banks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,12 @@ def create
end
end

def show
def edit
@deposit = current_user.deposits.find(params[:id])
end

def update
@deposit = current_user.deposits.find(params[:id])
@deposit.submit!
redirect_to send(model_kls.new_path), notice: t('.success')
end

def destroy
def show
@deposit = current_user.deposits.find(params[:id])
@deposit.cancel!
redirect_to send(model_kls.new_path), notice: t('.success')
end

private
Expand Down
19 changes: 19 additions & 0 deletions app/controllers/private/deposits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,24 @@ class DepositsController < BaseController
def index
@depostis = DepositChannel.all
end

def update
@deposit = current_user.deposits.find(params[:id])
if @deposit.submit!
redirect_to :back, notice: t('.notice')
else
redirect_to :back, alert: t('.alert')
end
end

def destroy
@deposit = current_user.deposits.find(params[:id])
if @deposit.cancel!
redirect_to :back, notice: t('.notice')
else
1/0
redirect_to :back, alert: t('.alert')
end
end
end
end
22 changes: 22 additions & 0 deletions app/grids/admin/deposits_grid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Admin
class DepositsGrid
include Datagrid
include Datagrid::Naming
include Datagrid::ColumnI18n

scope do |m|
Deposit.order('id DESC')
end

column :sn
column_i18n :created_at
column :full_name
column :channel_key_text
column :fund_extra_text do |o|
o.try(:fund_extra_text) || o.try(:fund_extra)
end
column :fund_uid
column :currency_text
column :aasm_state_text
end
end
10 changes: 8 additions & 2 deletions app/grids/bank_deposits_grid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ class BankDepositsGrid
column(:fund_uid)
column(:amount)
column(:aasm_state_text, html: true) do |o|
view_link = if o.may_submit?
link_to(o.aasm_state_text, url_for([:edit, o]))
else
link_to(o.aasm_state_text, url_for(o))
end
if o.aasm_state.submitting?
link_to o.aasm_state_text, url_for(o)
view_link + content_tag(:span, ' / ') +
link_to(t('actions.cancel'), deposit_path(o), method: :delete)
else
o.aasm_state_text
view_link
end
end
end
9 changes: 6 additions & 3 deletions app/models/deposit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ class Deposit < ActiveRecord::Base
include AASM::Locking
include Currencible

STATE = [:submitting, :submitted, :rejected, :accepted, :checked, :warning]
STATE = [:submitting, :cancelled, :submitted, :rejected, :accepted, :checked, :warning]
enumerize :aasm_state, in: STATE, scope: true

alias_attribute :sn, :id

delegate :key_text, to: :channel, prefix: true
delegate :full_name, to: :member

belongs_to :member
belongs_to :account
Expand All @@ -18,8 +21,6 @@ class Deposit < ActiveRecord::Base
:member, :currency
validates_numericality_of :amount, greater_than: 0

attr_accessor :sn

aasm :whiny_transitions => false do
state :submitting, initial: true, before_enter: :set_fee
state :cancelled
Expand Down Expand Up @@ -78,6 +79,8 @@ def self.new_path
"new_#{params_name}_path"
end

delegate :new_path, to: self

private
def do
account.lock!.plus_funds amount, reason: Account::DEPOSIT, ref: self
Expand Down
2 changes: 0 additions & 2 deletions app/models/deposits/bank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class Bank < ::Deposit
delegate :receive_fund_holder_text, :receive_fund_uid_text, :receive_fund_extra_text, to: :channel
delegate :sn, to: :member, prefix: true

alias_attribute :sn, :id

enumerize :fund_extra, in: channel.banks, scope: true, \
i18n_scope: ["deposit_channel.#{name.demodulize.underscore}.banks", 'banks']

Expand Down
2 changes: 2 additions & 0 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Member < ActiveRecord::Base
before_create :create_accounts
after_commit :send_activation

alias_attribute :full_name, :name

class << self
def from_auth(auth_hash)
member = locate_auth(auth_hash) || locate_email(auth_hash) || create_from_auth(auth_hash)
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/deposits/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.row: .col-md-12
= datagrid_table(@admin_deposits_grid, @assets)
2 changes: 2 additions & 0 deletions app/views/layouts/admin.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
a href='#{admin_documents_path}' = t(".menus.items.operating.documents")
- if can? :manage, Withdraw
li.ops: a href='#{admin_withdraws_path}' = t('.menus.items.operating.withdraws')
- if can? :manage, Deposit
li.ops: a href='#{admin_deposits_path}' = t('.menus.items.operating.deposits')

li.nav-header = t('.menus.sections.sites_statistics')
- if can? :read, Statistic::MembersGrid
Expand Down
11 changes: 11 additions & 0 deletions app/views/private/deposits/banks/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
= simple_form_for @deposit, defaults: {readonly: true}, url: deposit_path(@deposit) do |f|
= f.input :fund_extra_text, as: :string
= f.input :fund_uid
= f.input :receive_fund_holder_text
= f.input :receive_fund_uid_text
= f.input :receive_fund_extra_text
= f.input :amount
= f.input :member_sn
hr.split
= f.button :wrapped do
= link_to t('actions.cancel'), @deposit, method: :delete, class: 'btn btn-info btn-lg pull-right'
5 changes: 2 additions & 3 deletions app/views/private/deposits/banks/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= simple_form_for @deposit, defaults: {readonly: true} do |f|
= simple_form_for @deposit, defaults: {readonly: true}, url: send(@deposit.class.new_path), method: :get do |f|
= f.input :fund_extra_text, as: :string
= f.input :fund_uid
= f.input :receive_fund_holder_text
Expand All @@ -7,5 +7,4 @@
= f.input :amount
= f.input :member_sn
hr.split
= f.button :wrapped do
= link_to t('simple_form.buttons.cancel'), @deposit, method: :delete, class: 'btn btn-info btn-lg pull-right'
= f.button :wrapped, t('actions.back')
12 changes: 12 additions & 0 deletions config/locales/datagrids/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ en:
range_separator: " to "
form:
submit: Search
admin_deposits_grid:
columns:
sn: SN
created_at: At
channel_key_text: Channel
fund_extra_text: Extra
fund_uid: UID
amount: Amount
fee: Fee
currency_text: Currency
aasm_state_text: State
full_name: Member
bank_deposits_grid:
columns:
sn: SN
Expand Down
12 changes: 12 additions & 0 deletions config/locales/datagrids/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ zh-CN:
range_separator: " ~ "
form:
submit: 查询
admin_deposits_grid:
columns:
sn: 订单号
created_at: 时间
channel_key_text: 通道
fund_extra_text: 资金来源
fund_uid: 资金账户
amount: 金额
fee: 手续费
currency_text: 币种
aasm_state_text: 状态
full_name: 会员
bank_deposits_grid:
columns:
sn: 订单号
Expand Down
2 changes: 1 addition & 1 deletion config/locales/deposits/banks/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ zh-CN:
deposit_channel:
bank:
key: 银行转账
title: 银行转账
title: 人民币银行转账充值
intro: 使用银行卡转账进行充值,推荐用户大额充值使用。
latency: 10 分钟到账
transfer: 人工处理
Expand Down
9 changes: 8 additions & 1 deletion config/locales/enumerize/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ en:
satoshi: Bitcoin
bank: Bank
aasm_state:
accepted: Accepted
submitted: 受理中
submitting: 待提交
accepted: 已到账
cancelled: 已撤销
rejected: 已驳回
accepted: 已到账
checked: 完成
warning: 异常
withdraw:
address_type:
satoshi: Bitcoin
Expand Down
9 changes: 7 additions & 2 deletions config/locales/enumerize/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ zh-CN:
satoshi: 比特币
bank: 银行转账
aasm_state:
submitted: 已提交
submitting: 待提交
submitted: 受理中
submitting: 待处理
accepted: 已到账
cancelled: 已撤销
rejected: 已驳回
accepted: 已到账
checked: 充值成功
warning: 异常
withdraw:
address_type:
satoshi: 比特币 - 网络转账
Expand Down
2 changes: 2 additions & 0 deletions config/locales/models/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ en:
statistic/members_grid: Members Stat
statistic/deposits_grid: Deposits Stat
statistic/withdraws_grid: Withdraws Stat
admin/deposits_grid: Deposits
admin/withdraws_grid: Withdraws
attributes:
id_document:
name: Full Name
Expand Down
2 changes: 2 additions & 0 deletions config/locales/models/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ zh-CN:
statistic/members_grid: 用户统计
statistic/deposits_grid: 充值统计
statistic/withdraws_grid: 提现统计
admin/deposits_grid: 充值管理
admin/withdraws_grid: 提现管理
attributes:
id_document:
name: 真实姓名
Expand Down
1 change: 1 addition & 0 deletions config/locales/views/layouts/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ en:
operating: Operations
items:
operating:
deposits: Deposits
documents: Documents
withdraws: Withdraws
deposits:
Expand Down
1 change: 1 addition & 0 deletions config/locales/views/layouts/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ zh-CN:
operating: 运营管理
items:
operating:
deposits: 充值管理
documents: 文档管理
withdraws: 提现管理
deposits:
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace :admin do
get '/', to: 'dashboard#index', as: :dashboard
resources :deposits
resources :withdraws
resources :documents
resource :currency_deposit, :only => [:new, :create]
Expand All @@ -52,7 +53,7 @@
resource :id_document, :only => [:new, :create]
resource :two_factor, :only => [:new, :create, :edit, :destroy]

resources :deposits, only: :index
resources :deposits, only: [:index, :destroy, :update]
namespace :deposits do
Deposit.descendants.each do |w|
resources w.resource_name
Expand Down
2 changes: 1 addition & 1 deletion lib/extras/simple_form_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def wrapped_button(*args, &block)

if cancel = options.delete(:cancel)
class_text = 'btn btn-info btn-lg pull-right'
cancel_text = I18n.t('simple_form.buttons.cancel')
cancel_text = options.delete(:cancel_text) || I18n.t('simple_form.buttons.cancel')

submit(*args) + template.link_to(cancel_text, cancel, class: class_text)
else
Expand Down

0 comments on commit d0921e5

Please sign in to comment.