Ejemplo n.º 1
0
 public function editAction()
 {
     $p = $_REQUEST;
     $pWeight = empty($p['weight']) ? Tool_Fnc::ajaxMsg('干体重不能为空') : floatval($p['weight']);
     $tTime = time();
     $tDWLMO = new DryweightlogModel();
     $tDWLRow = $tDWLMO->field('id')->where('uid = ' . $this->tUid . ' and date = \'' . date('Y-m-d', $tTime) . '\'')->fRow();
     $tUMO = new UserModel();
     $tURow = $tUMO->field('user_type')->where(' id = ' . $this->tUid)->fRow();
     if ($tURow['user_type'] == 1) {
         Tool_Fnc::ajaxMsg('操作异常');
     }
     $tData = array('weight' => $pWeight);
     if (empty($tDWLRow['id'])) {
         $tData = array_merge($tData, array('created' => $tTime, 'uid' => $this->tUid, 'date' => date('Y-m-d', $tTime), 'year' => date('Y', $tTime), 'month' => date('Y-m', $tTime)));
     } else {
         $tData = array_merge($tData, array('updated' => $tTime, 'id' => $tDWLRow['id']));
     }
     $tUMO->begin();
     if (!$tDWLMO->save($tData)) {
         $tUMO->back();
         Tool_Fnc::ajaxMsg('修改失败 001');
     }
     $tUData = array('id' => $this->tUid, 'dry_weight' => $pWeight, 'updated' => $tTime);
     if (!$tUMO->update($tUData)) {
         $tUMO->back();
         Tool_Fnc::ajaxMsg('修改失败 002');
     }
     $tUMO->commit();
     Tool_Fnc::ajaxMsg('操作成功', 1);
 }
Ejemplo n.º 2
0
 public function editAction()
 {
     $p = $_REQUEST;
     $tUMO = new UserModel();
     $tURow = $tUMO->field('user_type')->where(' id = ' . $this->tUid)->fRow();
     if ($tURow['user_type'] == 1) {
         Tool_Fnc::ajaxMsg('操作异常');
     }
     $tData = array();
     if (isset($p['name'])) {
         $tData = array_merge($tData, array('nickname' => Tool_Fnc::safe_string($p['name'])));
     }
     if (isset($p['date_of_birth'])) {
         $tData = array_merge($tData, array('date_of_birth' => date('Y-m-d', strtotime($p['date_of_birth']))));
     }
     if (isset($p['sex'])) {
         $tData = array_merge($tData, array('sex' => intval($p['sex'])));
     }
     $tTime = time();
     //存在干体重修改,则更新干体重记录
     $pDryWeight = !isset($p['dry_weight']) ? '' : floatval($p['dry_weight']);
     $tUMO->begin();
     if (!empty($pDryWeight)) {
         $tData = array_merge($tData, array('dry_weight' => $pDryWeight));
         $tDWLMO = new DryweightlogModel();
         $tDWLRow = $tDWLMO->field('id')->where('uid = ' . $this->tUid . ' and date = \'' . date('Y-m-d', $tTime) . '\'')->fRow();
         if (empty($tDWLRow['id'])) {
             $tDWLData = array('weight' => $pDryWeight, 'uid' => $this->tUid, 'created' => $tTime, 'date' => date('Y-m-d', $tTime), 'month' => date('Y-m', $tTime), 'year' => date('Y', $tTime));
         } else {
             $tDWLData = array('weight' => $pDryWeight, 'updated' => $tTime, 'id' => $tDWLRow['id']);
         }
         if (!$tDWLMO->save($tDWLData)) {
             $tUMO->back();
             Tool_Fnc::ajaxMsg('修改失败 001');
         }
     }
     //存在名字修改,则更新健康档案中的名字字段
     if (isset($p['name']) && !empty($p['name'])) {
         $tUAMO = new UserassessmentModel();
         $tUARow = $tUAMO->field('id,name')->where('uid = ' . $this->tUid)->fRow();
         if (!empty($tUARow['id'])) {
             $tUADatas = array('id' => $tUARow['id'], 'name' => Tool_Fnc::safe_string($p['name']), 'updated' => $tTime);
             if (!$tUAMO->update($tUADatas)) {
                 $tUMO->back();
                 Tool_Fnc::ajaxMsg('修改失败 002');
             }
         } else {
             $tUADatas = array('uid' => $this->tUid, 'name' => Tool_Fnc::safe_string($p['name']), 'created' => $tTime);
             if (!$tUAMO->insert($tUADatas)) {
                 $tUMO->back();
                 Tool_Fnc::ajaxMsg('修改失败 002');
             }
         }
     }
     $tData = array_merge($tData, array('id' => $this->tUid, 'updated' => $tTime));
     if (!$tUMO->update($tData)) {
         $tUMO->back();
         Tool_Fnc::ajaxMsg('修改失败 003');
     }
     $tUMO->commit();
     Tool_Fnc::ajaxMsg('操作成功', 1);
 }