<?php

namespace App\Http\Controllers\Channel\Channel;

use App\Http\Controllers\Channel\BaseController;
use App\Modules\Channel\Services\ChannelService;
use App\Http\Controllers\Channel\Channel\Transformers\ChannelTransformer;
use App\Modules\Channel\Services\ChannelUserService;
use App\Modules\Finance\Services\CommissionRateService;//结算比例
use App\Modules\OfficialAccount\Services\PaySubstituteSwitchService;
use Illuminate\Http\Request;

class ChannelSwitchController extends BaseController
{
    public function getChannelPaySubstituteSwitch(Request $request) {
        $distribution_channel_id = $request->input('distribution_channel_id','');
        if(empty($distribution_channel_id)) {
            return response()->error('PARAM_EMPTY');
        }
        $switch = PaySubstituteSwitchService::getChannelSwitch($distribution_channel_id);
        $switch->status = (int)$switch->status;
        return response()->success($switch);
    }

    public function setChannelPaySubstituteSwitch(Request $request) {
        $distribution_channel_id = $request->input('distribution_channel_id','');
        $switch = $request->input('switch','');
        if(empty($distribution_channel_id)) {
            return response()->error('PARAM_EMPTY');
        }
        if(!in_array($switch,['1','0',1,0])){
            return response()->error('PARAM_ERROR');
        }
        $switch = PaySubstituteSwitchService::setChannelSwitch($distribution_channel_id,$switch);
        $switch->status = (int)$switch->status;
        return response()->success($switch);
    }
}