request->get(['user_id','pond_id']); if(empty($params['user_id']) || empty($params['pond_id'])){ return $this->fail('参数错误'); } //获取数据 $url = env('project.worker_domain').'/api/information/farmerPondInfo'; $curl_result = curl_post($url,[],$params); if($curl_result['code'] == 0){ return $this->fail($curl_result['msg']); } //获取养殖信息 $breedData = Db::name('farmer_pond_breed')->where('user_id',$params['user_id'])->where('pond_id',$params['pond_id'])->sum('number'); //获取捕捞信息 $catchData = Db::name('farmer_pond_catch')->where('user_id',$params['user_id'])->where('pond_id',$params['pond_id'])->sum('number'); if($breedData - $catchData != 0){ $curl_result['data']['is_culture'] = true; $curl_result['data']['total_num'] = $breedData - $catchData; //获取水产养殖种类 $fishKind = Db::name('farmer_pond_breed')->distinct(true)->where('user_id',$params['user_id'])->where('pond_id',$params['pond_id'])->limit(4)->column('kind'); //获取水产养殖具体品种 $fiskBreed = Db::name('farmer_pond_breed')->distinct(true)->where('user_id',$params['user_id'])->where('pond_id',$params['pond_id'])->limit(4)->column('breed'); $curl_result['data']['kind'] = $fishKind; $curl_result['data']['breed'] = $fiskBreed; //获取去最新的图片 $pic = Db::name('farmer_pond_pic')->field('pic,create_time')->where('pond_id',$params['pond_id'])->order('id desc')->findOrEmpty(); if(!empty($pic)){ $curl_result['data']['pic_detail'] = $pic; $curl_result['data']['pic_detail']['create_time'] = date('Y-m-d H:i:s',$pic['create_time']); }else{ $curl_result['data']['pic_detail'] = []; } //获取养殖时间 $firstBreed = Db::name('farmer_pond_breed')->where('user_id',$params['user_id'])->where('pond_id',$params['pond_id'])->findOrEmpty(); $curl_result['data']['source_code'] = $firstBreed['source_code']; $curl_result['data']['create_time'] = date('Y-m-d H:i:s',$firstBreed['create_time']); }else{ $curl_result['data']['is_culture'] = false; } //返回数据 return $this->success('请求成功',$curl_result['data']); } //添加水产养殖信息 public function addFish(): Json { //获取参数 $params = $this->request->post(['user_id','pond_id','kind','breed','number','buy_info','buy_cert']); if(empty($params['user_id']) || empty($params['pond_id']) || empty($params['kind']) || empty($params['breed']) || empty($params['number']) || empty($params['buy_info']) || empty($params['buy_cert'])){ return $this->fail('参数错误'); } //添加数据 $result = Db::name('farmer_pond_breed')->insert([ 'user_id' => $params['user_id'], 'pond_id' => $params['pond_id'], 'source_code' => 'NO'.time(), 'kind' => $params['kind'], 'breed' => $params['breed'], 'number' => $params['number'], 'buy_info' => $params['buy_info'], 'buy_cert' => $params['buy_cert'], 'create_time' => time(), ]); //返回信息 return $result ? $this->success('添加成功',[],1,1) : $this->fail('添加失败'); } //标记成熟 public function catchFish(): Json { $params = $this->request->post(['user_id','pond_id','kind','number']); if(empty($params['user_id']) || empty($params['pond_id']) || empty($params['kind']) || empty($params['number'])){ return $this->fail('参数错误'); } //判断是否养殖 $hasRes = Db::name('farmer_pond_breed')->where('user_id',$params['user_id'])->where('pond_id',$params['pond_id'])->select(); if($hasRes->isEmpty()){ return $this->fail('该池塘未养殖'); } //获取池塘养殖数量 $total = Db::name('farmer_pond_breed')->where('user_id',$params['user_id'])->where('pond_id',$params['pond_id'])->sum('number'); if($params['number'] > $total){ return $this->fail('捕捞数量大于池塘总数'); } $result = Db::name('farmer_pond_catch')->insert([ 'user_id' => $params['user_id'], 'pond_id' => $params['pond_id'], 'kind' => $params['kind'], 'number' => $params['number'], 'create_time' => time() ]); return $result ? $this->success('操作成功',[],1,1) : $this->fail('操作失败'); } //添加水产养殖图片 public function addFishPic(): Json { //获取参数 $params = $this->request->post(['pond_id','pic']); if(empty($params['pond_id']) || empty($params['pic'])){ return $this->fail('参数错误'); } //写入数据 $params['create_time'] = time(); $result = Db::name('farmer_pond_pic')->insert($params); //返回 return $result ? $this->success('添加成功',[],1,1) : $this->fail('添加失败'); } //水产养殖图片列表 public function fishPicList(): Json { //获取参数 $params = $this->request->get(['pond_id']); if(empty($params['pond_id'])){ return $this->fail('参数错误'); } $data = Db::name('farmer_pond_pic')->where('pond_id',$params['pond_id'])->order('id desc')->select()->each(function($item){ $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); return $item; })->toArray(); return $this->success('请求成功',$data); } //添加水产养殖操作记录 public function addFishRecord(): Json { //获取参数 $params = $this->request->post(['pond_id','action_id','action_content']); if(empty($params['pond_id']) || empty($params['action_id']) || empty($params['action_content'])){ return $this->fail('参数错误'); } if(empty(json_decode($params['action_content']))) { return $this->fail('参数错误'); } //写入数据 $params['create_time'] = time(); $result = Db::name('farmer_pond_record')->insert($params); //返回 return $result ? $this->success('添加成功',[],1,1) : $this->fail('添加失败'); } //删除水产养殖操作记录 public function delFishRecord(): Json { $params = $this->request->post(['record_id']); if(empty($params['record_id'])){ return $this->fail('参数错误'); } $resust = Db::name('farmer_pond_record')->where('id',$params['record_id'])->delete(); return $resust ? $this->success('删除成功',[],1,1) : $this->fail('删除失败'); } //编辑水产养殖操作记录 public function ediFishRecord(): Json { $params = $this->request->post(['record_id','action_content']); if(empty($params['record_id']) || empty($params['action_content'])){ return $this->fail('参数错误'); } if(empty(json_decode($params['action_content']))) { return $this->fail('参数错误'); } //修改数据 $result = Db::name('farmer_pond_record')->where('id',$params['record_id'])->update(['action_content'=>$params['action_content']]); //返回 return $result ? $this->success('修改成功',[],1,1) : $this->fail('修改失败',[],1,1); } //水产养殖操作记录列表 public function fishRecordList(): Json { //获取参数 $params = $this->request->get(['pond_id','action_type_id','page_no','page_size']); if(empty($params['pond_id']) || empty($params['action_type_id'])){ return $this->fail('参数错误'); } //设置分页条件 $pageNo = empty($params['page_no']) || $params['page_no'] < 0 ? 1 : $params['page_no']; $pageSize = empty($params['page_size']) || $params['page_size'] < 0 ? 10 : $params['page_size']; //获取操作分类下的操作id $actions = Db::name('farmer_action')->where('type_id',$params['action_type_id'])->select()->toArray(); $actionIds = array_column($actions,'id'); $data = Db::name('farmer_pond_record')->where('pond_id',$params['pond_id'])->where('action_id','in',$actionIds)->page($pageNo,$pageSize)->order('create_time desc')->select()->each(function($item){ $item['action_name'] = Db::name('farmer_action')->where('id',$item['action_id'])->findOrEmpty()['name']; $item['action_content'] = json_decode($item['action_content'],true); $item['create_time'] = date('Y-m-d H:i:s',$item['create_time']); return $item; })->toArray(); return $this->success('请求成功',$data); } //农户池塘环境监测数据实时数据 public function pondEnvData(): Json { $params = $this->request->get(['user_id']); if(empty($params['user_id'])){ return $this->fail('参数错误'); } $data = Db::name('farmer_pond_env_data')->where('user_id',$params['user_id'])->whereDay('create_time', date('Y-m-d',time()))->findOrEmpty(); if(!empty($data)){ $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']); } return $this->success('请求成功',$data); } }