基地经纬度

This commit is contained in:
chenbo 2024-02-03 16:01:29 +08:00
parent fb491ecf75
commit 4e0884678d
2 changed files with 90 additions and 2 deletions

View File

@ -55,7 +55,7 @@ class FarmLogic extends BaseLogic
'village' => $params['village'], 'village' => $params['village'],
'bridge' => $params['bridge'], 'bridge' => $params['bridge'],
'address' => $params['address'], 'address' => $params['address'],
'image' => $params['image'], 'pic' => $params['pic'],
'longitude' => $params['longitude'], 'longitude' => $params['longitude'],
'latitude' => $params['latitude'], 'latitude' => $params['latitude'],
]); ]);
@ -95,7 +95,7 @@ class FarmLogic extends BaseLogic
'village' => $params['village'], 'village' => $params['village'],
'bridge' => $params['bridge'], 'bridge' => $params['bridge'],
'address' => $params['address'], 'address' => $params['address'],
'image' => $params['image'], 'pic' => $params['pic'],
'longitude' => $params['longitude'], 'longitude' => $params['longitude'],
'latitude' => $params['latitude'], 'latitude' => $params['latitude'],
]); ]);

View File

@ -0,0 +1,88 @@
<?php
namespace app\api\controller\dataview;
use app\api\controller\BaseApiController;
use app\common\model\device\Device;
use app\common\model\farm\Farm;
use app\common\model\fence_house\FenceHouse;
use app\common\model\land\Land;
use app\common\model\land\Product;
use app\common\model\product\ProductDevice;
use think\exception\ValidateException;
class FarmController extends BaseApiController
{
public array $notNeedLogin = [
'farmCount'
];
public function initialize()
{
parent::initialize();
$this->areaCode = $this->request->param('areaCode', '');
$this->streetCode = $this->request->param('streetCode', '');
if ($this->areaCode == '') {
throw new ValidateException('未获取到位置信息');
}
}
public function farmCount()
{
$query = Farm::alias('f')->where(function ($query) {
if ($this->streetCode != '') {
$query->where('f.street', $this->streetCode);
} else {
$query->where('f.area', $this->areaCode);
}
});
// 地块数量
$farmCount = $query->count();
// 养殖规模
$totalScale = $query->sum('form_scale');
// 基地列表
$farmList = $query->select()->each(function ($farm){
$fenceHouse = FenceHouse::where('farm_id', $farm['id'])->order('id desc')->findOrEmpty()->toArray();
if(empty($fenceHouse)){
$farm['video_url'] = '';
$farm['device_id'] = 0;
return $farm;
}
$product = Product::where('fence_house_id', $fenceHouse['id'])->findOrEmpty()->toArray();
if(empty($product)){
$farm['video_url'] = '';
$farm['device_id'] = 0;
return $farm;
}
$deviceIds = ProductDevice::where('product_id', $product['id'])->column('device_id');
$device = Device::whereIn('id', $deviceIds)->where('type', 2)->findOrEmpty();
if(empty($device)){
$farm['video_url'] = '';
$farm['device_id'] = 0;
return $farm;
}
$farm['video_url'] = $device['video_url'];
$farm['device_id'] = $device['id'];
return $farm;
})->toArray();
return $this->success('成功', compact('farmCount', 'totalScale', 'farmList'));
}
public function centralCount()
{
$query = Farm::alias('f')->where(function ($query) {
if ($this->streetCode != '') {
$query->where('f.town_code', $this->streetCode);
} else {
$query->where('f.county_code', $this->areaCode);
}
});
// 地块数量
$farmCount = $query->count();
// 养殖规模
$totalScale = $query->sum('form_scale');
// 养殖种类
$breedCount = $query->group('breed_type')->count();
return $this->success('成功', compact('farmCount', 'totalScale', 'breedCount'));
}
}