filter($filter)->where(AdminMerchant::getMerchantWhere()); $area_ids = AdminUser::getAreaIdsByAdminId(Admin::user()->id); $punishments = $punishments->whereIn('area_id', $area_ids)->orderByDesc('id'); return $request->get('all') ? PunishmentOrderResource::collection($punishments->get()) : PunishmentOrderResource::collection($punishments->paginate()); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * store * * @param PunishmentOrderRequest $request * @return \Illuminate\Http\JsonResponse * @author Fx * */ public function store(PunishmentOrderRequest $request) { // $inputs = $request->validated(); if (!empty($inputs['order_no'])) { $order = Order::where('no', $inputs['order_no'])->first(); if (empty($order)) { $order = OrderRent::where('no', $inputs['order_no'])->first(); if (empty($order)) { return $this->error('找不到此订单号对应得订单'); } } } $user = User::query()->where('mobile', $inputs['user_mobile'])->first(); if (empty($user)) return $this->error('找不到用户信息,请检查用户手机号'); $bike = Bike::query()->where('bike_no', $inputs['bike_no'])->first(); if (empty($bike)) return $this->error('找不到车辆相关信息,请检查车牌号'); $data = [ 'user_id' => $user->id, 'area_id' => $bike->put_area_id, 'order_id' => empty($order) ? 0 : $order->id, 'order_no' => $inputs['order_no'] ?? '', 'bike_id' => $bike->id, 'no' => PunishmentOrder::makeNo(), 'detail' => $inputs['detail'], 'pay_money' => $inputs['pay_money'], 'occurrence_time' => $inputs['occurrence_time'], 'merchant_id' => AdminMerchant::putMerchantId(), ]; $res = PunishmentOrder::create($data); return $this->created(PunishmentOrderResource::make($res)); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(PunishmentOrder $punishmentOrder) { // return PunishmentOrderResource::make($punishmentOrder); } /** * update * * @param PunishmentOrderRequest $request * @return \Illuminate\Http\JsonResponse * @author Fx * */ public function update(PunishmentOrderRequest $request, PunishmentOrder $punishmentOrder) { // if ($punishmentOrder->pay_status == 1) return $this->error('订单已支付不可编辑'); $inputs = $request->validated(); if (!empty($inputs['order_no'])) { $order = Order::where('no', $inputs['order_no'])->first(); if (empty($order)) { $order = OrderRent::where('no', $inputs['order_no'])->first(); if (empty($order)) { return $this->error('找不到此订单号对应得订单'); } } } $user = User::query()->where('mobile', $inputs['user_mobile'])->first(); if (empty($user)) return $this->error('找不到用户信息,请检查用户手机号'); $bike = Bike::query()->where('bike_no', $inputs['bike_no'])->first(); if (empty($bike)) return $this->error('找不到车辆相关信息,请检查车牌号'); $data = [ 'user_id' => $user->id, 'area_id' => $bike->put_area_id, 'order_id' => empty($order) ? 0 : $order->id, 'bike_id' => $bike->id, 'order_no' => $inputs['order_no'] ?? '', 'detail' => $inputs['detail'], 'pay_money' => $inputs['pay_money'], 'occurrence_time' => $inputs['occurrence_time'], ]; $punishmentOrder->update($data); return $this->created(PunishmentOrderResource::make($punishmentOrder)); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(PunishmentOrder $punishmentOrder) { // if ($punishmentOrder->pay_status == PunishmentOrder::PAY_STATUS_OK) { return $this->error('罚单已支付,不可删除'); } $punishmentOrder->delete(); return $this->noContent(); } }