Withdraw.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\common\model\user;
  4. use app\common\library\helper;
  5. use app\common\model\store\User as UserStore;
  6. use app\common\model\BaseModel;
  7. /**
  8. * 用户提现模型
  9. * Class Withdraw
  10. * @package app\common\model\user
  11. */
  12. class Withdraw extends BaseModel
  13. {
  14. // 定义表名
  15. protected $name = 'user_withdrawals';
  16. // 定义主键
  17. protected $pk = 'id';
  18. const TRANSACTION_TYPE = [1 => '支付宝', 2 => '微信'];
  19. const AUDIT = [0 => '待审核', 1 => '审核通过', 2 => '审核不通过'];
  20. const PAYSTATE = [0 => '待打款', 1 => '已打款', 2 => '打款失败', 3 => '打款中'];
  21. const PAY_TYPE = [1 => '支付宝', 2 => '微信'];
  22. protected $autoWriteTimestamp = false;
  23. protected $append = ['transaction_type_text', 'audit_text', 'pay_state_text', 'pay_type_text', 'admin_name'];
  24. protected $auto = ['create_time'];
  25. public function getAdminNameAttr($value)
  26. {
  27. $admin = UserStore::where('store_user_id', $this->admin_id)->find();
  28. if ($admin) {
  29. return $admin->user_name ?? '';
  30. }
  31. return '';
  32. }
  33. public function getList($fc_user_id)
  34. {
  35. return $this->where('fc_user_id', '=', $fc_user_id)
  36. ->paginate();
  37. }
  38. //已提现佣金
  39. public function ytxyjAmountSum($user_id)
  40. {
  41. $amount = $this->where('user_id', $user_id)->where('audit', 'in', [0, 1])->where('pay_state', 'in', [0, 1])->sum('amount');
  42. return $amount;
  43. }
  44. // public function getCreateTimeAttr($time)
  45. // {
  46. // return $time > 0 ? date("Y-m-d H:i:s", $time) : '';
  47. // }
  48. public function getPayTypeTextAttr($value)
  49. {
  50. return self::PAY_TYPE[$this->pay_type] ?? '-';
  51. }
  52. public function getTransactionTypeTextAttr($value)
  53. {
  54. return self::TRANSACTION_TYPE[$this->transaction_type] ?? '-';
  55. }
  56. public function getAuditTextAttr($value)
  57. {
  58. return self::AUDIT[$this->audit] ?? '-';
  59. }
  60. public function getPayStateTextAttr($value)
  61. {
  62. return self::PAYSTATE[$this->pay_state] ?? '-';
  63. }
  64. /**
  65. * 关联用户
  66. * @return \think\model\relation\hasOne
  67. */
  68. public function user()
  69. {
  70. return $this->hasOne('app\common\model\User', 'user_id', 'user_id');
  71. }
  72. public static function makeTransactionNo()
  73. {
  74. return "TX".date('YmdHis') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 3);
  75. }
  76. public static function makePayTransactionNo()
  77. {
  78. return "DK".date('YmdHis') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 4);
  79. }
  80. /**
  81. * 计算本次提现个人所得税
  82. * @param $x *当月累计佣金提现
  83. * @param $hasHandle *本月已缴个税
  84. * @return int|string
  85. */
  86. public static function calculatorTax($x,$hasHandle){
  87. if (is_debug() == true){
  88. /* $x1 = 0.8;$x2 = 2;$x3 = 8; $x4 = 16;
  89. $y1 = 0.8;$y2 = 1.2;$y3 = 2;*/
  90. $x1 = 800;$x2 = 4000;$x3 = 25000; $x4 = 62500;
  91. $y1 = 800;$y2 = 2000;$y3 = 7000;
  92. }else{
  93. $x1 = 800;$x2 = 4000;$x3 = 25000; $x4 = 62500;
  94. $y1 = 800;$y2 = 2000;$y3 = 7000;
  95. }
  96. $tax = 0;
  97. if ( $x <= $x1){
  98. return $tax;
  99. }
  100. if ($x > $x1 && $x <= $x2){
  101. $tax0 =helper::bcsub( $x ,$y1,4);
  102. $tax =helper::bcmul( $tax0 ,0.2,4);
  103. }
  104. if ($x > $x2 && $x <= $x3){
  105. $tax = helper::bcmul( $x ,0.16,4);
  106. }
  107. if ($x > $x3 && $x <= $x4){
  108. $tax0 =helper::bcmul( $x ,0.24,4);
  109. $tax =helper::bcsub( $tax0 ,$y2,4);
  110. }
  111. if ($x > $x4 ){
  112. $tax0 =helper::bcmul( $x ,0.32,4);
  113. $tax =helper::bcsub( $tax0 ,$y3,4);
  114. }
  115. $tmpTax = helper::bcsub($tax , $hasHandle,4);
  116. //向上取两位小数0.111->0.12
  117. return bcdiv(strval(ceil($tmpTax * 100)),"100",2);
  118. /* $tax = 0;
  119. if ( $x <= 800){
  120. return $tax;
  121. }
  122. if ($x > 800 && $x <= 4000){
  123. $tax0 =helper::bcsub( $x ,800,2);
  124. $tax =helper::bcmul( $tax0 ,0.2,2);
  125. }
  126. if ($x > 4000 && $x <= 25000){
  127. $tax = helper::bcmul( $x ,0.16,2);
  128. }
  129. if ($x > 25000 && $x <= 62500){
  130. $tax0 =helper::bcmul( $x ,0.24,2);
  131. $tax =helper::bcsub( $tax0 ,2000,2);
  132. }
  133. if ($x > 62500 ){
  134. $tax0 =helper::bcmul( $x ,0.32,2);
  135. $tax =helper::bcsub( $tax0 ,7000,2);
  136. }
  137. return helper::bcsub($tax , $hasHandle,2);*/
  138. }
  139. }