コード例 #1
0
ファイル: HomeController.php プロジェクト: hachi-zzq/dajiayao
 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);
 }
コード例 #2
0
 /**
  * 获取第一个可用的微信设备
  * @author Hanxiang
  */
 private static function getFirstAvailableWxDevice()
 {
     $wxdevices = WeixinDevice::all();
     if (count($wxdevices) > 0) {
         foreach ($wxdevices as $wx) {
             $wx->sn = Device::where("wx_device_id", $wx->id)->get();
         }
     }
     $usedWxDeviceIDs = Device::where("wx_device_id", ">", 0)->get(['wx_device_id']);
     $usedIDArray = [];
     if (count($usedWxDeviceIDs) > 0) {
         foreach ($usedWxDeviceIDs as $usedID) {
             array_push($usedIDArray, $usedID['wx_device_id']);
         }
     }
     $firstWxDevice = WeixinDevice::whereNotIn('id', $usedIDArray)->first();
     if (count($firstWxDevice) > 0) {
         $firstWxDevice = $firstWxDevice->toArray();
     } else {
         $firstWxDevice = [];
     }
     return $firstWxDevice;
 }