This commit is contained in:
weiz 2023-10-24 09:12:23 +08:00
parent 2c3be5506d
commit 2c2b68a790
2 changed files with 118 additions and 251 deletions

View File

@ -1,55 +1,18 @@
<?php
namespace app\api\controller;
use think\facade\Db;
use think\facade\Filesystem;
use think\response\Json;
class SuYuanController extends BaseApiController
class LandPlantController extends BaseApiController
{
public array $notNeedLogin = ['farmerInfo','landInfo','addCropInfo','addCropInfoPic','cropInfoPicList','addCropRecord','delCropRecord','ediCropRecord','cropRecordInfo','cropRecordList','cropRipe','landEnvDataChart','landEnvDataCurr','actions','actionsDetail','imageUpload'];
//获取农户信息
public function farmerInfo(): Json
{
//获取参数
$params = $this->request->get(['user_id']);
if(empty($params['user_id'])){
return $this->fail('参数错误');
}
$url = env('project.worker_domain').'/api/information/farmerInfo';
$curl_result = curl_post($url,[],$params);
if($curl_result['code'] == 0){
return $this->fail($curl_result['msg']);
}
//判断是否是种植农户
if($curl_result['data']['is_zz_user']){
$lands = $curl_result['data']['land_detail'];
foreach($lands as $k=>$v) {
//查找种植信息
$land_crop = Db::name('farmer_land_crop')->where([
['user_id','=',$params['user_id']],
['land_id','=',$v['land_id']],
])->order('id desc')->findOrEmpty();
if(!empty($land_crop)){
$lands[$k]['is_cropped'] = true;
$lands[$k]['source_code'] = $land_crop['source_code'];
$lands[$k]['crop_name'] = $land_crop['crop_name'];
$lands[$k]['crop_variety'] = $land_crop['crop_variety'];
$lands[$k]['crop_brand'] = $land_crop['crop_brand'];
$lands[$k]['crop_yield'] = $land_crop['crop_yield'];
$lands[$k]['seed_time'] = date('Y-m-d H:i:s',$land_crop['seed_time']);
$lands[$k]['ripe_time'] = !empty($land_crop['ripe_time']) && !empty($land_crop['crop_yield']) ? date('Y-m-d H:i:s',$land_crop['ripe_time']) : $land_crop['ripe_time'];
}else{
$lands[$k]['is_cropped'] = false;
}
}
$curl_result['data']['land_detail'] = $lands;
}
//返回数据
return json($curl_result);
}
public array $notNeedLogin = [
'landInfo',
'addLandCrop','addLandCropPic','landCropPicList',
'addLandCropRecord','delLandCropRecord','ediLandCropRecord','landCropRecordInfo','landCropRecordList',
'setLandCropRipe',
'landEnvDataChart','landEnvDataCurr'
];
//获取农户土地信息
public function landInfo(): Json
@ -91,7 +54,7 @@
}
//添加种植信息
public function addCropInfo(): Json
public function addLandCrop(): Json
{
//获取参数
$params = $this->request->post(['user_id','land_id','crop_name','crop_variety','crop_brand','crop_buy_time','pic']);
@ -134,7 +97,7 @@
}
//添加播种图片
public function addCropInfoPic(): Json
public function addLandCropPic(): Json
{
//获取参数
$params = $this->request->post(['crop_id','pic']);
@ -149,7 +112,7 @@
}
//获取播种图片列表
public function cropInfoPicList(): Json
public function landCropPicList(): Json
{
//获取参数
$params = $this->request->get(['crop_id']);
@ -164,7 +127,7 @@
}
//添加农户种植信息操作记录
public function addCropRecord(): Json
public function addLandCropRecord(): Json
{
//获取参数
$params = $this->request->post(['crop_id','action_id','action_content']);
@ -182,7 +145,7 @@
}
//删除农户种植信息操作记录
public function delCropRecord(): Json
public function delLandCropRecord(): Json
{
$params = $this->request->post(['record_id']);
if(empty($params['record_id'])){
@ -193,7 +156,7 @@
}
//修改农户种植信息操作记录
public function ediCropRecord(): Json
public function ediLandCropRecord(): Json
{
$params = $this->request->post(['record_id','action_content']);
if(empty($params['record_id']) || empty($params['action_content'])){
@ -209,7 +172,7 @@
}
//获取农户种植信息操作记录详情
public function cropRecordInfo(): Json
public function landCropRecordInfo(): Json
{
$params = $this->request->get(['record_id']);
if(empty($params['record_id'])){
@ -222,7 +185,7 @@
}
//农户种植信息操作记录列表
public function cropRecordList(): Json
public function landCropRecordList(): Json
{
//获取参数
$params = $this->request->get(['crop_id','page_no','page_size']);
@ -241,7 +204,7 @@
}
//种植作物标记成熟
public function cropRipe(): Json
public function setLandCropRipe(): Json
{
$params = $this->request->post(['crop_id','crop_yield']);
if(empty($params['crop_id']) || empty($params['crop_yield'])){
@ -288,61 +251,4 @@
return $this->success('请求成功',$data);
}
/*************************************************************************************************************************************************************/
//获取操作信息
public function actions(): Json
{
//获取参数
$params = $this->request->get(['type']);
if(empty($params['type']) || !in_array($params['type'],[1,2,3,4])){
return $this->fail('参数错误');
}
//获取数据
$actions = Db::name('farmer_action')->where('farmer_type',$params['type'])->select()->each(function($item){
$actionType = Db::name('farmer_action_type')->where('id',$item['type_id'])->findOrEmpty();
$item['type_name'] = $actionType['name'];
return $item;
})->toArray();
$arr1 = [];
$ar2=[];
foreach ($actions as $value) {
foreach ($actions as $val) {
if($value['type_name']==$val['type_name']){
$ar2[]=$val;
}
}
$arr1[$value['type_name']] = $ar2;
$ar2 =[];
}
return $this->success('请求成功',$arr1);
}
//获取操作详情
public function actionsDetail(): Json
{
//获取参数
$params = $this->request->get(['action_id']);
if(empty($params['action_id'])){
return $this->fail('参数错误');
}
//获取数据
$data = Db::name('farmer_action_detail')->where('action_id','in',$params['action_id'])->select()->toArray();
//返回
return $this->success('请求成功',$data);
}
//上传图片
public function imageUpload(): Json
{
if(!$this->request->isPost()) {
return $this->fail('请求方式错误');
}
$file = request()->file('file');
if(empty($file)){
return $this->fail('上传文件不存在');
}
$save_name = Filesystem::disk('public')->putFile( '', $file);
return $this->success('上传成功',['image'=>$this->request->domain().'/uploads/'.$save_name]);
}
}

View File

@ -1,147 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\api\controller;
use think\facade\Db;
use think\facade\Filesystem;
use think\response\Json;
use app\api\logic\UserLogic;
use app\api\validate\PasswordValidate;
use app\api\validate\SetUserInfoValidate;
use app\api\validate\UserValidate;
/**
* 用户控制器
* Class UserController
* @package app\api\controller
*/
class UserController extends BaseApiController
{
public array $notNeedLogin = ['resetPassword'];
/**
* @notes 获取个人中心
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/16 18:19
*/
public function center()
{
$data = UserLogic::center($this->userInfo);
return $this->success('', $data);
}
/**
* @notes 获取个人信息
* @return \think\response\Json
* @author 段誉
* @date 2022/9/20 19:46
*/
public function info()
{
$result = UserLogic::info($this->userId);
return $this->data($result);
}
/**
* @notes 重置密码
* @return \think\response\Json
* @author 段誉
* @date 2022/9/16 18:06
*/
public function resetPassword()
{
$params = (new PasswordValidate())->post()->goCheck('resetPassword');
$result = UserLogic::resetPassword($params);
if (true === $result) {
return $this->success('操作成功', [], 1, 1);
}
return $this->fail(UserLogic::getError());
}
/**
* @notes 修改密码
* @return \think\response\Json
* @author 段誉
* @date 2022/9/20 19:16
*/
public function changePassword()
{
$params = (new PasswordValidate())->post()->goCheck('changePassword');
$result = UserLogic::changePassword($params, $this->userId);
if (true === $result) {
return $this->success('操作成功', [], 1, 1);
}
return $this->fail(UserLogic::getError());
}
/**
* @notes 获取小程序手机号
* @return \think\response\Json
* @author 段誉
* @date 2022/9/21 16:46
*/
public function getMobileByMnp()
{
$params = (new UserValidate())->post()->goCheck('getMobileByMnp');
$params['user_id'] = $this->userId;
$result = UserLogic::getMobileByMnp($params);
if ($result === false) {
return $this->fail(UserLogic::getError());
}
return $this->success('绑定成功', [], 1, 1);
}
/**
* @notes 编辑用户信息
* @return \think\response\Json
* @author 段誉
* @date 2022/9/21 17:01
*/
public function setInfo()
{
$params = (new SetUserInfoValidate())->post()->goCheck(null, ['id' => $this->userId]);
$result = UserLogic::setInfo($this->userId, $params);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->success('操作成功', [], 1, 1);
}
/**
* @notes 绑定/变更 手机号
* @return \think\response\Json
* @author 段誉
* @date 2022/9/21 17:29
*/
public function bindMobile()
{
$params = (new UserValidate())->post()->goCheck('bindMobile');
$params['user_id'] = $this->userId;
$result = UserLogic::bindMobile($params);
if($result) {
return $this->success('绑定成功', [], 1, 1);
}
return $this->fail(UserLogic::getError());
}
public array $notNeedLogin = ['userInfo','actions','actionsDetail','imageUpload'];
//获取农户信息
public function userInfo(): Json
{
//获取参数
$params = $this->request->get(['user_id']);
if(empty($params['user_id'])){
return $this->fail('参数错误');
}
$url = env('project.worker_domain').'/api/information/farmerInfo';
$curl_result = curl_post($url,[],$params);
if($curl_result['code'] == 0){
return $this->fail($curl_result['msg']);
}
//判断是否是种植农户
if($curl_result['data']['is_zz_user']){
$lands = $curl_result['data']['land_detail'];
foreach($lands as $k=>$v) {
//查找种植信息
$land_crop = Db::name('farmer_land_crop')->where([
['user_id','=',$params['user_id']],
['land_id','=',$v['land_id']],
])->order('id desc')->findOrEmpty();
if(!empty($land_crop)){
$lands[$k]['is_cropped'] = true;
$lands[$k]['source_code'] = $land_crop['source_code'];
$lands[$k]['crop_name'] = $land_crop['crop_name'];
$lands[$k]['crop_variety'] = $land_crop['crop_variety'];
$lands[$k]['crop_brand'] = $land_crop['crop_brand'];
$lands[$k]['crop_yield'] = $land_crop['crop_yield'];
$lands[$k]['seed_time'] = date('Y-m-d H:i:s',$land_crop['seed_time']);
$lands[$k]['ripe_time'] = !empty($land_crop['ripe_time']) && !empty($land_crop['crop_yield']) ? date('Y-m-d H:i:s',$land_crop['ripe_time']) : $land_crop['ripe_time'];
}else{
$lands[$k]['is_cropped'] = false;
}
}
$curl_result['data']['land_detail'] = $lands;
}
//返回数据
return json($curl_result);
}
//获取操作信息
public function actions(): Json
{
//获取参数
$params = $this->request->get(['type']);
if(empty($params['type']) || !in_array($params['type'],[1,2,3,4])){
return $this->fail('参数错误');
}
//获取数据
$actions = Db::name('farmer_action')->where('farmer_type',$params['type'])->select()->each(function($item){
$actionType = Db::name('farmer_action_type')->where('id',$item['type_id'])->findOrEmpty();
$item['type_name'] = $actionType['name'];
return $item;
})->toArray();
$arr1 = [];
$ar2=[];
foreach ($actions as $value) {
foreach ($actions as $val) {
if($value['type_name']==$val['type_name']){
$ar2[]=$val;
}
}
$arr1[$value['type_name']] = $ar2;
$ar2 =[];
}
return $this->success('请求成功',$arr1);
}
//获取操作详情
public function actionsDetail(): Json
{
//获取参数
$params = $this->request->get(['action_id']);
if(empty($params['action_id'])){
return $this->fail('参数错误');
}
//获取数据
$data = Db::name('farmer_action_detail')->where('action_id','in',$params['action_id'])->select()->toArray();
//返回
return $this->success('请求成功',$data);
}
//上传图片
public function imageUpload(): Json
{
if(!$this->request->isPost()) {
return $this->fail('请求方式错误');
}
$file = request()->file('file');
if(empty($file)){
return $this->fail('上传文件不存在');
}
$save_name = Filesystem::disk('public')->putFile( '', $file);
return $this->success('上传成功',['image'=>$this->request->domain().'/uploads/'.$save_name]);
}
}