Ejemplo n.º 1
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;
 }