Compare commits

..

5 Commits

Author SHA1 Message Date
zmj d751c4cfe7 fixes 2024-03-06 18:57:11 +08:00
zmj 2474758907 fixed 2024-03-06 18:25:44 +08:00
chenbo 2083bf58ef fixed 2024-02-27 10:08:42 +08:00
chenbo e9ad4bc757 fixed 2024-02-23 14:11:05 +08:00
chenbo 3b356f0617 fixed 2024-02-22 16:32:03 +08:00
4 changed files with 25 additions and 14 deletions

View File

@ -26,18 +26,18 @@ class DataCollectController extends BaseApiController
if(!$parmas || !isset($parmas['username']) || $parmas['username']==''){
return $this->fail('参数错误');
}
$user = User::where('account', $parmas['username'])->find();
$device = explode('_', $parmas['topic']); // 命名规则camera_deviceid deviceid为设备主键id
$deviceId = $device[1]; // 设备id
$productDevice = ProductDevice::where('device_id', $deviceId)->find();
$landProduct = LandProduct::where('product_id', $productDevice['product_id'])->find();
$landId = $landProduct['land_id']; // 土地id
// mqtt服务端 消息发布事件
if ($parmas['event'] == 'message.publish') {
$payload= json_decode($parmas['payload'], true);
$user = User::where('account', $parmas['username'])->find();
$device = explode('_', $parmas['topic']); // 命名规则camera_deviceid deviceid为设备主键id
$deviceId = $device[1]; // 设备id
$productDevice = ProductDevice::where('device_id', $deviceId)->find();
$landProduct = LandProduct::where('product_id', $productDevice['product_id'])->find();
$landId = $landProduct['land_id']; // 土地id
$data = [
'user_id' => $user['id'],
'land_id' => $landId,
@ -176,7 +176,15 @@ class DataCollectController extends BaseApiController
// mqtt服务端 连接断开事件 客户端断开表示该土块的所有设备都已断开 共用同一个mqtt客户端
if ($parmas['event'] == 'client.disconnected') {
// lihai_lot_walnutpi_dev_6 clientid 命名规则
$device = strstr($parmas['clientid'], 'dev_');
$device = explode('_', $device);
$deviceId = $device[1]; // 设备id
$productDevice = ProductDevice::where('device_id', $deviceId)->find();
$landProduct = LandProduct::where('product_id', $productDevice['product_id'])->find();
$landId = $landProduct['land_id']; // 土地id
// 查询该土地关联的设备
$addData = [
'land_id' => $landId,
@ -192,6 +200,10 @@ class DataCollectController extends BaseApiController
}
// 连接链接事件 设备已上线
if ($parmas['event'] == 'client.connected') {
// lihai_lot_walnutpi_dev_6 clientid 命名规则
$device = strstr($parmas['clientid'], 'dev_');
$device = explode('_', $device);
$deviceId = $device[1]; // 设备id
Device::where('id', $deviceId)->update(['is_online' => 1]);
return $this->success('接收成功');
}
@ -205,7 +217,7 @@ class DataCollectController extends BaseApiController
public static function createAlarm($user_id, $device_id, $type, $content, $value)
{
$data = [
'user_id' => $user_id,
'land_id' => $user_id,
'device_id' => $device_id,
'type' => $type,
'content' => $content,

View File

@ -155,9 +155,9 @@ class IndexController extends BaseApiController
if($plantInfo->isEmpty()){
return $this->fail('种植信息错误');
}
if($plantInfo['status'] != 2){
return $this->fail('种植信息状态错误');
}
// if($plantInfo['status'] != 2){
// return $this->fail('种植信息状态错误');
// }
$landInfo = Land::where('id',$plantInfo['land_id'])->findOrEmpty();
if($landInfo->isEmpty()){
return $this->fail('土地信息错误');

View File

@ -49,7 +49,6 @@ class DeviceController extends BaseApiController
}
}
})
->whereWeek('ma.create_time')
->order('ma.id', 'desc')
->limit(100)
->select();

View File

@ -44,7 +44,7 @@ class LandController extends BaseApiController
// 溯源产品统计
public function plantProductCount()
{
$list = LandPlant::alias('lp')->join('land l', 'l.id=lp.land_id')->field('lp.kind,lp.qr_code')
$list = LandPlant::alias('lp')->join('land l', 'l.id=lp.land_id')->field('lp.id,lp.kind,lp.qr_code')
->where(function ($query) {
if ($this->streetCode != '') {
$query->where('l.town_code', $this->streetCode);