StatWorkCatMonthClass.php 939 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace bizHd\stat\classes;
  3. use Yii;
  4. use bizHd\base\classes\BaseClass;
  5. class StatWorkCatMonthClass extends BaseClass
  6. {
  7. public static $baseFile = '\bizHd\stat\models\StatWorkCatMonth';
  8. public static function replace($main, $catId, $catName, $workNum, $num)
  9. {
  10. $time = date('Ym');
  11. $year = date('Y');
  12. $month = date('m');
  13. $mainId = $main->id ?? 0;
  14. $where = ['mainId' => $mainId, 'catId' => $catId, 'time' => $time,];
  15. $model = self::getByCondition($where, true);
  16. if (empty($model)) {
  17. $model = self::add(['mainId' => $mainId, 'catId' => $catId, 'catName' => $catName, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
  18. }
  19. $id = $model->id;
  20. $stat = self::getLockById($id);
  21. $stat->workNum = bcadd($workNum, $stat->workNum);
  22. $stat->num = bcadd($num, $stat->num);
  23. $stat->save();
  24. }
  25. }