镇农科下的三轮策划列表做空指针兼容
This commit is contained in:
parent
5940e5c6b6
commit
12f73c0934
@ -37,26 +37,39 @@ class Logistics extends BaseController
|
||||
{
|
||||
// 查区县的镇农科公司
|
||||
$list = [];
|
||||
$companyList = Db::connect('work_task')->name('company')->where(['area' => $this->areaCode, 'company_type'=>41])->select()->toArray();
|
||||
$companyList = Db::connect('work_task')->name('company')->where('id', 69)->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');
|
||||
|
||||
if (empty($serviceGroupCompanyIds)) {
|
||||
continue;
|
||||
}
|
||||
$userIdList = Db::connect('work_task')->name('user')
|
||||
->whereIn('company_id', $serviceGroupCompanyIds)
|
||||
->where(['group_id'=>5])
|
||||
->column('id');
|
||||
->field('id, nickname')->select()->toArray();
|
||||
|
||||
if (empty($userIdList)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 从物流系统 查物流订单排序 确定谁是 镇辖区内配送订单最多的配送员
|
||||
$topCourier = Db::connect('logistics')->name('logistics')
|
||||
->field(['courier_id','courier_name','COUNT(order_id) AS order_count'])
|
||||
->whereIn('courier_id', $userIdList)
|
||||
->whereIn('courier_id', array_column($userIdList, 'id'))
|
||||
->group('courier_id')
|
||||
->order('order_count DESC')
|
||||
->find();
|
||||
|
||||
if (!empty($userIdList) && empty($topCourier)) {
|
||||
$topCourier['courier_id'] = $userIdList[0]['id'];
|
||||
$topCourier['courier_name'] = $userIdList[0]['nickname'];
|
||||
$topCourier['order_count'] = 0;
|
||||
}
|
||||
|
||||
// 小组公司没有配送员或是没有三轮车
|
||||
if (empty($topCourier)) {
|
||||
continue;
|
||||
@ -65,8 +78,15 @@ class Logistics extends BaseController
|
||||
// 三轮车车牌号 根据配送员id反查公司id,公司id反查车牌号
|
||||
$courier = Db::connect('work_task')->name('user')->where(['id'=>$topCourier['courier_id']])->find();
|
||||
|
||||
if (empty($courier)) {
|
||||
continue;
|
||||
}
|
||||
$vehicleRent = Db::connect('work_task')->name('vehicle_rent')->where(['rent_company_id'=>$courier['company_id']])->find();
|
||||
|
||||
if (empty($vehicleRent)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$topCourier['id'] = $vehicleRent['car_id'];
|
||||
$topCourier['license'] = $vehicleRent['car_license'];
|
||||
$topCourier['area_code'] = $courier['area'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user