MAccountType.Class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: kang
  5. * Date: 2021/3/6
  6. * Time: 15:16
  7. */
  8. namespace JinDouYun\Model\Finance;
  9. use JinDouYun\Model\MBaseModel;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use JinDouYun\Dao\Order\DOrder;
  14. use JinDouYun\Dao\Stock\DInventoryOut;
  15. use JinDouYun\Dao\Finance\DAccountType;
  16. class MAccountType extends MBaseModel
  17. {
  18. private $objDAccountType;
  19. private $enterpriseId;
  20. private $userCenterId;
  21. public function __construct($enterpriseId, $userCenterId)
  22. {
  23. $this->userCenterId = $userCenterId;
  24. $this->enterpriseId = $enterpriseId;
  25. parent::__construct($enterpriseId, $userCenterId);
  26. $this->objDAccountType = new DAccountType('finance');
  27. }
  28. /**
  29. * 添加费用类型
  30. * @param $params
  31. * @return ResultWrapper
  32. * @throws Exception
  33. */
  34. public function addAccountType($params)
  35. {
  36. $dbResult = $this->objDAccountType->get(['name' => $params['name'],'type' => $params['type']]);
  37. if($dbResult === false){
  38. return ResultWrapper::fail($this->objDAccountType->error(), ErrorCode::$dberror);
  39. }
  40. if(!empty($dbResult)){
  41. return ResultWrapper::fail('该费用类型已存在', ErrorCode::$paramError);
  42. }
  43. unset($dbResult);
  44. $accountTypeId = $this->objDAccountType->insert($params);
  45. if($accountTypeId === false){
  46. return ResultWrapper::fail($this->objDAccountType->error(), ErrorCode::$dberror);
  47. }
  48. return ResultWrapper::success($accountTypeId);
  49. }
  50. /**
  51. * 获取指定费用类型
  52. */
  53. public function getAccountTypeInfo($accountTypeId)
  54. {
  55. if( empty($accountTypeId) ){
  56. return ResultWrapper::fail('接收不到要请求的费用类型', ErrorCode::$paramError);
  57. }
  58. $dbResult = $this->objDAccountType-> select($accountTypeId);
  59. if($dbResult === false){
  60. return ResultWrapper::fail($this->objDAccountType->error(), ErrorCode::$dberror);
  61. }else{
  62. return ResultWrapper::success($dbResult);
  63. }
  64. }
  65. /**
  66. * 编辑费用类型
  67. *
  68. * @param int|array $params 修改费用类型的数据
  69. *
  70. * @return ResultWrapper
  71. */
  72. public function editAccountType($params)
  73. {
  74. if( empty($params['id']) ){
  75. return ResultWrapper::fail('没有指定要修改的费用类型', ErrorCode::$paramError);
  76. }
  77. $updateAccountTypeId = $params['id'];
  78. unset($params['id']);
  79. $dbResult = $this->objDAccountType->update($params, $updateAccountTypeId);
  80. if($dbResult === false){
  81. return ResultWrapper::fail($this->objDAccountType->error(), ErrorCode::$dberror);
  82. }else{
  83. return ResultWrapper::success($dbResult);
  84. }
  85. }
  86. /**
  87. * 删除费用类型
  88. *
  89. * @param array $params 要删除费用类型
  90. *
  91. * @return ResultWrapper
  92. */
  93. public function delAccountType($accountTypeId)
  94. {
  95. $updateData = [
  96. 'deleteStatus' => StatusCode::$delete,
  97. ];
  98. $dbResult = $this->objDAccountType->update($updateData, $accountTypeId);
  99. if($dbResult === false){
  100. return ResultWrapper::fail($this->objDAccountType->error(), ErrorCode::$dberror);
  101. }else{
  102. return ResultWrapper::success($dbResult);
  103. }
  104. }
  105. /**
  106. * 获取所有费用类型
  107. *
  108. * @param array $selectParams 过滤条件
  109. *
  110. * @return ResultWrapper
  111. */
  112. public function getAllAccountType($conditon)
  113. {
  114. if( !empty($conditon['type']) ){
  115. $selectParams['type'] = $conditon['type'];
  116. }
  117. $selectParams['deleteStatus'] = StatusCode::$standard;
  118. $dbResult = $this->objDAccountType->select($selectParams, '*', 'createTime desc');
  119. if($dbResult === false){
  120. return ResultWrapper::fail($this->objDAccountType->error(), ErrorCode::$dberror);
  121. }
  122. return ResultWrapper::success($dbResult);
  123. }
  124. }