Withdraw.php 3.4 KB

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