PackageController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Http\Controllers\api\thirdPart\hengli;
  3. use App\Http\Controllers\api\thirdPart\weight\WeightBaseController;
  4. use Illuminate\Http\Request;
  5. class PackageController extends WeightBaseController
  6. {
  7. // 参数
  8. protected $weight = 'weight'; // 重量
  9. protected $length = 'length'; // 长
  10. protected $width = 'width'; // 宽
  11. protected $height = 'height'; // 高
  12. protected $code = 'code'; // 快递单号
  13. protected $weight_at = 'weight_at'; // 称重时间
  14. protected $hid = 'hid'; // 称重设备id
  15. protected $name = 'HengLi'; // 名称
  16. public function new_(Request $request)
  17. {
  18. app('LogService')->log(__METHOD__, $this->name, "记录上传日志:" . json_encode($request->all()) , null);
  19. return $this->new($request);
  20. }
  21. public function conversionRequest($request)
  22. {
  23. $params = [];
  24. $arr = $request->all();
  25. $data = array_key_first($arr);
  26. $data = explode(',', $data);
  27. foreach ($data as $key => $value) {
  28. switch ($key) {
  29. case '0':
  30. $params['hid'] = $value;
  31. break;
  32. case '1':
  33. $params['code'] = $value;
  34. // $params['code'] = $this->processCode($value);
  35. break;
  36. case '2':
  37. $params['weight'] = $value;
  38. break;
  39. case '3':
  40. $params['weight_at'] = $value;
  41. break;
  42. default:
  43. break;
  44. }
  45. }
  46. return $params;
  47. }
  48. public function getWeightValue($params)
  49. {
  50. $value = $this->getValue($this->weight, $params);
  51. return str_replace('_', '.', $value);
  52. }
  53. // 信息返回
  54. // 返回称重成功信息
  55. public function getSuccessMessage($params, $orderPackage): array
  56. {
  57. return ['success' => true, 'message' => '称重成功'];
  58. }
  59. // 返回包裹未找到异常
  60. public function getNotFindOrderPackageMessage($params, $orderPackage): string
  61. {
  62. return json_encode(['success' => false, 'message' => '未找打包裹信息', JSON_UNESCAPED_UNICODE]);
  63. }
  64. // 返回富勒信息未找到异常
  65. public function getNotFindOrderHeaderMessage($params, $orderPackage): string
  66. {
  67. return json_encode(['success' => false, 'message' => '富勒信息未找到'], JSON_UNESCAPED_UNICODE);
  68. }
  69. // 返回称重下发错误
  70. public function getWeightMessage($orderPackage, $e)
  71. {
  72. return json_encode(['success' => false, 'message' => $e->getMessage], JSON_UNESCAPED_UNICODE);
  73. }
  74. public function validator(Request $request): array
  75. {
  76. $params = $this->conversionRequest($request);
  77. $errors = [];
  78. $weight = $this->getWeightValue($params);
  79. if (empty($weight) || $weight == '') {
  80. $errors['weight'] = '称重重量为空';
  81. }
  82. $code = $this->getCodeValue($params);
  83. $code = trim($code, "'");
  84. if (empty($code) || $code == '') {
  85. $errors['code'] = '快递单号为空';
  86. }
  87. $hid = $this->getValue($this->hid, $params);
  88. if (empty($hid) || $hid == '') {
  89. $errors['hid'] = '称重设备号不能为空';
  90. }
  91. return $errors;
  92. }
  93. }