request->get(); $id = $get['id'] ?? 0; $info = OrderItemClass::getById($id, true); $name = $info->name ?? ''; $num = $info->xhNum ?? 0; $name = strtolower($name); $name = preg_replace('/\d/', '', $name); $arr = ['cm', '箱', '个', 'a', 'b', 'c', 'd', 'e', 'o', '梦金鹏', '拍市', '七彩', '市场', '(', ')', '(', ')', '-', '级', '红', '黄', '绿', '橙', '蓝', '基地', '支', '枝', '*', '张良', '配色', '混色', '浅粉', '粉', '玫红', '青铜', '深紫', '浅紫', '紫', '色', '重瓣', ' ', ' ']; foreach ($arr as $it) { $name = str_replace($it, '', $name); } util::success(['name' => $name, 'num' => $num]); } //修改预订单花材的数量和价格 public function actionModifyBookItem() { $post = Yii::$app->request->post(); $id = $post['id'] ?? 0; $data = $post['data'] ?? []; $packCost = $post['packCost'] ?? 0; $sendCost = $post['sendCost'] ?? 0; if (empty($data)) { util::fail('没有花材数据'); } $order = OrderClass::getById($id, true); if (empty($order)) { util::fail('没有订单'); } if ($order->mainId != $this->mainId) { util::fail('不是你的订单哦'); } if ($order->stockChange == 1) { util::fail('已经入库,不能修改'); } if ($order->status != 2) { util::fail('待发货订单才能修改'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $addData = []; $delData = []; foreach ($data as $item) { $id = $item['id'] ?? 0; $xhNum = $item['xhNum'] ?? 0; $xhUnitPrice = $item['xhUnitPrice'] ?? 0; $info = OrderItemClass::getById($id, true); if (empty($info)) { continue; } if ($info->orderSn != $order->orderSn) { continue; } $productId = $info->productId ?? 0; $preNum = $info->xhNum ?? 0; //新增预订花材 if ($xhNum > $preNum) { $diffNum = bcsub($xhNum, $preNum); $addData[] = [ 'productId' => $productId, 'num' => $diffNum, 'lastNum' => $xhNum, ]; } //删除预订花材 if ($preNum > $xhNum) { $diffNum = bcsub($preNum, $xhNum); $delData[] = [ 'productId' => $productId, 'num' => $diffNum, 'lastNum' => $xhNum, ]; } $info->xhNum = $xhNum; $info->xhPreNum = $xhNum; $info->xhUnitPrice = $xhUnitPrice; $info->xhPreUnitPrice = $xhUnitPrice; $info->save(); } $order->packCost = $packCost; $order->sendCost = $sendCost; $order->save(); $staff = $this->shopAdmin; $staffId = $staff->id ?? 0; $staffName = $staff->name ?? ''; $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,]; if (!empty($addData)) { BookItemClass::addBatchItem($addData, $order, $params); } if (!empty($delData)) { BookItemClass::delBathItem($delData, $order, $params); } $transaction->commit(); util::complete('保存成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("保存出错了:" . $e->getMessage()); util::fail('保存出错了'); } } //更换花材 ssh 20240430 public function actionChangeItem() { $post = Yii::$app->request->post(); $delId = $post['delId'] ?? 0; $orderSn = $post['orderSn'] ?? ''; $num = $post['num'] ?? 0; $price = $post['price'] ?? 0; $productId = $post['productId'] ?? 0; $order = OrderClass::getByCondition(['orderSn' => $orderSn], true); if (empty($order)) { util::fail('订单没有找到哦'); } if ($order->mainId != $this->mainId) { util::fail('不是你的订单'); } $delInfo = OrderItemClass::getById($delId, true); if (empty($delInfo)) { util::fail('没有找到要删除的花材'); } if ($delInfo->orderSn != $orderSn) { util::fail('这个花材你不能删除'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { OrderItemClass::delBookItem($order, $delId); $new = []; $new[$productId] = ['num' => $num, 'productId' => $productId, 'price' => $price]; OrderItemClass::addBookItemFn($order, $new); $transaction->commit(); util::complete('更换成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("出错了:" . $e->getMessage()); util::fail('出错了'); } } //删除花材 ssh 20240123 public function actionDelItem() { $post = Yii::$app->request->post(); $id = $post['id'] ?? 0; $smallId = $post['smallId'] ?? 0; $order = OrderClass::getById($id, true); if (empty($order)) { util::fail('没有订单'); } if ($order->status != 2) { util::fail('待发货才能添加'); } if ($order->book == 0) { util::fail('不是预订单'); } if ($order->mainId != $this->mainId) { util::fail('不是你的订单'); } if (floatval($order->actPrice) != 0) { util::fail('订单金额不是0'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $staff = $this->shopAdmin; $staffId = $staff->id ?? 0; $staffName = $staff->name ?? ''; $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,]; OrderItemClass::delBookItem($order, $smallId, $params); $transaction->commit(); util::complete('删除成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("删除出错了:" . $e->getMessage()); util::fail('删除出错了'); } } //添加花材 public function actionAddItem() { $post = Yii::$app->request->post(); $id = $post['id'] ?? 0; $data = $post['data'] ?? 0; $arr = json_decode($data, true); $order = OrderClass::getById($id, true); if (empty($order)) { util::fail('没有订单'); } if ($order->status != 2) { util::fail('待发货才能添加'); } if ($order->book == 0) { util::fail('不是预订单'); } if (floatval($order->actPrice) != 0) { util::fail('订单金额不是0'); } if (empty($arr)) { util::fail('请选花材'); } $new = []; foreach ($arr as $val) { $id = $val['id'] ?? 0; $num = $val['bigCount'] ?? 0; $name = $val['name'] ?? ''; $price = $val['price'] ?? 0; if ($num <= 0) { util::fail($name . ' 数量要大于0'); } $new[$id] = ['num' => $num, 'productId' => $id, 'price' => $price]; } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $staff = $this->shopAdmin; $staffId = $staff->id ?? 0; $staffName = $staff->name ?? ''; $params = ['staff' => $staff, 'staffId' => $staffId, 'staffName' => $staffName,]; OrderItemClass::addBookItemFn($order, $new, $params); $transaction->commit(); util::complete('添加成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("添加出错了:" . $e->getMessage()); util::fail('添加出错了'); } } //赠送花材 ssh 20230411 public function actionGiveItem() { $post = Yii::$app->request->post(); $id = $post['id'] ?? 0; $num = $post['num'] ?? 0; if (is_numeric($num) == false || $num <= 0) { util::fail('请填写赠送数量'); } $orderItem = OrderItemClass::getById($id, true); if (empty($orderItem)) { util::fail('没有找到花材'); } if ($orderItem->mainId != $this->mainId) { util::fail('无法操作'); } if (!in_array($this->mainId, [1496])) { util::fail('开发中'); } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $staff = $this->shopAdmin; $staffName = $staff->name ?? ''; $staffId = $staff->id ?? 0; $data = ['shopId' => $this->shopId, 'sjId' => $this->sjId, 'staffName' => $staffName, 'staffId' => $staffId]; $respond = OrderItemService::giveProduct($data, $orderItem, $num); $transaction->commit(); util::success(['info' => $respond], '赠送成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info("赠送出错了:" . $e->getMessage()); util::fail('出错了'); } } //重选花材 ssh 2021.3.2 public function actionReset() { $post = Yii::$app->request->post(); $id = $post['id'] ?? 0; $product = $post['product'] ?? '[]'; $product = json_decode($product, true); //检查花材是否都是同家门店的 ProductClass::valid($product, $this->mainId); $info = OrderService::getOrderInfo($id); OrderClass::valid($info, $this->shopId); //添加修改花材 $orderSn = $info['orderSn'] ?? ''; OrderItemClass::replaceItem($orderSn, $product); util::complete(); } //修改花材时获取订单花材和花材基本信息的组合 ssh 20210809 public function actionGetOrderProduct() { $id = Yii::$app->request->get('id', 0); $order = OrderClass::getById($id, true); OrderClass::valid($order, $this->shopId); $orderSn = $order->orderSn ?? ''; $itemList = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', 'productId'); $ids = array_column($itemList, 'productId'); if (empty($ids)) { util::fail('没有找到花材'); } $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id'); if (empty($productList)) { util::fail('没有找到花材信息'); } foreach ($productList as $key => $product) { $productId = $product['id'] ?? 0; $currentItem = $itemList[$productId] ?? []; $bigCount = $currentItem['bigNum'] ?? 0; $smallCount = $currentItem['smallNum'] ?? 0; $userPrice = $currentItem['userPrice'] ?? 0; $productList[$key]['bigCount'] = $bigCount; $productList[$key]['smallCount'] = $smallCount; $productList[$key]['userPrice'] = $userPrice; $cover = imgUtil::groupImg($product['cover']); $productList[$key]['cover'] = $cover; $bigPrice = $product['unitPrice'] ?? 0; $smallPrice = $product['smallUnitPrice'] ?? 0; $productList[$key]['bigPrice'] = $bigPrice; $productList[$key]['smallPrice'] = $smallPrice; $productList[$key]['cover'] = $cover; } util::success(['productList' => array_values($productList)]); } //根据花材id取订单列表 ssh 20211011 public function actionGetOrderInfoList() { $get = Yii::$app->request->get(); $productId = $get['productId'] ?? 0; $product = ProductClass::getById($productId, true); ProductClass::check($product, $this->mainId); $where = ['productId' => $productId]; $respond = OrderItemClass::getOrderInfoList($where); util::success($respond); } //修改花材的备注 ssh 20240514 public function actionUpdateItemRemark() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $remark = $get['remark'] ?? ''; $info = OrderItemClass::getById($id, true); if (empty($info)) { util::fail('没有找到'); } if ($info->mainId != $this->mainId) { util::fail('不是你的花材'); } $info->remark = $remark; $info->save(); $orderSn = $info->orderSn ?? ''; $productId = $info->productId ?? 0; $order = OrderClass::getByCondition(['orderSn' => $orderSn], true); if (empty($order)) { util::fail('没有找订单'); } $customId = $order->customId ?? 0; $shop = $this->shop; $bookSn = $shop->bookSn ?? 0; if (!empty($bookSn) && !empty($remark)) { $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $productId], true); if (!empty($bookItemRes)) { $bookItemRes->hasRemark = 1; $bookItemRes->save(); } $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true); if (!empty($bookCustomRes)) { $bookCustomRes->hasRemark = 1; $bookCustomRes->save(); } $bookItemCustomRes = BookItemCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId, 'itemId' => $productId], true); if (!empty($bookItemCustomRes)) { $bookItemCustomRes->hasRemark = 1; $bookItemCustomRes->remark = $remark; $bookItemCustomRes->save(); } } util::complete(); } //下载excel ssh 20241127 public function actionGetDownExcel() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $order = OrderClass::getById($id, true); if (empty($order)) { util::fail('没有找到订单'); } if ($order->mainId != $this->mainId) { util::fail('不是你的订单'); } $orderSn = $order->orderSn ?? ''; $list = OrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true); OrderItemClass::exportExcel($order, $list, $this->mainId); } }