where($where)->sum('amount'); } //更新当前商家的数据 lqh 2021.4.13 // 当采购后台,将价格更新 public static function updateOrInsert($main, $shop, $amount) { $mainId = $main->id ?? 0; $sjId = $shop->sjId ?? 0; $time = date('Ymd'); $stat = self::getByCondition(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time], true); if (empty($stat)) { $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time], 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(); //当月 StatOutMonthClass::updateOrInsert($main, $amount); } }