sjId ?? 0; $mainId = $order->mainId ?? 0; $ghsId = $order->ghsId ?? 0; $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'time' => $time], true); if (empty($stat)) { $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time, 'year' => $year, 'month' => $month], true); } $id = $stat->id; $unique = self::getLockById($id); if ($add) { $currentAmount = bcadd($unique->amount, $amount, 2); } else { $currentAmount = bcsub($unique->amount, $amount, 2); } $unique->amount = $currentAmount; $unique->num = bcadd($unique->num, $num); $unique->save(); } //每月采购统计 ssh 20211012 public static function ghsReplace($order, $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); } $sjId = $order->sjId ?? 0; $mainId = $order->mainId ?? 0; $ghsId = $order->ghsId ?? 0; $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'ghsId' => $ghsId, 'time' => $time], true); if (empty($stat)) { $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time, 'year' => $year, 'month' => $month], true); } $id = $stat->id; $unique = self::getLockById($id); $amount = $cgInfo->price ?? 0; $totalFreight = $cgInfo->totalFreight ?? 0; if ($totalFreight > 0) { $amount = bcadd($totalFreight, $amount, 2); } $num = $order->itemNum ?? 0; $currentNum = bcadd($unique->num, $num, 2); $unique->num = $currentNum; $currentAmount = bcadd($unique->amount, $amount, 2); $unique->amount = $currentAmount; $unique->save(); } //退款 public static function ghsRefundReplace($order, $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); } $sjId = $order['sjId'] ?? 0; $shopId = $order['shopId'] ?? 0; $ghsId = $order['ghsId'] ?? 0; $stat = self::getByCondition(['sjId' => $sjId, 'shopId' => $shopId, 'ghsId' => $ghsId, 'time' => $time], true); if (empty($stat)) { $stat = self::add(['shopId' => $shopId, 'sjId' => $sjId, 'ghsId' => $ghsId, 'time' => $time, 'year' => $year, 'month' => $month], true); } $id = $stat->id; $unique = self::getLockById($id); $num = $order->itemNum ?? 0; $currentRefundNum = bcadd($unique->refundNum, $num, 2); $refundPrice = $order->refundPrice ?? 0; $currentRefundAmount = bcadd($unique->refundAmount, $refundPrice, 2); $unique->refundNum = $currentRefundNum; $unique->refundAmount = $currentRefundAmount; $unique->save(); } }