Withdraw.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\model\shopro;
  3. use app\admin\model\shopro\Common;
  4. use app\admin\model\shopro\user\User;
  5. class Withdraw extends Common
  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. ];
  18. public function statusList()
  19. {
  20. return [
  21. -1 => '已拒绝',
  22. 0 => '待审核',
  23. 1 => '处理中',
  24. 2 => '已处理'
  25. ];
  26. }
  27. public function withdrawTypeList()
  28. {
  29. return [
  30. 'wechat' => '微信零钱',
  31. 'alipay' => '支付包账户',
  32. 'back' => '银行卡',
  33. ];
  34. }
  35. /**
  36. * 类型获取器
  37. */
  38. public function getWithdrawTypeTextAttr($value, $data)
  39. {
  40. $value = $value ?: ($data['withdraw_type'] ?? null);
  41. $list = $this->withdrawTypeList();
  42. return isset($list[$value]) ? $list[$value] : '';
  43. }
  44. public function getChargeRateFormatAttr($value, $data)
  45. {
  46. $value = $value ?: ($data['charge_rate'] ?? null);
  47. return bcmul((string)$value, '100', 1) . '%';
  48. }
  49. public function getWithdrawInfoHiddenAttr($value, $data)
  50. {
  51. $withdraw_info = $value ?: ($this->withdraw_info ?? null);
  52. foreach ($withdraw_info as $key => &$info) {
  53. if (in_array($key, ['微信用户', '真实姓名'])) {
  54. $info = string_hide($info, 2);
  55. } elseif (in_array($key, ['银行卡号', '支付宝账户', '微信ID'])) {
  56. $info = account_hide($info);
  57. }
  58. }
  59. return $withdraw_info;
  60. }
  61. public function user()
  62. {
  63. return $this->belongsTo(User::class, 'user_id', 'id')->field('id, nickname, avatar, total_consume');
  64. }
  65. }