From 01e31ae2832af3cf0a60dd52836ebc9b5951be69 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Tue, 5 Dec 2023 16:18:39 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E9=A6=96=E9=A1=B5=E4=B8=89=E8=BD=AE?= =?UTF-8?q?=E8=BD=A6=E5=88=97=E8=A1=A8-=E8=BF=94=E5=9B=9E=E6=AF=8F?= =?UTF-8?q?=E4=B8=AA=E4=B9=A1=E9=95=87=E8=AE=A2=E5=8D=95=E6=9C=80=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E4=B8=89=E8=BD=AE=E8=BD=A6=E3=80=82=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E9=A1=B5=E7=89=A9=E6=B5=81=E7=BB=9F=E8=AE=A1=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=A0=B9=E6=8D=AE=E5=88=97=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E7=9A=84=E9=85=8D=E9=80=81=E5=91=98id-courier=5Fid?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E6=9F=A5=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/dataview/Logistics.php | 118 +++++++++++++--------- 1 file changed, 68 insertions(+), 50 deletions(-) diff --git a/app/controller/api/dataview/Logistics.php b/app/controller/api/dataview/Logistics.php index 03055437..26bbdfa2 100755 --- a/app/controller/api/dataview/Logistics.php +++ b/app/controller/api/dataview/Logistics.php @@ -23,32 +23,64 @@ class Logistics extends BaseController } } - // 三轮车列表 从供销系统获取 + // 三轮车列表 每个乡镇订单最多的配送员的三轮车 public function vehicleList() { - // 镇区域码为空,查区县的公司 - if (empty($this->streetCode)) { - $companyList = Db::connect('work_task')->name('company')->where('area', $this->areaCode)->select()->toArray(); - } else { - $companyList = Db::connect('work_task')->name('company')->where('street', $this->streetCode)->select()->toArray(); + // 查区县的镇农科公司 + $list = []; + $companyList = Db::connect('work_task')->name('company')->where(['area' => $this->areaCode, 'company_type'=>41])->select()->toArray(); + + foreach ($companyList as $company) { + // 先从供销系统 查出镇下边的所有配送员-小组服务公司的负责人 + $serviceGroupCompanyIds = Db::connect('work_task')->name('company') + ->where(['street'=> $company['street'], 'company_type'=>18]) + ->column('id'); + + $userIdList = Db::connect('work_task')->name('user') + ->whereIn('company_id', $serviceGroupCompanyIds) + ->where(['group_id'=>5]) + ->column('id'); + + // 从物流系统 查物流订单排序 确定谁是 镇辖区内配送订单最多的配送员 + $topCourier = Db::connect('logistics')->name('logistics') + ->field(['courier_id','courier_name','COUNT(order_id) AS order_count']) + ->whereIn('courier_id', $userIdList) + ->group('courier_id') + ->order('order_count DESC') + ->find(); + // 小组公司没有配送员或是没有三轮车 + if (empty($topCourier)) { + continue; + } + + // 三轮车车牌号 根据配送员id反查公司id,公司id反查车牌号 + $courier = Db::connect('work_task')->name('user')->where(['id'=>$topCourier['courier_id']])->find(); + + $vehicleRent = Db::connect('work_task')->name('vehicle_rent')->where(['rent_company_id'=>$courier['company_id']])->find(); + + $topCourier['id'] = $vehicleRent['car_id']; + $topCourier['license'] = $vehicleRent['car_license']; + $topCourier['area_code'] = $courier['area']; + $topCourier['street_code'] = $courier['street']; + $list[] = $topCourier; } - $companyIds = array_column($companyList, 'id'); + // 查镇车辆列表 - $list = Db::connect('work_task')->name('vehicle_rent') - ->field('company_id, car_id as id, car_license as license') - ->append(['area_code','street_code']) - ->whereIn('company_id', $companyIds) - ->where('status','in','0,1,2') - ->withAttr('area_code', function ($value, $data){ - $company = Db::connect('work_task')->name('company')->where('id', $data['company_id'])->find(); - return $company['area']; - }) - ->withAttr('street_code', function ($value, $data){ - $company = Db::connect('work_task')->name('company')->where('id', $data['company_id'])->find(); - return $company['street']; - }) - ->group('company_id') - ->select()->toArray(); +// $list = Db::connect('work_task')->name('vehicle_rent') +// ->field('company_id, car_id as id, car_license as license') +// ->append(['area_code','street_code']) +// ->whereIn('company_id', $companyIds) +// ->where('status','in','0,1,2') +// ->withAttr('area_code', function ($value, $data){ +// $company = Db::connect('work_task')->name('company')->where('id', $data['company_id'])->find(); +// return $company['area']; +// }) +// ->withAttr('street_code', function ($value, $data){ +// $company = Db::connect('work_task')->name('company')->where('id', $data['company_id'])->find(); +// return $company['street']; +// }) +// ->group('company_id') +// ->select()->toArray(); $count = count($list); return app('json')->success(compact('count', 'list')); @@ -87,38 +119,24 @@ class Logistics extends BaseController // 第二页 物流信息统计 public function logisticsCount() { - // 查询镇辖区内配送订单最多的配送员 - - // 先从供销系统 查出镇下边的所有配送员-小组服务公司的负责人 - $serviceGroupCompanyIds = Db::connect('work_task')->name('company') - ->where(['street'=> $this->streetCode, 'company_type'=>18]) - ->column('id'); - $userIdList = Db::connect('work_task')->name('user') - ->whereIn('company_id', $serviceGroupCompanyIds) - ->where(['group_id'=>5]) - ->column('id'); - - // 从物流系统 查物流订单排序 确定谁是 镇辖区内配送订单最多的配送员 - $topCourier = Db::connect('logistics')->name('logistics') - ->field(['courier_id','courier_name','COUNT(order_id) AS order_count']) - ->whereIn('courier_id', $userIdList) - ->group('courier_id') - ->order('order_count DESC') - ->find(); - // 返查配送员的物流配送订单统计信息 + $courierId = $this->request->param('courier_id'); // 待取货数 - $topCourier['pending_order_count'] = Db::connect('logistics')->name('logistics')->where(['status'=>0, 'courier_id'=>$topCourier['courier_id']])->count(); + $pending_order_count = Db::connect('logistics')->name('logistics')->where(['status'=>0, 'courier_id'=>$courierId])->count(); // 配送中数 - $topCourier['delivering_order_count'] = Db::connect('logistics')->name('logistics')->where(['status'=>1, 'courier_id'=>$topCourier['courier_id']])->count(); + $delivering_order_count = Db::connect('logistics')->name('logistics')->where(['status'=>1, 'courier_id'=>$courierId])->count(); // 已完成数 - $topCourier['finished_order_count'] = Db::connect('logistics')->name('logistics')->where([['status', 'in', [2,3]], 'courier_id'=>$topCourier['courier_id']])->count(); + $finished_order_count = Db::connect('logistics')->name('logistics')->where([['status', 'in', [2,3]], 'courier_id'=>$courierId])->count(); - // 三轮车车牌号 根据配送员id反查公司id,公司id反查车牌号 - $courierCompanyId = Db::connect('work_task')->name('user')->where(['id'=>$topCourier['courier_id']])->value('company_id'); - $vehicleRent = Db::connect('work_task')->name('vehicle_rent')->where(['rent_company_id'=>$courierCompanyId])->find(); - $topCourier['car_id'] = $vehicleRent['car_id']; - $topCourier['car_license'] = $vehicleRent['car_license']; - return app('json')->success($topCourier); + return app('json')->success(compact('pending_order_count', 'delivering_order_count', 'finished_order_count')); } + + // 第二页 地图 最新的10笔配送订单地址 以及最近一次取货地址发散 + public function logisticsMapCount() + { + $courierId = $this->request->param('courier_id'); + // 最近一次取货地址 最新一笔的配送中订单的取货地址 + Db::connect('work_task')->name('vehicle_rent'); + // 最新的10笔订单 + } } \ No newline at end of file