Esempio n. 1
0
 public function updateTerm($termid, $postArr, $valArr = null)
 {
     $retArr = array('status' => 0, 'message' => '数据不合法', 'term' => null);
     $postArr = $this->removeArrayNull($postArr);
     if (!empty($valArr)) {
         if (empty($valArr['val'])) {
             $retArr['message'] = '指标数据不合法';
             return $retArr;
         }
     }
     //数据检查
     if (empty($postArr) || !$termid) {
         $retArr['message'] = '数据不合法';
         // return $retArr;
     }
     $old = $this->getTerm($termid);
     // print_r($old);
     if (!$old) {
         $retArr['message'] = 'term不存在!';
         return $retArr;
     }
     $postArr['utime'] = date("Y-m-d H:i:s");
     //end 数据检查
     if ($valArr) {
         $valueArr = CUtil::formArrayFormatting($valArr);
         foreach ($valueArr as $k => &$val) {
             if (empty($val['val'])) {
                 unset($valueArr[$k]);
                 continue;
             }
             $val = $this->removeArrayNull($val);
         }
     }
     $ok = $this->updateData($this->tTerm, $postArr, $termid);
     // var_dump(CUtil::IsFalse($ok));
     if (!CUtil::IsFalse($ok)) {
         $term = $this->getTerm($termid);
         //更新参考值=====================================
         if ($valArr && !empty($valueArr)) {
             $_wh_ = array('termid' => $termid);
             $oldValArr = $this->getVals(null, $_wh_, array('only_data' => true, 'keyas' => 'id', 'aggregated' => true, 'limit' => 1000));
             $this->deleteData($this->tVal, $_wh_, 1000);
             $sorter = 127;
             foreach ($valueArr as $r0003) {
                 $r0003['termid'] = $termid;
                 $r0003['sorter'] = $sorter;
                 // $r0003['ctime']   = date("Y-m-d H:i:s");
                 $_old_id = intval($r0003['id']);
                 if (0 == $_old_id) {
                     unset($r0003['id']);
                     //重要
                 } else {
                     $r0003['id'] = $_old_id;
                 }
                 // print_r($r0003);
                 if (isset($oldValArr[$_old_id])) {
                     $r0003 = array_merge($oldValArr[$_old_id], $r0003);
                 }
                 // print_r($r0003);
                 $this->addAtom($this->tVal, $r0003);
                 $sorter--;
             }
         }
         //更新参考值==================================end
         $retArr['term'] = $term;
         $retArr['status'] = 1;
         $retArr['message'] = '更新成功';
     }
     return $retArr;
 }
Esempio n. 2
0
 public function updateTpl($tplid, $postArr, $details = null)
 {
     $retArr = array('status' => 0, 'message' => '数据不合法', 'tpl' => null);
     $postArr = $this->removeArrayNull($postArr);
     if (!empty($details)) {
         if (empty($details['termid'])) {
             $retArr['message'] = '模板数据不合法';
             return $retArr;
         }
     }
     //数据检查
     if (empty($postArr) || !$tplid) {
         $retArr['message'] = '数据不合法';
         return $retArr;
     }
     $old = $this->getTpl($tplid);
     if (!$old) {
         $retArr['message'] = 'tpl不存在!';
         return $retArr;
     }
     $postArr['utime'] = date("Y-m-d H:i:s");
     if (!empty($postArr['name'])) {
         $oldt = $this->getTpl(null, array('hospitalid' => $old['hospitalid'], 'name' => $postArr['name']));
         if ($oldt) {
             $retArr['message'] = '该模板名已存在';
             return $retArr;
         }
     }
     //end 数据检查
     if ($details) {
         $valueArr = CUtil::formArrayFormatting($details);
         foreach ($valueArr as $k => &$val) {
             if (empty($val['termid'])) {
                 unset($valueArr[$k]);
                 continue;
             }
             $val = $this->removeArrayNull($val);
         }
     }
     // print_r($valueArr);exit;
     $ok = $this->updateData($this->tTpl, $postArr, $tplid);
     // var_dump(CUtil::IsFalse($ok));
     if (!CUtil::IsFalse($ok)) {
         $tpl = $this->getTpl($tplid);
         //更新参考值=====================================
         if ($details && !empty($valueArr)) {
             $_wh_ = array('tplid' => $tplid);
             //查询详情(tpl_detail)的条件
             $oldValArr = $this->getMore($this->tTdetail, $_wh_, array('only_data' => true, 'keyas' => 'id', 'aggregated' => true, 'limit' => 1000));
             // print_r($oldValArr);exit;
             $this->deleteData($this->tTdetail, $_wh_, 1000);
             $sorter = 127;
             foreach ($valueArr as $r0003) {
                 $r0003['tplid'] = $tplid;
                 $r0003['sorter'] = $sorter;
                 // $r0003['ctime']   = date("Y-m-d H:i:s");
                 if (!isset($r0003['id'])) {
                     $r0003['id'] = null;
                 }
                 $_old_id = intval($r0003['id']);
                 if (0 == $_old_id) {
                     unset($r0003['id']);
                     //重要
                 } else {
                     $r0003['id'] = $_old_id;
                 }
                 // print_r($r0003);
                 if (isset($oldValArr[$_old_id])) {
                     $r0003 = array_merge($oldValArr[$_old_id], $r0003);
                 }
                 // print_r($r0003);
                 $this->addAtom($this->tTdetail, $r0003);
                 $sorter--;
             }
         }
         //更新参考值==================================end
         $retArr['tpl'] = $tpl;
         $retArr['status'] = 1;
         $retArr['message'] = '更新成功';
     }
     return $retArr;
 }