Paid.Class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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\MPaid;
  14. use JinDouYun\Cache\FinanceCache;
  15. class Paid extends BaseController
  16. {
  17. private $objMPaid;
  18. private $objFinanceCache;
  19. public function __construct($isCheckAcl = true, $isMustLogin = true)
  20. {
  21. parent::__construct($isCheckAcl, $isMustLogin);
  22. $this->objFinanceCache = new FinanceCache();
  23. $this->objMPaid = new MPaid($this->onlineEnterpriseId, $this->onlineUserId);
  24. }
  25. /**
  26. * 添加和编辑付款单管理公共字段处理方法
  27. *
  28. * @return array
  29. */
  30. public function commonFieldFilter()
  31. {
  32. $params = $this->request->getRawJson();
  33. if (empty($params)) {
  34. $this->sendOutput('参数为空', ErrorCode::$paramError);
  35. }
  36. $paidData = [
  37. 'supplierId' => isset($params['supplierId']) ? $params['supplierId'] : '',
  38. 'supplierName' => isset($params['supplierName']) ? $params['supplierName'] : '',
  39. 'currentAccountName' => isset($params['currentAccountName']) ? $params['currentAccountName'] : '',
  40. 'financeType' => isset($params['financeType']) ? $params['financeType'] : '',
  41. 'financeTypeId' => isset($params['financeTypeId']) ? $params['financeTypeId'] : '',
  42. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  43. 'shopName' => isset($params['shopName']) ? $params['shopName'] : '',
  44. 'receiptTime' => isset($params['receiptTime']) ? $params['receiptTime'] : '',
  45. 'operatorId' => $this->onlineUserId,
  46. 'paidType' => getArrayItem($params,'receivedType',4),// 付款类型(预收,应收)
  47. 'accountList' => isset($params['accountList']) ? $params['accountList'] : ''
  48. ];
  49. $paidData['tempSave'] = true;
  50. if (isset($params['tempSave']) && $params['tempSave'] == true) {
  51. $paidData['sourceNo'] = isset($params['sourceNo']) ? $params['sourceNo'] : '';
  52. $paidData['sourceNoMoney'] = isset($params['sourceNoMoney']) ? $params['sourceNoMoney'] : 0;
  53. return $paidData;
  54. }
  55. //非暂存,则验证
  56. unset($paidData['tempSave']);
  57. foreach ($paidData as $key => $value) {
  58. if (empty($value) && $value !== 0) {
  59. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  60. }
  61. }
  62. foreach ($paidData['accountList'] as $account) {
  63. if(!empty($account)) {
  64. foreach ($account as $k =>$v) {
  65. if(in_array($k, ['accountId','money']) && empty($v)) {
  66. $this->sendOutput('请输入账户'.$k, ErrorCode::$paramError);
  67. }
  68. }
  69. }
  70. }
  71. $paidData['receiptOffsetData'] = getArrayItem($params, 'receiptOffsetData', []);
  72. // 没有 receiptOffsetData 数据说明是预收单据
  73. if(empty($paidData['receiptOffsetData'])){
  74. $paidData['paidType'] = StatusCode::$standard;
  75. }
  76. // receiptOffsetData 有数据 做判断
  77. if (!empty($receivedData['receiptOffsetData'])){
  78. foreach ($receivedData['receiptOffsetData'] as $val) {
  79. if(!empty($val)) {
  80. foreach ($val as $k =>$v) {
  81. if(in_array($k, ['payReceiptId','offsetMoney','paidId','payCreateTime']) && empty($v)) {
  82. $this->sendOutput('请输入'.$k, ErrorCode::$paramError);
  83. }
  84. }
  85. }
  86. }
  87. }
  88. $paidData['sourceNo'] = isset($params['sourceNo']) ? $params['sourceNo'] : '';
  89. $paidData['sourceNoMoney'] = isset($params['sourceNoMoney']) ? $params['sourceNoMoney'] : 0;
  90. $paidData['auditStatus'] = StatusCode::$auditStatus['auditing'];
  91. $paidData['createTime'] = time();
  92. $paidData['updateTime'] = time();
  93. return $paidData;
  94. }
  95. /**
  96. * 添加付款单
  97. */
  98. public function addPaid()
  99. {
  100. $paidData = $this->commonFieldFilter();
  101. if (isset($paidData['tempSave'])) {
  102. $this->objFinanceCache->savePaidReceipt($this->onlineEnterpriseId, $this->onlineUserId, $paidData);
  103. parent::sendOutput('暂存成功');
  104. } else {
  105. $result = $this->objMPaid->addPaid($paidData);
  106. if ($result->isSuccess()) {
  107. //删除暂存数据
  108. $this->objFinanceCache->delPaidReceipt($this->onlineEnterpriseId, $this->onlineUserId);
  109. parent::sendOutput($result->getData());
  110. } else {
  111. parent::sendOutput($result->getData(), $result->getErrorCode());
  112. }
  113. }
  114. }
  115. /**
  116. * 修改付款单
  117. */
  118. public function editPaid()
  119. {
  120. $paidId = $this->request->param('request_id');
  121. if(empty($paidId)){
  122. $this->sendOutput('参数错误', ErrorCode::$paramError);
  123. }
  124. $paidData = $this->commonFieldFilter();
  125. $paidData['id'] = $paidId;
  126. $result = $this->objMPaid->editPaid($paidData);
  127. if ($result->isSuccess()) {
  128. parent::sendOutput($result->getData());
  129. } else {
  130. parent::sendOutput($result->getData(), $result->getErrorCode());
  131. }
  132. }
  133. /**
  134. * 获取暂存信息
  135. */
  136. public function getTempPaidData()
  137. {
  138. $result = $this->objFinanceCache->getPaidReceipt($this->onlineEnterpriseId, $this->onlineUserId);
  139. $this->sendOutput($result);
  140. }
  141. /**
  142. * 获取指定付款单信息
  143. */
  144. public function getPaidInfo()
  145. {
  146. $params = $this->request->getRawJson();
  147. if (empty($params['id']) || empty($params['createTime'])) {
  148. $this->sendOutput('参数为空', ErrorCode::$paramError);
  149. }
  150. $result = $this->objMPaid->getPaidInfo($params);
  151. if ($result->isSuccess()) {
  152. $this->sendOutput($result->getData());
  153. } else {
  154. $this->sendOutput($result->getData(), $result->getErrorCode());
  155. }
  156. }
  157. /**
  158. * 付款单审核
  159. */
  160. public function updatePaidStatus()
  161. {
  162. $params = $this->request->getRawJson();
  163. if (empty($params['id']) && empty($params['createTime'])) {
  164. $this->sendOutput('参数为空', ErrorCode::$paramError);
  165. }
  166. $result = $this->objMPaid->updatePaidStatus($params);
  167. if ($result->isSuccess()) {
  168. parent::sendOutput($result->getData());
  169. } else {
  170. parent::sendOutput($result->getData(), $result->getErrorCode());
  171. }
  172. }
  173. /**
  174. * 后台所有付款单列表
  175. */
  176. public function getAllPaid()
  177. {
  178. $params = $this->request->getRawJson();
  179. if (empty($params)) {
  180. $this->sendOutput('参数为空', ErrorCode::$paramError);
  181. }
  182. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  183. $selectParams['limit'] = $pageParams['limit'];
  184. $selectParams['offset'] = $pageParams['offset'];
  185. $selectParams['no'] = getArrayItem($params,'no','');
  186. $selectParams['supplierId'] = getArrayItem($params, 'supplierId', '');
  187. $selectParams['start'] = getArrayItem($params, 'start', '');
  188. $selectParams['end'] = getArrayItem($params, 'end', '');
  189. $selectParams['auditStatus'] = getArrayItem($params, 'auditStatus', '');
  190. $selectParams['financeTypeId'] = getArrayItem($params, 'financeTypeId', '');
  191. $export = isset($params['export']) ? $params['export'] : 0;
  192. $result = $this->objMPaid->getAllPaid($selectParams,$export);
  193. if ($result->isSuccess()) {
  194. $returnData = $result->getData();
  195. $pageData = [
  196. 'pageIndex' => $params['page'],
  197. 'pageSize' => $params['pageSize'],
  198. 'pageTotal' => $returnData['total'],
  199. ];
  200. parent::sendOutput($returnData['data'], 0, $pageData);
  201. } else {
  202. parent::sendOutput($result->getData(), $result->getErrorCode());
  203. }
  204. }
  205. /**
  206. * 搜索
  207. */
  208. public function search()
  209. {
  210. $params = $this->request->getRawJson();
  211. if (empty($params)) {
  212. $this->sendOutput('参数为空', ErrorCode::$paramError);
  213. }
  214. $selectParams = [
  215. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  216. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  217. 'start' => isset($params['start']) ? $params['start'] : '',
  218. 'end' => isset($params['end']) ? $params['end'] : '',
  219. 'auditStatus' => isset($params['auditStatus']) ? $params['auditStatus'] : '',
  220. 'financeTypeId' => isset($params['financeTypeId']) ? $params['financeTypeId'] : '',
  221. ];
  222. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  223. $selectParams['limit'] = $pageParams['limit'];
  224. $selectParams['offset'] = $pageParams['offset'];
  225. $result = $this->objMPaid->search($selectParams);
  226. if ($result->isSuccess()) {
  227. $returnData = $result->getData();
  228. $pageData = [
  229. 'pageIndex' => $params['page'],
  230. 'pageSize' => $params['pageSize'],
  231. 'pageTotal' => $returnData['total'],
  232. ];
  233. parent::sendOutput($returnData['data'], 0, $pageData);
  234. } else {
  235. parent::sendOutput($result->getData(), $result->getErrorCode());
  236. }
  237. }
  238. /**
  239. * 付款查询核销记录
  240. */
  241. public function getAllPaidOffset()
  242. {
  243. $params = $this->request->getRawJson();
  244. if(empty($params['paidId'])){
  245. parent::sendOutput('paidId参数为空', ErrorCode::$paramError);
  246. }
  247. $result = $this->objMPaid->getAllPaidOffset($params);
  248. if ($result->isSuccess()) {
  249. parent::sendOutput($result->getData(), 0, ['pageTotal'=>count($result->getData())]);
  250. } else {
  251. parent::sendOutput($result->getData(), $result->getErrorCode());
  252. }
  253. }
  254. }