Пример #1
0
 /**
  * 更新资料.
  *  
  * @access public
  * @param array $data 包含 base(基本信息)一维, child(子女)二维, asset(资产)二维, exp(工作经历)二维.
  * 
  * @param integer $id 基本信息 ID.
  * @return boolean 成功返回 TRUE; 失败返回 FALSE.
  */
 public function updateInfo(array $data, $id = NULL)
 {
     $flagBase = $flagChild = $flagAsset = $flagExp = TRUE;
     // 成功标记位.
     $dataBase = $data['base'];
     $dataChild = $data['child'];
     $dataAsset = $data['asset'];
     $dataExp = $data['exp'];
     unset($data);
     $this->startTrans();
     // 开启事务.
     // 新增.
     if (NULL === $id) {
         // 基本信息.
         $flagBase = FALSE === $this->add($dataBase) ? FALSE : TRUE;
         if (FALSE === $flagBase) {
             $this->rollback();
             return FALSE;
         }
         $mainId = $this->getLastInsID();
         // 基本信息主键  ID.
         // 子女数据.
         if (!empty($dataChild)) {
             // 处理数据, 添加 base_id.
             foreach ($dataChild as &$row) {
                 $row['base_id'] = $mainId;
                 unset($row['id']);
             }
             unset($row);
             $flagChild = FALSE === D('FamousChildren')->addAll($dataChild) ? FALSE : TRUE;
         }
         // 资产数据.
         if (!empty($dataAsset)) {
             // 处理数据, 添加 base_id.
             foreach ($dataAsset as &$row) {
                 $row['base_id'] = $mainId;
                 unset($row['id']);
             }
             unset($row);
             $flagAsset = FALSE === D('FamousAsset')->addAll($dataAsset) ? FALSE : TRUE;
         }
         // 工作经历数据.
         if (!empty($dataExp)) {
             // 处理数据, 添加 base_id.
             foreach ($dataExp as &$row) {
                 $row['base_id'] = $mainId;
                 unset($row['id']);
             }
             unset($row);
             $flagExp = FALSE === D('FamousWorkExperience')->addAll($dataExp) ? FALSE : TRUE;
         }
         if ($flagBase && $flagChild && $flagAsset && $flagExp) {
             $this->commit();
             return TRUE;
         } else {
             $this->rollback();
             return FALSE;
         }
     }
     // 修改.
     // 基本信息.
     $flagBase = FALSE === $this->where(['id' => $id])->save($dataBase) ? FALSE : TRUE;
     if (FALSE === $flagBase) {
         $this->rollback();
         return FALSE;
     }
     // 子女.
     if (!empty($dataChild)) {
         $_tmpDataAdd = [];
         $model = new FamousChildrenModel();
         $_res = TRUE;
         foreach ($dataChild as $key => $row) {
             if (empty($row['id'])) {
                 $_tmpDataAdd[$key] = $row;
                 $_tmpDataAdd[$key]['base_id'] = $id;
                 unset($_tmpDataAdd[$key]['id']);
                 // 删除主键 ID.
             } else {
                 $_id = $row['id'];
                 unset($row['id']);
                 $_res = FALSE === $model->where(['id' => $_id])->save($row) ? FALSE : TRUE;
             }
             // 遇到处理失败直接返回.
             if (!$_res) {
                 $this->rollback();
                 return FALSE;
             }
         }
         $_tmpDataAdd = array_values($_tmpDataAdd);
         if (!empty($_tmpDataAdd)) {
             $flagChild = FALSE === $model->addAll($_tmpDataAdd) ? FALSE : TRUE;
             unset($_tmpDataAdd);
         }
     }
     // 资产.
     if (!empty($dataAsset)) {
         $_tmpDataAdd = [];
         $model = new FamousAssetModel();
         $_res = TRUE;
         foreach ($dataAsset as $key => $row) {
             if (empty($row['id'])) {
                 $_tmpDataAdd[$key] = $row;
                 $_tmpDataAdd[$key]['base_id'] = $id;
                 unset($_tmpDataAdd[$key]['id']);
                 // 删除主键 ID.
             } else {
                 $_id = $row['id'];
                 unset($row['id']);
                 $_res = FALSE === $model->where(['id' => $_id])->save($row) ? FALSE : TRUE;
             }
             // 遇到处理失败直接返回.
             if (!$_res) {
                 $this->rollback();
                 return FALSE;
             }
         }
         $_tmpDataAdd = array_values($_tmpDataAdd);
         if (!empty($_tmpDataAdd)) {
             $flagAsset = FALSE === $model->addAll($_tmpDataAdd) ? FALSE : TRUE;
             unset($_tmpDataAdd);
         }
     }
     // 工作经历.
     if (!empty($dataExp)) {
         $_tmpDataAdd = [];
         $model = new FamousWorkExperienceModel();
         $_res = TRUE;
         foreach ($dataExp as $key => $row) {
             if (empty($row['id'])) {
                 $_tmpDataAdd[$key] = $row;
                 $_tmpDataAdd[$key]['base_id'] = $id;
                 unset($_tmpDataAdd[$key]['id']);
                 // 删除主键 ID.
             } else {
                 $_id = $row['id'];
                 unset($row['id']);
                 $_res = FALSE === $model->where(['id' => $_id])->save($row) ? FALSE : TRUE;
             }
             // 遇到处理失败直接返回.
             if (!$_res) {
                 $this->rollback();
                 return FALSE;
             }
         }
         $_tmpDataAdd = array_values($_tmpDataAdd);
         if (!empty($_tmpDataAdd)) {
             $flagExp = FALSE === $model->addAll($_tmpDataAdd) ? FALSE : TRUE;
             unset($_tmpDataAdd);
         }
     }
     if ($flagBase && $flagChild && $flagAsset && $flagExp) {
         $this->commit();
         return TRUE;
     } else {
         $this->rollback();
         return FALSE;
     }
 }
Пример #2
0
 /**
  * 删除子女.
  * 
  * @access public
  * @return void
  */
 public function deleteChildren()
 {
     $result = ['status' => 1, 'msg' => '删除成功'];
     $id = (int) I('post.id', '');
     if ($id < 1) {
         $result['status'] = 0;
         $result['msg'] = '参数错误';
         $this->ajaxReturn($result, 'json');
     }
     $model = new FamousChildrenModel();
     if ($model->remove($id)) {
         $this->ajaxReturn($result, 'json');
     } else {
         $result['status'] = 0;
         $result['msg'] = '删除失败';
         $this->ajaxReturn($result, 'json');
     }
 }