新种植分类等接口

This commit is contained in:
彭桃 2023-03-28 17:55:50 +08:00
parent 8df482d949
commit b5a3a6666f

View File

@ -696,61 +696,64 @@ class Maintainentry extends BaseController
$map[] = ['user_id','=',$user_id];
$find=Db::table('fa_szxc_information_planting')->where($map)->find();
// 新增写入种植表
Db::table('fa_szxc_planting')->where('user_id',$user_id)->delete();
$mianji = 0;
if($post['crops_msg']){
$crops_msg_arr = json_decode($post['crops_msg'],1);
foreach ($crops_msg_arr as $k=>$v){
// 根据名字查询分类
if($v['name']){
$type = Db::table('fa_szxc_planting_type')->where('name',$v['name'])->find();
if($type){
$planting_data['type_id'] = $type['id'];
}else{
$type_data['name'] = $v['name'];
$type_data['createtime'] = $time;
$type_id = Db::table('fa_szxc_planting_type')->strict(false)->insertGetId($type_data);
$planting_data['type_id'] = $type_id;
}
$planting_data['user_id'] = $user_id;
$planting_data['num'] = $v['num']??0;
$planting_data['measure'] = $v['mianji']??0;
$planting_data['createtime'] = $time;
Db::table('fa_szxc_planting')->strict(false)->insertGetId($planting_data);
}
// 计算面积
if($v['mianji']){
$mianji += $v['mianji'];
}
}
}
// Db::table('fa_szxc_planting')->where('user_id',$user_id)->delete();
// $mianji = 0;
// if($post['crops_msg']){
// $crops_msg_arr = json_decode($post['crops_msg'],1);
// foreach ($crops_msg_arr as $k=>$v){
// // 根据名字查询分类
// if($v['name']){
// $type = Db::table('fa_szxc_planting_type')->where('name',$v['name'])->find();
// if($type){
// $planting_data['type_id'] = $type['id'];
// }else{
// $type_data['name'] = $v['name'];
// $type_data['createtime'] = $time;
// $type_id = Db::table('fa_szxc_planting_type')->strict(false)->insertGetId($type_data);
// $planting_data['type_id'] = $type_id;
// }
// $planting_data['user_id'] = $user_id;
// $planting_data['num'] = $v['num']??0;
// $planting_data['measure'] = $v['mianji']??0;
// $planting_data['createtime'] = $time;
// Db::table('fa_szxc_planting')->strict(false)->insertGetId($planting_data);
// }
// // 计算面积
// if($v['mianji']){
// $mianji += $v['mianji'];
// }
// }
// }
// 新增写入养殖表
Db::table('fa_szxc_breed')->where('user_id',$user_id)->delete();
// $mianji = 0;
if(isset($post['breed_msg']) && !empty($post['breed_msg'])){
$breed_msg_arr = json_decode($post['breed_msg'],1);
foreach ($breed_msg_arr as $k=>$v){
// 根据名字查询分类
if($v['name']){
$type = Db::table('fa_szxc_breed_type')->where('name',$v['name'])->find();
if($type){
$breed_data['type_id'] = $type['id'];
}else{
$type_data['name'] = $v['name'];
$type_data['createtime'] = $time;
$type_id = Db::table('fa_szxc_breed_type')->strict(false)->insertGetId($type_data);
$breed_data['type_id'] = $type_id;
}
$breed_data['user_id'] = $user_id;
$breed_data['num'] = $v['num']??0;
$breed_data['measure'] = $v['mianji']??0;
$breed_data['createtime'] = $time;
Db::table('fa_szxc_breed')->strict(false)->insertGetId($breed_data);
}
}
}
// Db::table('fa_szxc_breed')->where('user_id',$user_id)->delete();
//// $mianji = 0;
// if(isset($post['breed_msg']) && !empty($post['breed_msg'])){
// $breed_msg_arr = json_decode($post['breed_msg'],1);
// foreach ($breed_msg_arr as $k=>$v){
//// 根据名字查询分类
// if($v['name']){
// $type = Db::table('fa_szxc_breed_type')->where('name',$v['name'])->find();
// if($type){
// $breed_data['type_id'] = $type['id'];
// }else{
// $type_data['name'] = $v['name'];
// $type_data['createtime'] = $time;
// $type_id = Db::table('fa_szxc_breed_type')->strict(false)->insertGetId($type_data);
// $breed_data['type_id'] = $type_id;
// }
// $breed_data['user_id'] = $user_id;
// $breed_data['num'] = $v['num']??0;
// $breed_data['measure'] = $v['mianji']??0;
// $breed_data['createtime'] = $time;
// Db::table('fa_szxc_breed')->strict(false)->insertGetId($breed_data);
// }
// }
// }
$waste_land_area = 0;
$www5['user_id'] = $user_id;
$www5['type_id'] = 1;
$mianji = Db::table('cms_planting_information')->where($www5)->sum('measure');
if (!empty($post['land_area']) && !empty($post['breed_area']))
{
@ -760,13 +763,12 @@ class Maintainentry extends BaseController
}
}
if ($find) {
// 修改人员信息
$data['tools_msg'] = $post['tools_msg'];
$data['breed_msg'] = $post['breed_msg']??'';
// $data['tools_msg'] = $post['tools_msg'];
// $data['breed_msg'] = $post['breed_msg']??'';
$data['breed_area'] = $post['breed_area']??'';
$data['crops_msg'] = $post['crops_msg'];
// $data['crops_msg'] = $post['crops_msg'];
$data['land_area'] = $post['land_area'];
$data['nature_of_land'] = $post['nature_of_land_id'];
$data['is_wz'] = $post['is_wz'];
@ -781,10 +783,10 @@ class Maintainentry extends BaseController
}
}else{
// 修改人员信息
$data['tools_msg'] = $post['tools_msg'];
$data['breed_msg'] = $post['breed_msg']??'';
// $data['tools_msg'] = $post['tools_msg'];
// $data['breed_msg'] = $post['breed_msg']??'';
$data['breed_area'] = $post['breed_area']??'';
$data['crops_msg'] = $post['crops_msg'];
// $data['crops_msg'] = $post['crops_msg'];
$data['land_area'] = $post['land_area'];
$data['nature_of_land'] = $post['nature_of_land_id'];
$data['is_wz'] = $post['is_wz'];
@ -1905,5 +1907,128 @@ class Maintainentry extends BaseController
}
}
/**
* 获取分类(农作物、农机农具、养殖)
*
*/
public function get_category()
{
// 分类标识
$type = get_params('type_id');
if (empty($type)) {
$this->apiError('缺少参数');
} else {
$where[] = ['pid','<>',0];
$where[] = ['pid','=',$type];
$where[] = ['status','=','1'];
$result = Db::table('cms_planting_type')->where($where)->field('id,name')->order('id desc')->select()->toArray();
if ($result) {
$this->apiSuccess('获取成功', $result);
} else {
$this->apiError('暂无数据');
}
}
}
/**
* 新增分类(农作物、农机农具、养殖)
*
*/
public function add_category()
{
// 分类标识
$type = get_params('type_id');
$name = get_params('name');
if (empty($type) || empty($name)) {
$this->apiError('缺少参数');
} else {
$data['name'] = $name;
$data['pid'] = $type;
$data['createtime'] = time();
$result = Db::table('cms_planting_type')->strict(false)->insert($data);
if ($result) {
$this->apiSuccess('添加成功', $result);
} else {
$this->apiError('添加失败');
}
}
}
/**
* 添加(农作物、农机农具、养殖)
*
*/
public function add_information()
{
// 分类标识
$type = get_params('type_id');
if (empty($type)) {
$this->apiError('缺少参数');
} else {
$data = get_params();
$data['user_id'] = $this->request->uid;
$data['createtime'] = time();
$result = Db::table('cms_planting_information')->strict(false)->insert($data);
if ($result) {
$this->apiSuccess('添加成功', $result);
} else {
$this->apiError('添加失败');
}
}
}
/**
* 获取列表(农作物、农机农具、养殖)
*
*/
public function get_information()
{
// 分类标识
$type = get_params('type_id'); //1农作物2农机农具3养殖物
if (empty($type)) {
$this->apiError('缺少参数');
} else {
$where['user_id'] = $this->request->uid;
$where['type_id'] = $type;
$page = get_params('page')??1;
$limit = get_params('limit')??10;
$order = get_params('order')??'id';
$result = Db::table('cms_planting_information')->where($where)->page($page,$limit)->order($order. ' desc')->select()->toArray();
if ($result) {
$this->apiSuccess('获取成功', $result);
} else {
$this->apiError('获取失败');
}
}
}
/**
* 删除(农作物、农机农具、养殖)
*
*/
public function del_information()
{
// 分类标识
$id = get_params('id');
if (empty($id)) {
$this->apiError('缺少参数');
} else {
$where['user_id'] = $this->request->uid;
$where['id'] = $id;
$result = Db::table('cms_planting_information')->where($where)->delete();
if ($result) {
$this->apiSuccess('删除成功', $result);
} else {
$this->apiError('删除失败');
}
}
}
}