Przeglądaj źródła

add agent appy function

abiao 4 lat temu
rodzic
commit
4d3f81b314

+ 86 - 0
app/models/agent_apply.rb

@@ -0,0 +1,86 @@
+# encoding: utf-8
+class AgentApply < ActiveRecord::Base
+  has_paper_trail
+  self.table_name = "agent_applys"
+  belongs_to :wx_user, :foreign_key => :intro_user_id
+  belongs_to :depart_record, :foreign_key => :depart
+
+  validates :intro_user_id,:wx_user_id,:depart,presence: true
+
+  def com_user
+    linkUser = WxUser.where("id = ?", self.com_user_id).first
+    if !linkUser.blank?
+        return linkUser.NickName
+    else
+      return "--"
+    end
+  end
+
+
+
+
+  rails_admin do
+    navigation_label '用户管理'
+    parent WxUser
+    weight -500
+    list do
+      filters [:intro_user_id,:wx_user_id,:nickname]
+      field :id
+      field :happen_time do
+        formatted_value do
+          (value == 0 || value == nil) ? Time.at(0) : Time.at(value)
+        end
+      end
+      field :intro_user
+      field :wx_user_id
+      field :nickname
+      field :depart_record
+      field :com_user_id
+      field :com_user
+      field :com_time do
+        formatted_value do
+          (value == 0 || value == nil) ? Time.at(0) : Time.at(value)
+        end
+      end
+      field :status
+      field :created_at
+      # field :updated_at
+    end
+
+    show do
+      field :id
+      field :happen_time do
+        formatted_value do
+          (value == 0 || value == nil) ? Time.at(0) : Time.at(value)
+        end
+      end
+      field :intro_user
+      field :wx_user_id
+      field :nickname
+      field :depart_record
+      field :com_user_id
+      field :com_user
+      field :com_time do
+        formatted_value do
+          (value == 0 || value == nil) ? Time.at(0) : Time.at(value)
+        end
+      end
+      field :status
+      field :created_at
+      # field :updated_at
+    end
+
+    edit do
+      field :happen_time
+      field :intro_user_id
+      field :wx_user_id
+      field :nickname
+      field :depart_record
+      field :com_user_id
+      field :com_time
+      field :status
+    end
+
+  end
+
+end

+ 16 - 0
app/models/depart_record.rb

@@ -3,6 +3,22 @@ class DepartRecord < ActiveRecord::Base
   has_paper_trail
   self.table_name = "depart_records"
   belongs_to :wx_user, :foreign_key => :wx_user_id
+  after_save :after_save
+
+  def after_save
+    wxUsers = WxUser.where("depart=? and rank=3",self.id).All
+    wxUsers.each do |wuser|
+      wuser.rank=2
+      wuser.save
+    end
+
+    wxUser = WxUser.where("id = ?", self.wx_user_id).first
+    if !wxUser.blank?
+      wxUser.rank=3
+      wxUser.save
+    end
+  end
+
 
   rails_admin do
     navigation_label '用户管理'

+ 1 - 1
app/models/wx_user.rb

@@ -31,7 +31,7 @@ class WxUser < ActiveRecord::Base
   SEX_ENUM= [["未知","0"], ["男性","1"], ["女性", "2"]]
   DEPART_ENUM= [["部门1",1], ["部门2",2], ["部门3", 3], ["部门4", 4], ["部门5", 5]]
 
-  RANK_ENUM= [["普通会员","0"], ["群主","1"], ["店长", "2"]]
+  RANK_ENUM= [["普通会员","0"], ["群主","1"], ["店长", "2"], ["区域代理", "3"]]
 
   COPARTNET_STATE_ENUM = [["否",0],["是",1],["曾经是",2]]
 

+ 21 - 0
config/locales/models/agent_apply.yml

@@ -0,0 +1,21 @@
+zh-CN:
+  activerecord:
+    models:
+      agent_apply: 代理申请记录
+    attributes:
+      agent_apply:
+        id: ID
+        happen_time: 申请时间
+        intro_user_id: 申请人ID
+        intro_user: 申请人ID
+        wx_user_id: 微信会员id
+        nickname: 微信昵称
+        depart: 部门ID
+        depart_record: 部门
+        com_user_id: 审核人ID
+        com_user: 审核人
+        com_time:  审核时间
+        status: 是否审核
+        created_at: 创建时间
+        updated_at: 更新时间
+

+ 34 - 0
db/migrate/20210425114688_create_agent_applys.rb

@@ -0,0 +1,34 @@
+# encoding:utf-8
+class CreateAgentApplys < ActiveRecord::Migration
+  def up
+
+    create_table :agent_applys do |t|
+      # 申请时间
+      t.column :happen_time, :integer, :limit => 11, :default => 0
+      # 申请人ID
+      t.column :intro_user_id, :integer, :limit => 11, :default => 0
+      #微信会员id
+      t.column :wx_user_id, :integer, :limit => 11, :default => 0
+      # 昵称
+      t.column :nickname, :string, :limit => 255
+      # 部门ID
+      t.column :depart, :integer, :limit => 11, :default => 0
+      # 审核人ID
+      t.column :com_user_id, :integer, :limit => 11, :default => 0
+      # 审核时间
+      t.column :com_time, :integer, :limit => 11, :default => 0
+      # 是否审核
+      t.column :status, :boolean, :default=>0
+      t.timestamps
+    end
+
+    add_index :agent_applys,:intro_user_id,:name => "idx_intro_user_id"
+    add_index :agent_applys,:wx_user_id,:name => "idx_wx_user_id"
+
+  end
+
+  def down
+    drop_table :agent_applys
+  end
+
+end