122 lines
3.1 KiB
PHP
122 lines
3.1 KiB
PHP
<?php
|
|
|
|
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\Carbon;
|
|
|
|
class YunFeiController extends Controller
|
|
{
|
|
/**
|
|
* 杀虫灯回调通知
|
|
*/
|
|
public function insecticidalLampNotify(Request $request)
|
|
{
|
|
logger()->debug('杀虫灯回调通知', $request->input());
|
|
|
|
$payload = $request->input('payload');
|
|
|
|
if (! isset($payload['ext'])) {
|
|
return;
|
|
}
|
|
|
|
$device = Device::supplierBy('device-supplier-yunfei')->where('sn', $payload['ext']['imei'])->first();
|
|
|
|
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()->debug('虫情设备回调通知', $request->input());
|
|
|
|
$payload = $request->input('payload');
|
|
|
|
if (! isset($payload['ext'])) {
|
|
return;
|
|
}
|
|
|
|
$device = Device::supplierBy('device-supplier-yunfei')->where('sn', $payload['ext']['imei'])->first();
|
|
|
|
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()->debug('虫情图片通知', $request->input());
|
|
|
|
$device = Device::supplierBy('device-supplier-yunfei')->where('sn', $request->input('imei'))->first();
|
|
|
|
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(),
|
|
]);
|
|
}
|
|
}
|