123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- <?php
- /**
- * 财务类型管理模块
- * Created by PhpStorm.
- * User: wxj
- * Date: 2019/10/30
- * Time: 14:02
- */
- namespace JinDouYun\Model\Finance;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Dao\Finance\DFinanceType;
- use JinDouYun\Dao\System\DAdminSetting;
- class MFinanceType {
- private $objDFinanceType;
- private $objDAdminSetting;
- private $enterpriseId;
- private $userCenterId;
- public function __construct($enterpriseId, $userCenterId)
- {
- $this->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();
- }
-
- }
|