예제 #1
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);
 }
예제 #2
0
 /**
  * 处理用户扫描二维码后的操作
  * @author zhengqian@dajiayao.cc
  */
 public function urlHandler()
 {
     $inputData = \Input::only('sn');
     if (!array_key_exists('sn', $inputData)) {
         return "sn not found";
     }
     $dev = Device::getDeviceBySn($inputData['sn']);
     if (!$dev) {
         return sprintf("sn: %s not found", $inputData['sn']);
     }
     if (!($wxDevice = $dev->weixinDevice)) {
         return 'sn not bind weixin ID';
     }
     $url = $wxDevice->mp->app->device_url;
     if (!$url) {
         return $inputData['sn'];
     }
     return redirect($url);
 }
예제 #3
0
 /**
  * 设备列表
  * 设备列表
  * @param DeviceService $deviceService
  * @return $this
  * @author zhengqian@dajiayao.cc
  */
 public function index(Request $request, DeviceService $deviceService)
 {
     $inputData = $request->all();
     $arrMp = $this->mp;
     $wxDevices = WeixinDevice::whereIn('wx_mp_id', $arrMp);
     //过滤微信号
     if (isset($inputData['wx_mp_id']) && $inputData['wx_mp_id'] != 0) {
         $wxDevices = $wxDevices->where('wx_mp_id', $inputData['wx_mp_id']);
     }
     //过滤绑定条件
     if (isset($inputData['bind']) && $inputData['bind'] == 1) {
         $wxDevices = $wxDevices->whereIn('id', DB::table('device_page')->lists('wx_device_id'));
     } elseif (isset($inputData['bind']) && $inputData['bind'] == '-1') {
         $wxDevices = $wxDevices->whereNotIn('id', DB::table('device_page')->lists('wx_device_id'));
     }
     //        //过滤sn
     //        if(isset($inputData['sn']) && $inputData['sn'] != ''){
     //           $sn =  DB::table('devices')->where('sn','like',"%".$inputData['sn']."%")->lists('wx_device_id');
     //            $wxDevices = $wxDevices->whereIn('id',$sn);
     //        }
     //
     //        //过滤minor
     //        if(isset($inputData['minor']) && $inputData['minor'] != ''){
     //            $wxDevices = $wxDevices->where('minor',$inputData['minor']);
     //        }
     if (isset($inputData['kw']) && $inputData['kw'] != '') {
         $kw = $inputData['kw'];
         $ids = DB::table('devices')->where('sn', 'like', "%" . $kw . "%")->lists('wx_device_id');
         $wxDevices = $wxDevices->where(function ($query) use($kw, $ids) {
             $query->where('uuid', 'like', "%" . $kw . "%")->orwhere('device_id', 'like', "%" . $kw . "%")->orwhere('major', 'like', "%" . $kw . "%")->orwhere('minor', 'like', "%" . $kw . "%")->orwhere('comment', 'like', "%" . $kw . "%")->orwhereIn('id', $ids);
         });
     }
     $wxDevices = $wxDevices->paginate(20);
     //取得是否烧号?烧号后显示出sn
     foreach ($wxDevices as $d) {
         $d->sn = Device::where('wx_device_id', $d->id)->get();
         $d->devPage = DevicePage::where('wx_device_id', $d->id)->get()->toArray();
     }
     return view('admin.wx_device.index')->with('wx_devices', $wxDevices)->with('wx_mp_id', isset($inputData['wx_mp_id']) ? $inputData['wx_mp_id'] : 0)->with('bind', isset($inputData['bind']) ? $inputData['bind'] : 0)->with('kw', isset($inputData['kw']) ? $inputData['kw'] : '')->with('mps', $arrMp);
 }
예제 #4
0
 /**
  * 更新设备的地理位置
  * @param DeviceService $deviceService
  * @param $sn
  * @return string
  * @author zhengqian@dajiayao.cc
  */
 public function setLocation(DeviceService $deviceService, $sn)
 {
     if (!$sn) {
         return RestHelp::parametersIllegal('sn is required');
     }
     $dev = Device::getDeviceBySn($sn);
     if (!$dev) {
         return RestHelp::encodeResult(24001, sprintf("sn:%s not found", $sn));
     }
     $inputData = json_decode($this->inputData, true);
     $validator = Validator::make($inputData, ['longitude' => 'required', 'latitude' => 'required', 'address' => 'required', 'location' => 'required']);
     if ($validator->fails()) {
         return RestHelp::parametersIllegal($validator->messages()->first());
     }
     $dev->longitude = $inputData['longitude'];
     $dev->latitude = $inputData['latitude'];
     $dev->address = $inputData['address'];
     $dev->position = $inputData['position'];
     $dev->save();
     return RestHelp::success();
 }
예제 #5
0
 /**
  * 绑定页面
  * @author Hanxiang
  * @param $id
  * @return view
  */
 public function bind($id)
 {
     $wxpage = WeixinPage::find($id);
     if (!$wxpage) {
         return redirect('/admin/wxpages')->with('result', false)->with('msg', "操作失败,页面不存在");
     }
     $mp = $wxpage->mp;
     $wxDevices = WeixinDevice::where('wx_mp_id', $mp->id)->get();
     foreach ($wxDevices as $wxdvc) {
         $count = DevicePage::where('wx_device_id', $wxdvc->id)->where('wx_page_id', $id)->count();
         if ($count > 0) {
             $wxdvc->bind_status = 1;
         } else {
             $wxdvc->bind_status = 0;
         }
         $wxdvc->device = Device::where('wx_device_id', $wxdvc->id)->get();
     }
     return view('admin.wxpages.bind')->with('id', $id)->with('wxdevices', $wxDevices);
 }
예제 #6
0
 /**
  * @param PageService $pageService
  * @param ShakeAroundClient $shakeAroundClient
  * @param null $pageId
  * @return string
  */
 public function bindDevice(PageService $pageService, ShakeAroundClient $shakeAroundClient, $pageId = null)
 {
     if (!$pageId) {
         return RestHelp::parametersIllegal("sn is required");
     }
     $page = WeixinPage::find($pageId);
     if (!$page) {
         return RestHelp::encodeResult(23001, "page not found");
     }
     $requestData = json_decode($this->inputData, true);
     $pageIds = $requestData['sn'];
     if (!$pageIds or !is_array($requestData['sn'])) {
         return RestHelp::encodeResult(24002, 'sn must be arrary');
     }
     $validator = Validator::make($requestData, ['sn' => 'required', 'bind' => 'required|boolean', 'append' => 'required|boolean']);
     if ($validator->fails()) {
         return RestHelp::parametersIllegal($validator->messages()->first());
     }
     foreach ($requestData['sn'] as $k => &$v) {
         $device = Device::where('sn', $v)->first();
         if (!$device) {
             return RestHelp::encodeResult(24003, sprintf("sn %s not found", $v));
         }
         $requestData['sn'][$k] = $device->wx_device_id;
     }
     try {
         $pageService->bindDevice($shakeAroundClient, $page, $requestData['sn'], $requestData['bind'], $requestData['append']);
     } catch (\Exception $e) {
         return RestHelp::encodeResult($e->getCode(), $e->getMessage());
     }
     return RestHelp::success();
 }
예제 #7
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;
 }
예제 #8
0
 /**
  * 根据sn获取设备id
  * @param $sn
  * @author zhengqian@dajiayao.cc
  */
 public function getDeviceBySn($sn)
 {
     $dev = Device::where('sn', $sn)->first();
     if (!$dev) {
         throw new \Exception(24001, sprintf("the device sn: %s not found", $sn));
     }
     return $dev;
 }