<?php


namespace App\Http\Controllers\Admin;


use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class SysSmsConfigController
{
    public function index()
    {
        $list = DB::connection('write')->table('QPAccountsDB.dbo.SysSmsConfig as sc')
            ->leftJoin('agent.dbo.admin_users as au', 'sc.AdminID', '=', 'au.id')
            ->select('sc.*', 'au.account')
            ->get();

        return view('admin.sys_sms_config.index', compact('list'));
    }

    public function Update(Request $request, $id)
    {
        if ($request->isMethod('post')) {
            $post = $request->post();
            DB::connection('write')->table('QPAccountsDB.dbo.SysSmsConfig')
                ->where('ID', $id)
                ->update($post);
            return apiReturnSuc();
        }

        $info = DB::connection('write')->table('QPAccountsDB.dbo.SysSmsConfig')
            ->where('ID', $id)
            ->first();
        return view('admin.sys_sms_config.update', compact('info'));
    }

    // 修改状态
    public function updateStatus(Request $request, $id)
    {
        $Status = $request->statusVal;
        $adminID = session('admin')->id;

        if ($Status == 1) {
            DB::connection('write')->table('QPAccountsDB.dbo.SysSmsConfig')
                ->update(['Status' => 2]);
        } else {
            DB::connection('write')->table('QPAccountsDB.dbo.SysSmsConfig')
                ->update(['Status' => 1]);
        }

        DB::connection('write')->table('QPAccountsDB.dbo.SysSmsConfig')
            ->where('ID', $id)
            ->update(['Status' => $Status, 'AdminID' => $adminID]);
        return apiReturnSuc();
    }


    // 修改备注
    public function Remarks(Request $request, $id)
    {
        $Remarks = $request->remark;
        $adminID = session('admin')->id;
        DB::connection('write')->table('QPAccountsDB.dbo.SysSmsConfig')
            ->where('ID', $id)
            ->update(['Remarks' => $Remarks, 'AdminID' => $adminID]);
        return apiReturnSuc();
    }
}
