<?php


namespace App\Http\logic\api;


use App\dao\Pay\Recharge;
use App\Facade\TableName;
use Illuminate\Support\Facades\DB;

class RechargeLogic
{
    public function guidePayment($JumpOut)
    {
        $guidePayment = DB::table('agent.dbo.recharge_gear')->where('status', 1)->where('first_pay', 2)->first();

        if (!$guidePayment) {
            return [];
        }

        $names = (new Recharge())->poll();
        $list = DB::table('agent.dbo.recharge_gear')
            ->where('status', 1)
            ->where('first_pay', 2)
            ->orderBy('money', 'asc')->where('status', 1)->get();

        foreach ($list as $val) {

            $data = [];
            $gear = \GuzzleHttp\json_decode($val->gear, true);

            foreach ($names as $k => $va) {

                foreach ($gear as $key => &$value) {


                    if ($value['id'] == $va['id']) {
                        if ($value['status'] != -1) {
                            // type = 1 sdk跳转 type=2 外跳链接  type=0  默认
                            $type = $va['new_pay_type'] == 1 ? 3 : 2;
                            if($va['new_pay_type']  == 4){
                                $type = 0;
                            }
                            if (in_array($value['id'], $JumpOut)) {
                                $data[] = ['id' => $value['id'], 'name' => $va, 'status' => 1, 'type' => $type];
                            } else {
                                $data[] = ['id' => $value['id'], 'name' => $va, 'status' => 1, 'type' => $type];
                            }
                        }
                    }
                }
            }

            $gear = array_values($data);
            $val->gear = \GuzzleHttp\json_encode($gear);
        }
        return $list;
    }
}
