Example #1
0
 /**
  * 设备列表
  * @author Hanxiang
  */
 public function index()
 {
     // get devices by status
     $input = Input::all();
     if (!isset($input['status']) || $input['status'] == -1) {
         $devices = Device::where('status', '>=', 0);
         //->paginate(15);
         $status = -1;
     } else {
         $status = $input['status'];
         $devices = Device::where('status', $status);
         //->paginate(15);
     }
     if (isset($input['app_id']) && !empty($input['app_id'])) {
         $app_id = $input['app_id'];
         $device_ids = [];
         $device_apps = DeviceApp::where('app_id', $app_id)->get()->toArray();
         foreach ($device_apps as $da) {
             array_push($device_ids, $da['device_id']);
         }
         $devices = $devices->whereIn('id', $device_ids);
     }
     if (isset($input['sn']) && !empty($input['sn'])) {
         $devices = $devices->where('sn', 'like', '%' . $input['sn'] . '%');
     }
     if (isset($input['uuid']) && !empty($input['uuid'])) {
         $devices = $devices->where('uuid', 'like', '%' . $input['uuid'] . '%');
     }
     if (isset($input['major']) && !empty($input['major'])) {
         $devices = $devices->where('major', $input['major']);
     }
     if (isset($input['minor']) && !empty($input['minor'])) {
         $devices = $devices->where('minor', $input['minor']);
     }
     if (isset($input['date_from']) && !empty($input['date_from'])) {
         $devices = $devices->where('created_at', '>', self::convtDate($input['date_from']));
     }
     if (isset($input['date_to']) && !empty($input['date_to'])) {
         $devices = $devices->where('created_at', '<', self::convtDate($input['date_to'], false));
     }
     $devices = $devices->orderBy('updated_at', 'desc')->get();
     //->paginate(15);
     foreach ($devices as $device) {
         $device->status_cn = Device::$status[$device->status];
         if ($device->status > 0) {
             $deviceApp = DeviceApp::where("device_id", $device->id)->first();
             if ($deviceApp) {
                 $device->app = DeviceApp::find($deviceApp->id)->app;
             } else {
                 $app_empty = new \stdClass();
                 $app_empty->name = '';
                 $device->app = $app_empty;
             }
         }
     }
     $manufacturers = Manufacturer::getAllWithModels();
     // get all apps
     $apps = App::all();
     return view('admin.devices')->with('devices', $devices)->with('status', $status)->with('apps', $apps)->with('manufacturers', $manufacturers);
 }
Example #2
0
 public function index()
 {
     $user = Auth::user();
     if ($user->role == User::ROLE_ADMIN) {
         $devicesCount = Device::all()->count();
         $wxDevicesCount = WeixinDevice::all()->count();
         $appsCount = App::all()->count();
         $wxPagesCount = WeixinPage::all()->count();
     } else {
         $apps = App::where('user_id', $user->id)->lists('id');
         $devicesCount = DeviceApp::whereIn('app_id', $apps)->count();
         $mps = WeixinMp::whereIn('app_id', $apps)->lists('id');
         $wxDevicesCount = WeixinDevice::whereIn('wx_mp_id', $mps)->count();
         $appsCount = count($apps);
         $wxPagesCount = WeixinPage::whereIn('wx_mp_id', $mps)->count();
     }
     return view('admin.index')->with('devicesCount', $devicesCount)->with('wxDevicesCount', $wxDevicesCount)->with('appsCount', $appsCount)->with('wxPagesCount', $wxPagesCount);
 }
Example #3
0
 public function getApps()
 {
     return App::all();
 }