request->get(); $id = $get['id'] ?? 0; $orderItem = OrderItemClass::getById($id, true); if (empty($orderItem)) { util::fail('没有找到'); } if ($orderItem->kind != 2) { util::fail('不需要打印'); } $orderSn = $orderItem->orderSn ?? ''; $order = OrderClass::getByCondition(['orderSn' => $orderSn], true); if (empty($order)) { util::fail('没有找到订单'); } if ($order->mainId != $this->mainId) { util::fail('不是你的订单哦!'); } $customId = $order->customId ?? ''; $custom = CustomClass::getById($customId, true); $customName = $custom->name ?? ''; $productId = $orderItem->productId ?? ''; $productName = $orderItem->name ?? ''; $dishNum = $orderItem->dishNum ?? 0; $itemNum = $orderItem->num ?? 0; $itemNum = floatval($itemNum); $treeList = OrderTreeClass::getAllByCondition(['orderSn' => $orderSn, 'productId' => $productId], 'id asc', '*'); if (empty($treeList)) { util::fail('没有需要打印'); } $table = []; $numList = array_column($treeList, 'num'); foreach (array_chunk($numList, 10) as $numChunk) { $row = []; for ($i = 1; $i <= 10; $i++) { $row['num' . $i] = $numChunk[$i - 1] ?? ''; } $table[] = $row; } $shop = $this->shop; $sjName = $shop->merchantName ?? ''; $shopName = $shop->shopName ?? ''; $sjShopName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName; $printData = [ 'table' => $table, 'staffName' => '', 'orderSn' => $orderSn, 'customName' => $customName, 'sjShopName' => $sjShopName . ' 销售单', 'sjShopName2' => $sjShopName, 'productName' => $productName, 'dishNum' => $dishNum, 'itemNum' => $itemNum, 'saleName'=>'销售单', ]; $info = []; $info['printData'] = $printData; $template = '{"panels":[{"index":0,"name":1,"height":140,"width":210,"paperHeader":79.5,"paperFooter":383.4343434343434,"printElements":[{"options":{"left":115,"top":20,"height":25,"width":374,"title":"文本","right":488.99609375,"bottom":44.9921875,"vCenter":301.99609375,"hCenter":32.4921875,"field":"sjShopName2","testData":"小向花卉","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":21,"fontWeight":"bold","textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"fontFamily":"SimSun"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":424.5,"top":25.5,"height":21,"width":145,"title":"单号","field":"orderSn","testData":"PC563961","coordinateSync":false,"widthHeightSync":false,"fontSize":14.25,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":568.75,"bottom":43.5,"vCenter":496.25,"hCenter":33,"fontFamily":"SimSun","textAlign":"right"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":22.5,"top":85,"height":36,"width":550,"field":"table","coordinateSync":false,"widthHeightSync":false,"fontSize":11,"textAlign":"center","tableHeaderFontWeight":"bold","right":572.5,"bottom":90.99609375,"vCenter":297.5,"hCenter":72.99609375,"fontFamily":"SimSun","tableHeaderRepeat":"none","tableBorder":"noBorder","tableHeaderBorder":"noBorder","tableHeaderCellBorder":"noBorder","columns":[[{"width":56.70171229595743,"title":"","field":"num1","checked":true,"columnId":"num1","fixed":false,"rowspan":1,"colspan":1},{"width":59.07977608328001,"title":"","field":"num2","checked":true,"columnId":"num2","fixed":false,"rowspan":1,"colspan":1},{"width":57.094134615384505,"title":"","field":"num3","checked":true,"columnId":"num3","fixed":false,"rowspan":1,"colspan":1},{"width":52.07663313609472,"title":"","field":"num4","checked":true,"columnId":"num4","fixed":false,"rowspan":1,"colspan":1},{"width":57.083112653618585,"title":"","field":"num5","checked":true,"columnId":"num5","fixed":false,"rowspan":1,"colspan":1},{"width":53.10106937445619,"title":"","field":"num6","checked":true,"columnId":"num6","fixed":false,"rowspan":1,"colspan":1},{"width":56.05950964586556,"title":"","field":"num7","checked":true,"columnId":"num7","fixed":false,"rowspan":1,"colspan":1},{"width":47.09117873148696,"title":"","field":"num8","checked":true,"columnId":"num8","fixed":false,"rowspan":1,"colspan":1},{"width":54.07419941532827,"title":"","field":"num9","checked":true,"columnId":"num9","fixed":false,"rowspan":1,"colspan":1},{"width":57.63867404852769,"title":"","field":"num9","checked":true,"columnId":"num9","fixed":false,"rowspan":1,"colspan":1},{"width":54.223705213537556,"title":"序号","field":"orderNum","checked":false,"columnId":"orderNum","fixed":false,"rowspan":1,"colspan":1},{"width":175.72632876030514,"title":"花材名称","field":"name","checked":false,"columnId":"name","fixed":false,"rowspan":1,"colspan":1},{"width":69.07232544378695,"title":"单价","field":"unitPrice","checked":false,"columnId":"unitPrice","fixed":false,"rowspan":1,"colspan":1},{"width":72.10486265361865,"title":"数量","field":"num","checked":false,"columnId":"num","fixed":false,"rowspan":1,"colspan":1},{"width":67.11113461538461,"title":"金额","field":"price","checked":false,"columnId":"price","fixed":false,"rowspan":1,"colspan":1},{"width":57.08931639029012,"title":"已退","field":"refundNum","checked":false,"columnId":"refundNum","fixed":false,"rowspan":1,"colspan":1},{"width":54.67232692307692,"title":"备注","field":"remark","checked":false,"columnId":"remark","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1},{"width":100,"title":"","field":"","checked":false,"columnId":"","fixed":false,"rowspan":1,"colspan":1}]]},"printElementType":{"title":"空白表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":238.5,"top":148.5,"height":16,"width":178,"title":"客户","field":"customName","testData":"石头花艺","coordinateSync":false,"widthHeightSync":false,"fontSize":16.5,"textContentVerticalAlign":"middle","qrCodeLevel":0,"right":428.5,"bottom":127.75,"vCenter":339.5,"hCenter":119.75},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":424.5,"top":150,"height":16,"width":148,"title":"录单人","field":"staffName","testData":"小石","coordinateSync":false,"widthHeightSync":false,"fontSize":12.75,"textAlign":"right","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":571,"bottom":128.5,"vCenter":497,"hCenter":120.5},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":22.5,"top":28.5,"height":16,"width":143,"title":"名称","field":"productName","testData":"高原红","coordinateSync":false,"widthHeightSync":false,"fontFamily":"STHeitiSC-Light","fontSize":14.25,"fontWeight":"bold","qrCodeLevel":0,"right":141.75,"bottom":36,"vCenter":81.75,"hCenter":31.125},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":106.5,"top":148.5,"height":14,"width":112,"title":"株数","field":"itemNum","testData":"200","coordinateSync":false,"widthHeightSync":false,"fontSize":12.75,"textContentVerticalAlign":"middle","qrCodeLevel":0},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":22.5,"top":148.5,"height":15,"width":85,"title":"筛数","field":"dishNum","testData":"3","coordinateSync":false,"widthHeightSync":false,"fontSize":12,"qrCodeLevel":0,"right":108.25,"bottom":126,"vCenter":65.75,"hCenter":118.5},"printElementType":{"title":"这是更新后的元素","type":"text"}},{"options":{"left":241.5,"top":54,"height":20,"width":120,"title":"文本","field":"saleName","testData":"销售单","coordinateSync":false,"widthHeightSync":false,"hideTitle":true,"fontSize":19.5,"textAlign":"center","textContentVerticalAlign":"middle","qrCodeLevel":0,"right":363,"bottom":68,"vCenter":303,"hCenter":58},"printElementType":{"title":"文本","type":"text"}}],"paperNumberLeft":565.5,"paperNumberTop":389,"paperNumberDisabled":true,"paperNumberContinue":true,"orient":1,"watermarkOptions":{"content":"","rotate":25,"timestamp":false,"format":"YYYY-MM-DD HH:mm","fillStyle":"rgba(184, 184, 184, 0.3)","fontSize":"14px","width":200,"height":200},"panelLayoutOptions":{"layoutType":"column","layoutRowGap":0,"layoutColumnGap":0}}]}'; $info['template'] = $template; util::success($info); } public function actionPrintItemWlLabel() { $get = Yii::$app->request->get(); $orderSn = $get['orderSn'] ?? ''; $order = OrderClass::getByCondition(['orderSn' => $orderSn], true); if (empty($order)) { util::fail('没有找到订单'); } if ($order->mainId != $this->mainId) { util::fail('不是你的订单'); } $id = $get['id'] ?? 0; $orderItem = OrderItemClass::getById($id, true); if (empty($orderItem)) { util::fail('没有花材信息'); } if (empty($orderItem->productId)) { util::fail('花材信息缺失'); } $productId = $orderItem->productId; if ($orderItem->orderSn != $orderSn) { util::fail('你不能操作'); } $product = ProductClass::getById($productId, true); if (empty($product)) { util::fail('花材信息没有找到'); } $shop = $this->shop; $ext = $this->shopExt; $num = $get['num'] ?? 0; if ($num <= 0) { util::fail('请填写数量'); } $boxNum = $get['boxNum'] ?? 0; if ($boxNum <= 0) { util::fail('请填写装箱数'); } OrderClass::printItemLabel($order, $shop, $ext, $product, $num, $boxNum, $orderItem); util::complete('打印成功'); } //过滤名称 ssh 20240430 public function actionFilterName() { $get = Yii::$app->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 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); } }