From d9f1838fae4841bc74c40bd621a6b298f2af0aa6 Mon Sep 17 00:00:00 2001 From: Pan Xiong Date: Sun, 7 Jan 2024 00:05:56 +1100 Subject: [PATCH] update new platforms transactions page --- app/helpers/application_helper.rb | 6 ++- ...erate_origin_transactions_snapshots_job.rb | 2 +- app/jobs/get_gate_spot_trades_job.rb | 4 +- app/models/origin_transaction.rb | 4 +- app/models/user_spot_balance.rb | 2 +- .../origin_transactions/_new_list.html.erb | 39 +++++++++++++++++++ .../new_platforms.html.erb | 4 +- .../origin_transactions/new_platforms.js.erb | 2 +- 8 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 app/views/origin_transactions/_new_list.html.erb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5af1091..6205d07 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -128,7 +128,7 @@ def transactions_table_headers }, { name: "币种投入/总投入", - sort: "none" + sort: "cost_ratio" }, { name: "预计收益 / 实际收益", @@ -538,8 +538,10 @@ def get_list_url(source_type, params) def get_origin_list_url(source_type, params) if source_type == :public origin_transactions_path(params) - else + elsif source_type == :users users_origin_transactions_path(params) + else + new_platforms_origin_transactions_path(params) end end diff --git a/app/jobs/generate_origin_transactions_snapshots_job.rb b/app/jobs/generate_origin_transactions_snapshots_job.rb index 7b4430a..93251fc 100644 --- a/app/jobs/generate_origin_transactions_snapshots_job.rb +++ b/app/jobs/generate_origin_transactions_snapshots_job.rb @@ -18,7 +18,7 @@ def perform(date: Date.today) def generate_snapshot(transactions_snapshot_info) # 查找符合条件的原始交易记录 - origin_transactions = OriginTransaction.where(trade_type: 'buy', user_id: nil) + origin_transactions = OriginTransaction.year_to_date.where(trade_type: 'buy', user_id: nil) # 批量处理原始交易记录 origin_transactions.find_each(batch_size: 100) do |origin_transaction| diff --git a/app/jobs/get_gate_spot_trades_job.rb b/app/jobs/get_gate_spot_trades_job.rb index 132c5cb..28d36cf 100644 --- a/app/jobs/get_gate_spot_trades_job.rb +++ b/app/jobs/get_gate_spot_trades_job.rb @@ -91,8 +91,8 @@ def get_revenue(trade_type, amount, cost, qty, current_price) def get_spot_cost(user_id, origin_symbol, date) cost = SpotBalanceSnapshotRecord.joins(:spot_balance_snapshot_info) - .find_by(spot_balance_snapshot_info: {user_id: user_id, event_date: date}, origin_symbol: origin_symbol, source: SOURCE)&.price.to_f - cost = UserSpotBalance.find_by(user_id: user_id, origin_symbol: origin_symbol, source: SOURCE)&.price.to_f if cost.zero? && date == Date.today + .find_by(spot_balance_snapshot_info: {user_id: user_id, event_date: date}, origin_symbol: origin_symbol, source: SOURCE)&.price + cost = UserSpotBalance.find_by(user_id: user_id, origin_symbol: origin_symbol, source: SOURCE)&.price if cost.nil? && date == Date.today cost end end diff --git a/app/models/origin_transaction.rb b/app/models/origin_transaction.rb index de2c54a..393ce08 100644 --- a/app/models/origin_transaction.rb +++ b/app/models/origin_transaction.rb @@ -3,11 +3,11 @@ class OriginTransaction < ApplicationRecord FILTER_SYMBOL = %w(USDC).freeze def self.available - OriginTransaction.where.not(source: ['gate', 'bitget']).where('from_symbol NOT IN (?) and ((from_symbol IN (?) AND amount >= 50) OR from_symbol NOT IN (?))', FILTER_SYMBOL, SKIP_SYMBOLS, SKIP_SYMBOLS) + OriginTransaction.where('from_symbol NOT IN (?) and ((from_symbol IN (?) AND amount >= 50) OR from_symbol NOT IN (?))', FILTER_SYMBOL, SKIP_SYMBOLS, SKIP_SYMBOLS) end def self.year_to_date - OriginTransaction.where('event_time >= ?', DateTime.parse('2023-01-01')) + OriginTransaction.where.not(source: ['gate', 'bitget']).where('event_time >= ?', DateTime.parse('2023-01-01')) end def self.total_summary(user_id=nil) diff --git a/app/models/user_spot_balance.rb b/app/models/user_spot_balance.rb index 6ea9058..6727d84 100644 --- a/app/models/user_spot_balance.rb +++ b/app/models/user_spot_balance.rb @@ -5,7 +5,7 @@ class UserSpotBalance < ApplicationRecord scope :available, -> { where("qty > 0") } - enum source: [:binance, :okx, :huobi] + enum source: [:binance, :okx, :huobi, :gate] def current_price OriginTransaction.find_by(original_symbol: origin_symbol, source: source)&.current_price diff --git a/app/views/origin_transactions/_new_list.html.erb b/app/views/origin_transactions/_new_list.html.erb new file mode 100644 index 0000000..0621711 --- /dev/null +++ b/app/views/origin_transactions/_new_list.html.erb @@ -0,0 +1,39 @@ + + + + <% transactions_table_headers.each do |h| %> + <% next if h[:sort].in?(['cost_ratio', 'revenue_ratio']) %> + + <% end %> + + + + + <% @txs.each do |h| %> + + + + + + + + + + + + + + <% end %> + +
+ <% if h[:sort] == "none" %> + <%= "#{h[:name]}" %> + <% else %> + <% url = get_origin_list_url(source_type, ch_remote_params(params, h[:sort])) %> + <%= link_to "#{h[:name]}", url, remote: true, class: "#{params[:sort] == h[:sort] ? 'text-primary' : ''}" %> + <% end %> +
<%= h.event_time.strftime('%Y-%m-%d %H:%M:%S') rescue '' %><%= h.from_symbol %> / <%= h.to_symbol %><%= h.trade_type == 'buy' ? '买入' : '卖出' %><%= h.price.round(4) %> <%= h.to_symbol %><%= h.cost.round(4) %> <%= h.to_symbol %><%= h.current_price.round(4) %> <%= h.to_symbol %><%= h.qty.round(4) %><%= h.amount.round(4) %> <%= h.to_symbol %><%= display_spot_tx_revenue(h.revenue, h.to_symbol, h.trade_type) %><%= display_spot_tx_roi(h.roi, h.trade_type) %><%= h.source %>
+ +
+ <%= paginate @txs %> +
\ No newline at end of file diff --git a/app/views/origin_transactions/new_platforms.html.erb b/app/views/origin_transactions/new_platforms.html.erb index f14acbc..ccebfd7 100644 --- a/app/views/origin_transactions/new_platforms.html.erb +++ b/app/views/origin_transactions/new_platforms.html.erb @@ -5,8 +5,6 @@
<%= select_tag(:search, options_for_select(@total_txs.pluck(:original_symbol).uniq, @symbol), { prompt: '请选择币种...', class: 'select2-dropdown form-control' }) %> - <%= select_tag(:campaign, options_for_select(@total_txs.pluck(:campaign).compact.uniq, @campaign),{ prompt: '请选择campaign...', class: 'select2-dropdown form-control' }) %> - <%= select_tag(:trade_type, options_for_select([['买入', 'buy'], ['卖出', 'sell']], @trade_type),{ prompt: '请选择交易类别...', class: 'select2-dropdown form-control' }) %> <%= select_tag(:source, options_for_select(@total_txs.pluck(:source).compact.uniq, @source),{ prompt: '请选择来源...', class: 'select2-dropdown form-control' }) %> @@ -19,7 +17,7 @@ <% end %>
- <%= render partial: "list", locals: { source_type: :public } %> + <%= render partial: "new_list", locals: { source_type: :new_platform } %>
diff --git a/app/views/origin_transactions/new_platforms.js.erb b/app/views/origin_transactions/new_platforms.js.erb index 6a9c95b..300ced9 100644 --- a/app/views/origin_transactions/new_platforms.js.erb +++ b/app/views/origin_transactions/new_platforms.js.erb @@ -1,2 +1,2 @@ -$("#trading-histories-container").html("<%= j render partial: "list", locals: { source_type: :public } %>"); +$("#trading-histories-container").html("<%= j render partial: "new_list", locals: { source_type: :new_platform } %>"); $('[data-bs-toggle="tooltip"]').tooltip(); \ No newline at end of file