123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace App\Servers;
- use App\Models\ContractDistribution;
- use App\Models\GrantItem;
- use App\Models\GrantPond;
- use Carbon\Carbon;
- /**
- * 图片OSS管理
- */
- class GrantPondServer
- {
- static private $server = '';
- private function __construct()
- {
- }
- /**
- * 创建对象
- * @return GrantPondServer
- */
- static function creatServer()
- {
- if (empty(self::$server)) {
- self::$server = new GrantPondServer();
- }
- return self::$server;
- }
- /**
- * 积累均富池
- * @param ContractDistribution $distribution
- */
- function grandPond(ContractDistribution $distribution)
- {
- $pondData = $this->getPond();
- GrantPond::where('id',$pondData->{'id'})->increment('grand_total',$distribution->{'lk_num'});
- GrantItem::create([
- 'm_id' => $distribution->{'m_id'},
- 'contract_id' => $distribution->{'id'},
- 'add_money' => $distribution->{'lk_num'},
- ]);
- }
- function getPond()
- {
- $pondData = GrantPond::where('status', 1)->first();
- if (empty($pondData)) {
- $pondData=$this->creationPond();
- } else {
- //验证累计时间
- $endDate= Carbon::parse($pondData->{'end_date'}, config('app.timezone'))->format('Y-m-d H:i:s');
- if($endDate<date('Y-m-d H:i:s')){
- //更新原有状态,获取新积累
- $pondData->update(['status' => 2]);
- $pondData=$this->creationPond();
- }
- }
- return $pondData;
- }
- private function creationPond(){
- return GrantPond::create([
- 'grand_total'=>0,
- 'average_money' => 0,
- 'total_num' => 0,
- 'status' => 1,
- 'end_date' => $this->getEndDate(),
- 'distribute_date' => $this->getDistributeDate(),
- 'pond_sn' => IndentNumServer::creatServer()->getIndentNum(2)
- ]);
- }
- /**
- * 获取发放时间
- * @return false|string
- */
- function getDistributeDate(){
- $date = date('d');
- if ($date <= 5) {
- $distributeDate = date('Y-m-10 00:00:00');
- } elseif ($date <= 15) {
- $distributeDate = date('Y-m-20 00:00:00');
- } elseif ($date <= 25) {
- $distributeDate = date('Y-m-d 00:00:00',strtotime(date('Y-m-1 00:00:00',strtotime('+1 month')))-1);
- }else {
- $distributeDate = date('Y-m-10 00:00:00',strtotime('+1 month'));
- }
- return $distributeDate;
- }
- /**
- * 获取积累时间
- * @return false|string
- */
- function getEndDate()
- {
- $date = date('d');
- if ($date <= 5) {
- $endDate = date('Y-m-5 00:00:00');
- } elseif ($date <= 15) {
- $endDate = date('Y-m-15 00:00:00');
- } elseif ($date <= 25) {
- $endDate = date('Y-m-25 00:00:00');
- }else {
- $endDate = date('Y-m-5 00:00:00',strtotime('+1 month'));
- }
- return $endDate;
- }
- }
|