<?php


namespace App\dao\Estatisticas;


use App\Facade\TableName;
use App\Http\helper\NumConfig;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class RechargeWithDraw
{
    public function recharge($UserID, $Recharge)
    {
        $Recharge = $Recharge * NumConfig::NUM_VALUE;

        try {

            // 数据统计后台 -- 充值记录添加
            $UserRegisterDate = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')->where('UserID', $UserID)->select('RegisterDate', 'Channel')->first();

            if($UserID == 4293017 ){
//                $UserRegisterDate->Channel = 101;
            }

            DB::connection('mysql')->table('rummy_ltv_statistics')
                ->where('channel', $UserRegisterDate->Channel)
                ->where('at_date', Carbon::parse($UserRegisterDate->RegisterDate)->format('Ymd'))
                ->increment('total_recharge', $Recharge);

            DB::connection('mysql')->table('rummy_ltv_statistics')
                ->where('channel', -1)
                ->where('at_date', Carbon::parse($UserRegisterDate->RegisterDate)->format('Ymd'))
                ->increment('total_recharge', $Recharge);
        } catch (\Exception $exception) {
            Log::info('【充值】数据统计后台信息添加失败' . $UserID . ' - ' . $Recharge);
        }

    }

    public function withDraw($UserID, $WithDraw)
    {
        try {

            // 数据统计后台 -- 充值记录添加
            $UserRegisterDate = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')->where('UserID', $UserID)->select('RegisterDate', 'Channel')->first();

//            if($UserID == 4293017 ){
//                $UserRegisterDate->Channel = 101;
//            }

            DB::connection('mysql')->table('rummy_cash_statistics')
                ->where('channel', $UserRegisterDate->Channel)
                ->where('at_date', Carbon::parse($UserRegisterDate->RegisterDate)->format('Ymd'))
                ->increment('total_cash', $WithDraw);

            DB::connection('mysql')->table('rummy_cash_statistics')
                ->where('channel', -1)
                ->where('at_date', Carbon::parse($UserRegisterDate->RegisterDate)->format('Ymd'))
                ->increment('total_cash', $WithDraw);
        } catch (\Exception $exception) {
            Log::info('【提现】数据统计后台信息添加失败' . $UserID . ' - ' . $WithDraw);
        }
    }
}
