add: invite code

This commit is contained in:
2021-06-08 14:56:43 +08:00
parent 5ef9549b6b
commit d4b8b3e24f
4 changed files with 25 additions and 3 deletions

View File

@@ -0,0 +1,13 @@
module Dcodes
DCODES = %W(1 2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
extend ActiveSupport::Concern
def generate_dcode(field, num, pre='')
code = DCODES.sample(num).join
while self.class.exists?("#{field}": pre+code) do
code = DCODES.sample(num).join
end
code
end
end