11094], null, '*', null, true); if (empty($shopList)) { return false; } foreach ($shopList as $key => $shop) { $shopId = $shop->id ?? 0; $query = new \yii\db\Query(); $query->from(Custom::tableName()); $query->where(['ownShopId' => $shopId]); $query->orderBy('addTime ASC'); foreach ($query->batch(50) as $customList) { if (!empty($customList)) { foreach ($customList as $custom) { $customId = $custom['id'] ?? 0; $where = ['customId' => $customId, 'debt' => 1]; $orderList = OrderClass::getAllByCondition($where, 'addTime DESC', '*'); $ghsOrderDebtAmount = 0; if (!empty($orderList)) { foreach ($orderList as $order) { $actPrice = $order['remainDebtPrice'] ?? 0; $ghsOrderDebtAmount = bcadd($ghsOrderDebtAmount, $actPrice, 2); } } $ghsId = $custom['ghsId'] ?? 0; $ghs = \bizHd\ghs\classes\GhsClass::getById($ghsId); $where = ['ghsId' => $ghsId, 'debt' => PurchaseClass::DEBT_YES]; $cgList = PurchaseClass::getAllByCondition($where, 'addTime DESC', '*'); $hdCgOrderDebtAmount = 0; if (!empty($cgList)) { foreach ($cgList as $cg) { $actPrice = $cg['remainDebtPrice'] ?? 0; $hdCgOrderDebtAmount = bcadd($hdCgOrderDebtAmount, $actPrice, 2); } } if ($ghsOrderDebtAmount < 0 || $hdCgOrderDebtAmount < 0) { noticeUtil::push("!!!!!!!供货商 {$ghsId} 客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount", '15280215347'); echo "@@@@@@@@@@@@@供货商 {$ghsId} 客户id {$customId} 出现负数 $ghsOrderDebtAmount $hdCgOrderDebtAmount \n"; } $ghsOrderDebtAmount = floatval($ghsOrderDebtAmount); $hdCgOrderDebtAmount = floatval($hdCgOrderDebtAmount); if ($ghsOrderDebtAmount != $hdCgOrderDebtAmount) { noticeUtil::push("!!!!!!!供货商 {$ghsId} 客户id {$customId} 二边欠款单总金额不一致", '15280215347'); echo "---------供货商 {$ghsId} 客户id {$customId} 二边 欠款单 总金额 不一致 {$ghsOrderDebtAmount} {$hdCgOrderDebtAmount} \n"; continue; } $customSaveDebtAmount = $custom['debtAmount'] ? floatval($custom['debtAmount']) : 0; $ghsSaveDebtAmount = $ghs['debtAmount'] ? floatval($ghs['debtAmount']) : 0; if ($customSaveDebtAmount != $ghsOrderDebtAmount) { echo "*********客户 {$customId} 欠款 和 订单总额 不一致 $customSaveDebtAmount $ghsOrderDebtAmount \n"; noticeUtil::push("*********客户 {$customId} 欠款总金额 和 订单总合 不一致 $customSaveDebtAmount $ghsOrderDebtAmount ", '15280215347'); continue; } if ($ghsSaveDebtAmount != $hdCgOrderDebtAmount) { echo "#########欠供货商 {$ghsId} 和 订单总额 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount \n"; noticeUtil::push("#########欠供货商 {$ghsId} 金额 和 订单总合 不一致 $ghsSaveDebtAmount $hdCgOrderDebtAmount ", '15280215347'); continue; } } } } } } //在路上库存 ssh 20231218 public function actionOnStock() { ini_set('memory_limit', '2045M'); set_time_limit(0); $sql = 'UPDATE xhGhsItem SET onStock=0;'; Yii::$app->db->createCommand($sql)->execute(); $sql = 'truncate xhGhsOnStockRecord;'; Yii::$app->db->createCommand($sql)->execute(); $cgList = PurchaseOrderClass::getAllByCondition(['status' => 3], null, '*', null, true); if (!empty($cgList)) { foreach ($cgList as $key => $cg) { $orderSn = $cg->orderSn ?? ''; $sjId = $cg->sjId ?? 0; $shopId = $cg->shopId ?? 0; $mainId = $cg->mainId ?? 0; $ghsName = $cg->ghsName ?? ''; $itemList = PurchaseOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true); if (!empty($itemList)) { foreach ($itemList as $info) { $productId = $info->productId ?? 0; $itemId = $info->itemId ?? 0; $num = $info->itemNum ?? 0; $product = ProductClass::getLockById($productId); //增加路上库存 $onRecord = []; $onRecord['sjId'] = $sjId; $onRecord['shopId'] = $shopId; $onRecord['mainId'] = $mainId; $onRecord['orderSn'] = $orderSn; $onRecord['productId'] = $productId; $onRecord['itemId'] = $itemId; $onRecord['relateName'] = $ghsName; $onRecord['itemNum'] = $num; $oldOnStock = $product->onStock ?? 0; $onRecord['oldStock'] = $oldOnStock; $newOnStock = bcadd($oldOnStock, $num); $onRecord['newStock'] = $newOnStock; $onRecord['ptStyle'] = 2; OnStockRecordClass::addPurchaseOrderRecord($onRecord); \bizGhs\product\classes\ProductClass::addOnStockByItemNum($productId, $num); } } } } } public function actionLsOnStock() { ini_set('memory_limit', '2045M'); set_time_limit(0); $cgList = PurchaseClass::getAllByCondition(['status' => 3], null, '*', null, true); if (!empty($cgList)) { foreach ($cgList as $key => $cg) { $orderSn = $cg->orderSn ?? ''; $sjId = $cg->sjId ?? 0; $shopId = $cg->shopId ?? 0; $mainId = $cg->mainId ?? 0; $ghsName = $cg->ghsName ?? ''; $itemList = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true); if (!empty($itemList)) { foreach ($itemList as $val) { $productId = $val->productId ?? 0; $itemId = $val->itemId ?? 0; $num = $val->xhNum ?? 0; $product = ProductClass::getLockById($productId); if (empty($product)) { util::fail('没有找到花材呢'); } //增加路上库存 $onRecord = []; $onRecord['sjId'] = $sjId; $onRecord['shopId'] = $shopId; $onRecord['mainId'] = $mainId; $onRecord['orderSn'] = $orderSn; $onRecord['productId'] = $productId; $onRecord['itemId'] = $itemId; $onRecord['relateName'] = $ghsName; $onRecord['itemNum'] = $num; $oldOnStock = $product->onStock ?? 0; $onRecord['oldStock'] = $oldOnStock; $newOnStock = bcadd($oldOnStock, $num); $onRecord['newStock'] = $newOnStock; $onRecord['ptStyle'] = 1; OnStockRecordClass::addPurchaseOrderRecord($onRecord); \bizGhs\product\classes\ProductClass::addOnStockByItemNum($productId, $num); } } } } } public function actionCustom() { $list = CustomClass::getAllByCondition(['isHd' => 0], null, '*', null, true); if (!empty($list)) { foreach ($list as $custom) { $custom->level = 0; $custom->save(); $ghsId = $custom->ghsId; $ghs = GhsClass::getById($ghsId, true); if (!empty($ghs)) { $ghs->giveLevel = 0; $ghs->save(); echo 'customId:' . $custom->id . ' ghsId:' . $ghsId . "\n"; } } } } public function actionOut() { ini_set('memory_limit', '2045M'); set_time_limit(0); $list = StockOutOrderClass::getAllByCondition(['addTime>' => '2022-11-10 00:00:00'], null, '*', null, true); if (empty($list)) { return false; } foreach ($list as $out) { $orderSn = $out->orderSn ?? ''; $inOrderSn = $out->inOrderSn ?? ''; $in = StockInOrderClass::getByCondition(['orderSn' => $inOrderSn], true); if (empty($in)) { echo $orderSn . " 没有找到入库记录\n"; } $itemList = StockOutOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true); $totalCost = 0; if (!empty($itemList)) { foreach ($itemList as $item) { $itemNum = $item->itemNum ?? 0; $itemPrice = $item->itemPrice ?? 0; $current = bcmul($itemNum, $itemPrice, 2); $totalCost = bcadd($totalCost, $current, 2); } } $in->price = $totalCost; $in->save(); $out->price = $totalCost; $out->save(); echo $orderSn . " 总成本{$totalCost}\n"; } } }