| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Http\Controllers;
- use App\DeliveryAppointment;
- use App\Http\Requests\Api\ReceivingTaskRequest;
- use App\ReceivingTask;
- use App\Services\OwnerService;
- use App\Services\ReceivingTaskService;
- use App\Warehouse;
- use Illuminate\Http\Request;
- class ReceivingTaskController extends Controller
- {
- /**
- * @var ReceivingTaskService $service
- * @var OwnerService $ownerService
- */
- private $service;
- private $ownerService;
- public function __construct()
- {
- $this->service = app(ReceivingTaskService::class);
- $this->ownerService = app(OwnerService::class);
- }
- public function index()
- {
- $wareHouse = Warehouse::query()->get();
- $owners = $this->ownerService->getQuery()->select("id","code","name")->get();
- return view("store.receivingTasks.create",compact('wareHouse','owners'));
- }
- public function create()
- {
- }
- public function storeApi(ReceivingTaskRequest $request): array
- {
- $delivery_appointment_number = $request->input('delivery_appointment_number',null);
- $delivery_appointment = DeliveryAppointment::query()->where('procurement_number',$delivery_appointment_number)->first();
- if (!$delivery_appointment) return ['success' => false, 'message' => '预约号未找到'];
- if (ReceivingTask::query()->where('delivery_appointment_id',$delivery_appointment->id)->exists())
- return ['success' => false, 'message' => '预约号已有对应的任务'];
- try {
- $receiving_task = $this->service->createReceivingTask($delivery_appointment, $request->all());
- $receiving_task->loadMissing("deliveryAppointment");
- return ['success' => true, 'data' => $receiving_task];
- } catch (\Exception $e) {
- return ['success' => false, 'message' => '生成入库单任务失败,请重新尝试'];
- }
- }
- }
|