| 12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- use common\components\util;
- class StatOutMonthClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatOutMonth';
- public static function updateOrInsert($main, $amount)
- {
- $time = date('Ym');
- $year = date('Y');
- $month = date('m');
- $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], true);
- }
- $id = $stat->id;
- $unique = self::getLockById($id);
- if (empty($unique)) {
- util::fail('没有记录');
- }
- $currentAmount = bcadd($unique->amount, $amount, 2);
- $unique->amount = $currentAmount;
- $unique->totalAmount = $main->totalExpend;
- $unique->save();
- }
- }
|