链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7 KiB

  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\JsonReturn;
  4. use App\Models\ImsCjdcOrderMain;
  5. use Illuminate\Http\JsonResponse;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Validator;
  8. /**
  9. * 骑手抢单
  10. */
  11. class GrabOrderController extends Controller
  12. {
  13. use JsonReturn;
  14. public function index(Request $request)
  15. {
  16. $id = (int)$request->route('id');
  17. if (!$id || !$order = ImsCjdcOrderMain::find($id)) {
  18. return self::error('唉呀,来晚啦,订单已经被接走啦~~~');
  19. }
  20. /*$order = ImsCjdcOrderMain::with(['market:id,name'])
  21. ->where([['state', '=', 2], ['pay_time', '>', 0]])
  22. ->orderBy('pay_time')->orderByDesc('id')
  23. ->limit(15)->get();*/
  24. return view('web.grab_order', ['order_list' => $order ?? []]);
  25. }
  26. /**
  27. * 抢单post
  28. */
  29. public function grabOrder(Request $request): JsonResponse
  30. {
  31. try {
  32. $formData = $request->only(['id', 'name', 'mobile']);
  33. Validator::make($formData, [
  34. 'id' => 'required|int',
  35. 'name' => 'required|between:2,20',
  36. 'mobile' => ['required', 'regex:/^1\d{10}$/'],
  37. ], [
  38. '*.required' => ':attribute不能为空',
  39. 'name.between' => ':attribute输入不正确',
  40. 'mobile.regex' => ':attribute输入不正确',
  41. ], [
  42. 'id' => 'ID',
  43. 'name' => '姓名',
  44. 'mobile' => '手机号',
  45. ]);
  46. return self::success('恭喜您,运气太好啦,订单被您抢到啦!');
  47. } catch (\Exception $exception) {
  48. return self::error($exception->getMessage());
  49. }
  50. }
  51. }