PackageController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. return $this->new($request);
  19. }
  20. public function conversionRequest($request)
  21. {
  22. $params = [];
  23. $arr = $request->all();
  24. $data = array_key_first($arr);
  25. $data = explode(',',$data);
  26. foreach ($data as $key=>$value){
  27. switch ($key){
  28. case '0':
  29. $params['hid'] = $value;
  30. break;
  31. case '1':
  32. $params['code'] = $value;
  33. break;
  34. case '2':
  35. $params['weight'] = $value;
  36. break;
  37. case '3':
  38. $params['weight_at'] = $value;
  39. break;
  40. default:
  41. break;
  42. }
  43. }
  44. return $params;
  45. }
  46. public function getWeightValue($params)
  47. {
  48. $value = $this->getValue($this->weight,$params);
  49. return str_replace('_','.',$value);
  50. }
  51. // 信息返回
  52. // 返回称重成功信息
  53. public function getSuccessMessage($params, $orderPackage): array
  54. {
  55. return ['success' => true, 'message' => '称重成功'];
  56. }
  57. // 返回包裹未找到异常
  58. public function getNotFindOrderPackageMessage($params, $orderPackage): string
  59. {
  60. return json_encode(['success'=>false,'message'=>'未找打包裹信息',JSON_UNESCAPED_UNICODE]);
  61. }
  62. // 返回富勒信息未找到异常
  63. public function getNotFindOrderHeaderMessage($params, $orderPackage):string
  64. {
  65. return json_encode(['success'=>false,'message'=> '富勒信息未找到'],JSON_UNESCAPED_UNICODE);
  66. }
  67. // 返回称重下发错误
  68. public function getWeightMessage($orderPackage,$e)
  69. {
  70. return json_encode(['success'=>false,'message'=> $e->getMessage],JSON_UNESCAPED_UNICODE);
  71. }
  72. public function validator(Request $request): array
  73. {
  74. $params = $this->conversionRequest($request);
  75. $errors = [];
  76. $weight = $this->getWeightValue($params);
  77. if(empty($weight) || $weight == ''){
  78. $errors['weight'] = '称重重量为空';
  79. }
  80. $code = $this->getCodeValue($params);
  81. $code = trim($code,"'");
  82. if(empty($code) || $code == ''){
  83. $errors['code'] = '快递单号为空';
  84. }
  85. $hid = $this->getValue($this->hid, $params);
  86. if(empty($hid) || $hid == ''){
  87. $errors['hid'] = '称重设备号不能为空';
  88. }
  89. return $errors;
  90. }
  91. }