AccountType.Class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: kang
  5. * Date: 2021/3/6
  6. * Time: 15:14
  7. */
  8. namespace JinDouYun\Controller\Finance;
  9. use Mall\Framework\Core\ErrorCode;
  10. use Mall\Framework\Core\StatusCode;
  11. use JinDouYun\Controller\BaseController;
  12. use JinDouYun\Model\Finance\MAccountType;
  13. class AccountType extends BaseController
  14. {
  15. private $objMAccountType;
  16. public function __construct($isCheckAcl = true, $isMustLogin = true)
  17. {
  18. parent::__construct($isCheckAcl, $isMustLogin);
  19. $this->objMAccountType = new MAccountType($this->onlineEnterpriseId, $this->onlineUserId);
  20. }
  21. /**
  22. * 添加和编辑费用类型公共字段处理方法
  23. *
  24. * @return array
  25. */
  26. public function commonFieldFilter(){
  27. $params = $this->request->getRawJson();
  28. if( empty($params) ){
  29. $this->sendOutput('参数为空', ErrorCode::$paramError );
  30. }
  31. $accounTypeData = [
  32. 'enterpriseId' => $this->onlineEnterpriseId,
  33. 'name' => getArrayItem($params,'name'),
  34. 'type' => getArrayItem($params,'type' ,0),
  35. ];
  36. foreach($accounTypeData as $key => $value){
  37. if(empty($value) && $value !== 0){
  38. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  39. }
  40. }
  41. $accounTypeData['remarks'] = getArrayItem($params,'remarks','');
  42. return $accounTypeData;
  43. }
  44. /**
  45. * 添加费用类型
  46. */
  47. public function addAccountType()
  48. {
  49. $accounTypeData = $this->commonFieldFilter();
  50. $result = $this->objMAccountType ->addAccountType($accounTypeData);
  51. if($result->isSuccess()){
  52. parent::sendOutput($result->getData());
  53. }else{
  54. parent::sendOutput($result->getData(), $result->getErrorCode());
  55. }
  56. }
  57. /**
  58. * 获取指定费用类型
  59. */
  60. public function getAccountTypeInfo()
  61. {
  62. $accountTypeId = $this->request->param('request_id');
  63. if ( !$accountTypeId ) {
  64. $this->sendOutput('参数错误', ErrorCode::$paramError );
  65. }
  66. $result = $this->objMAccountType->getAccountTypeInfo($accountTypeId);
  67. if($result->isSuccess()){
  68. $this->sendOutput($result->getData());
  69. }else{
  70. $this->sendOutput($result->getData(), $result->getErrorCode());
  71. }
  72. }
  73. /**
  74. * 编辑费用类型
  75. */
  76. public function editAccountType()
  77. {
  78. $params = $this->request->getRawJson();
  79. if(empty($params)){
  80. $this->sendOutput('参数错误', ErrorCode::$paramError);
  81. }
  82. $result = $this->objMAccountType->editAccountType($params);
  83. if($result->isSuccess()){
  84. parent::sendOutput($result->getData());
  85. }else{
  86. parent::sendOutput($result->getData(), $result->getErrorCode());
  87. }
  88. }
  89. /**
  90. * 删除费用类型
  91. */
  92. public function delAccountType()
  93. {
  94. $accountTypeId = $this->request->param('request_id');
  95. if ( !$accountTypeId ) {
  96. $this->sendOutput('参数错误', ErrorCode::$paramError );
  97. }
  98. $result = $this->objMAccountType->delAccountType($accountTypeId);
  99. if($result->isSuccess()){
  100. parent::sendOutput($result->getData());
  101. }else{
  102. parent::sendOutput($result->getData(), $result->getErrorCode());
  103. }
  104. }
  105. /**
  106. * 后台所有费用类型
  107. */
  108. public function getAllAccountType()
  109. {
  110. $params = $this->request->getRawJson();
  111. if(empty($params)){
  112. $this->sendOutput('参数错误', ErrorCode::$paramError);
  113. }
  114. $conditon = [
  115. 'type' => getArrayItem($params, 'type', 0)
  116. ];
  117. $result = $this->objMAccountType->getAllAccountType($conditon);
  118. if($result->isSuccess()){
  119. parent::sendOutput($result->getData(), 0);
  120. }else{
  121. parent::sendOutput($result->getData(), $result->getErrorCode());
  122. }
  123. }
  124. }