request->get('orderId', 0); $order = OrderClass::getById($orderId, true); OrderClass::valid($order, $this->mainId); $info = WorkClass::getByCondition(['orderId' => $orderId], true); if (empty($info)) { util::fail('没有找到'); } util::success(['info' => $info]); } //打印制作单 ssh 20220601 public function actionPrint() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $work = WorkClass::getById($id, true); WorkClass::valid($work, $this->mainId); WorkClass::print($work, $this->shop); util::complete(); } //制作单列表 ssh 20220319 public function actionList() { $get = Yii::$app->request->get(); $where = []; $where['mainId'] = $this->mainId; if (isset($get['status']) && $get['status'] >= 0) { $status = $get['status']; $where['status'] = $status; } if (isset($get['fromType']) && is_numeric($get['fromType'])) { //$where['fromType'] = $get['fromType']; } if (isset($get['searchType'])) { if ($get['searchType'] == 0) { util::fail('暂不支持名称搜索'); } elseif ($get['searchType'] == 1) { if (!empty($get['name'])) { if (!is_numeric($get['name'])) { util::fail('编号必须是数字'); } $where['sn'] = $get['name']; } } } $list = WorkClass::getWorkList($where); $list['today'] = date("Y-m-d"); util::success($list); } //锁定用材 ssh 20220320 public function actionLock() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $work = WorkClass::getById($id, true); WorkClass::valid($work, $this->mainId); WorkItemClass::lock($work); util::complete(); } //新建制作单 ssh 20220319 public function actionCreate() { $post = Yii::$app->request->post(); $post['mainId'] = $this->mainId ?? 0; $post['sjId'] = $this->sjId ?? 0; $post['shopId'] = $this->shopId ?? 0; $orderSn = orderSn::getWorkSn(); $post['workSn'] = $orderSn; $post['staffId'] = $this->shopAdminId; $post['staffName'] = $this->shopAdmin->name; $post['name'] = isset($post['name']) && !empty($post['name']) ? $post['name'] : '花束'; $post['cover'] = isset($post['cover']) && !empty($post['cover']) ? $post['cover'] : 'default-img.png'; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $product = $post['product'] ?? ''; $post['product'] = []; if (!empty($product)) { $arr = json_decode($product, true); if (!empty($arr)) { $post['product'] = $arr; } } $post['num'] = isset($post['num']) && $post['num'] > 0 ? $post['num'] : 1; $catId = $post['catId'] ?? 0; $cat = CategoryClass::getById($catId, true); if ($cat->mainId != $this->mainId) { util::fail('请选择你自己的分类'); } $post['catName'] = $cat->categoryName ?? ''; $main = $this->main; $work = WorkClass::createFinish($post, $main); $transaction->commit(); $complete = $post['complete'] ?? 0; if ($complete == 1) { WorkClass::print($work, $this->shop, false); } util::success($work); } catch (\Exception $e) { $transaction->rollBack(); Yii::error("失败原因:" . $e->getMessage()); util::fail('操作失败'); } } //商品新建制作 ssh 20220320 public function actionGoodsCreate() { $post = Yii::$app->request->post(); $post['mainId'] = $this->mainId ?? 0; $post['sjId'] = $this->sjId ?? 0; $post['shopId'] = $this->shopId ?? 0; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $goodsJson = $post['goods'] ?? ''; $goods = json_decode($goodsJson, true); if (empty($goods)) { util::fail('没有找到商品'); } $post['goods'] = $goods; $main = $this->main; WorkClass::goodsCreateFinish($post, $main); $transaction->commit(); util::complete(); } catch (\Exception $e) { $transaction->rollBack(); Yii::error("失败原因:" . $e->getMessage()); util::fail('操作失败'); } } //包括制作单和用材信息 ssh 20220319 public function actionFullInfo() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $work = WorkClass::getById($id, true); WorkClass::valid($work, $this->mainId); $workItem = WorkItemClass::getWorkAllItem($work); $goods = []; $goodsId = $work->goodsId ?? 0; if (!empty($goodsId)) { $goods = GoodsClass::getGoodsInfo($goodsId); } $work = $work->attributes; $shortCover = $work['cover'] ?? ''; $work['shortCover'] = $shortCover; $work['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700"; $work['bigCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700"; $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130"; $today = date("Y-m-d"); util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods, 'today' => $today]); } //取消 ssh 20220320 public function actionCancel() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $work = WorkClass::getById($id, true); WorkClass::valid($work, $this->mainId); WorkClass::cancel($work); util::complete(); } //完成制作单 ssh 20220319 public function actionFinish() { $post = Yii::$app->request->post(); $workId = $post['id'] ?? 0; $connection = Yii::$app->db;//事务处理 $transaction = $connection->beginTransaction(); try { $work = WorkClass::getById($workId, true); WorkClass::valid($work, $this->mainId); if ($work->status == 1) { util::fail('制作单已完成'); } if ($work->status == 2) { util::fail('制作单已取消'); } //花材未锁定,需要锁定并扣库存 if ($work->stockLock == 0) { $itemList = $post['itemList'] ?? ''; if (!empty($itemList)) { $product = json_decode($itemList, true); if (!empty($product)) { WorkItemClass::modifyItem($work, $product); WorkItemClass::lock($work); } } } WorkClass::finish($work); $transaction->commit(); //美团的订单完成时不需要打标签 if ($work->fromType != dict::getDict('fromType', 'mt')) { WorkClass::print($work, $this->shop, false); } util::complete(); } catch (\Exception $e) { $transaction->rollBack(); Yii::error("失败原因:" . $e->getMessage()); util::fail('操作失败'); } } }