WaybillController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace App\Http\ApiControllers;
  3. use App\Components\ApiResponse;
  4. use App\Http\Requests\AndroidGateRequest;
  5. use App\Http\Requests\Api\WaybillDispatch;
  6. use App\Services\WaybillService;
  7. use App\Waybill;
  8. class WaybillController
  9. {
  10. use ApiResponse;
  11. /**
  12. * @api {get} /waybill/dispatch 获取调度数据
  13. * @apiName dispatch
  14. * @apiGroup Waybill
  15. *
  16. * @apiParam {string} search 搜索文本(运单号或物流单号)
  17. * @apiParam {string} deliver_at 发货时间
  18. * @apiParam {int} page 页数
  19. * @apiParam {int} paginate 每页多少
  20. *
  21. * @apiSuccess {string} message 响应描述
  22. * @apiSuccess {int} status_code HTTP响应码
  23. * @apiSuccess {array} data 数据列表
  24. *
  25. * @apiSuccessExample {json} Success-Response:
  26. * HTTP/1.1 200 OK
  27. * {
  28. * "message": "请求成功",
  29. * "status_code": "200"
  30. * "data":[
  31. * {
  32. * "waybill_number"=>"宝时单号",
  33. * "destination" =>"目的地",
  34. * "recipient" =>"收件人",
  35. * "recipient_mobile"=>"收件人电话",
  36. * "carrier_bill"=>"承运商单号",
  37. * "carrier_name"=>"承运商",
  38. * "warehouse_weight"=>"预估体积",
  39. * "carrier_weight"=>"实际体积",
  40. * "inquire_tel"=>"查件电话",
  41. * "warehouse_weight_other"=>"预估重量",
  42. * "carrier_weight_other"=>"实际重量",
  43. * "amount"=>"数量",
  44. * "amount_unit_name"=>"数量单位",
  45. * "origination"=>"提货仓"
  46. * "subjoin_fee"=>"附加费"
  47. * }
  48. * ]
  49. * }
  50. */
  51. public function getData(AndroidGateRequest $request)
  52. {
  53. $search = $request->input("search");
  54. $deliverAt = $request->input("deliver_at");
  55. $page = $request->input("page",1);
  56. $paginate = $request->input("paginate",20);
  57. /** @var WaybillService $service */
  58. $service = app("WaybillService");
  59. $query = $service->getDispatchQuery();
  60. if ($search)$query->where(function ($query)use($search){
  61. $query->where("waybill_number","like","%{$search}%")
  62. ->orWhere("carrier_bill","like","%{$search}%");
  63. });
  64. if ($deliverAt)$query->where("deliver_at","like",$deliverAt."%");
  65. $this->response($query->paginate($paginate,'*', 'page',$page)->append(["carrier_name","amount_unit_name","remove_relation"]));
  66. }
  67. /**
  68. * @api {post} /waybill/dispatch 修改调度信息
  69. * @apiName updateDispatch
  70. * @apiGroup Waybill
  71. *
  72. * @apiParam {int} id 唯一码
  73. * @apiParam {string} carrier_bill 物流单号
  74. * @apiParam {string} inquire_tel 查件电话
  75. * @apiParam {int} amount 货品数量
  76. * @apiParam {string} amount_unit_name 数量单位(件/托)
  77. * @apiParam {number} carrier_weight_other 重量/KG
  78. * @apiParam {number} carrier_weight 体积/M³
  79. * @apiParam {string} subjoin_fee 附加费描述
  80. *
  81. * @apiSuccess {string} message 响应描述
  82. * @apiSuccess {int} status_code HTTP响应码
  83. * @apiSuccess {bool} data 结果
  84. *
  85. * @apiSuccessExample {json} Success-Response:
  86. * HTTP/1.1 200 OK
  87. * {
  88. * "message": "请求成功",
  89. * "status_code": "200"
  90. * "data":true
  91. * }
  92. *
  93. */
  94. public function dispatch(WaybillDispatch $request)
  95. {
  96. $result = Waybill::query()->where("id",$request->input("id"))
  97. ->update($request->validated());
  98. if ($result==0)$this->response(false,204,"单据状态发生变化,修改失败");
  99. // $startDate = "";
  100. // $endDate = "";
  101. // $res = ["2021-10-08"=>20,"2021-10-09"=>21];
  102. $this->response(true);
  103. }
  104. /**
  105. * @api {post} /waybill/dispatch/dailyBilling 修改每日专线费
  106. * @apiName dailyBilling
  107. * @apiGroup Waybill
  108. *
  109. * @apiParam {string} deliver_at 发货时间
  110. * @apiParam {number} fee 费用
  111. *
  112. * @apiSuccess {string} message 响应描述
  113. * @apiSuccess {int} status_code HTTP响应码
  114. * @apiSuccess {bool} data 结果
  115. *
  116. * @apiSuccessExample {json} Success-Response:
  117. * HTTP/1.1 200 OK
  118. * {
  119. * "message": "请求成功",
  120. * "status_code": "200"
  121. * "data":true
  122. * }
  123. */
  124. public function dailyBilling(AndroidGateRequest $request)
  125. {
  126. $deliverAt = $request->input("deliver_at");
  127. $fee = $request->input("fee");
  128. if (!$deliverAt || !$fee || !is_numeric($fee) || !$fee<0)
  129. $this->response(false,400,"非法参数或不满足需求");
  130. $param=array('screenDate'=>$deliverAt,'billing'=>$fee);
  131. $waybills=app('waybillService')->dailyBilling($param);
  132. if ($waybills===0 || $waybills===1 || !isset($waybills)) $this->response(false);
  133. $this->response(true);
  134. }
  135. }