WaybillController.php 6.0 KB

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