| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- namespace bizHd\part\classes;
- use bizHd\base\classes\BaseClass;
- use Yii;
- class StatPartMonthClass extends BaseClass
- {
- public static $baseFile = '\bizHd\part\models\StatPartMonth';
- //每月拆散统计 ssh 20230208
- public static function replace($main, $amount, $totalNum, $date = null)
- {
- if ($date == null) {
- $time = date('Ym');
- $year = date('Y');
- $month = date('m');
- } else {
- $timestamp = strtotime($date);
- $time = date('Ym', $timestamp);
- $year = date('Y', $timestamp);
- $month = date('m', $timestamp);
- }
- $mainId = $main->id ?? 0;
- $stat = self::getByCondition(['mainId' => $mainId, 'time' => $time], true);
- if (empty($stat)) {
- $stat = self::add(['mainId' => $mainId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- $currentAmount = bcadd($unique->amount, $amount, 2);
- $unique->amount = $currentAmount;
- $unique->totalAmount = $main->totalWast;
- $unique->num = bcadd($totalNum, $unique->num);
- $unique->save();
- }
- }
|