objFinanceCache = new FinanceCache(); $this->objMReceived = new MReceived($this->onlineEnterpriseId, $this->onlineUserId); } /** * 添加和编辑收款单管理公共字段处理方法 * * @return array */ public function commonFieldFilter() { $params = $this->request->getRawJson(); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $receivedData = [ 'currentAccountName' => isset($params['currentAccountName']) ? $params['currentAccountName'] : '', 'financeType' => isset($params['financeType']) ? $params['financeType'] : '', 'financeTypeId' => isset($params['financeTypeId']) ? $params['financeTypeId'] : '', 'shopId' => isset($params['shopId']) ? $params['shopId'] : '', 'shopName' => isset($params['shopName']) ? $params['shopName'] : '', 'receiptTime' => isset($params['receiptTime']) ? $params['receiptTime'] : '', 'operatorId' => $this->onlineUserId, 'receivedType' => getArrayItem($params,'receivedType',4),// 收款类型(预收,应收) 'accountList' => isset($params['accountList']) ? $params['accountList'] : '' ]; $receivedData['tempSave'] = true; //暂存 if (isset($params['tempSave']) && $params['tempSave'] == true) { $receivedData['sourceNo'] = isset($params['sourceNo']) ? $params['sourceNo'] : ''; $receivedData['sourceNoMoney'] = isset($params['sourceNoMoney']) ? $params['sourceNoMoney'] : '';//源单据应收总额 return $receivedData; } unset($receivedData['tempSave']); foreach ($receivedData as $key => $value) { if (empty($value) && $value !== 0) { $this->sendOutput($key . '参数错误', ErrorCode::$paramError); } } foreach ($receivedData['accountList'] as $account) { if(!empty($account)) { foreach ($account as $k =>$v) { if(in_array($k, ['accountId','money']) && empty($v)) { $this->sendOutput('请输入账户'.$k, ErrorCode::$paramError); } } } } $receivedData['receiptOffsetData'] = getArrayItem($params, 'receiptOffsetData', []); // 没有 receiptOffsetData 数据说明是预收单据 if (empty($receivedData['receiptOffsetData'])){ $receivedData['receivedType'] = StatusCode::$standard; } // receiptOffsetData 有数据 做判断 if (!empty($receivedData['receiptOffsetData'])){ foreach ($receivedData['receiptOffsetData'] as $val) { if(!empty($val)) { foreach ($val as $k =>$v) { if(in_array($k, ['receivedId','offsetMoney','receiveReceiptId','receiveCreateTime']) && empty($v)) { $this->sendOutput('请输入'.$k, ErrorCode::$paramError); } } } } } $receivedData['customerId'] = isset($params['customerId']) ? $params['customerId'] : 0; $receivedData['customerName'] = isset($params['customerName']) ? $params['customerName'] : '匿名客户'; $receivedData['no'] = isset($params['no']) ? $params['no'] : ''; $receivedData['sourceId'] = isset($params['sourceId']) ? $params['sourceId'] : 0; $receivedData['sourceNo'] = isset($params['sourceNo']) ? $params['sourceNo'] : ''; $receivedData['originId'] = isset($params['originId']) ? $params['originId'] : 0; $receivedData['originNo'] = isset($params['originNo']) ? $params['originNo'] : ''; $receivedData['sourceNoMoney'] = isset($params['sourceNoMoney']) ? $params['sourceNoMoney'] : 0;//源单据应收总额 $receivedData['auditStatus'] = StatusCode::$auditStatus['auditing']; $receivedData['createTime'] = isset($params['createTime']) ? $params['createTime'] : ''; $receivedData['updateTime'] = time(); //分割no $explodeSourceNo = explode('-',$receivedData['sourceNo']); if(count($explodeSourceNo) == 3){ $receivedData['sourceNo'] = $explodeSourceNo[1].'-'.$explodeSourceNo[2]; } $explodeOriginNo = explode('-',$receivedData['originNo']); if(count($explodeOriginNo) == 3){ $receivedData['originNo'] = $explodeOriginNo[1].'-'.$explodeOriginNo[2]; } if(strpos($receivedData['sourceNo'],'YS') !== false){ $receivedData['sourceNo'] = substr($receivedData['sourceNo'], 3); } return $receivedData; } /** * 添加收款单 */ public function addReceived() { $receivedData = $this->commonFieldFilter(); $receivedData['createTime'] = time(); if (isset($receivedData['tempSave'])) { $this->objFinanceCache->saveReceivedReceipt($this->onlineEnterpriseId, $this->onlineUserId, $receivedData); parent::sendOutput('暂存成功'); } else { $result = $this->objMReceived->addReceived($receivedData); if ($result->isSuccess()) { //删除暂存数据 $this->objFinanceCache->delReceivedReceipt($this->onlineEnterpriseId, $this->onlineUserId); parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } } /** * 修改收款单 */ public function editReceived() { $receivedId = $this->request->param('request_id'); if(empty($receivedId)){ $this->sendOutput('参数错误', ErrorCode::$paramError); } $receivedData = $this->commonFieldFilter(); $receivedData['id'] = $receivedId; $result = $this->objMReceived->editReceived($receivedData); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 获取暂存信息 */ public function getTempReceivedData() { $result = $this->objFinanceCache->getReceivedReceipt($this->onlineEnterpriseId, $this->onlineUserId); $this->sendOutput($result); } /** * 获取指定收款单信息 * @throws \Exception */ public function getReceivedInfo() { $params = $this->request->getRawJson(); if (empty($params['id']) || empty($params['createTime'])) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $result = $this->objMReceived->getReceivedInfo($params); if ($result->isSuccess()) { $this->sendOutput($result->getData()); } else { $this->sendOutput($result->getData(), $result->getErrorCode()); } } /** * 收款单审核 */ public function updateReceivedStatus() { $params = $this->request->getRawJson(); if (empty($params['id']) || empty($params['createTime'])) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $result = $this->objMReceived->updateReceivedStatus($params); if ($result->isSuccess()) { parent::sendOutput($result->getData()); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 后台所有收款单列表 */ public function getAllReceived() { $params = $this->request->getRawJson(); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $selectParams['no'] = getArrayItem($params,'no',''); $selectParams['financeTypeId'] = getArrayItem($params, 'financeTypeId',''); $selectParams['start'] = getArrayItem($params, 'start',''); $selectParams['end'] = getArrayItem($params, 'end',''); $selectParams['auditStatus'] = getArrayItem($params, 'auditStatus',''); $selectParams['customerId'] = getArrayItem($params, 'customerId',''); $export = isset($params['export']) ? $params['export'] : 0; $result = $this->objMReceived->getAllReceived($selectParams,$export); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 搜索 */ public function search() { $params = $this->request->getRawJson(); if (empty($params)) { $this->sendOutput('参数为空', ErrorCode::$paramError); } $selectParams = [ 'keyword' => isset($params['keyword']) ? $params['keyword'] : '', 'customerId' => isset($params['customerId']) ? $params['customerId'] : '', 'start' => isset($params['start']) ? $params['start'] : '', 'end' => isset($params['end']) ? $params['end'] : '', 'auditStatus' => isset($params['auditStatus']) ? $params['auditStatus'] : '', 'financeTypeId' => isset($params['financeTypeId']) ? $params['financeTypeId'] : '', ]; $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10); $selectParams['limit'] = $pageParams['limit']; $selectParams['offset'] = $pageParams['offset']; $result = $this->objMReceived->search($selectParams); if ($result->isSuccess()) { $returnData = $result->getData(); $pageData = [ 'pageIndex' => $params['page'], 'pageSize' => $params['pageSize'], 'pageTotal' => $returnData['total'], ]; parent::sendOutput($returnData['data'], 0, $pageData); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } /** * 根据订单no查询应收单 * @throws \Exception */ public function getReceivedByOrder() { $params = $this->request->getRawJson(); if(empty($params)){ parent::sendOutput('参数为空', ErrorCode::$paramError); } $data = [ 'sourceNo' => isset($params['sourceNo']) ? $params['sourceNo'] : '', ]; foreach ($data as $key => $value){ if(empty($value)){ parent::sendOutput($key.'参数为空', ErrorCode::$paramError); } } $result = $this->objMReceived->getReceivedByOrder($data); if(!$result->isSuccess()){ parent::sendOutput($result->getData(), $result->getErrorCode()); } $pageData = [ 'pageIndex' => 0, 'pageSize' => 0, 'pageTotal' => 0, ]; parent::sendOutput($result->getData(), 0, $pageData); } /** * 收款查询核销记录 */ public function getAllReceivedOffset() { $params = $this->request->getRawJson(); if(empty($params['receivedId'])){ parent::sendOutput('receivedId参数为空', ErrorCode::$paramError); } $result = $this->objMReceived->getAllReceivedOffset($params); if ($result->isSuccess()) { parent::sendOutput($result->getData(), 0, ['pageTotal'=>count($result->getData())]); } else { parent::sendOutput($result->getData(), $result->getErrorCode()); } } }