Withdraw.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 = 'shopro_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 getWithdrawTypeTextAttr($value, $data)
  60. {
  61. $value = $value ?: ($data['withdraw_type'] ?? null);
  62. $list = $this->withdrawTypeList();
  63. return isset($list[$value]) ? $list[$value] : '';
  64. }
  65. public function getWechatTransferStateTextAttr($value, $data)
  66. {
  67. $value = $value ?: ($data['wechat_transfer_state'] ?? null);
  68. $list = self::WECHAT_TRANSFER_STATE;
  69. return isset($list[$value]) ? $list[$value] : $value;
  70. }
  71. public function getChargeRateFormatAttr($value, $data)
  72. {
  73. $value = $value ?: ($data['charge_rate'] ?? null);
  74. return bcmul((string)$value, '100', 1) . '%';
  75. }
  76. public function getWithdrawInfoHiddenAttr($value, $data)
  77. {
  78. $withdraw_info = $value ?: ($this->withdraw_info ?? null);
  79. foreach ($withdraw_info as $key => &$info) {
  80. if (in_array($key, ['微信用户', '真实姓名'])) {
  81. $info = string_hide($info, 2);
  82. } elseif (in_array($key, ['银行卡号', '支付宝账户', '微信ID'])) {
  83. $info = account_hide($info);
  84. }
  85. }
  86. return $withdraw_info;
  87. }
  88. public function user()
  89. {
  90. return $this->belongsTo(User::class, 'user_id', 'id')->field('id, nickname, avatar, total_consume');
  91. }
  92. }