FinanceCron.Class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wxj
  5. * Date: 2019/11/14
  6. * Time: 15:45
  7. */
  8. namespace JinDouYun\Controller\Cron;
  9. use JinDouYun\Cache\FinanceCache;
  10. use JinDouYun\Model\Finance\MReceive;
  11. use JinDouYun\Model\Finance\MReceived;
  12. use JinDouYun\Model\Finance\MPay;
  13. use JinDouYun\Dao\Finance\DReceivedReceiptCheckQueue;
  14. class FinanceCron
  15. {
  16. private $objFinanceCache;
  17. private $objMReceive;
  18. private $objMReceived;
  19. private $objDReceivedReceiptCheckQueue;
  20. public function __construct()
  21. {
  22. $this->objFinanceCache = new FinanceCache();
  23. $this->objDReceivedReceiptCheckQueue = new DReceivedReceiptCheckQueue('finance');
  24. }
  25. // 自动审核应付单
  26. public function autoAuditPayReceipt()
  27. {
  28. $result = $this->objFinanceCache->getExistPayEnterprise();
  29. if(!$result){
  30. echo '没有企业下有应付单需要去审核'.PHP_EOL;
  31. return false;
  32. }
  33. // 每个企业去单独处理
  34. foreach ($result as $key => $value){
  35. // 查询指定企业下所有未审核的应付单
  36. $objMPay =new MPay($value, 0);
  37. $payReceiptData = $objMPay->getAllAuditingPay();
  38. if(!$payReceiptData->isSuccess()){
  39. echo $payReceiptData->getData().PHP_EOL;
  40. continue;
  41. }
  42. $payReceiptData = $payReceiptData->getData();
  43. foreach ($payReceiptData as $k => $v){
  44. $params = [
  45. 'createTime' => $v['createTime'],
  46. 'id' => $v['payReceiptId'],
  47. ];
  48. $updateResult = $objMPay->updatePayStatus($params);
  49. if(!$updateResult->isSuccess()){
  50. echo '应付审核失败:原因是---'.$updateResult->getData().PHP_EOL;
  51. continue;
  52. }
  53. }
  54. // 处理完一个企业删除一个企业
  55. $this->objFinanceCache->delExistPayEnterprise($value);
  56. unset($params);
  57. }
  58. }
  59. //自动审核销售出库应收单
  60. public function ReviewReceiveReceipt()
  61. {
  62. $result = $this->objFinanceCache->getAllSalesOutReceive();
  63. if (!$result) {
  64. echo "没有需要审核的应收单据". PHP_EOL;;
  65. return false;
  66. }
  67. foreach ($result as $key => $value) {
  68. $this->objMReceive = new MReceive($key, false);
  69. foreach ($value as $params) {
  70. $dbResult = $this->objMReceive->updateReceiveStatus($params);
  71. if ($dbResult->isSuccess()) {
  72. $this->objFinanceCache->delSalesOutReceive($key, $params['id']);
  73. echo "应收单审核成功 -- id: ". $params['id'] . ', 所属表: '. date('Y', $params['createTime']) . '_' . ceil(date('m', $params['createTime']) / 3);
  74. } else {
  75. echo "应收单审核失败,失败原因:" . $dbResult->getData();
  76. }
  77. }
  78. }
  79. }
  80. //自动审核收款单队列中的数据,并删除记录
  81. public function AutoCheckReceivedReceipt() {
  82. $dbResult = $this->objDReceivedReceiptCheckQueue->select();
  83. if($dbResult === false){
  84. echo "收款单审核错误,原因:" . $this->objDReceivedReceiptCheckQueue->error();die;
  85. }
  86. if(empty($dbResult)) {
  87. echo "暂无需要审核的收款单". PHP_EOL;;die;
  88. }
  89. foreach ($dbResult as $record) {
  90. $this->objMReceived = new MReceived($record['enterpriseId'], false);
  91. $params = [
  92. 'no'=>$record['receivedNo'],
  93. 'createTime'=>$record['createTime'],
  94. ];
  95. $updateResult = $this->objMReceived->updateReceivedStatus($params);
  96. if($updateResult->isSuccess() == false) {
  97. echo "企业".$record['enterpriseId']."下的收款单".$record['receivedNo']."审核失败001,原因:" . $updateResult->getData();
  98. if($updateResult->getData()=="当前收款单已经审核过了"){
  99. echo "正在删除失效队列记录";
  100. $result = $this->objDReceivedReceiptCheckQueue->delete($record['id']);
  101. if($result === false){
  102. echo "队列记录删除失败,原因:".$this->objDReceivedReceiptCheckQueue->error();
  103. } else {
  104. echo "队列记录删除成功";
  105. }
  106. }
  107. } else {
  108. //审核成功后删除队列数据
  109. echo "企业".$record['enterpriseId']."下的收款单".$record['receivedNo']."审核成功,正在删除队列记录". PHP_EOL;;
  110. $result = $this->objDReceivedReceiptCheckQueue->delete($record['id']);
  111. if($result === false){
  112. echo "队列记录删除失败,原因:".$this->objDReceivedReceiptCheckQueue->error();
  113. } else {
  114. echo "队列记录删除成功";
  115. }
  116. }
  117. echo PHP_EOL;
  118. }
  119. }
  120. }