赶得上的话也去凑下热闹↖(^ω^)↗
来晚了~
我们也使用 Padrino
,同样是 garbage_collector
。
输出
# -*- encoding: utf-8 -*-
require 'securerandom' unless defined?(::SecureRandom)
require 'mime/types' unless defined?(::MIME::Types)
module Helpers
module File
# 根据 RFC 2397 约定,将文件转字符
def file_encode(file_path)
return nil unless File.file?(file_path)
file = File.open(file_path, 'rb')
type = MIME::Types.type_for( File.basename(file_path) ).first.to_s
content = Base64.encode64( file.read )
return "data:#{type};base64,#{content}"
end
# 还原,文件信息
def file_for(file_enc, attr_name)
file_info = file_enc.match(/data:(.*);base64,([.\w\s\/\/+]*)/)
if file_info && file_info.size == 3
# 文件信息
type = file_info[1]
content = file_info[2]
# 找扩展名
mime_type = MIME::Types[file_info[1]].first
extname = mime_type.extensions.first
# 文件名
filename = SecureRandom.hex(10) + ".#{extname}"
return {
filename: filename,
type: type,
name: attr_name,
tempfile: file_restore(filename, content),
head: "Content-Disposition: form-data; name=\"#{attr_name}\"; filename=\"#{filename}\"\r\nContent-Type: #{type}\r\n"
}
end
return nil
end
# 还原,临时文件
def file_restore(filename, content)
temp_file = Tempfile.new(filename, binmode: true)
temp_file.write( Base64.decode64(content) )
temp_file.close
return temp_file
end
end
end
product 是产品(静态)属性:款号、材质、品牌。。。
item 是(可售)商品,包含了:颜色、尺码、SKU 编码、库存、销售价
在 销售 过程中,唯一频繁变动的就是 stock
有前途,很多电商也需要~
轻松的话题总能激起感慨欲^ω^
# -*- encoding: utf-8 -*-
class User
include Mongoid::Document
include Store
store_in collection: 'users'
# Referenced
belongs_to :ownable, polymorphic: true, index: true # 店长
has_many :shops, foreign_key: 'nick' # 店铺
has_many :employees, foreign_key: 'seller_nick' # 店铺
# -*- encoding: utf-8 -*-
class Employee # 伙计
include Mongoid::Document
# Referenced
belongs_to :account
belongs_to :employee, class_name: 'Account', foreign_key: 'employee_id'
belongs_to :seller, class_name: 'User', foreign_key: 'seller_nick'
attr_accessor :email
# Fields
field :employee_id, type: String
field :employee_name, type: String
field :seller_nick, type: String
field :role, type: String
field :_id, type: String, default: -> { "#{seller_nick}:#{employee_name}" }
# Validations
validates_presence_of :seller_nick, :role
角色:
def title
case role
when 'admin'
'店长'
when 'op'
'运营'
when 'cs'
'客服'
end
end
确实是记录 IP 的,我现在的方案是放在前端,通过用户的 IP 不停的请求~
User. where(nickname: /#{"ta"}/).first
#39 楼 @larina_gu 谢谢,挺期待的~
如果有玩 3DS 的就是我啦~
@larina_gu 能给个语意果的邀请码不?[email protected]
今天有雨~
@yfractal 没人愿意占这个便宜,偶来,支付宝帐号给偶;
杭州滨江区长江南路 336 号(白马湖生态创意城)3 幢 503.