|
@@ -1348,58 +1348,54 @@ class Orders extends Auth {
|
|
|
//
|
|
|
// }
|
|
|
$userIds = array_column($newUser, 'id');
|
|
|
- $todoCounts = Db::name('todo')
|
|
|
+ $taskCounts = Db::name('todo')
|
|
|
->where('to_user_id', 'in', $userIds)
|
|
|
->where('work_type_mode', 3)
|
|
|
->where('create_yyyymmdd', date('Ymd'))
|
|
|
->where('todo_mode', 'in', [1, 2, 3])
|
|
|
+ ->field([
|
|
|
+ 'to_user_id',
|
|
|
+ 'COUNT(*) as nums',
|
|
|
+ 'SUM(CASE WHEN todo_mode IN (1, 2) THEN 1 ELSE 0 END) as nums2' // 进行中任务数(todo_mode in [1,2])
|
|
|
+ ])
|
|
|
->group('to_user_id')
|
|
|
- ->column('to_user_id, COUNT(*) as nums');
|
|
|
- $todoStatusCounts = Db::name('todo')
|
|
|
- ->where('to_user_id', 'in', $userIds)
|
|
|
- ->where('work_type_mode', 3)
|
|
|
- ->where('todo_mode', 'in', [1, 2])
|
|
|
- ->group('to_user_id')
|
|
|
- ->column('to_user_id, COUNT(*) as nums2');
|
|
|
+ ->select();
|
|
|
+ $taskCountMap = array_column($taskCounts, null, 'to_user_id');
|
|
|
$addrInfo = Db::name('order_convey')
|
|
|
->alias('cpr')
|
|
|
->join('todo os', 'cpr.order_id = os.order_id')
|
|
|
- ->join('orders ods', 'cpr.order_id = ods.id')
|
|
|
- ->join('address ca', 'ca.id = cpr.start')
|
|
|
- ->join('address cad', 'cad.id = cpr.end')
|
|
|
- ->field('os.to_user_id, os.todo_mode, ca.title as start_name, cad.title as end_name, os.create_time')
|
|
|
+ ->field('os.to_user_id, os.todo_mode, cpr.end,cpr.start,os.create_time')
|
|
|
->where('os.to_user_id', 'in', $userIds)
|
|
|
->where('os.del', 0)
|
|
|
- ->where('ods.del', 0)
|
|
|
->select();
|
|
|
$addrMap = [];
|
|
|
foreach ($addrInfo as $addr) {
|
|
|
$addrMap[$addr['to_user_id']] = $addr;
|
|
|
}
|
|
|
- $userSex = Db::name('user')
|
|
|
- ->where('id', 'in', $userIds)
|
|
|
- ->column('id, sex');
|
|
|
+ $start = array_column($addrInfo,'start');
|
|
|
+ $end = array_column($addrInfo,'end');
|
|
|
+ $addressIds = array_unique(array_merge($start,$end));
|
|
|
+ $address = Db::name('address')
|
|
|
+ ->where('id','in',$addressIds)
|
|
|
+ ->column('title','id');
|
|
|
foreach ($newUser as $key => $value) {
|
|
|
$userId = $value['id'];
|
|
|
- $newUser[$key]['nums'] = isset($todoCounts[$userId]) ? $todoCounts[$userId] : 0;
|
|
|
- $newUser[$key]['cur_status'] = 0; // 默认空闲
|
|
|
- if (isset($todoStatusCounts[$userId]) && $todoStatusCounts[$userId] > 0) {
|
|
|
- $newUser[$key]['cur_status'] = 1; // 任务中
|
|
|
- }
|
|
|
+ $counts = $taskCountMap[$userId] ?? ['nums' => 0, 'nums2' => 0];
|
|
|
+
|
|
|
+ $newUser[$key]['nums'] = $counts['nums'];
|
|
|
+ $newUser[$key]['cur_status'] = $counts['nums2'] > 0 ? 1 : 0;
|
|
|
|
|
|
$newUser[$key]['title'] = '';
|
|
|
$newUser[$key]['addr_time'] = '';
|
|
|
if (isset($addrMap[$userId])) {
|
|
|
$addr = $addrMap[$userId];
|
|
|
if (in_array($addr['todo_mode'], [1, 2])) {
|
|
|
- $newUser[$key]['title'] = $addr['start_name'];
|
|
|
+ $newUser[$key]['title'] = $address[$addr['start']];
|
|
|
} else {
|
|
|
- $newUser[$key]['title'] = $addr['end_name'];
|
|
|
+ $newUser[$key]['title'] = $address[$addr['end']];
|
|
|
}
|
|
|
$newUser[$key]['addr_time'] = $addr['create_time'];
|
|
|
}
|
|
|
-
|
|
|
- $newUser[$key]['sex_name'] = isset($mm->sex[$userSex[$userId]]) ? $mm->sex[$userSex[$userId]] : "";
|
|
|
}
|
|
|
$newUser = list_sort_by($newUser,"addr_time", 'asc');
|
|
|
if($this->orgId==3){
|