123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace App\Services\Client;
- use App\Models\AgentConfig;
- use App\Models\AgentInfo;
- use App\Models\Project;
- class AgentService
- {
-
- public function getAgentConfig($agentId)
- {
-
- $agent = AgentInfo::where('id', $agentId)
- ->where('state', 'enable')
- ->firstOrFail();
-
-
-
-
-
-
-
- }
-
- public function getAgent($areaCode)
- {
-
- $agent = AgentInfo::where('business_area', 'like', "%{$areaCode}%")
- ->where('state', 'enable')
- ->first();
- if (! $agent) {
-
- $areaCodeParts = str_split($areaCode, 2);
- foreach ($areaCodeParts as $index => $part) {
- $searchCode = implode('', array_slice($areaCodeParts, 0, $index + 1));
- $agent = AgentInfo::where('business_area', 'like', "%{$searchCode}%")
- ->where('state', 'enable')
- ->first();
- if ($agent) {
- break;
- }
- }
- }
- return $agent;
- }
-
- public function getProjectList($categoryId, $agentId)
- {
-
- $agent = AgentInfo::where('id', $agentId)
- ->where('state', 'enable')
- ->firstOrFail();
-
- $query = Project::where('state', 'enable');
- if ($categoryId) {
- $query->where('category_id', $categoryId);
- }
- $projects = $query->whereHas('agents', function ($q) use ($agentId) {
- $q->where('agent_id', $agentId);
- })
- ->with(['category:id,name'])
- ->orderBy('sort', 'desc')
- ->paginate(10);
- return $projects;
- }
-
- public function getProjectDetail($projectId, $agentId)
- {
-
- $agent = AgentInfo::where('id', $agentId)
- ->where('state', 'enable')
- ->firstOrFail();
-
- $project = Project::where('id', $projectId)
- ->where('state', 'enable')
- ->whereHas('agents', function ($q) use ($agentId) {
- $q->where('agent_id', $agentId);
- })
- ->with([
- 'category:id,name',
- 'agents' => function ($q) use ($agentId) {
- $q->where('agent_id', $agentId);
- },
- ])
- ->firstOrFail();
- return $project;
- }
- }
|