<?php

namespace Modules\Channel\Http\Controllers;

use Catch\Base\CatchController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class CompanyUserController extends CatchController
{
    /**
     * 商户列表
     * @param Request $request
     */
    public function list(Request $request) {
        $username = $request->input('username');
        return DB::table('users')
            ->join('user_has_roles','users.id', 'user_has_roles.user_id')
            ->when($username, function ($query, $username){
                return $query->where('users.username', 'like', '%'. $username. '%');
            })
            ->where([
                'user_has_roles.role_id' => 1,
                'users.status' => 1,
                'users.deleted_at' => 0
            ])->select('users.username', 'users.id')
            ->get();
    }
}
