abiao преди 5 години
родител
ревизия
4552f09f4a

+ 56 - 0
app/models/cent_award.rb

@@ -0,0 +1,56 @@
+# encoding: utf-8
+class CentAward < ActiveRecord::Base
+  self.table_name = "cent_awards"
+  validates :c_type,:count,presence: true
+
+  TYPE_ENUM = [
+                 ["第一天", "one_day"],
+                 ["第二天", "two_day"],
+                 ["第三天", "three_day"],
+                 ["第四天", "four_day"],
+                 ["第五天", "five_day"],
+                 ["第六天", "six_day"],
+                 ["第七天", "seven_day"],
+                 ["首次登录", "first_login"],
+                 ["新人注册", "new_man"],
+  ]
+  rails_admin do
+    navigation_label '积分奖励配置'
+    parent CentBalance
+    weight -500
+    list do
+      filters [:version,:state]
+      field :id
+      field :c_type, :enum do
+        enum do
+          TYPE_ENUM
+        end
+      end
+      field :count
+      field :created_at
+      # field :updated_at
+    end
+    show do
+      field :id
+      field :c_type, :enum do
+        enum do
+          TYPE_ENUM
+        end
+      end
+      field :count
+      field :created_at
+      field :updated_at
+    end
+    edit do
+      field :c_type, :enum do
+        enum do
+          TYPE_ENUM
+        end
+      end
+      field :count
+      field :state    
+    end
+
+  end
+
+end

+ 90 - 0
app/models/cent_balance.rb

@@ -0,0 +1,90 @@
+# encoding:utf-8
+class CentBalance < ActiveRecord::Base
+  has_paper_trail
+  self.table_name = "cent_balances"
+  belongs_to :wx_user, :foreign_key => :wx_uid
+  validates_presence_of :wx_uid, :count, :relate_id, :source
+  attr_accessor :remain_sum
+
+  SOURCE_ENUM = [["首次登录", "first_login"],
+                 ["新人注册", "new_man"],
+                 ["签到打卡", "check_in"],
+               ]
+
+  def remain_sum
+    b = CentBalance.where("wx_uid = ? and id < ?", self.wx_uid, self.id).last
+    if !b.blank?
+      return self.count + b.remain_sum
+    else
+      return self.count
+    end
+  end
+  rails_admin do
+    navigation_label '资金管理'
+    weight -920
+
+    list do
+      items_per_page 10
+      filters [:id, :source, :wx_user, :relate_id, :created_at]
+      # include_all_fields
+      field :id
+      field :wx_user
+      field :wx_uid
+      field :count do
+        formatted_value do
+          value.to_f / 100.0
+        end
+      end
+      field :remain_sum do
+        formatted_value do
+          value.to_f / 100.0
+        end
+      end
+      field :relate_id
+      field :source, :enum do
+        enum do
+          SOURCE_ENUM
+        end
+      end
+      field :remark
+      field :created_at
+      # field :updated_at
+    end
+
+    show do
+      field :wx_uid
+      field :count do
+        formatted_value do # used in form views
+          value.to_f / 100.0
+        end
+      end
+      field :remain_sum do
+        formatted_value do
+          value.to_f / 100.0
+        end
+      end
+      field :source, :enum do
+        enum do
+          SOURCE_ENUM
+        end
+      end
+      field :relate_id
+      field :remark
+      field :created_at
+    end
+
+    edit do
+      field :wx_uid
+      field :count do
+        label "变动金额,单位(分)"
+      end
+      field :relate_id
+      field :source, :enum do
+        enum do
+          SOURCE_ENUM
+        end
+      end
+      field :remark
+    end
+  end
+end

+ 11 - 0
config/locales/models/cent_award.yml

@@ -0,0 +1,11 @@
+zh-CN:
+  activerecord:
+    models:
+      cent_awards: 积分奖励配置
+    attributes:
+      cent_awards:
+        id: Id
+        count: 奖励金额(分)
+        c_type: 类型
+        created_at: 创建时间
+        updated_at: 更新时间

+ 16 - 0
config/locales/models/cent_balance.yml

@@ -0,0 +1,16 @@
+zh-CN:
+  activerecord:
+    models:
+      cent_balances: 积分账户
+    attributes:
+      cent_balances:
+        id: Id
+        wx_user: 微信用户
+        wx_uid: 微信ID
+        count: 变动金额(元)
+        remain_sum: 余额(元)
+        source: 来源
+        relate_id: 关联订单号
+        remark: 备注
+        created_at: 创建时间
+        updated_at: 更新时间

+ 38 - 0
db/migrate/20201114114698_create_cent_balances.rb

@@ -0,0 +1,38 @@
+# encoding:utf-8
+class CreateCentBalances < ActiveRecord::Migration
+  def up
+    #积分账户
+    create_table :cent_balances do |t|
+      #用户ID
+      t.column :wx_uid, :integer, :null=>false
+      #变动金额(分)
+      t.column :count, :integer, :null=>false
+      #来源
+      t.column :source, :string, :limit=>64
+      #关联ID
+      t.column :relate_id, :string
+      #备注
+      t.column :remark,:string
+      t.timestamps
+    end
+    #积分活动配置
+    create_table :cent_awards do |t|
+      #变动金额(分)
+      t.column :count, :integer, :null=>false
+      #活动类型
+      t.column :c_type, :string, :limit=>64
+      #备注
+      t.column :remark,:string
+      t.timestamps
+    end
+    add_index :cent_balances, :wx_uid
+    add_index :cent_awards, :c_type
+
+  end
+
+  def down
+    drop_table :cent_balances
+    drop_table :cent_awards
+  end
+
+end