WaybillController.php 5.3 KB

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