|
@@ -4,12 +4,12 @@ namespace App\Service;
|
|
|
|
|
|
use App\Model\Device;
|
|
|
use App\Model\DeviceType;
|
|
|
-use App\Model\Gateway;
|
|
|
use App\Model\Screen;
|
|
|
use App\Model\ScreenDevice;
|
|
|
use App\Model\ScreenGateway;
|
|
|
use App\Model\SystemL;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
class ScreenService extends Service
|
|
|
{
|
|
@@ -28,6 +28,7 @@ class ScreenService extends Service
|
|
|
$model->remark = $data['remark'];
|
|
|
$model->address = $data['address'] ?? '';
|
|
|
$model->coordinate = $data['coordinate'] ?? '';
|
|
|
+ $model->img = $data['img'] ?? "";
|
|
|
$model->save();
|
|
|
|
|
|
ScreenGateway::where('screen_id',$data['id'])->update(['del_time' => time()]);
|
|
@@ -67,6 +68,7 @@ class ScreenService extends Service
|
|
|
$model->remark = $data['remark'];
|
|
|
$model->address = $data['address'] ?? '';
|
|
|
$model->coordinate = $data['coordinate'] ?? '';
|
|
|
+ $model->img = $data['img'] ?? "";
|
|
|
$model->save();
|
|
|
|
|
|
if(isset($data['gateway_id'])){
|
|
@@ -383,4 +385,66 @@ class ScreenService extends Service
|
|
|
|
|
|
return $data;
|
|
|
}
|
|
|
+
|
|
|
+ public function screenGps($data){
|
|
|
+ if(empty($data['screen_id'])) return [false,'请选择仓'];
|
|
|
+
|
|
|
+ //gps类
|
|
|
+ $gps = ScreenDevice::from('screen_device as a')
|
|
|
+ ->leftJoin('device as b','b.id','a.device_id')
|
|
|
+ ->where('b.device_type_id',4)
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->select('b.code')
|
|
|
+ ->first();
|
|
|
+ if(empty($gps)) return [true,''];
|
|
|
+ $gps = $gps->toArray();
|
|
|
+
|
|
|
+ $sys_data = SystemL::where('device_no',$gps['code'])
|
|
|
+ ->orderBy('id','desc')
|
|
|
+ ->select('value')
|
|
|
+ ->first();
|
|
|
+ if(empty($sys_data)) return [true,''];
|
|
|
+ $location = $sys_data->value;//经纬度
|
|
|
+ $url = 'https://restapi.amap.com/v3/geocode/regeo?location='.$location.'&key='.SystemL::GaoDeMapKey;
|
|
|
+ try{
|
|
|
+ $return = $this->curlOpen($url);
|
|
|
+ $return = json_decode($return,true);
|
|
|
+ if(empty($return['status'])) return [false,'定位失败'];
|
|
|
+
|
|
|
+ $position = $return['regeocode']['addressComponent'] ?? [];
|
|
|
+ $result = [
|
|
|
+ 'province' => $position['province'] ?? '',
|
|
|
+ 'city' => $position['city'] ?? '',
|
|
|
+ 'district' => $position['district'] ?? '',
|
|
|
+ 'location' => $location
|
|
|
+ ];
|
|
|
+ return [true, $result];
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ return [false,$exception->getMessage()];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function uploadScreenFile($file){
|
|
|
+ // 获取文件相关信息
|
|
|
+ $ext = $file->getClientOriginalExtension(); // 扩展名
|
|
|
+ $realPath = $file->getRealPath(); //临时文件的绝对路径
|
|
|
+
|
|
|
+ $ext = strtolower($ext);
|
|
|
+ if (!in_array($ext, Screen::FILE_TYPE)){
|
|
|
+ $str = '文件格式为:';
|
|
|
+ foreach (Screen::FILE_TYPE as $value){
|
|
|
+ $str.= $value . ' ' ;
|
|
|
+ }
|
|
|
+ return [false,$str];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传文件
|
|
|
+ $file_name = time().rand(1000,9999);
|
|
|
+ $filename = $file_name.'.' . $ext;
|
|
|
+ // 使用我们新建的uploads本地存储空间(目录)
|
|
|
+ Storage::disk('public')->put('screen/'.$filename, file_get_contents($realPath));
|
|
|
+
|
|
|
+ return [true, '/api/screen/'.$file_name];
|
|
|
+ }
|
|
|
}
|