GrantPondServer.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Servers;
  3. use App\Models\ContractDistribution;
  4. use App\Models\GrantItem;
  5. use App\Models\GrantPond;
  6. use Carbon\Carbon;
  7. /**
  8. * 图片OSS管理
  9. */
  10. class GrantPondServer
  11. {
  12. static private $server = '';
  13. private function __construct()
  14. {
  15. }
  16. /**
  17. * 创建对象
  18. * @return GrantPondServer
  19. */
  20. static function creatServer()
  21. {
  22. if (empty(self::$server)) {
  23. self::$server = new GrantPondServer();
  24. }
  25. return self::$server;
  26. }
  27. /**
  28. * 积累均富池
  29. * @param ContractDistribution $distribution
  30. */
  31. function grandPond(ContractDistribution $distribution)
  32. {
  33. $pondData = $this->getPond();
  34. GrantPond::where('id',$pondData->{'id'})->increment('grand_total',$distribution->{'lk_num'});
  35. GrantItem::create([
  36. 'm_id' => $distribution->{'m_id'},
  37. 'contract_id' => $distribution->{'id'},
  38. 'add_money' => $distribution->{'lk_num'},
  39. ]);
  40. }
  41. function getPond()
  42. {
  43. $pondData = GrantPond::where('status', 1)->first();
  44. if (empty($pondData)) {
  45. $pondData=$this->creationPond();
  46. } else {
  47. //验证累计时间
  48. $endDate= Carbon::parse($pondData->{'end_date'}, config('app.timezone'))->format('Y-m-d H:i:s');
  49. if($endDate<date('Y-m-d H:i:s')){
  50. //更新原有状态,获取新积累
  51. $pondData->update(['status' => 2]);
  52. $pondData=$this->creationPond();
  53. }
  54. }
  55. return $pondData;
  56. }
  57. private function creationPond(){
  58. return GrantPond::create([
  59. 'grand_total'=>0,
  60. 'average_money' => 0,
  61. 'total_num' => 0,
  62. 'status' => 1,
  63. 'end_date' => $this->getEndDate(),
  64. 'distribute_date' => $this->getDistributeDate(),
  65. 'pond_sn' => IndentNumServer::creatServer()->getIndentNum(2)
  66. ]);
  67. }
  68. /**
  69. * 获取发放时间
  70. * @return false|string
  71. */
  72. function getDistributeDate(){
  73. $date = date('d');
  74. if ($date <= 5) {
  75. $distributeDate = date('Y-m-10 00:00:00');
  76. } elseif ($date <= 15) {
  77. $distributeDate = date('Y-m-20 00:00:00');
  78. } elseif ($date <= 25) {
  79. $distributeDate = date('Y-m-d 00:00:00',strtotime(date('Y-m-1 00:00:00',strtotime('+1 month')))-1);
  80. }else {
  81. $distributeDate = date('Y-m-10 00:00:00',strtotime('+1 month'));
  82. }
  83. return $distributeDate;
  84. }
  85. /**
  86. * 获取积累时间
  87. * @return false|string
  88. */
  89. function getEndDate()
  90. {
  91. $date = date('d');
  92. if ($date <= 5) {
  93. $endDate = date('Y-m-5 00:00:00');
  94. } elseif ($date <= 15) {
  95. $endDate = date('Y-m-15 00:00:00');
  96. } elseif ($date <= 25) {
  97. $endDate = date('Y-m-25 00:00:00');
  98. }else {
  99. $endDate = date('Y-m-5 00:00:00',strtotime('+1 month'));
  100. }
  101. return $endDate;
  102. }
  103. }