ProjectService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Services\Client;
  3. use App\Models\CoachUser;
  4. use App\Models\ShopCoachService;
  5. use App\Models\Project;
  6. use Illuminate\Support\Facades\DB;
  7. class ProjectService
  8. {
  9. /**
  10. * 获取项目详情
  11. */
  12. public function getProjectDetail($projectId, $areaCode)
  13. {
  14. // 根据区域代码获取代理商
  15. $agent = AgentInfo::where('business_area', 'like', "%{$areaCode}%")
  16. ->where('state', 'enable')
  17. ->first();
  18. if (!$agent) {
  19. throw new \Exception('该区域暂无代理商');
  20. }
  21. // 获取项目详情
  22. $project = Project::where('id', $projectId)
  23. ->where('state', 'enable')
  24. ->where(function($query) use ($areaCode) {
  25. // 根据区域地址过滤项目
  26. $query->where('area_code', $areaCode);
  27. })
  28. ->with([
  29. 'category:id,name',
  30. 'agent' => function($query) use ($agent) {
  31. $query->where('id', $agent->id);
  32. }
  33. ])
  34. ->firstOrFail();
  35. return $project;
  36. }
  37. /**
  38. * 获取技师开通的项目列表
  39. */
  40. public function getCoachProjectList($coachId, $areaCode)
  41. {
  42. // 查询技师信息
  43. $coach = CoachUser::where('id', $coachId)
  44. ->where('state', 'enable')
  45. ->where('auth_state', 'passed')
  46. ->firstOrFail();
  47. // 获取技师开通的项目ID列表
  48. $projectIds = ShopCoachService::where('coach_id', $coachId)
  49. ->where('state', 'enable')
  50. ->pluck('shop_service_id');
  51. // 查询项目列表
  52. $projects = Project::whereIn('id', $projectIds)
  53. ->where('state', 'enable')
  54. ->where(function($query) use ($areaCode) {
  55. // TODO: 根据区域地址过滤项目
  56. $query->where('area_code', $areaCode);
  57. })
  58. ->with([
  59. 'category:id,name',
  60. // 其他关联
  61. ])
  62. ->orderBy('sort', 'desc')
  63. ->paginate(10);
  64. return $projects;
  65. }
  66. }