|
@@ -2,125 +2,139 @@
|
|
|
|
|
|
namespace App\Services\Client;
|
|
|
|
|
|
+use App\Models\AgentInfo;
|
|
|
use App\Models\CoachUser;
|
|
|
-use App\Models\ShopCoachService;
|
|
|
use App\Models\Project;
|
|
|
-use App\Models\AgentInfo;
|
|
|
-use Illuminate\Support\Facades\DB;
|
|
|
+use App\Models\ProjectCate;
|
|
|
|
|
|
class ProjectService
|
|
|
{
|
|
|
-
|
|
|
/**
|
|
|
* 获取项目列表
|
|
|
*/
|
|
|
- public function getProjectList($areaCode)
|
|
|
+ public function getProjectList($areaCode, $projectCateId = null)
|
|
|
{
|
|
|
// 根据区域代码获取代理商
|
|
|
$agent = $this->findAvailableAgent($areaCode);
|
|
|
|
|
|
// 获取项目列表
|
|
|
if ($agent) {
|
|
|
+ dd($agent->cates());
|
|
|
$projects = Project::where('state', 'enable')
|
|
|
->where('agent_id', $agent->id)
|
|
|
->paginate(10);
|
|
|
} else {
|
|
|
- $projects = Project::where('state', 'enable')
|
|
|
- ->paginate(10);
|
|
|
+ $projectCate = ProjectCate::find($projectCateId);
|
|
|
+ $projects = $projectCate?->services;
|
|
|
}
|
|
|
|
|
|
return $projects;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 递归查找可用的代理商
|
|
|
- *
|
|
|
- * @param string $areaCode 区域代码
|
|
|
- * @return Agent|null
|
|
|
+ * 获取项目详情
|
|
|
*/
|
|
|
- private function findAvailableAgent($areaCode)
|
|
|
+ public function getProjectDetail($projectId, $areaCode)
|
|
|
{
|
|
|
- // 先查找当前区域的代理商
|
|
|
- $agent = AgentInfo::where('area_code', $areaCode)
|
|
|
- ->where('state', 'enable')
|
|
|
- ->first();
|
|
|
+ // 根据区域代码获取代理商
|
|
|
+ $agent = $this->findAvailableAgent($areaCode);
|
|
|
|
|
|
- if ($agent) {
|
|
|
- return $agent;
|
|
|
+ // 查询系统项目
|
|
|
+ $project = Project::where('state', 'enable')->find($projectId);
|
|
|
+
|
|
|
+ if (! $project) {
|
|
|
+ throw new \Exception('项目不存在');
|
|
|
}
|
|
|
|
|
|
- // 如果找不到,且区域代码长度大于2,则向上查找
|
|
|
- if (strlen($areaCode) > 2) {
|
|
|
- // 去掉最后两位,获取上级区域代码
|
|
|
- $parentAreaCode = substr($areaCode, 0, -2);
|
|
|
- return $this->findAvailableAgent($parentAreaCode);
|
|
|
+ if ($agent) {
|
|
|
+ // 查询代理商项目
|
|
|
+ $project = $agent->projects()->where('project_id', $projectId)->first();
|
|
|
}
|
|
|
|
|
|
- return null;
|
|
|
+ return $project;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取项目详情
|
|
|
+ * 获取技师开通的项目列表
|
|
|
*/
|
|
|
- public function getProjectDetail($projectId, $areaCode)
|
|
|
+ public function getCoachProjectList($coachId, $areaCode, $projectCateId)
|
|
|
{
|
|
|
- // 根据区域代码获取代理商
|
|
|
- $agent = AgentInfo::where('business_area', 'like', "%{$areaCode}%")
|
|
|
+ // 查询技师信息
|
|
|
+ $coach = CoachUser::where('id', $coachId)
|
|
|
->where('state', 'enable')
|
|
|
- ->first();
|
|
|
+ ->find($coachId);
|
|
|
|
|
|
- if (!$agent) {
|
|
|
- throw new \Exception('该区域暂无代理商');
|
|
|
+ if (! $coach) {
|
|
|
+ throw new \Exception('技师不存在');
|
|
|
}
|
|
|
|
|
|
- // 获取项目详情
|
|
|
- $project = Project::where('id', $projectId)
|
|
|
- ->where('state', 'enable')
|
|
|
- ->where(function($query) use ($areaCode) {
|
|
|
- // 根据区域地址过滤项目
|
|
|
- $query->where('area_code', $areaCode);
|
|
|
- })
|
|
|
- ->with([
|
|
|
- 'category:id,name',
|
|
|
- 'agent' => function($query) use ($agent) {
|
|
|
- $query->where('id', $agent->id);
|
|
|
- }
|
|
|
- ])
|
|
|
- ->firstOrFail();
|
|
|
+ $coachInfo = $coach->info;
|
|
|
+ if (! $coachInfo) {
|
|
|
+ throw new \Exception('技师信息不存在');
|
|
|
+ }
|
|
|
|
|
|
- return $project;
|
|
|
+ if ($coachInfo->state !== 'approved') {
|
|
|
+ throw new \Exception('技师未通过审核');
|
|
|
+ }
|
|
|
+
|
|
|
+ $coachQual = $coach->qual;
|
|
|
+ if (! $coachQual) {
|
|
|
+ throw new \Exception('技师资格证书不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($coachQual->state !== 'approved') {
|
|
|
+ throw new \Exception('技师资格证书未通过审核');
|
|
|
+ }
|
|
|
+
|
|
|
+ $coachReal = $coach->real;
|
|
|
+
|
|
|
+ if (! $coachReal) {
|
|
|
+ throw new \Exception('技师实名认证记录不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($coachReal->state !== 'approved') {
|
|
|
+ throw new \Exception('技师实名认证未通过审核');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取技师开通的项目ID列表
|
|
|
+ $projectIds = $coach->projects()->where('state', 'enable')->pluck('project_id');
|
|
|
+
|
|
|
+ // 根据区域代码获取代理商
|
|
|
+ $agent = $this->findAvailableAgent($areaCode);
|
|
|
+
|
|
|
+ if ($agent) {
|
|
|
+ $agentCate = $agent->cates()->where('project_cate_id', $projectCateId)->first();
|
|
|
+ $projectIds = $agentCate->projects()->whereIn('project_id', $projectIds)->pluck('project_id');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $coach->projects()->with('basicInfo')->whereIn('project_id', $projectIds)->get();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取技师开通的项目列表
|
|
|
+ * 递归查找可用的代理商
|
|
|
+ *
|
|
|
+ * @param string $areaCode 区域代码
|
|
|
+ * @return Agent|null
|
|
|
*/
|
|
|
- public function getCoachProjectList($coachId, $areaCode)
|
|
|
+ private function findAvailableAgent($areaCode)
|
|
|
{
|
|
|
- // 查询技师信息
|
|
|
- $coach = CoachUser::where('id', $coachId)
|
|
|
+ // 先查找当前区域的代理商
|
|
|
+ $agent = AgentInfo::where('area_code', $areaCode)
|
|
|
->where('state', 'enable')
|
|
|
- ->where('auth_state', 'passed')
|
|
|
- ->firstOrFail();
|
|
|
+ ->first();
|
|
|
|
|
|
- // 获取技师开通的项目ID列表
|
|
|
- $projectIds = ShopCoachService::where('coach_id', $coachId)
|
|
|
- ->where('state', 'enable')
|
|
|
- ->pluck('shop_service_id');
|
|
|
+ if ($agent) {
|
|
|
+ return $agent;
|
|
|
+ }
|
|
|
|
|
|
- // 查询项目列表
|
|
|
- $projects = Project::whereIn('id', $projectIds)
|
|
|
- ->where('state', 'enable')
|
|
|
- ->where(function($query) use ($areaCode) {
|
|
|
- // TODO: 根据区域地址过滤项目
|
|
|
- $query->where('area_code', $areaCode);
|
|
|
- })
|
|
|
- ->with([
|
|
|
- 'category:id,name',
|
|
|
- // 其他关联
|
|
|
- ])
|
|
|
- ->orderBy('sort', 'desc')
|
|
|
- ->paginate(10);
|
|
|
+ // 如果找不到,且区域代码长度大于2,则向上查找
|
|
|
+ if (strlen($areaCode) > 2) {
|
|
|
+ // 去掉最后两位,获取上级区域代码
|
|
|
+ $parentAreaCode = substr($areaCode, 0, -2);
|
|
|
|
|
|
- return $projects;
|
|
|
+ return $this->findAvailableAgent($parentAreaCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|