示例#1
0
 /**
  * 获取所有厂商,附带型号
  * @author Hanxiang
  */
 public static function getAllWithModels()
 {
     $manufacturers = self::all();
     if (count($manufacturers) > 0) {
         foreach ($manufacturers as $man) {
             $deviceModels = DeviceModel::where('manufacturer_id', $man->id)->get();
             $man->models = $deviceModels;
         }
         return $manufacturers;
     } else {
         // TODO
         $m = new \stdClass();
         $m->id = '';
         $m->name = '';
         $model = new \stdClass();
         $model->id = '';
         $model->name = '';
         $model->manufacturer_sn = '';
         $model->created_at = '';
         $model->battery_lifetime = '';
         $model->default_password = '';
         $m->models = [0 => $model];
         return [0 => $m];
     }
 }
示例#2
0
 public function getDeviceModelById($id)
 {
     return DeviceModel::where('id', $id)->first();
 }
示例#3
0
 /**
  * 获取厂商数据ajax
  * @author Hanxiang
  */
 public function manufacturersAjax()
 {
     $input = Input::only('id');
     $manufacturers = Manufacturer::find($input['id']);
     if (!$manufacturers) {
         return response()->json(['mans' => [], 'models' => []]);
     }
     $models = DeviceModel::where('manufacturer_id', $input['id'])->get();
     if (count($models) > 0) {
         foreach ($models as $model) {
             $batteryOutDate = date("m/d/Y", strtotime($model->created_at) + (int) $model->battery_lifetime * 2952000);
             $model->battery_outdate = $batteryOutDate;
             $model->generated_at = self::reconvtDate(date($model->created_at));
         }
     } else {
         $models = new \stdClass();
     }
     $manufacturers->models = $models;
     return response()->json($manufacturers);
 }