123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- <?php
- /**
- * 收款单管理模块
- * Created by PhpStorm.
- * User: tpl
- * Date: 2019/10/30
- * Time: 13:54
- */
- namespace JinDouYun\Controller\Finance;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Finance\MReceived;
- use JinDouYun\Cache\FinanceCache;
- class Received extends BaseController
- {
- private $objMReceived;
- private $objFinanceCache;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->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());
- }
- }
- }
|