241 lines
8.3 KiB
PHP
241 lines
8.3 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\model\informationg\UserInformationg;
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\model\informationg\UserInformationgDemand;
|
|
use app\common\model\task\Task;
|
|
use app\common\model\task_template\TaskTemplate;
|
|
use app\common\model\user\User;
|
|
use think\response\Json;
|
|
|
|
class InformationController extends BaseApiController
|
|
{
|
|
public array $notNeedLogin = ['farmerInfo','farmerLandInfo','farmerPondInfo'];
|
|
|
|
public function list()
|
|
{
|
|
$param = Request()->param();
|
|
[$page, $limit] = $this->getPage();
|
|
if (isset($param['user_id']) && $param['user_id'] > 0) {
|
|
$data[] = ['create_user_id', '=', $param['user_id']];
|
|
} else {
|
|
$data[] = ['company_id', '=', $this->userInfo['company_id']];
|
|
}
|
|
if (isset($param['arr']) && count($param['arr']) > 0) {
|
|
$data[] = ['id', 'in', $param['arr']];
|
|
}
|
|
if (isset($param['is_update'])) {
|
|
if ($param['is_update'] > 0) {
|
|
$data[] = ['is_update', '=', 1];
|
|
} else {
|
|
$data[] = ['is_update', '=', 0];
|
|
}
|
|
}
|
|
$res = UserInformationg::list($data, $page, $limit);
|
|
if ($res != true) {
|
|
return $this->fail(BaseLogic::getError());
|
|
}
|
|
return $this->success('ok', $res->toArray());
|
|
}
|
|
|
|
/**
|
|
* 添加
|
|
*/
|
|
public function add()
|
|
{
|
|
$param = Request()->param();
|
|
$user = User::where('id', $this->userId)->find();
|
|
if (isset($param['street']) && $param['street'] > 0) {
|
|
$param['street_id'] = $param['street'];
|
|
} else {
|
|
$param['street_id'] = $user['street'];
|
|
}
|
|
if (isset($param['village']) && $param['village'] > 0) {
|
|
$param['village_id'] = $param['village'];
|
|
} else {
|
|
$param['village_id'] = $user['village'];
|
|
}
|
|
if (isset($param['brigade']) && $param['brigade'] > 0) {
|
|
$param['brigade_id'] = $param['brigade'];
|
|
} else {
|
|
$param['brigade_id'] = $user['brigade'];
|
|
}
|
|
$param['admin_id'] = $this->userId;
|
|
$param['company_id'] = $this->userInfo['company_id'];
|
|
$param['province_id'] = $user['province'];
|
|
$param['city_id'] = $user['city'];
|
|
$param['area_id'] = $user['area'];
|
|
$res = UserInformationg::add($param);
|
|
if ($res != true) {
|
|
return $this->fail(BaseLogic::getError());
|
|
}
|
|
return $this->success('成功');
|
|
}
|
|
|
|
/**
|
|
* 详情
|
|
*/
|
|
public function details()
|
|
{
|
|
$param = Request()->param();
|
|
$res = UserInformationg::details($param['id']);
|
|
if ($res != true) {
|
|
return $this->fail(BaseLogic::getError());
|
|
}
|
|
return $this->success('成功', $res->toArray());
|
|
}
|
|
|
|
/**
|
|
* 商机更新
|
|
*/
|
|
public function opportunity_update()
|
|
{
|
|
$param = Request()->param();
|
|
foreach ($param['datas'] as $k => $v) {
|
|
$res = UserInformationg::informationg_demand($v, $param['id'], $this->userId);
|
|
}
|
|
if ($res != true) {
|
|
return $this->fail(BaseLogic::getError());
|
|
}
|
|
if (isset($param['task_id']) && $param['task_id'] > 0) {
|
|
$task = Task::where('id', $param['task_id'])->find();
|
|
$extend = $task['extend'];
|
|
if (isset($extend['informationg']['update'])) {
|
|
$extend['informationg']['update'] += 1;
|
|
} else {
|
|
$extend['informationg']['update'] = 1;
|
|
}
|
|
$extend['informationg']['ids'][] = $param['id'];
|
|
$task->extend = json_encode($extend);
|
|
if ($extend['informationg']['update'] >= 5) {
|
|
$task->status = 3;
|
|
}
|
|
$task->save();
|
|
TaskTemplate::where('id', $task['template_id'])->inc('information_count', 1)->update();
|
|
}
|
|
|
|
UserInformationg::where('id', $param['id'])->update(['update_time' => time(), 'is_update' => 1]);
|
|
return $this->success('成功');
|
|
}
|
|
|
|
/**
|
|
* 编辑
|
|
*/
|
|
public function edit()
|
|
{
|
|
$param = Request()->param();
|
|
$res = UserInformationg::edit($param);
|
|
if ($res != true) {
|
|
return $this->fail(BaseLogic::getError());
|
|
}
|
|
return $this->success('成功');
|
|
}
|
|
|
|
//获取农户信息,该接口溯源系统调用
|
|
public function farmerInfo(): Json
|
|
{
|
|
//获取参数
|
|
$params = $this->request->post(['user_id']);
|
|
if(empty($params['user_id'])){
|
|
return $this->fail('参数错误_worker');
|
|
}
|
|
//获取农户信息
|
|
$farmerInfo = UserInformationg::where('id', $params['user_id'])->field('id,create_user_id,company_id,name,phone,area_id,street_id,village_id,brigade_id,area_id area_name,street_id street_name,village_id village_name,brigade_id brigade_name')->findOrEmpty()->toArray();
|
|
if(empty($farmerInfo)){
|
|
return $this->fail('用户不存在_worker');
|
|
}
|
|
unset($farmerInfo['area_id'],$farmerInfo['street_id'],$farmerInfo['village_id'],$farmerInfo['brigade_id']);
|
|
$data = UserInformationgDemand::field('id,category_child,data')->where('information_id', $params['user_id'])->where('category_id',6)->where('category_child','in','7,32')->order('id', 'desc')->select()->toArray();
|
|
//是否是种植户
|
|
$farmerInfo['is_zz_user'] = false;
|
|
//是否是水产养殖户
|
|
$farmerInfo['is_sc_user'] = false;
|
|
//是否是家禽养殖户
|
|
$farmerInfo['is_jq_user'] = false;
|
|
//是否是大型动物养殖户
|
|
$farmerInfo['is_dw_user'] = false;
|
|
//土地总面积
|
|
$farmerInfo['total_land_area'] = 0;
|
|
//池塘总面积
|
|
$farmerInfo['total_pond_area'] = 0;
|
|
//家禽养殖场总面积
|
|
$farmerInfo['total_henhouse_area'] = 0;
|
|
//动物养殖场总面积
|
|
$farmerInfo['total_pasture_area'] = 0;
|
|
foreach($data as $v){
|
|
if($v['category_child'] == 7){
|
|
$farmerInfo['is_zz_user'] = true;
|
|
$farmerInfo['total_land_area'] += floatval($v['data']['area']);
|
|
$farmerInfo['land_detail'][] = [
|
|
'land_id' => $v['id'],
|
|
'land_area' => $v['data']['area'],
|
|
'land_notes' => $v['data']['notes'],
|
|
];
|
|
}
|
|
if($v['category_child'] == 32){
|
|
if($v['data']['breeding_type'] == 1){//水产
|
|
$farmerInfo['is_sc_user'] = true;
|
|
$farmerInfo['total_pond_area'] += floatval($v['data']['area']);
|
|
$farmerInfo['pond_detail'][] = [
|
|
'pond_id' => $v['id'],
|
|
'pond_area' => $v['data']['area'],
|
|
'pond_notes' => $v['data']['notes'],
|
|
];
|
|
}elseif ($v['data']['breeding_type'] == 2) {//脯乳动物
|
|
$farmerInfo['is_jq_user'] = true;
|
|
$farmerInfo['total_henhouse_area'] += floatval($v['data']['area']);
|
|
}elseif ($v['data']['breeding_type'] == 3){//家禽
|
|
$farmerInfo['is_dw_user'] = true;
|
|
$farmerInfo['total_pasture_area'] += floatval($v['data']['area']);
|
|
}
|
|
}
|
|
}
|
|
return $this->success('请求成功',$farmerInfo);
|
|
}
|
|
|
|
//获取农户土地信息
|
|
public function farmerLandInfo(): Json
|
|
{
|
|
//获取参数
|
|
$params = $this->request->post(['user_id','land_id']);
|
|
if(empty($params['user_id']) || empty($params['land_id'])){
|
|
return $this->fail('参数错误_worker');
|
|
}
|
|
//获取农户信息
|
|
$data = UserInformationgDemand::field('id,data')->where('id',$params['land_id'])->where('information_id', $params['user_id'])->where('category_id',6)->where('category_child',7)->findOrEmpty()->toArray();
|
|
if(empty($data)){
|
|
return $this->fail('数据不存在_worker');
|
|
}
|
|
$resData = [
|
|
'land_id' => $data['id'],
|
|
'land_area' => $data['data']['area']
|
|
];
|
|
return $this->success('请求成功',$resData);
|
|
}
|
|
|
|
//获取农户鱼塘信息
|
|
public function farmerPondInfo(): Json
|
|
{
|
|
//获取参数
|
|
$params = $this->request->post(['user_id','pond_id']);
|
|
if(empty($params['user_id']) || empty($params['pond_id'])){
|
|
return $this->fail('参数错误_worker');
|
|
}
|
|
//获取农户信息
|
|
$data = UserInformationgDemand::field('id,data')->where('id',$params['pond_id'])->where('information_id', $params['user_id'])->where('category_id',6)->where('category_child',32)->findOrEmpty()->toArray();
|
|
if(empty($data) || empty($data['data'])){
|
|
return $this->fail('数据不存在_worker');
|
|
}
|
|
if($data['data']['breeding_type'] != 1){
|
|
return $this->fail('数据错误_work');
|
|
}
|
|
$resData = [
|
|
'pond_id' => $data['id'],
|
|
'pond_area' => $data['data']['area']
|
|
];
|
|
return $this->success('请求成功',$resData);
|
|
}
|
|
}
|