suyuan/app/api/controller/dataview/LandController.php

58 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace app\api\controller\dataview;
use app\api\controller\BaseApiController;
use app\common\model\land\LandPlant;
use app\common\model\LandCollection;
use think\exception\ValidateException;
class LandController extends BaseApiController
{
public array $notNeedLogin = ['plantProductCount', 'landCollectionList'];
public $areaCode;
public $streetCode;
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 plantProductCount()
{
$list = LandPlant::alias('lp')->join('land l', 'l.id=lp.land_id')->field('lp.kind,lp.qr_code')
->where(function ($query) {
if ($this->streetCode != '') {
$query->where('l.town_code', $this->streetCode);
} else {
$query->where('l.county_code', $this->areaCode);
}
})->limit(30)->select();
return $this->success('成功', compact('list'));
}
// 智能预警数据
public function landCollectionList()
{
$list = LandCollection::alias('lc')
->field('lc.*,l.title')
->join('land l', 'l.id=lc.land_id')
->where(function ($query) {
if ($this->streetCode != '') {
$query->where('l.town_code', $this->streetCode);
} else {
$query->where('l.county_code', $this->areaCode);
}
})->limit(30)->select();
return $this->success('成功', compact('list'));
}
}