diff --git a/app/Services/OfflineOrderService.php b/app/Services/OfflineOrderService.php index 5efcfef..baeca02 100644 --- a/app/Services/OfflineOrderService.php +++ b/app/Services/OfflineOrderService.php @@ -6,6 +6,7 @@ use App\Facades\CommonService; use App\Facades\WechatService; use App\Http\Controllers\H5\OrderController; use App\Jobs\UnfreezeCommission; +use App\Models\DmaServiceUserRole; use App\Models\Group; use App\Models\GroupUser; use App\Models\OfflineOrder; @@ -243,6 +244,14 @@ class OfflineOrderService $this->joinServiceGroup($imChatId, $groupId, $orderId, $mainCoachRoleId, $mainCoachUserId); } + // 副教练 + $coachRoleId = 2; + $coachUserId = $this->getOrderService($userId, $coachRoleId); + Log::info("副教练用户id:" . $coachUserId); + if ($coachUserId) { + $this->joinServiceGroup($imChatId, $groupId, $orderId, $coachRoleId, $coachUserId); + } + // 客服 $customerRoleId = 3; $customerUserId = $this->getOrderService($userId, $customerRoleId); @@ -307,24 +316,28 @@ class OfflineOrderService */ public function getOrderService($userId, $roleId): int { - $userIds = []; - switch ($roleId) { - case 1: - if ($userId == 3740 || $userId == 6) - return 1; - // $userIds = [218, 178, 175, 176]; - $userIds = [218, 175, 176]; - // $userIds = [153, 152, 11043, 1]; // 测试 - break; - case 3: - if ($userId == 3740 || $userId == 6) - return 7; - $userIds = [181, 177, 184]; - // $userIds = [7, 3306]; // 测试 - break; - } + if ($userId == 3740 || $userId == 6) // 测试用户 + return 1; + // $userIds = []; + // switch ($roleId) { + // case 1: + // if ($userId == 3740 || $userId == 6) + // return 1; + // // $userIds = [218, 178, 175, 176]; + // $userIds = [218, 175, 176]; + // // $userIds = [153, 152, 11043, 1]; // 测试 + // break; + // case 3: + // if ($userId == 3740 || $userId == 6) + // return 7; + // $userIds = [181, 177, 184]; + // // $userIds = [7, 3306]; // 测试 + // break; + // } - $userIds = ServiceOrderStatus::whereIn("user_id", $userIds)->where("order_status", 1)->pluck("user_id")->toArray(); + $userIds = DmaServiceUserRole::where("role", $roleId)->where("status", 1)->pluck("user_id")->toArray(); + + $userIds = ServiceOrderStatus::whereIn("user_id", $userIds)->where("order_status", 1)->orderByDesc("id")->pluck("user_id")->toArray(); $serviceUserId = $this->getLastServiceUserId($roleId, $userIds); return $serviceUserId; } @@ -332,16 +345,17 @@ class OfflineOrderService public function getLastServiceUserId($roleId, $userIds): int { $serviceUserId = 0; - if ($roleId != 1 && $roleId != 3) - return $serviceUserId; + // if ($roleId != 1 && $roleId != 3) + // return $serviceUserId; if (count($userIds) == 0) return $serviceUserId; + // 上一个订单对应服务人员id $serviceRoleOrder = ServiceRoleOrder::where("role_id", $roleId)->whereIn("user_id", $userIds)->orderByDesc("id")->first(); if (!$serviceRoleOrder) - return $serviceUserId; + return $userIds[0]; $serviceUserId = $this->findIndex($userIds, $serviceRoleOrder->user_id); return $serviceUserId;