FinanceType.Class.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /**
  3. * 财务类型管理模块
  4. * Created by PhpStorm.
  5. * User: tpl
  6. * Date: 2019/10/30
  7. * Time: 13:54
  8. */
  9. namespace JinDouYun\Controller\Finance;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Finance\MFinanceType;
  14. class FinanceType extends BaseController
  15. {
  16. private $objMFinanceType;
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMFinanceType = new MFinanceType($this->onlineEnterpriseId, $this->onlineUserId);
  21. }
  22. /**
  23. * 添加和编辑财务类型管理公共字段处理方法
  24. *
  25. * @return array
  26. */
  27. public function commonFieldFilter(){
  28. $params = $this->request->getRawJson();
  29. if( empty($params) ){
  30. $this->sendOutput('参数为空', ErrorCode::$paramError );
  31. }
  32. $financeTypeData = [
  33. 'enterpriseId' => $this->onlineEnterpriseId,
  34. 'link' => isset($params['link']) ? $params['link'] : '',
  35. 'name' => isset($params['name']) ? $params['name'] : '',
  36. 'isDefault' => isset($params['isDefault']) ? $params['isDefault'] : '',
  37. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  38. ];
  39. foreach($financeTypeData as $key => $value){
  40. if(empty($value) && $value !== 0){
  41. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  42. }
  43. }
  44. $financeTypeData['deleteStatus']= StatusCode::$standard;
  45. $financeTypeData['createTime'] = time();
  46. $financeTypeData['updateTime'] = time();
  47. return $financeTypeData;
  48. }
  49. /**
  50. * 添加财务类型
  51. */
  52. public function addFinanceType()
  53. {
  54. $financeTypeData = $this->commonFieldFilter();
  55. $result = $this->objMFinanceType ->addFinanceType($financeTypeData);
  56. if($result->isSuccess()){
  57. parent::sendOutput($result->getData());
  58. }else{
  59. parent::sendOutput($result->getData(), $result->getErrorCode());
  60. }
  61. }
  62. /**
  63. * 获取指定财务类型信息
  64. */
  65. public function getFinanceTypeInfo()
  66. {
  67. $financeTypeId = $this->request->param('request_id');
  68. if ( !$financeTypeId ) {
  69. $this->sendOutput('参数错误', ErrorCode::$paramError );
  70. }
  71. $result = $this->objMFinanceType->getFinanceTypeInfo($financeTypeId);
  72. if($result->isSuccess()){
  73. $this->sendOutput($result->getData());
  74. }else{
  75. $this->sendOutput($result->getData(), $result->getErrorCode());
  76. }
  77. }
  78. /**
  79. * 编辑财务类型
  80. */
  81. public function editFinanceType()
  82. {
  83. $financeTypeId = $this->request->param('request_id');
  84. if(empty($financeTypeId)){
  85. $this->sendOutput('参数错误', ErrorCode::$paramError);
  86. }
  87. $financeTypeData = $this->commonFieldFilter();
  88. $financeTypeData['id'] = $financeTypeId;
  89. unset($financeTypeData['createTime']);
  90. $result = $this->objMFinanceType->editFinanceType($financeTypeData);
  91. if($result->isSuccess()){
  92. parent::sendOutput($result->getData());
  93. }else{
  94. parent::sendOutput($result->getData(), $result->getErrorCode());
  95. }
  96. }
  97. /**
  98. * 删除财务类型
  99. */
  100. public function delFinanceType()
  101. {
  102. $financeTypeId = $this->request->param('request_id');
  103. if(!$financeTypeId){
  104. $this->sendOutput('参数错误', ErrorCode::$paramError);
  105. }
  106. $result = $this->objMFinanceType->delFinanceType($financeTypeId);
  107. if($result->isSuccess()){
  108. parent::sendOutput($result->getData());
  109. }else{
  110. parent::sendOutput($result->getData(), $result->getErrorCode());
  111. }
  112. }
  113. /**
  114. * 财务类型启用和禁用
  115. */
  116. public function updateFinanceTypeStatus()
  117. {
  118. $params = $this->request->getRawJson();
  119. if( empty($params['id']) && empty($params['enableStatus'])){
  120. $this->sendOutput('参数为空', ErrorCode::$paramError );
  121. }
  122. $result = $this->objMFinanceType->updateFinanceTypeStatus($params);
  123. if($result->isSuccess()){
  124. parent::sendOutput($result->getData());
  125. }else{
  126. parent::sendOutput($result->getData(), $result->getErrorCode());
  127. }
  128. }
  129. /**
  130. * 财务类型默认
  131. */
  132. public function updateFinanceTypeDefaultStatus()
  133. {
  134. $params = $this->request->getRawJson();
  135. if( empty($params['id']) && empty($params['isDefault'])){
  136. $this->sendOutput('参数为空', ErrorCode::$paramError );
  137. }
  138. $result = $this->objMFinanceType->updateFinanceTypeDefaultStatus($params);
  139. if($result->isSuccess()){
  140. parent::sendOutput($result->getData());
  141. }else{
  142. parent::sendOutput($result->getData(), $result->getErrorCode());
  143. }
  144. }
  145. /**
  146. * 后台所有财务类型列表
  147. */
  148. public function getAllFinanceType()
  149. {
  150. $params = $this->request->getRawJson();
  151. if( empty($params) ){
  152. $this->sendOutput('参数为空', ErrorCode::$paramError );
  153. }
  154. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  155. $selectParams['limit'] = $pageParams['limit'];
  156. $selectParams['offset'] = $pageParams['offset'];
  157. $result = $this->objMFinanceType->getAllFinanceType($selectParams);
  158. if($result->isSuccess()){
  159. $returnData = $result->getData();
  160. $pageData = [
  161. 'pageIndex' => $params['page'],
  162. 'pageSize' => $params['pageSize'],
  163. 'pageTotal' => $returnData['total'],
  164. ];
  165. parent::sendOutput($returnData['data'], 0, $pageData);
  166. }else{
  167. parent::sendOutput($result->getData(), $result->getErrorCode());
  168. }
  169. }
  170. /**
  171. * 后台所有财务类型列表 (不分页)
  172. */
  173. public function getAllFinanceTypeNoPage()
  174. {
  175. $link = $this->request->param('request_id');
  176. $selectParams = [];
  177. if($link) {
  178. $selectParams['link'] = $link;
  179. }
  180. $result = $this->objMFinanceType->getAllFinanceTypeNoPage($selectParams);
  181. if($result->isSuccess()){
  182. $returnData = $result->getData();
  183. parent::sendOutput($returnData);
  184. }else{
  185. parent::sendOutput($result->getData(), $result->getErrorCode());
  186. }
  187. }
  188. }