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 <?php
namespace app\api\controller; namespace app\api\controller;
use think\facade\Db; use think\facade\Db;
use think\facade\Filesystem;
use think\response\Json; 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 array $notNeedLogin = [
'landInfo',
//获取农户信息 'addLandCrop','addLandCropPic','landCropPicList',
public function farmerInfo(): Json 'addLandCropRecord','delLandCropRecord','ediLandCropRecord','landCropRecordInfo','landCropRecordList',
{ 'setLandCropRipe',
//获取参数 'landEnvDataChart','landEnvDataCurr'
$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 landInfo(): Json 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']); $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']); $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']); $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']); $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']); $params = $this->request->post(['record_id']);
if(empty($params['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']); $params = $this->request->post(['record_id','action_content']);
if(empty($params['record_id']) || empty($params['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']); $params = $this->request->get(['record_id']);
if(empty($params['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']); $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']); $params = $this->request->post(['crop_id','crop_yield']);
if(empty($params['crop_id']) || empty($params['crop_yield'])){ if(empty($params['crop_id']) || empty($params['crop_yield'])){
@ -288,61 +251,4 @@
return $this->success('请求成功',$data); 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 <?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; 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 class UserController extends BaseApiController
{ {
public array $notNeedLogin = ['resetPassword']; public array $notNeedLogin = ['userInfo','actions','actionsDetail','imageUpload'];
//获取农户信息
/** public function userInfo(): Json
* @notes 获取个人中心 {
* @return \think\response\Json //获取参数
* @throws \think\db\exception\DataNotFoundException $params = $this->request->get(['user_id']);
* @throws \think\db\exception\DbException if(empty($params['user_id'])){
* @throws \think\db\exception\ModelNotFoundException return $this->fail('参数错误');
* @author 段誉 }
* @date 2022/9/16 18:19 $url = env('project.worker_domain').'/api/information/farmerInfo';
*/ $curl_result = curl_post($url,[],$params);
public function center() if($curl_result['code'] == 0){
{ return $this->fail($curl_result['msg']);
$data = UserLogic::center($this->userInfo); }
return $this->success('', $data); //判断是否是种植农户
} if($curl_result['data']['is_zz_user']){
$lands = $curl_result['data']['land_detail'];
foreach($lands as $k=>$v) {
/** //查找种植信息
* @notes 获取个人信息 $land_crop = Db::name('farmer_land_crop')->where([
* @return \think\response\Json ['user_id','=',$params['user_id']],
* @author 段誉 ['land_id','=',$v['land_id']],
* @date 2022/9/20 19:46 ])->order('id desc')->findOrEmpty();
*/ if(!empty($land_crop)){
public function info() $lands[$k]['is_cropped'] = true;
{ $lands[$k]['source_code'] = $land_crop['source_code'];
$result = UserLogic::info($this->userId); $lands[$k]['crop_name'] = $land_crop['crop_name'];
return $this->data($result); $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'];
* @notes 重置密码 }else{
* @return \think\response\Json $lands[$k]['is_cropped'] = false;
* @author 段誉 }
* @date 2022/9/16 18:06 }
*/ $curl_result['data']['land_detail'] = $lands;
public function resetPassword() }
{ //返回数据
$params = (new PasswordValidate())->post()->goCheck('resetPassword'); return json($curl_result);
$result = UserLogic::resetPassword($params); }
if (true === $result) {
return $this->success('操作成功', [], 1, 1); //获取操作信息
} public function actions(): Json
return $this->fail(UserLogic::getError()); {
} //获取参数
$params = $this->request->get(['type']);
if(empty($params['type']) || !in_array($params['type'],[1,2,3,4])){
/** return $this->fail('参数错误');
* @notes 修改密码 }
* @return \think\response\Json //获取数据
* @author 段誉 $actions = Db::name('farmer_action')->where('farmer_type',$params['type'])->select()->each(function($item){
* @date 2022/9/20 19:16 $actionType = Db::name('farmer_action_type')->where('id',$item['type_id'])->findOrEmpty();
*/ $item['type_name'] = $actionType['name'];
public function changePassword() return $item;
{ })->toArray();
$params = (new PasswordValidate())->post()->goCheck('changePassword'); $arr1 = [];
$result = UserLogic::changePassword($params, $this->userId); $ar2=[];
if (true === $result) { foreach ($actions as $value) {
return $this->success('操作成功', [], 1, 1); foreach ($actions as $val) {
} if($value['type_name']==$val['type_name']){
return $this->fail(UserLogic::getError()); $ar2[]=$val;
} }
}
$arr1[$value['type_name']] = $ar2;
/** $ar2 =[];
* @notes 获取小程序手机号 }
* @return \think\response\Json return $this->success('请求成功',$arr1);
* @author 段誉 }
* @date 2022/9/21 16:46
*/ //获取操作详情
public function getMobileByMnp() public function actionsDetail(): Json
{ {
$params = (new UserValidate())->post()->goCheck('getMobileByMnp'); //获取参数
$params['user_id'] = $this->userId; $params = $this->request->get(['action_id']);
$result = UserLogic::getMobileByMnp($params); if(empty($params['action_id'])){
if ($result === false) { return $this->fail('参数错误');
return $this->fail(UserLogic::getError()); }
} //获取数据
return $this->success('绑定成功', [], 1, 1); $data = Db::name('farmer_action_detail')->where('action_id','in',$params['action_id'])->select()->toArray();
} //返回
return $this->success('请求成功',$data);
}
/**
* @notes 编辑用户信息 //上传图片
* @return \think\response\Json public function imageUpload(): Json
* @author 段誉 {
* @date 2022/9/21 17:01 if(!$this->request->isPost()) {
*/ return $this->fail('请求方式错误');
public function setInfo() }
{ $file = request()->file('file');
$params = (new SetUserInfoValidate())->post()->goCheck(null, ['id' => $this->userId]); if(empty($file)){
$result = UserLogic::setInfo($this->userId, $params); return $this->fail('上传文件不存在');
if (false === $result) { }
return $this->fail(UserLogic::getError()); $save_name = Filesystem::disk('public')->putFile( '', $file);
} return $this->success('上传成功',['image'=>$this->request->domain().'/uploads/'.$save_name]);
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());
}
} }