Received.Class.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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\MReceived;
  14. use JinDouYun\Cache\FinanceCache;
  15. class Received extends BaseController
  16. {
  17. private $objMReceived;
  18. private $objFinanceCache;
  19. public function __construct($isCheckAcl = true, $isMustLogin = true)
  20. {
  21. parent::__construct($isCheckAcl, $isMustLogin);
  22. $this->objFinanceCache = new FinanceCache();
  23. $this->objMReceived = new MReceived($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. $receivedData = [
  37. 'currentAccountName' => isset($params['currentAccountName']) ? $params['currentAccountName'] : '',
  38. 'financeType' => isset($params['financeType']) ? $params['financeType'] : '',
  39. 'financeTypeId' => isset($params['financeTypeId']) ? $params['financeTypeId'] : '',
  40. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  41. 'shopName' => isset($params['shopName']) ? $params['shopName'] : '',
  42. 'receiptTime' => isset($params['receiptTime']) ? $params['receiptTime'] : '',
  43. 'operatorId' => $this->onlineUserId,
  44. 'receivedType' => getArrayItem($params,'receivedType',4),// 收款类型(预收,应收)
  45. 'accountList' => isset($params['accountList']) ? $params['accountList'] : ''
  46. ];
  47. $receivedData['tempSave'] = true;
  48. //暂存
  49. if (isset($params['tempSave']) && $params['tempSave'] == true) {
  50. $receivedData['sourceNo'] = isset($params['sourceNo']) ? $params['sourceNo'] : '';
  51. $receivedData['sourceNoMoney'] = isset($params['sourceNoMoney']) ? $params['sourceNoMoney'] : '';//源单据应收总额
  52. return $receivedData;
  53. }
  54. unset($receivedData['tempSave']);
  55. foreach ($receivedData as $key => $value) {
  56. if (empty($value) && $value !== 0) {
  57. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  58. }
  59. }
  60. foreach ($receivedData['accountList'] as $account) {
  61. if(!empty($account)) {
  62. foreach ($account as $k =>$v) {
  63. if(in_array($k, ['accountId','money']) && empty($v)) {
  64. $this->sendOutput('请输入账户'.$k, ErrorCode::$paramError);
  65. }
  66. }
  67. }
  68. }
  69. $receivedData['receiptOffsetData'] = getArrayItem($params, 'receiptOffsetData', []);
  70. // 没有 receiptOffsetData 数据说明是预收单据
  71. if (empty($receivedData['receiptOffsetData'])){
  72. $receivedData['receivedType'] = StatusCode::$standard;
  73. }
  74. // receiptOffsetData 有数据 做判断
  75. if (!empty($receivedData['receiptOffsetData'])){
  76. foreach ($receivedData['receiptOffsetData'] as $val) {
  77. if(!empty($val)) {
  78. foreach ($val as $k =>$v) {
  79. if(in_array($k, ['receivedId','offsetMoney','receiveReceiptId','receiveCreateTime']) && empty($v)) {
  80. $this->sendOutput('请输入'.$k, ErrorCode::$paramError);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. $receivedData['customerId'] = isset($params['customerId']) ? $params['customerId'] : 0;
  87. $receivedData['customerName'] = isset($params['customerName']) ? $params['customerName'] : '匿名客户';
  88. $receivedData['no'] = isset($params['no']) ? $params['no'] : '';
  89. $receivedData['sourceId'] = isset($params['sourceId']) ? $params['sourceId'] : 0;
  90. $receivedData['sourceNo'] = isset($params['sourceNo']) ? $params['sourceNo'] : '';
  91. $receivedData['originId'] = isset($params['originId']) ? $params['originId'] : 0;
  92. $receivedData['originNo'] = isset($params['originNo']) ? $params['originNo'] : '';
  93. $receivedData['sourceNoMoney'] = isset($params['sourceNoMoney']) ? $params['sourceNoMoney'] : 0;//源单据应收总额
  94. $receivedData['auditStatus'] = StatusCode::$auditStatus['auditing'];
  95. $receivedData['createTime'] = isset($params['createTime']) ? $params['createTime'] : '';
  96. $receivedData['updateTime'] = time();
  97. //分割no
  98. $explodeSourceNo = explode('-',$receivedData['sourceNo']);
  99. if(count($explodeSourceNo) == 3){
  100. $receivedData['sourceNo'] = $explodeSourceNo[1].'-'.$explodeSourceNo[2];
  101. }
  102. $explodeOriginNo = explode('-',$receivedData['originNo']);
  103. if(count($explodeOriginNo) == 3){
  104. $receivedData['originNo'] = $explodeOriginNo[1].'-'.$explodeOriginNo[2];
  105. }
  106. if(strpos($receivedData['sourceNo'],'YS') !== false){
  107. $receivedData['sourceNo'] = substr($receivedData['sourceNo'], 3);
  108. }
  109. return $receivedData;
  110. }
  111. /**
  112. * 添加收款单
  113. */
  114. public function addReceived()
  115. {
  116. $receivedData = $this->commonFieldFilter();
  117. $receivedData['createTime'] = time();
  118. if (isset($receivedData['tempSave'])) {
  119. $this->objFinanceCache->saveReceivedReceipt($this->onlineEnterpriseId, $this->onlineUserId, $receivedData);
  120. parent::sendOutput('暂存成功');
  121. } else {
  122. $result = $this->objMReceived->addReceived($receivedData);
  123. if ($result->isSuccess()) {
  124. //删除暂存数据
  125. $this->objFinanceCache->delReceivedReceipt($this->onlineEnterpriseId, $this->onlineUserId);
  126. parent::sendOutput($result->getData());
  127. } else {
  128. parent::sendOutput($result->getData(), $result->getErrorCode());
  129. }
  130. }
  131. }
  132. /**
  133. * 修改收款单
  134. */
  135. public function editReceived()
  136. {
  137. $receivedId = $this->request->param('request_id');
  138. if(empty($receivedId)){
  139. $this->sendOutput('参数错误', ErrorCode::$paramError);
  140. }
  141. $receivedData = $this->commonFieldFilter();
  142. $receivedData['id'] = $receivedId;
  143. $result = $this->objMReceived->editReceived($receivedData);
  144. if ($result->isSuccess()) {
  145. parent::sendOutput($result->getData());
  146. } else {
  147. parent::sendOutput($result->getData(), $result->getErrorCode());
  148. }
  149. }
  150. /**
  151. * 获取暂存信息
  152. */
  153. public function getTempReceivedData()
  154. {
  155. $result = $this->objFinanceCache->getReceivedReceipt($this->onlineEnterpriseId, $this->onlineUserId);
  156. $this->sendOutput($result);
  157. }
  158. /**
  159. * 获取指定收款单信息
  160. * @throws \Exception
  161. */
  162. public function getReceivedInfo()
  163. {
  164. $params = $this->request->getRawJson();
  165. if (empty($params['id']) || empty($params['createTime'])) {
  166. $this->sendOutput('参数为空', ErrorCode::$paramError);
  167. }
  168. $result = $this->objMReceived->getReceivedInfo($params);
  169. if ($result->isSuccess()) {
  170. $this->sendOutput($result->getData());
  171. } else {
  172. $this->sendOutput($result->getData(), $result->getErrorCode());
  173. }
  174. }
  175. /**
  176. * 收款单审核
  177. */
  178. public function updateReceivedStatus()
  179. {
  180. $params = $this->request->getRawJson();
  181. if (empty($params['id']) || empty($params['createTime'])) {
  182. $this->sendOutput('参数为空', ErrorCode::$paramError);
  183. }
  184. $result = $this->objMReceived->updateReceivedStatus($params);
  185. if ($result->isSuccess()) {
  186. parent::sendOutput($result->getData());
  187. } else {
  188. parent::sendOutput($result->getData(), $result->getErrorCode());
  189. }
  190. }
  191. /**
  192. * 后台所有收款单列表
  193. */
  194. public function getAllReceived()
  195. {
  196. $params = $this->request->getRawJson();
  197. if (empty($params)) {
  198. $this->sendOutput('参数为空', ErrorCode::$paramError);
  199. }
  200. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  201. $selectParams['limit'] = $pageParams['limit'];
  202. $selectParams['offset'] = $pageParams['offset'];
  203. $selectParams['no'] = getArrayItem($params,'no','');
  204. $selectParams['financeTypeId'] = getArrayItem($params, 'financeTypeId','');
  205. $selectParams['start'] = getArrayItem($params, 'start','');
  206. $selectParams['end'] = getArrayItem($params, 'end','');
  207. $selectParams['auditStatus'] = getArrayItem($params, 'auditStatus','');
  208. $selectParams['customerId'] = getArrayItem($params, 'customerId','');
  209. $export = isset($params['export']) ? $params['export'] : 0;
  210. $result = $this->objMReceived->getAllReceived($selectParams,$export);
  211. if ($result->isSuccess()) {
  212. $returnData = $result->getData();
  213. $pageData = [
  214. 'pageIndex' => $params['page'],
  215. 'pageSize' => $params['pageSize'],
  216. 'pageTotal' => $returnData['total'],
  217. ];
  218. parent::sendOutput($returnData['data'], 0, $pageData);
  219. } else {
  220. parent::sendOutput($result->getData(), $result->getErrorCode());
  221. }
  222. }
  223. /**
  224. * 搜索
  225. */
  226. public function search()
  227. {
  228. $params = $this->request->getRawJson();
  229. if (empty($params)) {
  230. $this->sendOutput('参数为空', ErrorCode::$paramError);
  231. }
  232. $selectParams = [
  233. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  234. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  235. 'start' => isset($params['start']) ? $params['start'] : '',
  236. 'end' => isset($params['end']) ? $params['end'] : '',
  237. 'auditStatus' => isset($params['auditStatus']) ? $params['auditStatus'] : '',
  238. 'financeTypeId' => isset($params['financeTypeId']) ? $params['financeTypeId'] : '',
  239. ];
  240. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  241. $selectParams['limit'] = $pageParams['limit'];
  242. $selectParams['offset'] = $pageParams['offset'];
  243. $result = $this->objMReceived->search($selectParams);
  244. if ($result->isSuccess()) {
  245. $returnData = $result->getData();
  246. $pageData = [
  247. 'pageIndex' => $params['page'],
  248. 'pageSize' => $params['pageSize'],
  249. 'pageTotal' => $returnData['total'],
  250. ];
  251. parent::sendOutput($returnData['data'], 0, $pageData);
  252. } else {
  253. parent::sendOutput($result->getData(), $result->getErrorCode());
  254. }
  255. }
  256. /**
  257. * 根据订单no查询应收单
  258. * @throws \Exception
  259. */
  260. public function getReceivedByOrder()
  261. {
  262. $params = $this->request->getRawJson();
  263. if(empty($params)){
  264. parent::sendOutput('参数为空', ErrorCode::$paramError);
  265. }
  266. $data = [
  267. 'sourceNo' => isset($params['sourceNo']) ? $params['sourceNo'] : '',
  268. ];
  269. foreach ($data as $key => $value){
  270. if(empty($value)){
  271. parent::sendOutput($key.'参数为空', ErrorCode::$paramError);
  272. }
  273. }
  274. $result = $this->objMReceived->getReceivedByOrder($data);
  275. if(!$result->isSuccess()){
  276. parent::sendOutput($result->getData(), $result->getErrorCode());
  277. }
  278. $pageData = [
  279. 'pageIndex' => 0,
  280. 'pageSize' => 0,
  281. 'pageTotal' => 0,
  282. ];
  283. parent::sendOutput($result->getData(), 0, $pageData);
  284. }
  285. /**
  286. * 收款查询核销记录
  287. */
  288. public function getAllReceivedOffset()
  289. {
  290. $params = $this->request->getRawJson();
  291. if(empty($params['receivedId'])){
  292. parent::sendOutput('receivedId参数为空', ErrorCode::$paramError);
  293. }
  294. $result = $this->objMReceived->getAllReceivedOffset($params);
  295. if ($result->isSuccess()) {
  296. parent::sendOutput($result->getData(), 0, ['pageTotal'=>count($result->getData())]);
  297. } else {
  298. parent::sendOutput($result->getData(), $result->getErrorCode());
  299. }
  300. }
  301. }