Withdraw.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. use app\common\model\User;
  5. class Withdraw extends Model
  6. {
  7. protected $name = 'shop_withdraw';
  8. protected $type = [
  9. 'withdraw_info' => 'json'
  10. ];
  11. // 追加属性
  12. protected $append = [
  13. 'status_text',
  14. 'charge_rate_format',
  15. 'withdraw_info_hidden',
  16. 'withdraw_type_text',
  17. 'wechat_transfer_state_text',
  18. ];
  19. // 微信商家转账状态
  20. const WECHAT_TRANSFER_STATE = [
  21. 'ACCEPTED' => '单据已受理,请稍等',
  22. 'PROCESSING' => '单据处理中,请稍等',
  23. 'SUCCESS' => '转账成功',
  24. 'FAIL' => '转账失败',
  25. 'CANCELING' => '单据撤销中',
  26. 'CANCELLED' => '单据已撤销',
  27. 'WAIT_USER_CONFIRM' => '待收款用户确认',
  28. 'TRANSFERING' => '转账中',
  29. 'NOT_FOUND' => '未申请微信提现',
  30. ];
  31. // 可以安全退还佣金的状态
  32. const CAN_CANCEL_STATE = [
  33. 'FAIL',
  34. 'WAIT_USER_CONFIRM',
  35. 'CANCELLED'
  36. ];
  37. public function statusList()
  38. {
  39. return [
  40. -3 => '撤销提现',
  41. -2 => '提现失败',
  42. -1 => '已拒绝',
  43. 0 => '待审核',
  44. 1 => '处理中',
  45. 2 => '已处理'
  46. ];
  47. }
  48. public function withdrawTypeList()
  49. {
  50. return [
  51. 'wechat' => '微信零钱',
  52. 'alipay' => '支付包账户',
  53. 'bank' => '银行卡',
  54. ];
  55. }
  56. /**
  57. * 状态获取器
  58. */
  59. public function getStatusTextAttr($value, $data)
  60. {
  61. $value = $value ?: ($data['status'] ?? null);
  62. $list = $this->statusList();
  63. return isset($list[$value]) ? $list[$value] : '';
  64. }
  65. /**
  66. * 类型获取器
  67. */
  68. public function getWithdrawTypeTextAttr($value, $data)
  69. {
  70. $value = $value ?: ($data['withdraw_type'] ?? null);
  71. $list = $this->withdrawTypeList();
  72. return isset($list[$value]) ? $list[$value] : '';
  73. }
  74. public function getWechatTransferStateTextAttr($value, $data)
  75. {
  76. $value = $value ?: ($data['wechat_transfer_state'] ?? null);
  77. $list = self::WECHAT_TRANSFER_STATE;
  78. return isset($list[$value]) ? $list[$value] : $value;
  79. }
  80. public function getChargeRateFormatAttr($value, $data)
  81. {
  82. $value = $value ?: ($data['charge_rate'] ?? null);
  83. return bcmul((string)$value, '100', 1) . '%';
  84. }
  85. public function getWithdrawInfoHiddenAttr($value, $data)
  86. {
  87. $withdraw_info = $value ?: ($this->withdraw_info ?? null);
  88. foreach ($withdraw_info as $key => &$info) {
  89. if (in_array($key, ['微信用户', '真实姓名'])) {
  90. $info = string_hide($info, 2);
  91. } elseif (in_array($key, ['银行卡号', '支付宝账户', '微信ID'])) {
  92. $info = account_hide($info);
  93. }
  94. }
  95. return $withdraw_info;
  96. }
  97. public function user()
  98. {
  99. return $this->belongsTo(User::class, 'user_id', 'id')->field('id, nickname, avatar, total_consume');
  100. }
  101. }