AccountTransfer.Class.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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\ResultWrapper;
  12. use Mall\Framework\Core\StatusCode;
  13. use JinDouYun\Controller\BaseController;
  14. use JinDouYun\Model\Finance\MAccountTransfer;
  15. use JinDouYun\Cache\FinanceCache;
  16. class AccountTransfer extends BaseController
  17. {
  18. private $objMAccountTransfer;
  19. private $objFinanceCache;
  20. public function __construct($isCheckAcl = true, $isMustLogin = true)
  21. {
  22. parent::__construct($isCheckAcl, $isMustLogin);
  23. $this->objMAccountTransfer = new MAccountTransfer($this->onlineEnterpriseId, $this->onlineUserId);
  24. $this->objFinanceCache = new FinanceCache();
  25. }
  26. /**
  27. * 添加和编辑资金转账管理公共字段处理方法
  28. *
  29. * @return array
  30. */
  31. public function commonFieldFilter(){
  32. $params = $this->request->getRawJson();
  33. if( empty($params) ){
  34. $this->sendOutput('参数为空', ErrorCode::$paramError );
  35. }
  36. $accountTransferData = [
  37. 'operatorId' => $this->onlineEnterpriseId,
  38. 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
  39. 'auditStatus' => StatusCode::$auditStatus['auditing'],
  40. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  41. 'shopName' => isset($params['shopName']) ? $params['shopName'] : '',
  42. 'records' => isset($params['records']) ? $params['records'] : '',
  43. ];
  44. foreach($accountTransferData as $key => $value){
  45. if(empty($value) && $value !== 0){
  46. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  47. }
  48. }
  49. if(isset($accountTransferData['records']['outAccountNumber']) && $accountTransferData['records']['inAccountNumber'] && $accountTransferData['records']['outAccountNumber'] == $accountTransferData['records']['inAccountNumber']){
  50. $this->sendOutput('出入账户不能是同一个', ErrorCode::$paramError );
  51. }
  52. $accountTransferData['tempSave'] = true;
  53. if(isset($params['tempSave']) && $params['tempSave'] == false) {
  54. unset($accountTransferData['tempSave']);
  55. $totalMoney = 0;
  56. foreach ($accountTransferData['records'] as $record) {
  57. $totalMoney += $record['money'];
  58. }
  59. $accountTransferData['totalMoney'] = $totalMoney;
  60. $accountTransferData['records'] = json_encode($accountTransferData['records']);
  61. $accountTransferData['createTime'] = time();
  62. $accountTransferData['updateTime'] = time();
  63. }
  64. return $accountTransferData;
  65. }
  66. /**
  67. * 添加资金转账
  68. */
  69. public function addAccountTransfer()
  70. {
  71. $accountTransferData = $this->commonFieldFilter();
  72. if(isset($accountTransferData['tempSave'])) {
  73. $this->objFinanceCache->saveAccountTransfer($this->onlineEnterpriseId, $this->onlineUserId, $accountTransferData);
  74. parent::sendOutput('暂存成功');
  75. }else {
  76. $result = $this->objMAccountTransfer ->addAccountTransfer($accountTransferData);
  77. if($result->isSuccess()){
  78. //删除暂存数据
  79. $this->objFinanceCache->delAccountTransfer($this->onlineEnterpriseId, $this->onlineUserId);
  80. parent::sendOutput($result->getData());
  81. }else{
  82. parent::sendOutput($result->getData(), $result->getErrorCode());
  83. }
  84. }
  85. }
  86. /**
  87. * 获取暂存信息
  88. */
  89. public function getTempAccountTransferData() {
  90. $result = $this->objFinanceCache->getAccountTransfer($this->onlineEnterpriseId, $this->onlineUserId);
  91. $this->sendOutput($result);
  92. }
  93. /**
  94. * 获取指定资金转账信息
  95. */
  96. public function getAccountTransferInfo()
  97. {
  98. $accountTransferId = $this->request->param('request_id');
  99. if ( !$accountTransferId ) {
  100. $this->sendOutput('参数错误', ErrorCode::$paramError );
  101. }
  102. $result = $this->objMAccountTransfer->getAccountTransferInfo($accountTransferId);
  103. if($result->isSuccess()){
  104. $this->sendOutput($result->getData());
  105. }else{
  106. $this->sendOutput($result->getData(), $result->getErrorCode());
  107. }
  108. }
  109. /**
  110. * 编辑资金转账
  111. */
  112. public function editAccountTransfer()
  113. {
  114. $accountTransferId = $this->request->param('request_id');
  115. if(empty($accountTransferId)){
  116. $this->sendOutput('参数错误', ErrorCode::$paramError);
  117. }
  118. $accountTransferData = $this->commonFieldFilter();
  119. $accountTransferData['id'] = $accountTransferId;
  120. unset($accountTransferData['createTime']);
  121. $result = $this->objMAccountTransfer->editAccountTransfer($accountTransferData);
  122. if($result->isSuccess()){
  123. //删除暂存数据
  124. $this->objFinanceCache->delAccountTransfer($this->onlineEnterpriseId, $this->onlineUserId);
  125. parent::sendOutput($result->getData());
  126. }else{
  127. parent::sendOutput($result->getData(), $result->getErrorCode());
  128. }
  129. }
  130. /**
  131. * 资金转账审核
  132. */
  133. public function updateAccountTransferStatus()
  134. {
  135. $accountTransferId = $this->request->param('request_id');
  136. if(empty($accountTransferId)){
  137. $this->sendOutput('参数错误', ErrorCode::$paramError);
  138. }
  139. $result = $this->objMAccountTransfer->updateAccountTransferStatus($accountTransferId);
  140. if($result->isSuccess()){
  141. parent::sendOutput($result->getData());
  142. }else{
  143. parent::sendOutput($result->getData(), $result->getErrorCode());
  144. }
  145. }
  146. /**
  147. * 后台所有资金转账列表
  148. */
  149. public function getAllAccountTransfer()
  150. {
  151. $params = $this->request->getRawJson();
  152. if( empty($params) ){
  153. $this->sendOutput('参数为空', ErrorCode::$paramError );
  154. }
  155. $selectParams['no'] = isset($params['no']) ? $params['no'] : '';
  156. $selectParams['start'] = isset($params['start']) ? $params['start'] : '';
  157. $selectParams['end'] = isset($params['end']) ? $params['end'] : '';
  158. $selectParams['outAccountId'] = isset($params['outAccountId']) ? $params['outAccountId'] : '';
  159. $selectParams['inAccountId'] = isset($params['inAccountId']) ? $params['inAccountId'] : '';
  160. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  161. $selectParams['limit'] = $pageParams['limit'];
  162. $selectParams['offset'] = $pageParams['offset'];
  163. $result = $this->objMAccountTransfer->getAllAccountTransfer($selectParams);
  164. if($result->isSuccess()){
  165. $returnData = $result->getData();
  166. $pageData = [
  167. 'pageIndex' => $params['page'],
  168. 'pageSize' => $params['pageSize'],
  169. 'pageTotal' => $returnData['total'],
  170. ];
  171. parent::sendOutput($returnData['data'], 0, $pageData);
  172. }else{
  173. parent::sendOutput($result->getData(), $result->getErrorCode());
  174. }
  175. }
  176. }