<?php


namespace App\Http\logic\admin;


use Illuminate\Support\Facades\DB;

class MailLogic
{
    public function mailRecord($type,$GameID,$amount,$amount_search)
    {
        !empty($GameID) && $where[] = ['ai.GameID', 'like', $GameID . '%'];

        if (!empty($amount)) {
            $where[] = ['pm.amount', '=', $amount * 100];
        }

        $where[] = ['pm.type', '=', $type];
        $build_sql = DB::table('QPAccountsDB.dbo.PrivateMail as pm')->join('QPAccountsDB.dbo.AccountsInfo as ai', 'pm.UserID', 'ai.UserID');

        switch ($amount_search) {
            case 100:
                $where[] = ['pm.amount', '<', 10000];
                break;
            case 500:
                $where[] = ['pm.amount', '>=', 10000];
                $where[] = ['pm.amount', '<=', 50000];
                break;
            case 1000:
                $where[] = ['pm.amount', '>=', 50000];
                $where[] = ['pm.amount', '<=', 100000];
                break;
            case 1001:
                $where[] = ['pm.amount', '>', 100000];
                break;
        }




        $field = ['pm.*', 'ai.GameID'];

        $list = $build_sql
            ->where($where)
            ->select($field)
            ->orderByDesc('CreateTime')
            ->paginate(10);

        $prize = DB::connection('write')->table('QPTreasureDB.dbo.PropCfg')->select('PropID', 'PropName')->get()->toArray();
        //$prop = DB::connection('write')->table('QPAccountsDB.dbo.YN_MatchProp')->select('PropID', 'PropName')->get()->toArray();
//        $data = array_merge($prize, $prop);
//        foreach ($data as $key => $value) {
//            $prop_arr[$value->PropID] = $value->PropName;
//        }

        foreach ($list as $key => &$value) {
            if (!empty($value->BonusString)) {
                $bonus = $value->BonusString;

                $bonus = explode(';', $bonus);
                $value->BonusString = '';
                foreach ($bonus as $k => &$v) {
                    $v = explode(',', $v);
                    if (count($v) >1) {
                        $value->BonusString .= '金币x' . ($v[1] / 100) . ',';
                    }

                }
            }
        }
        return $list;
    }
}
