Class: EricWeixin::Redpack

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/eric_weixin/redpack.rb

Constant Summary collapse

STATUS =
{
    "SENDING" => "发放中",
    "SENT" => "已发放待领取",
    "FAILED" => "发放失败",
    "RECEIVED" => "已领取",
    "REFUND" => "已退款"
}

Class Method Summary collapse

Class Method Details

.create_redpack(options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/eric_weixin/redpack.rb', line 15

def self.create_redpack options
  self.transaction do
    packs = EricWeixin::Redpack.where weixin_redpack_order_id: options[:weixin_redpack_order_id],
                                      openid: options[:openid]
    return packs[0] unless packs.blank?

    redpack = self.new status: options[:status],
                       openid: options[:openid],
                       amount: options[:amount],
                       rcv_time: options[:rcv_time],
                       weixin_redpack_order_id: options[:weixin_redpack_order_id]
    redpack.save!
    redpack
  end
end