<?php

namespace App\Models\Withdraw;


use Illuminate\Database\Eloquent\Model;

class UserWithDrawCash extends Model
{
    protected $table = 'user_withdraw_cashes';

    protected $fillable = ['uid', 'distribution_channel_id', 'distribution_channel_name', 'amount','trans_fund_result', 'tallage','status',
        'withdraw_type','withdraw_info','alipay_username','alipay_account','remark','serial_number','check_user_id',
        'check_user_name','pay_merchant_company_id','created_at','updated_at','trans_time','trans_trade_no','tiktok_trade_no'];


    public static function getUserWithdrawCashsByUid($uid) {
        
        $result = self::where('uid',$uid)->select('*')->get();
        return $result;
    }
    
    public static function getToTransUserWithdrawCashes($before_limit_minute=60){
        $start_time = date('Y-m-d H:i:s',time() - $before_limit_minute*60);
        return self::where('created_at','>=',$start_time)->where('status','待打款')->get();
    }
    
    // 获取用户打款记录
    public static function getUserWithdrawCashes($data){
        $obj = self::select('*')->whereIn('status',['系统已打款','手动已打款']);
        if(empty($data['start_date'])){
            $data['start_date'] = date('Y-m-d 00:00:00');
        }
        if(empty($data['end_date'])){
            $data['end_date'] = date('Y-m-d 23:59:59');
        }
        
        $obj->where('created_at','>=',$data['start_date'])->where('created_at','<=',$data['end_date']);
        
        if(!empty($data['uid'])){
            $obj->where('uid',$data['uid']);
        }
        
        if(!empty($data['alipay_account'])){
            $obj->where('alipay_account',$data['alipay_account']);
        }
        
        
        return $obj->get();
    }
    
}