|
|
|
@ -4,8 +4,11 @@ namespace App\Http\Controllers; |
|
|
|
|
|
|
|
use App\Http\JsonReturn; |
|
|
|
use App\Models\ImsCjdcOrderMain; |
|
|
|
use App\Models\v3\LanzuEmployees; |
|
|
|
use App\Models\v3\User; |
|
|
|
use Illuminate\Http\JsonResponse; |
|
|
|
use Illuminate\Http\Request; |
|
|
|
use Illuminate\Support\Facades\Redis; |
|
|
|
use Illuminate\Support\Facades\Validator; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -33,27 +36,64 @@ class GrabOrderController extends Controller |
|
|
|
/** |
|
|
|
* 抢单post |
|
|
|
*/ |
|
|
|
public function grabOrder(Request $request): JsonResponse |
|
|
|
public function grabOrder(Request $request) |
|
|
|
{ |
|
|
|
try { |
|
|
|
$formData = $request->only(['id', 'name', 'mobile']); |
|
|
|
Validator::make($formData, [ |
|
|
|
'id' => 'required|int', |
|
|
|
$validator = Validator::make($request->all(), [ |
|
|
|
'order_num' => ['required', 'regex:/^\d+$/'], |
|
|
|
'name' => 'required|between:2,20', |
|
|
|
'mobile' => ['required', 'regex:/^1\d{10}$/'], |
|
|
|
'tel' => ['required', 'regex:/^1\d{10}$/'], |
|
|
|
], [ |
|
|
|
'*.required' => ':attribute不能为空', |
|
|
|
'*.regex' => ':attribute格式不正确', |
|
|
|
'name.between' => ':attribute输入不正确', |
|
|
|
'mobile.regex' => ':attribute输入不正确', |
|
|
|
], [ |
|
|
|
'id' => 'ID', |
|
|
|
'order_num' => '订单号', |
|
|
|
'name' => '姓名', |
|
|
|
'mobile' => '手机号', |
|
|
|
'tel' => '手机号', |
|
|
|
]); |
|
|
|
|
|
|
|
return self::success('恭喜您,运气太好啦,订单被您抢到啦!'); |
|
|
|
if ($validator->fails()) { |
|
|
|
throw new \Exception($validator->errors()->first()); |
|
|
|
} |
|
|
|
|
|
|
|
$formData = $validator->validated(); |
|
|
|
|
|
|
|
$user = User::where('tel', $formData['tel'])->first(); |
|
|
|
if (!$user) { |
|
|
|
throw new \Exception('用户信息不存在'); |
|
|
|
} |
|
|
|
|
|
|
|
$employee = LanzuEmployees::where(['user_id' => $user->id, 'name' => $formData['name']])->orderByDesc('id')->first(); |
|
|
|
if (!$employee || !in_array(29, $employee->position)) { //29是骑手,见:config("role.position")
|
|
|
|
throw new \Exception("您还不是骑手,请联系管理员增加骑手权限"); |
|
|
|
} |
|
|
|
|
|
|
|
$order = ImsCjdcOrderMain::where('order_num', $formData['order_num'])->first(); |
|
|
|
if (!$order) { |
|
|
|
throw new \Exception('订单跑丢了~~'); |
|
|
|
} else if ($order->state != 3) { |
|
|
|
throw new \Exception('您来晚啦,订单已经被人接走啦~~'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 抢单逻辑详见: |
|
|
|
* @see \App\Admin\Forms\SelectHorseman |
|
|
|
*/ |
|
|
|
$SelectHorseman = new \App\Admin\Forms\SelectHorseman; |
|
|
|
$result = $SelectHorseman->handle(['horseman_id' => $employee->id, 'order_id' => $order->id]); |
|
|
|
|
|
|
|
return self::success('抢单成功,已消息通知客户,请尽快配送'); |
|
|
|
} catch (\Exception $exception) { |
|
|
|
return self::error($exception->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取订单信息 |
|
|
|
*/ |
|
|
|
public function orderInfo() |
|
|
|
{ |
|
|
|
$order_num = \request('order_num'); |
|
|
|
} |
|
|
|
} |