|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Services\Client;
|
|
|
|
|
|
+use App\Enums\ProjectStatus;
|
|
|
use App\Models\AgentConfig;
|
|
|
use App\Models\AgentInfo;
|
|
|
use App\Models\CoachConfig;
|
|
@@ -66,7 +67,6 @@ class OrderService
|
|
|
|
|
|
// 查询技师数据
|
|
|
$coach = $this->validateCoach($data['coach_id']);
|
|
|
-
|
|
|
// 获取项目详情
|
|
|
$project = $this->projectService->getProjectDetail($data['project_id'], $areaCode);
|
|
|
abort_if(! $project, 400, '项目不存在');
|
|
@@ -77,7 +77,10 @@ class OrderService
|
|
|
$address?->id ?? 0,
|
|
|
$data['coach_id'],
|
|
|
$data['project_id'],
|
|
|
- $project->agent_id
|
|
|
+ $project->agent_id,
|
|
|
+ false,
|
|
|
+ $data['latitude'],
|
|
|
+ $data['longitude']
|
|
|
);
|
|
|
|
|
|
return [
|
|
@@ -820,6 +823,8 @@ class OrderService
|
|
|
* @param int $agentId 代理商ID
|
|
|
* @param bool $useBalance 是否使用余额
|
|
|
* @param float $distance 距离
|
|
|
+ * @param int $lat 纬度
|
|
|
+ * @param int $lng 经度
|
|
|
*
|
|
|
* @throws Exception
|
|
|
*/
|
|
@@ -830,7 +835,9 @@ class OrderService
|
|
|
int $projectId,
|
|
|
?int $agentId = null,
|
|
|
bool $useBalance = false,
|
|
|
- float $distance = 0
|
|
|
+ float $distance = 0,
|
|
|
+ int $lat = 0,
|
|
|
+ int $lng = 0
|
|
|
): array {
|
|
|
try {
|
|
|
// 1. 参数校验
|
|
@@ -848,19 +855,18 @@ class OrderService
|
|
|
->first();
|
|
|
|
|
|
abort_if(! $coachProject, 404, '技师项目不存在');
|
|
|
-
|
|
|
// 3. 查询基础项目
|
|
|
+
|
|
|
$project = Project::where('id', $projectId)
|
|
|
- ->where('state', 'enable')
|
|
|
+ ->where('state', ProjectStatus::OPEN->value())
|
|
|
->first();
|
|
|
|
|
|
abort_if(! $project, 404, '项目不存在或状态异常');
|
|
|
-
|
|
|
// 4. 计算距离
|
|
|
- if ($distance <= 0) {
|
|
|
- $address = $user->addresses()->findOrFail($addressId);
|
|
|
+ if (floatval($distance) <= 0) {
|
|
|
+ $address = $addressId && $user->addresses()->find($addressId) ?? ['latitude' => $lat, 'longitude' => $lng];
|
|
|
$coachService = app(CoachService::class);
|
|
|
- $coachDetail = $coachService->getCoachDetail($coachId, $address->latitude, $address->longitude);
|
|
|
+ $coachDetail = $coachService->getCoachDetail($coachId, $address['latitude'], $address['longitude']);
|
|
|
$distance = $coachDetail['distance'] ?? 0;
|
|
|
}
|
|
|
|
|
@@ -977,6 +983,47 @@ class OrderService
|
|
|
return [$balanceAmount, $payAmount];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取订单抢单池列表
|
|
|
+ *
|
|
|
+ * @param int $orderId 订单ID
|
|
|
+ * @return array 抢单池列表
|
|
|
+ */
|
|
|
+ public function getOrderGrabList(int $orderId): array
|
|
|
+ {
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 查询订单信息
|
|
|
+ $order = Order::where('id', $orderId)
|
|
|
+ ->whereIn('state', ['wait_pay', 'wait_service'])
|
|
|
+ ->firstOrFail();
|
|
|
+ // 查询抢单池列表
|
|
|
+ $grabList = $order->grabRecords()->with(['coach.info'])->get();
|
|
|
+
|
|
|
+ // 格式化返回数据
|
|
|
+ $result = [];
|
|
|
+ foreach ($grabList as $grab) {
|
|
|
+ $coach = $grab->coach;
|
|
|
+ $result[] = [
|
|
|
+ 'id' => $grab->id,
|
|
|
+ 'coach_id' => $coach->id,
|
|
|
+ 'nickname' => $coach->info->nickname,
|
|
|
+ 'avatar' => $coach->info->avatar,
|
|
|
+ 'created_at' => $grab->created_at->format('Y-m-d H:i:s'),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::error('获取订单抢单池列表失败', [
|
|
|
+ 'error' => $e->getMessage(),
|
|
|
+ 'order_id' => $orderId,
|
|
|
+ ]);
|
|
|
+ throw $e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 指定技师
|
|
|
*/
|