<?php

namespace App\Http\Controllers\Wap\Web;

use App\Modules\Activity\Services\ActivityService;
use App\Modules\Product\Services\ProductService;
use App\Modules\User\Services\UserService;
use Illuminate\Http\Request;
use App\Http\Controllers\Wap\BaseController;
use Redis;
use DB;
use Log;

class ActivityController extends BaseController
{

    //渠道自定义活动  可以多少充值
    public function channelCustomActivity(Request $request)
    {
        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
        $token = $request->input('token');
        $activity_info = ActivityService::getByToken($token);
        $img = 'https://cdn-novel.iycdm.com/h5/activity-chanel-custom/btn48.jpg';
        if ($activity_info && $activity_info->product_id) {
            $customer_activity_info = DB::table('channel_custom_activity')->where('product_id', $activity_info->product_id)->select('setting')->first();
            if ($customer_activity_info && $customer_activity_info->setting) {
                $img = json_decode($customer_activity_info->setting, 1)['img'];
            }
            $from = $request->input('fromtype', 'main');
            $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
            $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
            $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
            $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
            Redis::sadd($uv_key, $this->uid);
            Redis::hincrby($pv_key, date('Y-m-d'), 1);
            //$order = Order::where('uid',$this->uid)->where('status','PAID')->where('activity_id',$activity_info->id)->count();
            //渠道不符合
            if ($activity_info->distribution_channel_id != $this->distribution_channel_id) {
                return view('pay.activity.ChannelCustomerV1', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
            }
            //活动未开始
            if (time() < strtotime($activity_info->start_time)) {
                return view('pay.activity.ChannelCustomerV1', ['url' => '###', 'img' => $img, 'code' => -3, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
            }
            //活动结束
            if (time() > strtotime($activity_info->end_time)) {
                return view('pay.activity.ChannelCustomerV1', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
            }

            if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
                $param = [
                    'uid' => $this->uid,
                    'distribution_channel_id' => $this->distribution_channel_id,
                    'product_id' => $activity_info->product_id,
                    'activity_id' => $activity_info->id,
                    'fromtype' => $from,
                    'limit' => 100,
                    'pay_redirect_url' => env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person'
                ];
                $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
                return view('pay.activity.ChannelCustomerV1', ['url' => $url, 'img' => $img, 'code' => 0, 'start_time' => date('Y-m-d', strtotime($activity_info->start_time)), 'end_time' => date('Y-m-d', strtotime($activity_info->end_time) - 100)]);
            }
        }
        return view('pay.activity.ChannelCustomerV1', ['url' => '###', 'img' => $img, 'code' => -1, 'start_time' => date('Y-m-d', time() - 86400 * 2), 'end_time' => date('Y-m-d', time() - 86400)]);
    }


    public function commonActivity(Request $request)
    {
        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
        $token = $request->input('token');
        $activity_info = ActivityService::getByToken($token);
        if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting)) {
            $imgs = json_decode($activity_info->setting, 1);
            $from = $request->input('fromtype', 'main');
            $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
            $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
            $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
            $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);

            $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
            if ($request->input('redirect_url')) {
                $redirect_url = $request->input('redirect_url');
                $redirect_url = urldecode($redirect_url);
            }
            $product_id = $activity_info->product_id;
            if ($activity_info->id == 6000) {
                $imgs['page_bd_img'] = 'https://cdn-novel.iycdm.com/h5/activity-2019-04-29/bg2.jpg';
                $product_id = 5788;
            }
            if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
                Redis::sadd($uv_key, $this->uid);
                Redis::hincrby($pv_key, date('Y-m-d'), 1);
                $param = [
                    'uid' => $this->uid,
                    'distribution_channel_id' => $this->distribution_channel_id,
                    'product_id' => $product_id,
                    'activity_id' => $activity_info->id,
                    'fromtype' => $from,
                    'pay_redirect_url' => $redirect_url,
                    'limit' => 100,
                ];
                $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);

                return view('pay.order.common', ['url' => $url, 'code' => 0, 'img' => $imgs]);
            } else if (time() <= strtotime($activity_info->start_time)) {
                return view('pay.order.common', ['url' => [], 'code' => 1, 'img' => $imgs]);
            } else {
                return view('pay.order.common', ['url' => [], 'code' => 2, 'img' => $imgs]);
            }
        }
        $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
        return redirect()->to($default_url);
    }

    public function crmActivity(Request $request)
    {
        $default_url = env('H5_SCHEME', 'https') . '://site' . $this->en_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';

        $token = $request->input('token');
        if (!$token) {
            return redirect()->to($default_url);
        }
        $activity_info = ActivityService::getByToken($token);
        if (!$activity_info) {
            return redirect()->to($default_url);
        }
        $crm = $request->get('crm', 'crm' );
        $img = \GuzzleHttp\json_decode($activity_info->setting, 1);
        $param = [
            'uid' => $this->uid,
            'distribution_channel_id' => $this->distribution_channel_id,
            'product_id' => $activity_info->product_id,
            'activity_id' => $activity_info->id,
            'fromtype' => 'crm',
            'pay_redirect_url' => $default_url . 'person',
            'limit' => 100,
            'crm'=>$crm
        ];
        $product_info = ProductService::getProductSingle($activity_info->product_id);
        $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
        $fee = $product_info->price * 100 + $product_info->given;
        return view('crm.crmActivity', ['url' => $url, 'img' => $img['button'], 'fee' => $fee]);
    }


    public function huaweiActivity(Request $request)
    {
        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
        $activity_id = redisEnv('HUAWEI_ACTIVITY_ID', 0);
        $activity_info = ActivityService::getById($activity_id);
        if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting)) {
            $from = $request->input('fromtype', 'main');
            $display_dialog = $request->input('display_dialog', 'none');
            $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
            $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
            $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
            $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
            if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
                Redis::sadd($uv_key, $this->uid);
                Redis::hincrby($pv_key, date('Y-m-d'), 1);
                $products = explode(',', $activity_info->setting);
                $url = [];
                $request_param = $request->except('_url');
                $request_param['display_dialog'] = 'block';
                $count_info = DB::table('huaweilottery_user_counts')->where('uid', $this->uid)->select('count')->first();
                $count = 0;
                if ($count_info && $count_info->count) {
                    $count = $count_info->count;
                }
                $default_url = env('H5_SCHEME', 'https') . '://site' . $this->en_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com';
                foreach ($products as $v) {
                    $param = [
                        'uid' => $this->uid,
                        'distribution_channel_id' => $this->distribution_channel_id,
                        'product_id' => $v,
                        'activity_id' => $activity_info->id,
                        'fromtype' => $from,
                        'pay_redirect_url' => $default_url . '/activity/huaweiActivity?' . http_build_query($request_param),
                        'limit' => 100,
                    ];
                    $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
                }
                return view('pay.activity.huaweiActivity', ['url' => $url, 'code' => 0, 'display_dialog' => $display_dialog, 'count' => $count, 'end_time' => date('n月d日',strtotime($activity_info->end_time))]);
            } else if (time() <= strtotime($activity_info->start_time)) {
                return view('pay.activity.huaweiActivity', ['url' => [], 'code' => 1, 'display_dialog' => 'none', 'count' => 0, 'end_time' => date('n月d日',strtotime($activity_info->end_time))]);
            } else {
                return view('pay.activity.huaweiActivity', ['url' => [], 'code' => 2, 'display_dialog' => 'none', 'count' => 0, 'end_time' => date('n月d日',strtotime($activity_info->end_time))]);
            }
        }
        $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
        return redirect()->to($default_url);
    }

    //端午活动
    public function ragonBoatActivity(Request $request)
    {
        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
        $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
        $token = $request->input('token');
        if (!$token) {
            return redirect()->to($default_url);
        }
        $activity_info = ActivityService::getByToken($token);
        if (!$activity_info) {
            return redirect()->to($default_url);
        }
        $from = $request->input('fromtype', 'main');
        $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
        $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
        $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
        $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);

        $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
        if ($request->input('redirect_url')) {
            $redirect_url = $request->input('redirect_url');
            $redirect_url = urldecode($redirect_url);
        }
        //$product_id = $activity_info->product_id;
        if (in_array($this->distribution_channel_id, [123, 211, 146, 155, 255, 256, 691, 722, 4364, 4427, 695, 4174, 4025, 4593, 4426, 4889, 4891, 4742, 4053, 4334, 4487, 5611, 6122, 6123, 6124, 8, 5, 160, 4236, 4237, 4241, 273, 148, 266, 202, 271])) {
            if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
                Redis::sadd($uv_key, $this->uid);
                Redis::hincrby($pv_key, date('Y-m-d'), 1);
                $url = [];
                $product_ids = [6172, 6173, 6174];
                foreach ($product_ids as $item) {
                    $param = [
                        'uid' => $this->uid,
                        'distribution_channel_id' => $this->distribution_channel_id,
                        'product_id' => $item,
                        'activity_id' => $activity_info->id,
                        'fromtype' => $from,
                        'pay_redirect_url' => $redirect_url,
                        'limit' => 100,
                    ];
                    $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
                }
                return view('pay.activity.ragonBoatInnerActivity', ['url' => $url, 'code' => 0]);
            } elseif (time() <= strtotime($activity_info->start_time)) {
                return view('pay.activity.ragonBoatInnerActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)', 'javascript:void(0)'], 'code' => 1]);
            } else {
                return view('pay.activity.ragonBoatInnerActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)', 'javascript:void(0)'], 'code' => 2]);
            }
        } else {
            if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
                Redis::sadd($uv_key, $this->uid);
                Redis::hincrby($pv_key, date('Y-m-d'), 1);
                $url = [];
                $product_ids = [6191, 6192];
                foreach ($product_ids as $item) {
                    $param = [
                        'uid' => $this->uid,
                        'distribution_channel_id' => $this->distribution_channel_id,
                        'product_id' => $item,
                        'activity_id' => $activity_info->id,
                        'fromtype' => $from,
                        'pay_redirect_url' => $redirect_url,
                        'limit' => 100
                    ];
                    $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
                }
                return view('pay.activity.ragonBoatActivity', ['url' => $url, 'code' => 0]);
            } elseif (time() <= strtotime($activity_info->start_time)) {
                return view('pay.activity.ragonBoatActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => 1]);
            } else {
                return view('pay.activity.ragonBoatActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)'], 'code' => 2]);
            }
        }
    }

    public function huaweiLotteryView()
    {
        $count_info = DB::table('huaweilottery_user_counts')->where('uid', $this->uid)->select('count')->first();
        $total = DB::table('huaweilottery_record')->sum('price');
        $left_total = 5000000 - ($total ? $total : 0);
        $count = 0;
        if ($count_info && $count_info->count) {
            $count = $count_info->count;
        }
        $activity_id = redisEnv('HUAWEI_ACTIVITY_ID', 0);

        $activity_info = ActivityService::getById($activity_id);
        \Log::info($activity_info);
        if (!$activity_info) {
            $diff = 0;
        } else {
            $diff = strtotime($activity_info->end_time) - time();
            $diff = $diff > 0 ? $diff : 0;
        }
        $list = DB::table('huaweilottery_record')
            ->where('uid', $this->uid)
            ->where('price', '>', 0)
            ->select('created_at', 'price')
            ->get();
        return view('pay.activity.huaweiLottery', ['count' => $count, 'time_diff' => $diff, 'list' => $list, 'total' => $left_total]);
    }

    public function huaweiLottery()
    {
        $count_info = DB::table('huaweilottery_user_counts')->where('uid', $this->uid)->select('count')->first();
        $rest_count = 0;
        if ($count_info && $count_info->count) {
            $rest_count = $count_info->count;
        }
        $count = random_int(6, 10);
        if ($rest_count <= 0) {
            //Log::info('--------------------------');
            return response()->success(['rotate' => 20 + 45 * 2 + 360 * $count]);
        }


        DB::table('huaweilottery_user_counts')->where('uid', $this->uid)->update([
            'count' => $rest_count - 1,
            'updated_at' => date('Y-m-d H:i:s')
        ]);

        $code = random_int(1, 1000);
        if ($code <= 20) {
            //Log::info('00000000000000000000000');
            // 1000书币
            $point = 20 + 45 * 7;
            $price = 1000;
        } elseif ($code <= 200) {
            //100
            $point = 20 + 45;
            $price = 100;
            //Log::info('11111111111111111111');
        } elseif ($code <= 700) {
            //50
            $point = 20 + 45 * 3;
            $price = 50;
            //Log::info('2222222222222222222222222');
        } else {
            $point = 20 + 45 * 2;
            $price = 0;
            //Log::info('333333333333333333333333');
        }
        $rotate = $point + 360 * $count;
        if ($price > 0) {
            UserService::addBalance($this->uid, $price, 0, $price);
        }
        DB::table('huaweilottery_record')->insert([
            'uid' => $this->uid,
            'price' => $price,
            'created_at' => date('Y-m-d H:i:s'),
            'updated_at' => date('Y-m-d H:i:s'),
        ]);
        return response()->success(compact('rotate', 'price'));
    }

    public function summerHoliday(Request $request)
    {

        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
        //$encode_distribution_channel_id = 2;
        /*$sites = env('YEAR_ACTIVITY_CHANNEL', '');
        $not_access_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
        if (empty($sites)) {
            return redirect()->to($not_access_url);
        }
        $site_arr = explode(',', $sites);
        if (!in_array($this->distribution_channel_id, $site_arr)) {
            return redirect()->to($not_access_url);
        }*/
        $token = $request->input('token');
        $activity_info = ActivityService::getByToken($token);
        if (!$activity_info) {
            $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
            return redirect()->to($default_url);
        }

        $from = $request->get('fromtype', 'main');
        $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
        $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
        $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
        $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);
        Redis::sadd($uv_key, $this->uid);
        Redis::hincrby($pv_key, date('Y-m-d'), 1);
        $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
        if ($request->input('redirect_url')) {
            $redirect_url = $request->input('redirect_url');
            $redirect_url = urldecode($redirect_url);
        }

        //$product_ids = [6621, 6622,6623];
        $imgs = [
            'page_bd_img'=>'https://cdn-novel.iycdm.com/h5/activity-2019-07-25/bg.jpg',
            'page_btn_pre_img'=>'https://cdn-novel.iycdm.com/h5/activity-2019-07-25/undone.png',
            'page_btn_doing_img'=>'https://cdn-novel.iycdm.com/h5/activity-2019-07-25/doing.png',
            'page_btn_end_img'=>'https://cdn-novel.iycdm.com/h5/activity-2019-07-25/over.png'
        ];
        //未开始
        if (time() < strtotime($activity_info->start_time)) {
            //return view('pay.activity.summerHoliday', ['url' => ['javascript:void(0)', 'javascript:void(0)','javascript:void(0)'], 'code' => -1]);
            return view('pay.order.common', ['url' => [], 'code' => 1, 'img' => $imgs]);
        }
        //结束
        if (time() > strtotime($activity_info->end_time)) {
            //return view('pay.order.common', ['url' => [], 'code' => 2, 'img' => $imgs]);
            return view('pay.activity.summerHoliday', ['url' => ['javascript:void(0)', 'javascript:void(0)','javascript:void(0)'], 'code' => -2]);
        }
        /*$url = [];
        foreach ($product_ids as $product_id) {
            $param = [
                'uid' => $this->uid,
                'distribution_channel_id' => $this->distribution_channel_id,
                'product_id' => $product_id,
                'activity_id' => $activity_info->id,
                'fromtype' => $from,
                'pay_redirect_url' => $redirect_url,
                'limit' => 100
            ];
            $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
        }*/
        $param = [
            'uid' => $this->uid,
            'distribution_channel_id' => $this->distribution_channel_id,
            'product_id' => $activity_info->product_id,
            'activity_id' => $activity_info->id,
            'fromtype' => $from,
            'pay_redirect_url' => $redirect_url,
            'limit' => 100,
        ];
        $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
        return view('pay.order.common', ['url' => $url, 'code' => 0, 'img' => $imgs]);
        //return view('pay.activity.summerHoliday', ['url' => $url, 'code' => 0]);
    }

    public function crmYearActivity(Request $request)
    {
        $default_url = env('H5_SCHEME', 'https') . '://site' . $this->en_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';

        $activity_info = ActivityService::getById(11378);
        if (!$activity_info) {
            return redirect()->to($default_url);
        }
        $crm = $request->get('crm', 'crm_year_activity' );

        $param = [
            'uid' => $this->uid,
            'distribution_channel_id' => $this->distribution_channel_id,
            'product_id' => $activity_info->product_id,
            'activity_id' => $activity_info->id,
            'fromtype' => 'crm',
            'pay_redirect_url' => $default_url . 'person',
            'limit' => 100,
            'crm'=>$crm
        ];

        $url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
        $is_get = 0;
        $discount_coupon = DB::table('discount_coupons')->where('uid', $this->uid)->where('activity_id', $activity_info->id)->count();
        if($discount_coupon){
            $is_get = 1;
        }else{
            DB::table('discount_coupons')->insert([
                'uid' => $this->uid,
                'activity_id' => $activity_info->id,
                'created_at' => date('Y-m-d H:i:s'),
                'updated_at' => date('Y-m-d H:i:s')
            ]);
        }
        return view('crm.crmYearActivity', ['url' => $url,'is_get'=>$is_get]);
    }

    /**
     * @return string
     */
    public function nationDayActivity(Request $request)
    {
        $encode_distribution_channel_id = encodeDistributionChannelId($this->distribution_channel_id);
        $token = $request->input('token');
        $activity_info = ActivityService::getByToken($token);
        if ($activity_info && isset($activity_info->setting) && empty(!$activity_info->setting)) {
            $is_show_year_order = in_array($this->distribution_channel_id,[123,211,4326,4556,5204,6929,146,155,255,256,691,722,4364,4427,4488,695,4174,4025,4593,4426,4889,4891,4742,4053,4334,4487,5611,6122,6123,6124,8,5,160,4236,4237,4241,6987,148,202,266,271,273,6985]) ?1:0;
            $imgs = json_decode($activity_info->setting, 1);
            $from = $request->input('fromtype', 'main');
            $uv_key_format = 'activity:%s:distribution_channel_id:%s:date:%s:uv';
            $pv_key_format = 'activity:%s:distribution_channel_id:%s:pv';
            $uv_key = sprintf($uv_key_format, $activity_info->id, $this->distribution_channel_id, date('Y-m-d'));
            $pv_key = sprintf($pv_key_format, $activity_info->id, $this->distribution_channel_id);

            $redirect_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/person';
            if ($request->input('redirect_url')) {
                $redirect_url = $request->input('redirect_url');
                $redirect_url = urldecode($redirect_url);
            }
            if (time() > strtotime($activity_info->start_time) && time() < strtotime($activity_info->end_time)) {
                Redis::sadd($uv_key, $this->uid);
                Redis::hincrby($pv_key, date('Y-m-d'), 1);
                $product_ids = explode(',',$activity_info->setting);
                $param = [
                    'uid' => $this->uid,
                    'distribution_channel_id' => $this->distribution_channel_id,
                    //'product_id' => $activity_info->product_id,
                    'activity_id' => $activity_info->id,
                    'fromtype' => $from,
                    'pay_redirect_url' => $redirect_url,
                    'limit' => 100,
                ];
                $url = [];
                foreach ($product_ids as $product_id)  {
                    $param['product_id'] = $product_id;
                    $url[] = env('CREATE_PAY_URL') . '?' . http_build_query($param);
                }
                //$url = env('CREATE_PAY_URL') . '?' . http_build_query($param);
                return view('pay.activity.wapnationDayActivity', ['url' => $url, 'code' => 0,'is_show_year_order'=>$is_show_year_order]);
            } else if (time() <= strtotime($activity_info->start_time)) {
                return view('pay.activity.wapnationDayActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)', 'javascript:void(0)'], 'code' => 1,'is_show_year_order'=>$is_show_year_order]);
            } else {
                return view('pay.activity.wapnationDayActivity', ['url' => ['javascript:void(0)', 'javascript:void(0)', 'javascript:void(0)'], 'code' => 2,'is_show_year_order'=>$is_show_year_order]);
            }
        }
        $default_url = env('H5_SCHEME', 'https') . '://site' . $encode_distribution_channel_id . '.' . env('CUSTOM_HOST') . '.com/';
        return redirect()->to($default_url);
    }
}
