Update
parent
84bb61ec7c
commit
83281649fb
|
|
@ -2,8 +2,13 @@
|
|||
|
||||
namespace App\Http\Controllers\Callback;
|
||||
|
||||
use App\Enums\DeviceStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Device;
|
||||
use App\Models\DeviceLog;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class YunFeiController extends Controller
|
||||
{
|
||||
|
|
@ -1043,18 +1048,111 @@ class YunFeiController extends Controller
|
|||
'1066' => '星天牛',
|
||||
];
|
||||
|
||||
/**
|
||||
* 杀虫灯回调通知
|
||||
*/
|
||||
public function insecticidalLampNotify(Request $request)
|
||||
{
|
||||
logger('杀虫灯通知', $request->input());
|
||||
logger()->debug('杀虫灯回调通知', $request->input());
|
||||
|
||||
$payload = $request->input('payload');
|
||||
|
||||
if (! isset($payload['ext'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$device = Device::supplierBy('device-supplier-yunfei')->find($payload['ext']['imei']);
|
||||
|
||||
if ($device === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! in_array($device->status, [DeviceStatus::Online, DeviceStatus::Offline])) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($payload['cmd']) {
|
||||
case 'data':
|
||||
$device->update([
|
||||
'status' => DeviceStatus::Online,
|
||||
]);
|
||||
|
||||
DeviceLog::firstOrCreate([
|
||||
'device_id' => $device->id,
|
||||
'reported_at' => Carbon::createFromFormat('YmdHis', $payload['ext']['stamp']),
|
||||
], [
|
||||
'data' => $payload['ext'],
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'offline':
|
||||
$device->update([
|
||||
'status' => DeviceStatus::Offline,
|
||||
]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测报灯回调通知
|
||||
*/
|
||||
public function wormNotify(Request $request)
|
||||
{
|
||||
logger('虫情设备通知', $request->input());
|
||||
logger()->debug('虫情设备回调通知', $request->input());
|
||||
|
||||
$payload = $request->input('payload');
|
||||
|
||||
if (! isset($payload['ext'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$device = Device::supplierBy('device-supplier-yunfei')->find($payload['ext']['imei']);
|
||||
|
||||
if ($device === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! in_array($device->status, [DeviceStatus::Online, DeviceStatus::Offline])) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($payload['cmd']) {
|
||||
case 'data':
|
||||
$device->update([
|
||||
'status' => DeviceStatus::Online,
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'offline':
|
||||
$device->update([
|
||||
'status' => DeviceStatus::Offline,
|
||||
]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测报灯照片回调通知
|
||||
*/
|
||||
public function wormPhotoNotify(Request $request)
|
||||
{
|
||||
logger('虫情图片通知', $request->input());
|
||||
logger()->debug('虫情图片通知', $request->input());
|
||||
|
||||
$device = Device::supplierBy('device-supplier-yunfei')->find($request->input('imei'));
|
||||
|
||||
if ($device === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! in_array($device->status, [DeviceStatus::Online, DeviceStatus::Offline])) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeviceLog::firstOrCreate([
|
||||
'device_id' => $device->id,
|
||||
'reported_at' => now(),
|
||||
], [
|
||||
'data' => $request->input(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue