PaymentOrder.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Models;
  3. /**
  4. * @property $amount
  5. * @property $bank_name
  6. * @property $account
  7. * @property $card_no
  8. * @property $status
  9. * @property $member_id
  10. * @property $id
  11. */
  12. class PaymentOrder extends BaseModel
  13. {
  14. protected $table = 'payment_orders';
  15. protected $fillable = ['type', 'order_no', 'member_id', 'amount', 'channel', 'admin_note','bank_name', 'account', 'card_no', 'status', 'callback_url', 'callback_data', 'remark', 'pay_no', 'pay_url', 'pay_data', 'fee', 'payment_type', 'is_send', 'is_locked', 'recharge_bonus_snapshot'];
  16. protected $hidden = ['recharge_bonus_snapshot'];
  17. protected $casts = ['recharge_bonus_snapshot' => 'array'];
  18. protected static function booted()
  19. {
  20. parent::booted();
  21. static::creating(function ($order) {
  22. if ((int)$order->type === 3 && $order->channel === 'rgcz' && !array_key_exists('recharge_bonus_snapshot', $order->getAttributes())) {
  23. $snapshot = \App\Services\RechargeBonusService::capture('rgcz', (string)$order->member_id);
  24. if ($snapshot !== null) $order->recharge_bonus_snapshot = $snapshot;
  25. }
  26. });
  27. }
  28. // // 添加这个
  29. // protected $visible = [
  30. // 'type', 'order_no', 'member_id', 'amount', 'channel',
  31. // 'bank_name', 'account', 'card_no', 'status', 'callback_url',
  32. // 'callback_data', 'remark', 'pay_no', 'pay_url', 'pay_data', 'fee',
  33. // 'created_at', 'updated_at' // 添加时间戳字段
  34. // ];
  35. public function userInfo()
  36. {
  37. return $this->belongsTo(User::class, 'member_id', 'member_id')
  38. ->select(['id', 'member_id', 'username', 'first_name', 'admin_note', 'status', 'phone', 'visitor_id', 'register_ip']);
  39. }
  40. }