userCenterId = $userCenterId; $this->enterpriseId = $enterpriseId; $this->objDFinanceType = new DFinanceType('finance'); $this->objDAdminSetting = new DAdminSetting('default'); } /** * 添加财务类型 * * @param array $params 财务类型数据 * * @return ResultWrapper */ public function addFinanceType($params) { $setDefault = self::createDefaultValue(); if ($setDefault->isSuccess() == false) { return ResultWrapper::fail($setDefault->getData(), $setDefault->getErrorCode()); } if($params['isDefault'] == StatusCode::$standard) { $result = self::updateDefaultStatus(); if($result->isSuccess() == false) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } } $FinanceTypeId = $this->objDFinanceType->insert($params); if($FinanceTypeId === false){ return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); }else{ return ResultWrapper::success($FinanceTypeId); } } public function updateDefaultStatus() { $result = $this->objDFinanceType->update(['isDefault'=>StatusCode::$delete]); if($result === false){ return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); }else{ return ResultWrapper::success($result); } } /** * 获取指定财务类型信息 */ public function getFinanceTypeInfo($FinanceTypeIds) { $dbResult = $this->objDFinanceType->get($FinanceTypeIds); if($dbResult === false){ return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); }else{ return ResultWrapper::success($dbResult); } } /** * 编辑财务类型 * * @param int|array $params 修改财务类型的数据 * * @return ResultWrapper */ public function editFinanceType($params) { if( empty($params['id']) ){ return ResultWrapper::fail('没有指定要修改的FinanceTypeid', ErrorCode::$paramError); } if($params['isDefault'] == StatusCode::$standard) { $result = self::updateDefaultStatus(); if($result->isSuccess() == false) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } } $updateFinanceTypeId = $params['id']; unset($params['id']); $dbResult = $this->objDFinanceType->update($params, $updateFinanceTypeId); if($dbResult === false){ return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); }else{ return ResultWrapper::success($dbResult); } } /** * 删除财务类型 * * @param array $delFinanceIds 要删除的财务类型id * * @return ResultWrapper */ public function delFinanceType($delFinanceTypeIds) { if (empty($delFinanceTypeIds)) { return ResultWrapper::fail('参数错误', ErrorCode::$paramError); } $dbResult = $this->objDFinanceType->update( ['deleteStatus'=>StatusCode::$delete], $delFinanceTypeIds ); if($dbResult === false){ return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); }else{ return ResultWrapper::success($dbResult); } } /** * 财务类型启用和禁用 * @param array $params * @return ResultWrapper */ public function updateFinanceTypeStatus($params) { $dbResult = $this->objDFinanceType->update( ['enableStatus'=>$params['enableStatus']], $params['id'] ); if($dbResult === false){ return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); }else{ return ResultWrapper::success($dbResult); } } /** * 财务类型是否默认 * @param array $params * @return ResultWrapper */ public function updateFinanceTypeDefaultStatus($params) { $result = self::updateDefaultStatus(); if($result->isSuccess() == false) { return ResultWrapper::fail($result->getData(), $result->getErrorCode()); } $dbResult = $this->objDFinanceType->update( ['isDefault'=>$params['isDefault']], $params['id'] ); if($dbResult === false){ return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); }else{ return ResultWrapper::success($dbResult); } } /** * 获取所有财务类型数据 * * @param array $selectParams 过滤条件 * * @return ResultWrapper */ public function getAllFinanceType($selectParams) { $setDefault = self::createDefaultValue(); if ($setDefault->isSuccess() == false) { return ResultWrapper::fail($setDefault->getData(), $setDefault->getErrorCode()); } $limit = $selectParams['limit']; unset($selectParams['limit']); $offset = $selectParams['offset']; unset($selectParams['offset']); $selectParams['deleteStatus'] = StatusCode::$standard; $selectParams['enterpriseId'] = [0,$this->enterpriseId]; $dbResult = $this->objDFinanceType->select($selectParams, '*', 'createTime desc', $limit, $offset); if($dbResult === false){ return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); } $total = $this->objDFinanceType->count($selectParams); $return = [ 'data' => $dbResult, 'total' => ($total)?intval($total):0, ]; return ResultWrapper::success($return); } /** * 获取所有财务类型数据(不分页) * @param $selectParams * @return ResultWrapper */ public function getAllFinanceTypeNoPage($selectParams) { $setDefault = self::createDefaultValue(); if ($setDefault->isSuccess() == false) { return ResultWrapper::fail($setDefault->getData(), $setDefault->getErrorCode()); } $selectParams['deleteStatus'] = StatusCode::$standard; $selectParams['enterpriseId'] = [0,$this->enterpriseId]; $dbResult = $this->objDFinanceType->select($selectParams, '*', 'createTime desc'); if($dbResult === false){ return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); } return ResultWrapper::success($dbResult); } /** * 打入默认数据 */ public function createDefaultValue() { //查出当前企业有没有系统设定的财务类型,没有则打入数据 $selectParams['isSystem'] = StatusCode::$standard; $dbResult = $this->objDFinanceType->select($selectParams); if($dbResult === false){ return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); } if (empty($dbResult)) { $defaultFinanceType = $this->objDAdminSetting->select(['type' => StatusCode::$adminSettingType['financeType']]); if(empty($defaultFinanceType)) { return ResultWrapper::fail('系统未配置默认财务类型,请联系管理员', ErrorCode::$dberror); } foreach ($defaultFinanceType as $value) { $content = json_decode($value['content'], true); $v=[]; $v['isSystem'] = StatusCode::$standard; $v['enterpriseId'] = 0; $v['createTime'] = time(); $v['link'] =$content['link']; $v['name'] =$content['name']; $v['isDefault'] =$content['isDefault']; $v['createTime'] = time(); $v['updateTime'] = time(); $result = $this->objDFinanceType->insert($v); if($result === false) { return ResultWrapper::fail($this->objDFinanceType->error(), ErrorCode::$dberror); } unset($result); } } return ResultWrapper::success(); } }