委 托

[size=medium]需要提供一个接口来判读用户今天是否已经签到[/size]
[size=medium]刚开始在customer_sign_in.rb中写了一个类方法,把customer当作一个参数传进去。[/size]

customer_sign_in.rb文件中
def self.had_not_signin(customer)
CustomerSigninLog.where(customer_id: customer.id).select {|log| log.created_at > Time.now.at_beginning_of_day } == []
end

CustomerSignInStateDefine文件中
handler :customer_sign_in_handler do |input|
CustomerSigninLog.add_signin_log(input[:customer]) if CustomerSignIn.had_not_signin(input[:customer]) //调用had_not_signin接口
input[:customer].update(points: input[:customer].points + 1)
end


[size=medium]由于判断用户是否签到是判断customer_signin_logs表中是否有当天的签到记录,所以在customer_signin_log.rb中写了判断用户签到的类方法,但是这个方法真正的调用接口放在了customer.rb中。[/size]

customer_signin_log.rb文件中
def self._has_signin?(customer_id)
where(customer_id: customer_id).select {|log| log.created_at > Time.now.at_beginning_of_day }.present?
end

customer.rb文件中
def has_signin?
CustomerSigninLog._has_signin?(self.id)
end

CustomerSignInStateDefine文件中
handler :customer_sign_in_handler do |input|
CustomerSigninLog.add(input[:customer]) unless input[:customer].has_signin?
input[:customer].update(points: input[:customer].points + 1) //调用has_signin?接口
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值