Best way to generate order numbers for an online store?

前端 未结 13 2053
野的像风
野的像风 2021-01-31 00:09

Every order in my online store has a user-facing order number. I\'m wondering the best way to generate them. Criteria include:

  • Short
  • Easy to say over the
13条回答
  •  南方客
    南方客 (楼主)
    2021-01-31 00:24

    Douglas Crockford's Base32 Encoding works superbly well for this.

    http://www.crockford.com/wrmg/base32.html

    Store the ID itself in your database as an auto-incrementing integer, starting at something suitably large like 100000, and simply expose the encoded value to the customer/interface.

    5 characters will see you through your first ~32 million orders, whilst performing very well and satisfying most of these requirements. It doesn't allow for the exclusion of similar sounding characters though.

提交回复
热议问题