create(['content' => json_encode($requestInitial->all()),'interface' => 'HaoChuang']); $request = []; foreach ($requestInitial->all() as $k => $v) { $request[strtolower($k)] = $v; } $weight_at = Carbon::now()->format(Carbon::DEFAULT_TO_STRING_FORMAT); $errors = $this->validatorWeight($request)->errors(); if (count($errors) > 0) { app('LogService')->log(__METHOD__, 'error' . __FUNCTION__, json_encode($request) . '||' . json_encode($errors), null); return json_encode(["msg" => $errors, "code" => 500, "data" => null]); } $request['weight_at'] = $weight_at; /** @var HaoChuangWeightService $service */ $service = app(HaoChuangWeightService::class); $response = $service->new($request); if ($response['code'] == 500) LogService::log(__CLASS__, $service->name, '称重失败!' . json_encode($request['msg'] ?? '') . json_encode($request)); else LogService::log(__CLASS__, $service->name, '称重成功!' . json_encode($request)); return json_encode($response); } public function validatorWeight(array $request): \Illuminate\Contracts\Validation\Validator { return Validator::make($request, [ 'id' => ['nullable', 'max:30'], 'barcode' => ['required', 'max:191'], 'weight' => ['required', 'numeric', 'min:0'], 'length' => ['nullable', 'numeric', 'min:0'], 'width' => ['nullable', 'numeric', 'min:0'], 'height' => ['nullable', 'numeric', 'min:0'], ], [ 'required' => ':attribute 为必填项', 'max' => ':attribute 字符过多或数值过大', 'min' => ':attribute 不得为负', 'numeric' => ':attribute 应为数字', ], []); } }