forgeplus/app/models/identity_verification.rb

52 lines
1.4 KiB
Ruby

# == Schema Information
#
# Table name: identity_verifications
#
# id :integer not null, primary key
# user_id :integer not null
# number :string(255) not null
# name :string(255) not null
# card_front :integer
# card_back :integer
# hold_card_front :integer
# hold_card_back :integer
# state :integer default("0")
# description :string(255)
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_identity_verifications_on_user_id (user_id)
#
class IdentityVerification < ApplicationRecord
belongs_to :user
enum state: { "待审核": 0, "已通过": 1, "已拒绝": 2}
after_create do
Attachment.where(id:[card_front,card_back,hold_card_front,hold_card_back]).update_all(is_public:0)
end
after_save do
if state == "已通过"
user.update(id_card_verify: true, website_permission: true)
end
end
def card_front_attachment
Attachment.find_by_id card_front
end
def card_back_attachment
Attachment.find_by_id card_back
end
def hold_card_front_attachment
Attachment.find_by_id hold_card_front
end
def hold_card_back_attachment
Attachment.find_by_id hold_card_back
end
end