|
|
@ -0,0 +1,59 @@ |
|
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers; |
|
|
|
|
|
|
|
|
|
|
|
use App\Http\JsonReturn; |
|
|
|
|
|
use App\Models\ImsCjdcOrderMain; |
|
|
|
|
|
use Illuminate\Http\JsonResponse; |
|
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
|
use Illuminate\Support\Facades\Validator; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 骑手抢单 |
|
|
|
|
|
*/ |
|
|
|
|
|
class GrabOrderController extends Controller |
|
|
|
|
|
{ |
|
|
|
|
|
use JsonReturn; |
|
|
|
|
|
|
|
|
|
|
|
public function index(Request $request) |
|
|
|
|
|
{ |
|
|
|
|
|
$id = (int)$request->route('id'); |
|
|
|
|
|
if (!$id || !$order = ImsCjdcOrderMain::find($id)) { |
|
|
|
|
|
return self::error('唉呀,来晚啦,订单已经被接走啦~~~'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*$order = ImsCjdcOrderMain::with(['market:id,name']) |
|
|
|
|
|
->where([['state', '=', 2], ['pay_time', '>', 0]]) |
|
|
|
|
|
->orderBy('pay_time')->orderByDesc('id') |
|
|
|
|
|
->limit(15)->get();*/ |
|
|
|
|
|
|
|
|
|
|
|
return view('web.grab_order', ['order_list' => $order ?? []]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 抢单post |
|
|
|
|
|
*/ |
|
|
|
|
|
public function grabOrder(Request $request): JsonResponse |
|
|
|
|
|
{ |
|
|
|
|
|
try { |
|
|
|
|
|
$formData = $request->only(['id', 'name', 'mobile']); |
|
|
|
|
|
Validator::make($formData, [ |
|
|
|
|
|
'id' => 'required|int', |
|
|
|
|
|
'name' => 'required|between:2,20', |
|
|
|
|
|
'mobile' => ['required', 'regex:/^1\d{10}$/'], |
|
|
|
|
|
], [ |
|
|
|
|
|
'*.required' => ':attribute不能为空', |
|
|
|
|
|
'name.between' => ':attribute输入不正确', |
|
|
|
|
|
'mobile.regex' => ':attribute输入不正确', |
|
|
|
|
|
], [ |
|
|
|
|
|
'id' => 'ID', |
|
|
|
|
|
'name' => '姓名', |
|
|
|
|
|
'mobile' => '手机号', |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
return self::success('恭喜您,运气太好啦,订单被您抢到啦!'); |
|
|
|
|
|
} catch (\Exception $exception) { |
|
|
|
|
|
return self::error($exception->getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |