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); 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']; } 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', [1, 2, 3]]; } } if (isset($get['sn']) && !empty($get['sn']) && is_numeric($get['sn'])) { $where['sn'] = $get['sn']; } if (isset($get['thirdSn']) && !empty($get['thirdSn']) && is_numeric($get['thirdSn'])) { $where['thirdSn'] = $get['thirdSn']; } $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() { $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_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('制作单已取消'); } //花材未锁定,需要锁定并扣库存 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 != 4) { WorkClass::print($work, $this->shop, false); } $msg = '已完成'; $orderId = $work->orderId ?? 0; if (!empty($orderId) && $work->fromType == dict::getDict('fromType', 'mt')) { $allWork = WorkClass::getAllByCondition(['orderId' => $orderId], null, '*', null, true); //订单下如果还有制作单未完成,则不通知美图已经完成拣货 $allComplete = true; if (!empty($allWork)) { foreach ($allWork as $current) { if ($current->status != 1) { $allComplete = false; } } } if ($allComplete) { $order = OrderClass::getById($orderId, true); $thirdOrderId = $order->thirdOrderId ?? ''; $fromType = $order->fromType ?? 0; if (!empty($thirdOrderId) && $fromType == dict::getDict('fromType', 'mt')) { // $shopId = $order->shopId ?? 0; // $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true); // $config = dict::getDict('mtConfig'); // $app = new Application($config); // $accessToken = mtUtil::getAccessToken($ext); // $params = ['order_id' => $thirdOrderId, 'access_token' => $accessToken]; // $mtRes = $app->order->logisticsPush($params); // $mtRes = json_decode($mtRes, true); // if (isset($mtRes['data']) && $mtRes['data'] == 'ok') { // $msg = '已完成,已通知骑手'; // } } } } util::complete($msg); } catch (\Exception $e) { $transaction->rollBack(); Yii::error("失败原因:" . $e->getMessage()); util::fail('操作失败'); } } }