| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- namespace App\Http\ApiControllers;
- use App\Components\ApiResponse;
- use App\Http\Requests\AndroidGateRequest;
- use App\Http\Requests\Api\WaybillDispatch;
- use App\Services\WaybillService;
- use App\Waybill;
- use Illuminate\Database\Eloquent\Collection;
- use Illuminate\Support\Facades\DB;
- class WaybillController
- {
- use ApiResponse;
- /**
- * @api {get} /waybill/dispatch 获取调度数据
- * @apiName dispatch
- * @apiGroup Waybill
- *
- * @apiParam {string} search 搜索文本(运单号或物流单号)
- * @apiParam {string} deliver_at 发货时间
- * @apiParam {int} page 页数
- * @apiParam {int} paginate 每页多少
- *
- * @apiSuccess {string} message 响应描述
- * @apiSuccess {int} status_code HTTP响应码
- * @apiSuccess {array} data 数据列表
- *
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "message": "请求成功",
- * "status_code": "200"
- * "data":[
- * {
- * "waybill_number"=>"宝时单号",
- * "destination" =>"目的地",
- * "recipient" =>"收件人",
- * "recipient_mobile"=>"收件人电话",
- * "carrier_bill"=>"承运商单号",
- * "carrier_name"=>"承运商",
- * "warehouse_weight"=>"预估体积",
- * "carrier_weight"=>"实际体积",
- * "inquire_tel"=>"查件电话",
- * "warehouse_weight_other"=>"预估重量",
- * "carrier_weight_other"=>"实际重量",
- * "amount"=>"数量",
- * "amount_unit_name"=>"数量单位",
- * "origination"=>"提货仓"
- * "subjoin_fee"=>"附加费"
- * }
- * ]
- * }
- */
- public function getData(AndroidGateRequest $request)
- {
- $search = $request->input("search");
- $deliverAt = $request->input("deliver_at");
- $page = $request->input("page",1);
- $paginate = $request->input("paginate",20);
- /** @var WaybillService $service */
- $service = app("WaybillService");
- $query = $service->getDispatchQuery()->orderByDesc("deliver_at");
- if ($search)$query->where(function ($query)use($search){
- $query->where("waybill_number","like","%{$search}%")
- ->orWhere("carrier_bill","like","%{$search}%");
- });
- if ($deliverAt)$query->where("deliver_at","like",$deliverAt."%");
- /** @var Collection $waybills */
- $waybills = $query->paginate($paginate,'*', 'page',$page)->append(["carrier_name","amount_unit_name","remove_relation"]);
- $result = [];
- if ($waybills->count()>0){
- $startDate = substr($waybills->first()->deliver_at,0,10);
- $endDate = substr($waybills->last()->deliver_at,0,10);
- $sql = <<<sql
- 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
- sql;
- foreach (DB::select(DB::raw($sql)) as $item){
- $result[$item->date] = $item->sum!==null ? round((double)$item->sum) : 0.0;
- }
- }
- return response()->json(["status_code"=>200,
- "data"=>["waybills"=>$waybills,"mapping"=>$result],
- "message"=>null]);
- //$this->response(["waybills"=>$waybills,"mapping"=>$result]);
- }
- /**
- * @api {post} /waybill/dispatch 修改调度信息
- * @apiName updateDispatch
- * @apiGroup Waybill
- *
- * @apiParam {int} id 唯一码
- * @apiParam {string} carrier_bill 物流单号
- * @apiParam {string} inquire_tel 查件电话
- * @apiParam {int} amount 货品数量
- * @apiParam {string} amount_unit_name 数量单位(件/托)
- * @apiParam {number} carrier_weight_other 重量/KG
- * @apiParam {number} carrier_weight 体积/M³
- * @apiParam {string} subjoin_fee 附加费描述
- *
- * @apiSuccess {string} message 响应描述
- * @apiSuccess {int} status_code HTTP响应码
- * @apiSuccess {bool} data 结果
- *
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "message": "请求成功",
- * "status_code": "200"
- * "data":true
- * }
- *
- */
- public function dispatch(WaybillDispatch $request)
- {
- $result = Waybill::query()->where("id",$request->input("id"))
- ->update($request->validated());
- if ($result==0)$this->response(false,204,"单据状态发生变化,修改失败");
- return response()->json(["status_code"=>200,
- "data"=>true,
- "message"=>null]);
- //$this->response(true);
- }
- /**
- * @api {post} /waybill/dispatch/dailyBilling 修改每日专线费
- * @apiName dailyBilling
- * @apiGroup Waybill
- *
- * @apiParam {string} deliver_at 发货时间
- * @apiParam {number} fee 费用
- *
- * @apiSuccess {string} message 响应描述
- * @apiSuccess {int} status_code HTTP响应码
- * @apiSuccess {bool} data 结果
- *
- * @apiSuccessExample {json} Success-Response:
- * HTTP/1.1 200 OK
- * {
- * "message": "请求成功",
- * "status_code": "200"
- * "data":true
- * }
- */
- public function dailyBilling(AndroidGateRequest $request)
- {
- $deliverAt = $request->input("deliver_at");
- $fee = $request->input("fee");
- if (!$deliverAt || !$fee || !is_numeric($fee) || !$fee<0)
- $this->response(false,400,"非法参数或不满足需求");
- $param=array('screenDate'=>$deliverAt,'billing'=>$fee);
- $waybills=app('WaybillService')->dailyBilling($param,true);
- if ($waybills===0 || $waybills===1 || !isset($waybills)) $this->response(false);
- return response()->json(["status_code"=>200,
- "data"=>true,
- "message"=>null]);
- //$this->response(true);
- }
- }
|