diff --git a/app/Model/PickupCode.php b/app/Model/PickupCode.php index 57f9909..ed8036a 100644 --- a/app/Model/PickupCode.php +++ b/app/Model/PickupCode.php @@ -25,9 +25,13 @@ class PickupCode extends Model * The attributes that are mass assignable. */ protected array $fillable = []; + protected array $guarded = []; /** * The attributes that should be cast to native types. */ protected array $casts = ['id' => 'integer', 'order_id' => 'integer', 'copies' => 'integer']; + + const string CREATED_AT = 'create_time'; + const null UPDATED_AT = null; } diff --git a/app/Service/Admin/Catering/Option/CateringService.php b/app/Service/Admin/Catering/Option/CateringService.php index 0956930..bdbdd74 100644 --- a/app/Service/Admin/Catering/Option/CateringService.php +++ b/app/Service/Admin/Catering/Option/CateringService.php @@ -133,7 +133,7 @@ class CateringService extends CateringBaseService if (empty($this->orderList)) throw new ErrException('无数据打印'); // 打印或者喷码 - $res = match ($this->request->input('type')) { + $res = match ((int)$this->request->input('type')) { CateringCode::OPTION_PRINT_YLY => $this->printOrderByYly(), CateringCode::OPTION_PRINT_CODING => $this->printOrderByCoding(), }; @@ -199,7 +199,7 @@ class CateringService extends CateringBaseService $currentCode++; $paddedCode = str_pad((string)$currentCode, 3, '0', STR_PAD_LEFT); $fullCode = "$prefix-$paddedCode"; - $copiesItem['take_food_code'] = $fullCode; + $copiesItem['pickup_code'] = $fullCode; $copiesItem['heapsort'] = $codeRanges[$currentCode] ?? ''; $takeFoodCodes[] = [ 'order_id' => $order['id'], @@ -231,7 +231,7 @@ class CateringService extends CateringBaseService { $pickupCodeList = $this->pickupCodeModel ->whereIn('order_id',$this->orderIds) - ->get(['take_food_code', 'order_id', 'box_num', 'heapsort', 'id']) + ->get(['pickup_code', 'order_id', 'copies', 'heapsort', 'id']) ->toArray(); if (empty($pickupCodeList)) { @@ -243,8 +243,9 @@ class CateringService extends CateringBaseService foreach ($this->orderList as &$order) { foreach ($order['copies_list'] as &$copiesItem) { - $copiesItem['take_food_code'] = $pickupCodeArrList[$copiesItem['id']][$copiesItem]['take_food_code']; - $copiesItem['heapsort'] = $pickupCodeArrList[$copiesItem['id']][$copiesItem]['heapsort']; + + $copiesItem['pickup_code'] = $pickupCodeArrList[$order['id']][$copiesItem['copies']]['pickup_code']; + $copiesItem['heapsort'] = $pickupCodeArrList[$order['id']][$copiesItem['copies']]['heapsort']; } } unset($pickupCodeArrList); @@ -262,11 +263,11 @@ class CateringService extends CateringBaseService try { Db::beginTransaction(); - $delRes = $this->pickupCodeModel->whereIn('order_id',$this->orderIds)->delete(); + $this->pickupCodeModel->whereIn('order_id',$this->orderIds)->delete(); $insertModel = new PickupCode(); $insertRes = $insertModel->insert($codeRanges); - if (!$insertRes || !$delRes) throw new Exception('取餐码生成失败'); + if (!$insertRes) throw new Exception('取餐码生成失败'); $this->buildPickupCodeCache(); @@ -358,6 +359,8 @@ class CateringService extends CateringBaseService // $adminInfo = $this->adminUserModel->find($this->siteInfo->delivered_id); $driverInfo = $this->driverSequenceModel->where('driver_id',$this->siteInfo->delivered_id)->first(); if (empty($driverInfo)) throw new ErrException('配送员信息丢失,请联系管理员'); + if ($driverInfo->driver_num <= 0) throw new ErrException('配送员编号丢失,请联系管理员'); + if (empty($driverInfo->driver_name)) throw new ErrException('配送员姓名丢失,请联系管理员'); foreach ($orderList as &$one) { $one['dates'] = date('Y-m-d'); @@ -435,13 +438,11 @@ class CateringService extends CateringBaseService } if (!isset($result[$orderId][$copies])) { - $result[$orderId][$copies] = []; + $result[$orderId][$copies] = [ + 'pickup_code' => $pickupCode, + 'heapsort' => $heapsort, + ]; } - - $result[$orderId][$copies][] = [ - 'pickup_code' => $pickupCode, - 'heapsort' => $heapsort, - ]; } return $result; @@ -477,6 +478,8 @@ class CateringService extends CateringBaseService if (empty($this->logInfo)) throw new ErrException('配餐数据不存在'); if ($this->logInfo->quantity <= 0) throw new ErrException('该配餐数量为0,不可配餐'); + + if ($this->siteInfo->sequence <= 0) throw new ErrException('请先配置点位顺序'); } /** @@ -492,7 +495,7 @@ class CateringService extends CateringBaseService */ private function printOrderByYly(): true { - $service = $this->printOrderFactory->handle($this->request->input('type')); + $service = $this->printOrderFactory->handle((int)$this->request->input('type')); $service->printId = (int)$this->request->input('print_id'); $service->handle(); @@ -506,13 +509,13 @@ class CateringService extends CateringBaseService //todo 数据加载做一下 $service->data = [ 'pickup_code' => $copiesItem['pickup_code'], - 'driver_num' => '', - 'site_order' => '', - 'site_text' => '', - 'order_sno' => '', - 'username' => '', - 'date' => '', - 'mobile' => '', + 'driver_num' => $one['driver_num'], + 'site_order' => $one['site_order'], + 'site_text' => $one['site_text'], + 'order_sno' => $one['order_sno'], + 'username' => $one['nickname'], + 'date' => $one['dates'], + 'mobile' => $one['mobile'], 'heapsort' => $copiesItem['heapsort'], 'sku' => $copiesItem['sku'], ]; @@ -530,10 +533,10 @@ class CateringService extends CateringBaseService if ($printBoxNum != 0) continue; $service->data = [ - 'driver_num' => '', - 'site_order' => '', - 'site_text' => '', - 'driver_name' => '', + 'driver_num' => $one['driver_num'], + 'site_order' => $one['site_order'], + 'site_text' => $one['site_text'], + 'driver_name' => $one['real_name'], 'current_num' => $printCurrentNum, 'date_text' => date('Y-m-d'), 'copies_num' => $this->copiesCount, @@ -554,7 +557,7 @@ class CateringService extends CateringBaseService */ private function printOrderByCoding(): array { - $service = $this->printOrderFactory->handle($this->request->input('type')); + $service = $this->printOrderFactory->handle((int)$this->request->input('type')); $printBoxNum = 0; $printCurrentNum = 0; @@ -565,13 +568,13 @@ class CateringService extends CateringBaseService foreach ($one['copies_list'] as $copiesItem) { $service->data = [ 'pickup_code' => $copiesItem['pickup_code'], - 'driver_num' => '', - 'site_order' => '', - 'site_text' => '', - 'order_sno' => '', - 'username' => '', - 'date' => '', - 'mobile' => '', + 'driver_num' => $one['driver_num'], + 'site_order' => $one['site_order'], + 'site_text' => $one['site_text'], + 'order_sno' => $one['order_sno'], + 'username' => $one['nickname'], + 'date' => $one['dates'], + 'mobile' => $one['mobile'], 'heapsort' => $copiesItem['heapsort'], 'sku' => $copiesItem['sku'], ]; diff --git a/app/Service/Admin/Catering/Option/CompletePrintService.php b/app/Service/Admin/Catering/Option/CompletePrintService.php index 40422a4..1d80725 100644 --- a/app/Service/Admin/Catering/Option/CompletePrintService.php +++ b/app/Service/Admin/Catering/Option/CompletePrintService.php @@ -99,12 +99,16 @@ class CompletePrintService extends CateringBaseService $siteInfo = $this->siteModel->find($orderInfo->site_id); + if ($siteInfo->sequence <= 0) throw new ErrException('请先配置点位顺序'); $userInfo = $this->userModel->find($orderInfo->user_id); $driverInfo = $this->driverSequenceModel->find($siteInfo->delivered_id); + if (empty($driverInfo)) throw new ErrException('配送员信息丢失,请联系管理员'); + if ($driverInfo->driver_num <= 0) throw new ErrException('配送员编号丢失,请联系管理员'); + if (empty($driverInfo->driver_name)) throw new ErrException('配送员姓名丢失,请联系管理员'); - $this->printService = $this->printOrderFactory->handle($this->request->input('type')); + $this->printService = $this->printOrderFactory->handle((int)$this->request->input('type')); // 打印或者喷码 match ($this->request->input('type')) { CateringCode::OPTION_PRINT_YLY => $this->printOrderByYly(), diff --git a/app/Service/Admin/Catering/Print/YlyPrintService.php b/app/Service/Admin/Catering/Print/YlyPrintService.php index bd8c9bd..1fec0b1 100644 --- a/app/Service/Admin/Catering/Print/YlyPrintService.php +++ b/app/Service/Admin/Catering/Print/YlyPrintService.php @@ -101,8 +101,8 @@ class YlyPrintService implements PrintOrderInterface if ( empty($this->data['pickup_code']) || - empty($this->data['driver_num']) || - empty($this->data['site_order']) || +// empty($this->data['driver_num']) || +// empty($this->data['site_order']) || empty($this->data['site_text']) || empty($this->data['sku']) || empty($this->data['order_sno']) || @@ -278,7 +278,7 @@ class YlyPrintService implements PrintOrderInterface $this->content .= "\n"; // 箱数 - $currentNum = str_pad($this->data['current_num'], 2, '0', STR_PAD_LEFT); + $currentNum = str_pad((string)$this->data['current_num'], 2, '0', STR_PAD_LEFT); $this->content .= "箱数:$currentNum\n"; $this->content .= "\n";