StatOutMonthClass.php 957 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace biz\stat\classes;
  3. use biz\base\classes\BaseClass;
  4. use common\components\util;
  5. class StatOutMonthClass extends BaseClass
  6. {
  7. public static $baseFile = '\biz\stat\models\StatOutMonth';
  8. public static function updateOrInsert($main, $amount)
  9. {
  10. $time = date('Ym');
  11. $year = date('Y');
  12. $month = date('m');
  13. $mainId = $main->id ?? 0;
  14. $stat = self::getByCondition(['mainId' => $mainId, 'time' => $time], true);
  15. if (empty($stat)) {
  16. $stat = self::add(['mainId' => $mainId, 'time' => $time, 'year' => $year, 'month' => $month], true);
  17. }
  18. $id = $stat->id;
  19. $unique = self::getLockById($id);
  20. if (empty($unique)) {
  21. util::fail('没有记录');
  22. }
  23. $currentAmount = bcadd($unique->amount, $amount, 2);
  24. $unique->amount = $currentAmount;
  25. $unique->totalAmount = $main->totalExpend;
  26. $unique->save();
  27. }
  28. }