class Order extends Model const REFUND_STATUS_PENDING = pending; const REFUND_STATUS_APPLIED = applied; const REFUND_STATUS_PROCESSING = processing; const REFUND_STATUS_SUCCESS = success;
class Order < ApplicationRecord enum refund_status: { pending: 'pending', applied: 'applied', processing: 'processing', success: 'success', failed: 'failed' }
enum ship_status: { pending: 'pending', delivered: 'delivered', received: 'received' }
serialize :address, JSON serialize :ship_data, JSON serialize :extra, JSON
belongs_to :user has_many :order_items
before_create :generate_order_no
def generate_order_no prefix = Time.now.strftime('%Y%m%d%H%M%S') 10.times do no = "#{prefix}#{format('%06d', Random.rand(999999))}" return no unless Order.exists?(no: no) end Rails.logger.warn('find order no failed') false end en
原文地址: https://www.cveoy.top/t/topic/igFS 著作权归作者所有。请勿转载和采集!