AgentPaymentOrder.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Models\Agent;
  3. use App\Constants\Util;
  4. use App\Models\PaymentOrder;
  5. /**
  6. * 代理人民币充值订单。字段和状态码与会员 payment_orders 一致,
  7. * 所以 PaymentOrderService 的三方下单、回调、查单可以直接作用于本模型;入账走代理钱包。
  8. * 订单号统一以 ag 开头,回调时据此区分会员订单和代理订单。
  9. */
  10. class AgentPaymentOrder extends PaymentOrder
  11. {
  12. public const ORDER_PREFIX = 'ag';
  13. public const STATUS_TEXT = [
  14. 0 => '待处理', 1 => '处理中', 2 => '已到账', 3 => '失败', 4 => '待提交凭证', 5 => '待审核', 6 => '已撤回', 7 => '超时',
  15. ];
  16. protected $table = 'agent_payment_orders';
  17. protected $guarded = ['id'];
  18. protected $fillable = [];
  19. protected $hidden = ['callback_data', 'callback_url'];
  20. protected $appends = ['status_text', 'type_text'];
  21. protected $casts = [
  22. 'agent_id' => 'integer', 'type' => 'integer', 'status' => 'integer', 'payment_type' => 'integer',
  23. 'amount' => 'decimal:2', 'fee' => 'decimal:4', 'is_send' => 'integer', 'audit_admin_id' => 'integer',
  24. ];
  25. public function agent()
  26. {
  27. return $this->belongsTo(Agent::class);
  28. }
  29. public function getStatusTextAttribute(): string
  30. {
  31. return self::STATUS_TEXT[(int) $this->status] ?? '';
  32. }
  33. public function getTypeTextAttribute(): string
  34. {
  35. return (int) $this->type === 3 ? '人工充值' : '在线充值';
  36. }
  37. public function getImageAttribute($value)
  38. {
  39. return $value ? Util::ensureUrl($value) : '';
  40. }
  41. public function setImageAttribute($value)
  42. {
  43. $this->attributes['image'] = (string) Util::replacePartInUrl($value);
  44. }
  45. }