| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Http\Controllers\api\thirdPart\weight;
- use App\Http\Controllers\Controller;
- use App\Services\LogService;
- use App\Services\weight\HaoChuangWeightService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\Validator;
- class PackageController extends Controller
- {
- public function new_(Request $requestInitial)
- {
- $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 应为数字',
- ], []);
- }
- }
|