request->get(); $id = $get['id'] ?? 0; $order = OrderClass::getById($id, true); if (empty($order)) { util::fail('没有订单'); } $mainId = $this->mainId; if ($order->mainId != $mainId) { util::fail('不是你的订单'); } if ($order->hasWork == 1) { util::fail('已经通知制作了'); } $main = $this->main; WorkClass::needWork($order, $main); $has = WorkClass::getByCondition(['orderId' => $id], true); if (!empty($has)) { $shopExt = ShopExtClass::getByCondition(['shopId' => $this->shopId], true); ShopExtClass::newWorkRemind($shopExt, $order); $order->hasWork = 1; $order->save(); util::complete('通知成功'); } util::fail('通知失败'); } //根据订单id查询制作单信息 ssh 20220625 public function actionGetInfoByOrderId() { $orderId = Yii::$app->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, 'order' => $order]); } //打印制作单 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, true); util::complete(); } //制作单列表 ssh 20220319 public function actionList() { $get = Yii::$app->request->get(); $where = []; $where['mainId'] = $this->mainId; $str = $get['sh'] ?? ''; if ($str == 'yes') { $where['sh'] = 1; } else { $where['sh'] = 0; if (isset($get['fromType']) && is_numeric($get['fromType'])) { $where['fromType'] = $get['fromType']; } else { $shopId = $this->shopId; $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true); $mtAlone = $ext->mtAlone ?? 0; $isCashier = $get['isCashier'] ?? 0; if ($mtAlone == 1 && $isCashier == 1) { $where['fromType'] = ['in', [0, 1, 2, 3]]; } } } if (isset($get['sendNum']) && !empty($get['sendNum']) && is_numeric($get['sendNum'])) { $where['sendNum'] = $get['sendNum']; } if (isset($get['thirdSn']) && !empty($get['thirdSn']) && is_numeric($get['thirdSn'])) { $where['thirdSn'] = $get['thirdSn']; } if (isset($get['status']) && $get['status'] >= 0) { $status = $get['status']; $where['status'] = $status; } $list = WorkClass::getWorkList($where); 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() { util::fail('请联系管理员'); $post = Yii::$app->request->post(); $post['mainId'] = $this->mainId ?? 0; $post['sjId'] = $this->sjId ?? 0; $post['shopId'] = $this->shopId ?? 0; $orderSn = orderSn::getWorkSn(); $mainId = $this->mainId; $post['workSn'] = $orderSn; if (!empty($post['staffId'])) { $staffId = $post['staffId']; $staffName = $post['staffName'] ?? ''; } else { $staffId = $this->shopAdminId; $staffName = $this->shopAdmin->name; } $post['staffId'] = $staffId; $post['staffName'] = $staffName; $post['name'] = !empty($post['name']) ? $post['name'] : '花束'; $post['cover'] = !empty($post['cover']) ? $post['cover'] : 'default-img.png'; $post['reachDate'] = date("Y-m-d"); $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { //去掉花束所用的花材,没有意义,不考虑花束用了多少花材 $post['product'] = []; $post['num'] = isset($post['num']) && $post['num'] > 0 ? $post['num'] : 1; $default = CategoryClass::getByCondition(['mainId' => $mainId, 'flower' => 1, 'default' => 1], true); if (empty($default)) { $catData = [ 'mainId' => $mainId, 'sjId' => $this->sjId, 'shopId' => $this->shopId, 'default' => 1, 'flower' => 1, 'categoryName' => '未分类', 'inTurn' => 0, 'status' => 0, ]; $default = CategoryClass::add($catData, true); } $catId = $default->id ?? 0; if (empty($catId)) { util::fail('没有找到分类'); } $post['catId'] = $catId; $post['catName'] = $cat->categoryName ?? ''; $main = $this->main; $work = WorkClass::createFinish($post, $main); $transaction->commit(); $complete = $post['complete'] ?? 0; $print = $post['print'] ?? 1; if ($complete == 1 && $print == 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)) { $params = []; $shop = $this->shop; //这边传的是空的,有影响,后面要解决,请搜索关键词 work_if_need_custom $custom = []; $goods = GoodsClass::getGoodsInfo($goodsId, $shop, $custom, $params); } $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_1000,w_1000"; $work['smallCover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130"; $today = date("Y-m-d"); $tomorrow = date("Y-m-d", strtotime('+1 day')); $work['today'] = $today; $work['tomorrow'] = $tomorrow; $addTime = $work['addTime'] ?? 0; $currentTime = strtotime($addTime) + 60; $diffTime = bcsub($currentTime, time()); $beginCount = $diffTime > 0 ? $diffTime : 0; $work['beginCount'] = $beginCount; util::success(['info' => $work, 'item' => $workItem, 'goods' => $goods]); } //取消 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('制作单已取消'); } $staffId = $post['staffId'] ?? 0; if (empty($staffId)) { util::fail('请选择制作人'); } $staffName = $post['staffName'] ?? ''; $staffData = ['staffId' => $staffId, 'staffName' => $staffName]; WorkClass::finish($work, $staffData); $transaction->commit(); //美团的暂时不打小票 if ($work->fromType != 4) { WorkClass::print($work, $this->shop, true); } $msg = '已完成'; util::complete($msg); } catch (\Exception $e) { $transaction->rollBack(); Yii::error("失败原因:" . $e->getMessage()); util::fail('操作失败'); } } }