diff --git a/app/admin/controller/nk/User.php b/app/admin/controller/nk/User.php index bb2387c..91c6b89 100644 --- a/app/admin/controller/nk/User.php +++ b/app/admin/controller/nk/User.php @@ -253,7 +253,7 @@ class User extends BaseController public function postedit() { $params = get_params(); - halt($params); +// halt($params); if ($params['type'] == 1) { unset($params['type']); $res = Db::table('fa_szxc_information_usermsg')->where('user_id', $params['user_id'])->update($params); @@ -264,15 +264,80 @@ class User extends BaseController } } if ($params['type'] == 2) { - halt($params); + $params['crops_msg'] = json_encode($params['crops_msg']); unset($params['type']); - $find = Db::table('fa_szxc_information_insurance')->where('user_id', $params['user_id'])->find(); + $find = Db::table('fa_szxc_information_planting')->where('user_id', $params['user_id'])->find(); if ($find) { - $res = Db::table('fa_szxc_information_insurance')->where('id', $find['id'])->update($params); + $res = Db::table('fa_szxc_information_planting')->where('id', $find['id'])->update($params); + $id = $find['id']; } else { - $res = Db::table('fa_szxc_information_insurance')->where('user_id', $params['user_id'])->insert($params); + $res = Db::table('fa_szxc_information_planting')->where('user_id', $params['user_id'])->insertGetId($params); + $id = $res; } if ($res) { + $time = time(); + // 新增写入种植表 + Db::table('fa_szxc_planting')->where('user_id',$params['user_id'])->delete(); + $mianji = 0; + if($params['crops_msg']){ + $crops_msg_arr = json_decode($params['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'] = $params['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',$params['user_id'])->delete(); +// $mianji = 0; + if(isset($params['breed_msg']) && !empty($params['breed_msg'])){ + $breed_msg_arr = json_decode($params['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'] = $params['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 = $params['land_area'] - $mianji; + if($waste_land_area < 0){ + $waste_land_area = 0; + } + $ddd['waste_land_area'] = $waste_land_area; + Db::table('fa_szxc_information_planting')->where('id', $id)->update($ddd); return to_assign(0, '操作成功'); } else { return to_assign(1, '操作失败'); diff --git a/app/admin/view/nk/user/edit.html b/app/admin/view/nk/user/edit.html index bb68706..93d2e85 100644 --- a/app/admin/view/nk/user/edit.html +++ b/app/admin/view/nk/user/edit.html @@ -181,27 +181,27 @@
- +
-
+
- {volist name="planting.crops_msg" id="vo"} -
+ {volist name="planting.crops_msg" key="key" id="vo"} +
- 农作物名称 + 农作物名称
- 数量 + 数量
- 面积 + 面积
-
+ {/volist} - +
@@ -498,27 +498,37 @@ {block name="script"}