2], null, '*', null, true); if (empty($shopList)) { return false; } Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs'); Yii::$app->params['errorReport'] = 1; foreach ($shopList as $shop) { $mainId = $shop->mainId; $shopName = $shop->shopName ?? ''; $sjName = $shop->merchantName ?? ''; $shopId = $shop->id ?? 0; $sjId = $shop->sjId ?? 0; $name = $sjName . ' ' . $shopName; $cacheKey = 'live_order_' . $mainId; $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]); if (empty($has)) { continue; } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $list = LiveOrderClass::getAllByCondition(['mainId' => $mainId, 'switchOrder' => 0], null, '*'); if (empty($list)) { continue; } $customInfo = CustomClass::getAllByCondition(['ownMainId' => $mainId], null, '*', 'id'); $total = []; $format = []; $staffId = 0; $staffName = ''; $historyDate = date("Y-m-d"); foreach ($list as $key => $live) { $liveId = $live['id'] ?? 0; LiveOrderClass::updateById($liveId, ['switchOrder' => 1]); $addTime = $live['addTime']; $historyDate = date("Y-m-d", strtotime($addTime)); $orderSn = $live['orderSn']; $itemId = $live['itemId']; $ptItemId = $live['ptItemId']; $staffId = $live['staffId'] ?? 0; $staffName = $live['staffName'] ?? ''; $date = date("Y-m-d", strtotime($addTime)); $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*'); if (empty($customList)) { continue; } $total[$date] = 1; foreach ($customList as $k => $v) { $customId = $v['customId'] ?? 0; $num = $v['num'] ?? 0; $unitPrice = $v['unitPrice'] ?? 0; $currentCustom = $customInfo[$customId] ?? []; if (empty($currentCustom)) { throw new \Exception("出现不存在的客户 customId:{$customId}"); } $format[$customId][] = [ 'productId' => $itemId, 'bigNum' => $num, 'itemId' => $ptItemId, 'smallNum' => 0, 'price' => $unitPrice, ]; } } if (count($total) > 1) { noticeUtil::push($name . " mainId:{$mainId} live order 有记录不是同一天的", '15280215347'); continue; } if (empty($format)) { noticeUtil::push($name . " mainId:{$mainId} live order 没有找到客户预订", '15280215347'); continue; } foreach ($format as $customId => $mat) { $modifyPrice = 0; foreach ($mat as $ma) { $cNum = $ma['bigNum'] ?? 0; $cPrice = $ma['price'] ?? 0; $cTotal = bcmul($cNum, $cPrice, 2); $modifyPrice = bcadd($modifyPrice, $cTotal, 2); } $currentCustom = $customInfo[$customId] ?? []; if (empty($currentCustom)) { throw new \Exception("出现不存在的客户哦 customId:{$customId}"); } $customName = $currentCustom['name'] ?? ''; $customMobile = $currentCustom['mobile'] ?? ''; $customPy = $currentCustom['py'] ?? ''; $ghsId = $currentCustom['ghsId'] ?? 0; $hasPay = 2; $custom = CustomClass::getCustom($customId); $post = []; $post['modifyPrice'] = $modifyPrice; $post['shopId'] = $shopId; $post['sendType'] = 0; $post['transType'] = 0; $post['sendSide'] = 0; $post['sendCost'] = 0; $post['packCost'] = 0; $post['customId'] = $customId; $post['customName'] = $customName; $post['payWay'] = 0; $post['needPrint'] = 2; $post['hasPay'] = 2; $post['product'] = $mat; $post['deadline'] = date("Y-m-d H:i:s", time() + 86400); $post['debt'] = 1; $post['mainId'] = $mainId; $post['fromType'] = 1; $post['expressId'] = 0; $post['sjId'] = $sjId; $post['shopAdminId'] = $staffId; $post['shopAdminName'] = $staffName; $post['getStaffId'] = $staffId; $post['getStaffName'] = $staffName; $post['customMobile'] = $customMobile; $post['customNamePy'] = $customPy; $post['customAvatar'] = ''; $post['newVersion'] = 1; $post['book'] = 0; $post['wlName'] = ''; $post['dealPrice'] = 1; $post['ghsId'] = $ghsId; $post['historyDate'] = $historyDate; //多处有用到此方法,需要同步修改,搜索关键词create_new_order $order = OrderService::createNewOrder($post, $custom, $hasPay); //清掉一天多单的汇总 $sameDate = date("Y_m_d"); $sameAddress = $order->showAddress ?? ''; $addressMd5 = md5($sameAddress); $sameKey = $customId . '_' . $addressMd5 . '_' . $sameDate; Yii::$app->redis->executeCommand('DEL', [$sameKey]); } //清空货位 CustomClass::updateByCondition(['ownMainId' => $mainId], ['seatSn' => 0, 'printSeatSn' => 0]); LiveSeatClass::updateByCondition(['mainId' => $mainId], ['customId' => 0, 'customName' => '']); $transaction->commit(); Yii::$app->redis->executeCommand('DEL', [$cacheKey]); noticeUtil::push($name . " mainId:{$mainId} live order 转换订单成功", '15280215347'); } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); noticeUtil::push($name . " mainId:{$mainId} live order 报错了:" . $msg, '15280215347'); } } } }