public function updateRice()
 {
     $user_id = session('user_id');
     $riceKind = I("rice_kind");
     $riceModel = D("InfoRice");
     if (IS_POST) {
         $rice_id = I("rice_id");
         if ($this->canUpdateRice($riceKind, $rice_id)) {
             //判断是否可以更改
             $dist_id = getDistrictIdByName(I("rice_region"));
             $data['rice_id'] = $rice_id;
             switch ($riceKind) {
                 case '1':
                     $data['user_id'] = $user_id;
                     $data['dist_id'] = $dist_id;
                     $data['year'] = I('year');
                     $data['population'] = I('population');
                     $data['agri_population'] = I('agri_population');
                     $data['agri_area'] = I('agri_area');
                     $data['field_area'] = I('field_area');
                     $data['total_sown_area'] = I('total_sown_area');
                     $data['zone_area'] = I('zone_area');
                     break;
                 case '2':
                     //早稻信息
                     $data['e_sown_area'] = I('e_sown_area');
                     $data['e_disaster_area'] = I('e_disaster_area');
                     $data['e_production'] = I('e_production');
                     $data['e_market_price'] = I('e_market_price');
                     $data['e_purchase_price'] = I('e_purchase_price');
                     $data['e_fertilizer_price'] = I('e_fertilizer_price');
                     break;
                 case '3':
                     //晚稻信息
                     $data['l_sown_area'] = I('l_sown_area');
                     $data['l_disaster_area'] = I('l_disaster_area');
                     $data['l_production'] = I('l_production');
                     $data['l_market_price'] = I('l_market_price');
                     $data['l_purchase_price'] = I('l_purchase_price');
                     $data['l_fertilizer_price'] = I('l_fertilizer_price');
                     break;
             }
             $result = $riceModel->updateRice($data, $riceKind);
             if ($result) {
                 $riceModel->setRiceState($data["rice_id"], 2, $riceKind);
                 $this->success("修改成功!", U("manageRice"));
             } else {
                 $this->error($riceModel->getError());
             }
         } else {
             if (empty($riceStatus) && $riceStatus != 0) {
                 $this->error("记录不存在");
             }
         }
     } else {
         $rice_id = I('rice_id');
         $ricedata = M("InfoRice")->where("rice_id='{$rice_id}'")->find();
         $ricedata['brice_status'] = $riceModel->getBRiceState($rice_id);
         $ricedata['erice_status'] = $riceModel->getERiceState($rice_id);
         $ricedata['lrice_status'] = $riceModel->getLRiceState($rice_id);
         $ricedata["rice_region"] = getDistrictNameById($ricedata["dist_id"]);
         $this->assign("ricedata", $ricedata);
         $this->display();
     }
 }
 public function updateDisaster()
 {
     $disa_id = I("disa_id");
     if (IS_POST) {
         $disaster = D("InfoDisaster");
         $data["disa_id"] = $disa_id;
         $data["disa_dist"] = getDistrictIdByName(I("disa_dist"));
         $data["disa_begindate"] = date(I("disa_begindate"));
         $data["disa_enddate"] = date(I("disa_enddate"));
         $data["disa_situ"] = I("disa_situ");
         $data["disa_area"] = I("disa_area");
         $data["disa_eloss"] = I("disa_eloss");
         if ($data["disa_begindate"] <= $data["disa_enddate"]) {
             //判断灾难开始时间和结束时间的大小
             $result = $disaster->updateDisaster($data);
             if ($result) {
                 $this->success("修改成功!", U("manageDisaster"));
             } else {
                 //$this->redirect(U("updateDisaster"),"",3, $disaster->getError());
                 $this->error($disaster->getError());
             }
         } else {
             $this->error("起始时间不能晚于结束时间!");
         }
     } else {
         $disaster = M("InfoDisaster");
         $data = $disaster->where("disa_id='{$disa_id}'")->find();
         $data["disa_begindate"] = date("Y-m-d", strtotime($data["disa_begindate"]));
         $data["disa_enddate"] = date("Y-m-d", strtotime($data["disa_enddate"]));
         $data["disa_dist"] = getDistrictNameById($data["disa_dist"]);
         $disalist = $this->getDisasterData();
         $ricedata["disa_number"] = count($disalist);
         $wavedata = $this->getWaveRice();
         $ricedata["wave_number"] = count($wavedata);
         $this->assign("wavedata", $wavedata);
         $this->assign("disalist", $disalist);
         $this->assign("ricedata", $ricedata);
         $this->assign("disadata", $data);
         $this->display();
     }
 }
 public function updateInfo()
 {
     if (isLogin() != 0 && session('user_level') == 1) {
         if (IS_POST) {
             $data["user_region"] = getDistrictIdByName(I("user_region"));
             $data["user_name"] = I("user_name");
             $data["user_pw"] = I("user_pw");
             $data["user_phone"] = I("user_phone");
             $data['user_email'] = I('user_email');
             $data["user_address"] = I("user_address");
             $data["user_id"] = I("user_id");
             $user = D('InfoUser');
             $uid = $user->updateUserInfo($data);
             if ($uid > 0) {
                 $this->success("修改成功!");
             } else {
                 $this->error($user->getError());
             }
         } else {
             $user_id = I("user_id");
             $user = M("InfoUser");
             $userinfo = $user->where("user_id='{$user_id}'")->find();
             $userinfo['user_region'] = getDistrictNameById($userinfo['user_region']);
             $disalist = $this->getDisasterData();
             $ricedata["disa_number"] = count($disalist);
             $wavedata = $this->getWaveRice();
             $ricedata["wave_number"] = count($wavedata);
             $this->assign("wavedata", $wavedata);
             $this->assign("disalist", $disalist);
             $this->assign("ricedata", $ricedata);
             $this->assign("userinfo", $userinfo);
             $this->display();
         }
     } else {
         $this->error("请先登录", U('Home/User/login'));
     }
 }
 public function updateRice()
 {
     if (IS_POST) {
         $user_id = (int) session('user_id');
         $modifier['modifier_level'] = (int) session('user_level');
         $modifier['modifier_id'] = (int) $user_id;
         $rice = D("InfoRice");
         $rice_id = (int) I('rice_id');
         $rice_kind = (int) I("rice_kind");
         $rice_status = $rice->where("rice_id='{$rice_id}'")->getField("rice_status");
         $reason = trim(I("reason"));
         //修改理由
         if ($modifier['modifier_level'] == 1) {
             $dist_name = I('rice_region');
             $dist_id = getDistrictIdByName($dist_name);
             $data['rice_id'] = $rice_id;
             $data['rice_status'] = $rice_status;
             if (1 == $rice_kind) {
                 $data['dist_id'] = $dist_id;
                 $data['population'] = I('population');
                 $data['agri_population'] = I('agri_population');
                 $data['agri_area'] = I('agri_area');
                 $data['field_area'] = I('field_area');
                 $data['total_sown_area'] = I('total_sown_area');
                 $data['zone_area'] = I('zone_area');
             } else {
                 if (2 == $rice_kind) {
                     //早稻信息
                     $data['e_sown_area'] = I('e_sown_area');
                     $data['e_disaster_area'] = I('e_disaster_area');
                     $data['e_production'] = I('e_production');
                     $data['e_market_price'] = I('e_market_price');
                     $data['e_purchase_price'] = I('e_purchase_price');
                     $data['e_fertilizer_price'] = I('e_fertilizer_price');
                 } else {
                     //晚稻信息
                     $data['l_sown_area'] = I('l_sown_area');
                     $data['l_disaster_area'] = I('l_disaster_area');
                     $data['l_production'] = I('l_production');
                     $data['l_market_price'] = I('l_market_price');
                     $data['l_purchase_price'] = I('l_purchase_price');
                     $data['l_fertilizer_price'] = I('l_fertilizer_price');
                 }
             }
             $rid = $rice->updateRice($data, $rice_kind, $reason);
             //会自动计算分析指标(如果都通过审核了)
             if ($rid) {
                 $this->success("修改成功!");
             } else {
                 $this->error($rice->getError());
             }
         }
     } else {
         //显示水稻信息更新的输入页面
         $rice_id = I("rice_id");
         $rice = D("InfoRice");
         $data = $rice->where("rice_id='{$rice_id}'")->find();
         $data['rice_region'] = getDistrictNameById($data['dist_id']);
         $bstatus = $data["rice_status"] & 7;
         $estatus = $data["rice_status"] >> 3 & 7;
         $lstatus = $data["rice_status"] >> 6 & 7;
         $data['brice_status'] = $rice->getRiceState($bstatus);
         $data['erice_status'] = $rice->getRiceState($estatus);
         $data['lrice_status'] = $rice->getRiceState($lstatus);
         $disalist = $this->getDisasterData();
         $data["disa_number"] = count($disalist);
         $wavedata = $this->getWaveRice();
         $data["wave_number"] = count($wavedata);
         $this->assign("wavedata", $wavedata);
         $this->assign("disalist", $disalist);
         $this->assign("ricedata", $data);
         $this->display();
     }
 }