request->get(); $staffId = $get['staffId'] ?? 0; $switchOrder = $get['switchOrder'] ?? -1; $searchContent = $get['searchContent'] ?? ''; $where = []; $where['mainId'] = $this->mainId; if (!empty($staffId)) { $where['staffId'] = $staffId; } if (!empty($searchContent)) { if (stringUtil::isLetter($searchContent)) { $where['itemPy'] = ['like', $searchContent]; } else { $where['itemName'] = ['like', $searchContent]; } } if ($switchOrder > -1) { $where['switchOrder'] = $switchOrder; } $searchTime = $get['searchTime'] ?? ''; if (!empty($searchTime)) { $startTime = $get['startTime'] ?? ''; $endTime = $get['endTime'] ?? ''; $period = dateUtil::formatTime($searchTime, $startTime, $endTime); $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]]; } $respond = LiveOrderClass::getOrderList($where); util::success($respond); } //添加订单 ssh 20241003 public function actionAddOrder() { $post = Yii::$app->request->post(); $itemId = $post['itemId'] ?? 0; if (empty($itemId)) { util::fail('请选花材'); } $product = ProductClass::getById($itemId, true); if (empty($product)) { util::fail('没有找到花材'); } if ($product->mainId != $this->mainId) { util::fail('不是你的花材'); } $selectCustom = $post['selectCustom'] ?? ''; if (empty($selectCustom)) { util::fail('没有客户'); } $arr = json_decode($selectCustom, true); if (empty($arr) || is_array($arr) == false) { util::fail('没有客户信息'); } $mainId = $this->mainId; $hasItem = LiveOrderClass::getByCondition(['mainId' => $mainId, 'itemId' => $itemId, 'switchOrder' => 0], true); if (!empty($hasItem)) { util::fail('这个花材已添加过'); } $has = []; $customList = []; foreach ($arr as $key => $info) { $customId = $info['customId'] ?? 0; if (isset($has[$customId])) { util::fail('重复的客户'); } $has[$customId] = 1; $customName = $info['customName'] ?? ''; $num = $info['num'] ?? 0; $price = $info['price'] ?? 0; $customList[] = ['customId' => $customId, 'customName' => $customName, 'num' => $num, 'price' => $price]; } $staff = $this->shopAdmin; $staffId = $staff->id ?? 0; $staffName = $staff->name ?? ''; $params = ['product' => $product, 'customList' => $customList, 'staffId' => $staffId, 'staffName' => $staffName]; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { LiveOrderClass::addOrder($params, $mainId); $transaction->commit(); util::complete('创建成功'); } catch (\Exception $e) { Yii::info("操作失败原因:" . $e->getMessage()); $transaction->rollBack(); util::fail('操作失败'); } } //获取明细 ssh 20241005 public function actionGetDetail() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $live = LiveOrderClass::getById($id, true); if (empty($live)) { util::fail('没有找到记录'); } if ($live->mainId != $this->mainId) { util::fail('不是你的记录'); } $orderSn = $live->orderSn ?? ''; $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*'); util::success(['customList' => $customList, 'info' => $live]); } //添加客户 ssh 20241005 public function actionAddCustom() { $post = Yii::$app->request->post(); $id = $post['id'] ?? 0; $customId = $post['customId'] ?? 0; $custom = CustomClass::getById($customId, true); if (empty($custom)) { util::fail('没有找到客户'); } if ($custom->ownMainId != $this->mainId) { util::fail('不是你的客户'); } $num = $post['num'] ?? 0; $price = $post['price'] ?? 0; $live = LiveOrderClass::getById($id, true); if (empty($live)) { util::fail('没有找到记录'); } if ($live->mainId != $this->mainId) { util::fail('不是你的记录'); } if ($live->switchOrder == 1) { util::fail('已转订单,不能添加'); } $params = ['num' => $num, 'price' => $price]; LiveOrderClass::addCustom($params, $custom, $live); util::complete('添加成功'); } }