StatPartMonthClass.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace bizHd\part\classes;
  3. use bizHd\base\classes\BaseClass;
  4. use Yii;
  5. class StatPartMonthClass extends BaseClass
  6. {
  7. public static $baseFile = '\bizHd\part\models\StatPartMonth';
  8. //每月拆散统计 ssh 20230208
  9. public static function replace($main, $amount, $totalNum, $date = null)
  10. {
  11. if ($date == null) {
  12. $time = date('Ym');
  13. $year = date('Y');
  14. $month = date('m');
  15. } else {
  16. $timestamp = strtotime($date);
  17. $time = date('Ym', $timestamp);
  18. $year = date('Y', $timestamp);
  19. $month = date('m', $timestamp);
  20. }
  21. $mainId = $main->id ?? 0;
  22. $stat = self::getByCondition(['mainId' => $mainId, 'time' => $time], true);
  23. if (empty($stat)) {
  24. $stat = self::add(['mainId' => $mainId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
  25. }
  26. $id = $stat->id;
  27. $unique = self::getLockById($id);
  28. $currentAmount = bcadd($unique->amount, $amount, 2);
  29. $unique->amount = $currentAmount;
  30. $unique->totalAmount = $main->totalWast;
  31. $unique->num = bcadd($totalNum, $unique->num);
  32. $unique->save();
  33. }
  34. }