123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- declare (strict_types=1);
- namespace app\common\model\user;
- use app\common\library\helper;
- use app\common\model\store\User as UserStore;
- use app\common\model\BaseModel;
- /**
- * 用户提现模型
- * Class Withdraw
- * @package app\common\model\user
- */
- class Withdraw extends BaseModel
- {
- // 定义表名
- protected $name = 'user_withdrawals';
- // 定义主键
- protected $pk = 'id';
- const TRANSACTION_TYPE = [1 => '支付宝', 2 => '微信'];
- const AUDIT = [0 => '待审核', 1 => '审核通过', 2 => '审核不通过'];
- const PAYSTATE = [0 => '待打款', 1 => '已打款', 2 => '打款失败', 3 => '打款中'];
- const PAY_TYPE = [1 => '支付宝', 2 => '微信'];
- protected $autoWriteTimestamp = false;
- protected $append = ['transaction_type_text', 'audit_text', 'pay_state_text', 'pay_type_text', 'admin_name'];
- protected $auto = ['create_time'];
- public function getAdminNameAttr($value)
- {
- $admin = UserStore::where('store_user_id', $this->admin_id)->find();
- if ($admin) {
- return $admin->user_name ?? '';
- }
- return '';
- }
- public function getList($fc_user_id)
- {
- return $this->where('fc_user_id', '=', $fc_user_id)
- ->paginate();
- }
- //已提现佣金
- public function ytxyjAmountSum($user_id)
- {
- $amount = $this->where('user_id', $user_id)->where('audit', 'in', [0, 1])->where('pay_state', 'in', [0, 1])->sum('amount');
- return $amount;
- }
- // public function getCreateTimeAttr($time)
- // {
- // return $time > 0 ? date("Y-m-d H:i:s", $time) : '';
- // }
- public function getPayTypeTextAttr($value)
- {
- return self::PAY_TYPE[$this->pay_type] ?? '-';
- }
- public function getTransactionTypeTextAttr($value)
- {
- return self::TRANSACTION_TYPE[$this->transaction_type] ?? '-';
- }
- public function getAuditTextAttr($value)
- {
- return self::AUDIT[$this->audit] ?? '-';
- }
- public function getPayStateTextAttr($value)
- {
- return self::PAYSTATE[$this->pay_state] ?? '-';
- }
- /**
- * 关联用户
- * @return \think\model\relation\hasOne
- */
- public function user()
- {
- return $this->hasOne('app\common\model\User', 'user_id', 'user_id');
- }
- public static function makeTransactionNo()
- {
- return "TX".date('YmdHis') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 3);
- }
- public static function makePayTransactionNo()
- {
- return "DK".date('YmdHis') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 4);
- }
- /**
- * 计算本次提现个人所得税
- * @param $x *当月累计佣金提现
- * @param $hasHandle *本月已缴个税
- * @return int|string
- */
- public static function calculatorTax($x,$hasHandle){
- if (is_debug() == true){
- /* $x1 = 0.8;$x2 = 2;$x3 = 8; $x4 = 16;
- $y1 = 0.8;$y2 = 1.2;$y3 = 2;*/
- $x1 = 800;$x2 = 4000;$x3 = 25000; $x4 = 62500;
- $y1 = 800;$y2 = 2000;$y3 = 7000;
- }else{
- $x1 = 800;$x2 = 4000;$x3 = 25000; $x4 = 62500;
- $y1 = 800;$y2 = 2000;$y3 = 7000;
- }
- $tax = 0;
- if ( $x <= $x1){
- return $tax;
- }
- if ($x > $x1 && $x <= $x2){
- $tax0 =helper::bcsub( $x ,$y1,4);
- $tax =helper::bcmul( $tax0 ,0.2,4);
- }
- if ($x > $x2 && $x <= $x3){
- $tax = helper::bcmul( $x ,0.16,4);
- }
- if ($x > $x3 && $x <= $x4){
- $tax0 =helper::bcmul( $x ,0.24,4);
- $tax =helper::bcsub( $tax0 ,$y2,4);
- }
- if ($x > $x4 ){
- $tax0 =helper::bcmul( $x ,0.32,4);
- $tax =helper::bcsub( $tax0 ,$y3,4);
- }
- $tmpTax = helper::bcsub($tax , $hasHandle,4);
- //向上取两位小数0.111->0.12
- return bcdiv(strval(ceil($tmpTax * 100)),"100",2);
- /* $tax = 0;
- if ( $x <= 800){
- return $tax;
- }
- if ($x > 800 && $x <= 4000){
- $tax0 =helper::bcsub( $x ,800,2);
- $tax =helper::bcmul( $tax0 ,0.2,2);
- }
- if ($x > 4000 && $x <= 25000){
- $tax = helper::bcmul( $x ,0.16,2);
- }
- if ($x > 25000 && $x <= 62500){
- $tax0 =helper::bcmul( $x ,0.24,2);
- $tax =helper::bcsub( $tax0 ,2000,2);
- }
- if ($x > 62500 ){
- $tax0 =helper::bcmul( $x ,0.32,2);
- $tax =helper::bcsub( $tax0 ,7000,2);
- }
- return helper::bcsub($tax , $hasHandle,2);*/
- }
- }
|