Class: EricWeixin::RedpackOrder
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- EricWeixin::RedpackOrder
- Defined in:
- app/models/eric_weixin/redpack_order.rb
Constant Summary collapse
- SENDTYPE =
{ "API" => "通过API接口发放", "UPLOAD" => "通过上传文件方式发放", "ACTIVITY" => "通过活动方式发放" }
- HBTYPE =
{ "GROUP" => "裂变红包", "NORMAL" => "普通红包" }
Class Method Summary collapse
-
.create_redpack_order(options) ⇒ Object
必填参数=================== re_openid total_amount wishing client_ip act_name remark send_name ================选填参数=================== wxappid mch_id mch_key total_num.
Instance Method Summary collapse
-
#get_info ⇒ Object
定时使用 redpack_order 实例变量来完善补充红包信息。.
Class Method Details
.create_redpack_order(options) ⇒ Object
必填参数===================
re_openid total_amount wishing client_ip act_name remark send_name
选填参数===================
wxappid mch_id mch_key total_num
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/eric_weixin/redpack_order.rb', line 31 def self.create_redpack_order self.transaction do weixin_user = ::Weixin::WeixinUser.find_by_openid([:re_openid]) public_account = weixin_user.weixin_public_account||EricWeixin::PublicAccount.find_by_weixin_app_id(params[:wxappid]) BusinessException.raise '查找不到对应的公众号。' if public_account.blank? [:wxappid] = [:wxappid]||public_account.weixin_app_id [:mch_id] = [:mch_id]||public_account.mch_id [:total_num] ||= 1 [:mch_key] = [:mch_key]||public_account.mch_key result = EricWeixin::Pay.sendredpack pp "*********************** 发红包结果 **************************" pp result return result['err_code'] if result['return_code'] == 'FAIL' redpack_order = self.new redpack_order.mch_billno = result['mch_billno'] redpack_order.weixin_public_account_id = public_account.id redpack_order.save! redpack_order end end |
Instance Method Details
#get_info ⇒ Object
定时使用 redpack_order 实例变量来完善补充红包信息。
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/models/eric_weixin/redpack_order.rb', line 53 def get_info return unless self.redpacks.blank? EricWeixin::RedpackOrder.transaction do = {} [:mch_billno] = self.mch_billno [:mch_id] = self.public_account.mch_id [:appid] = self.public_account.weixin_app_id [:mch_key] = self.public_account.mch_key result = EricWeixin::Pay.gethbinfo pp "************************ 查询红包结果 *****************************" pp result return result['err_code'] if result['return_code'] == 'FAIL' self.detail_id = result['detail_id'] self.send_type = result['send_type'] self.hb_type = result['hb_type'] self.total_num = result['total_num'] self.total_amount = result['total_amount'] self.reason = result['reason'] self.send_time = result['send_time'] self.refund_time = result['refund_time'] self.refund_amount = result['refund_amount'] self.wishing = result['wishing'] self.remark = result['emark'] self.act_name = result['act_name'] self.save! hbinfo = (result['hblist']['hbinfo'] rescue '') unless hbinfo.blank? [:status] = hbinfo['status'] [:openid] = hbinfo['openid'] [:amount] = hbinfo['amount'] [:rcv_time] = hbinfo['rcv_time'] [:weixin_redpack_order_id] = self.id EricWeixin::Redpack.create_redpack end end end |