| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace biz\stat\classes;
- use biz\base\classes\BaseClass;
- use common\components\util;
- class StatCgPlantMonthClass extends BaseClass
- {
- public static $baseFile = '\biz\stat\models\StatCgPlantMonth';
- //采购统计 ssh 20210528
- public static function replace($main, $amount, $num)
- {
- $time = date('Ym');
- $year = date('Y');
- $month = date('m');
- $mainId = $main->mainId ?? 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);
- if (empty($unique)) {
- util::fail('没有记录');
- }
- $currentAmount = bcadd($unique->amount, $amount, 2);
- $unique->amount = $currentAmount;
- $unique->totalAmount = $main->totalPurchase;
- $unique->num += $num;
- $unique->save();
- }
- }
|