update 首页三轮车列表-返回每个乡镇订单最多的三轮车。第二页物流统计信息接口根据列表接口的配送员id-courier_id直接查统计数据

This commit is contained in:
chenbo 2023-12-05 16:18:39 +08:00
parent b72d791ff9
commit 01e31ae283

View File

@ -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笔订单
}
}