第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel 中的預(yù)訂時段,帶設(shè)備庫存查詢

Laravel 中的預(yù)訂時段,帶設(shè)備庫存查詢

PHP
富國滬深 2023-09-22 16:12:36
這是一個對大家來說很有趣的事情。我發(fā)現(xiàn)自己陷入了實施難題。我正在 Laravel 中開發(fā)一個預(yù)訂應(yīng)用程序,允許人們在特定時間預(yù)訂空間的房間和設(shè)備??捎迷O(shè)備的數(shù)量有限,因此必須根據(jù)與預(yù)訂相關(guān)的時段來查詢庫存量。我以為我已經(jīng)通過迭代同時發(fā)生的“其他預(yù)訂”并計算當(dāng)前正在使用的物品來解決問題 -> 然后對照庫存中的可用物品進行檢查。對于我 90% 的測試來說,這工作得很好,但我剛剛發(fā)現(xiàn)了一個不允許我這樣做的錯誤。    $guitarheadcount = 0;    $guitarcabcount = 0;    $guitarcombocount = 0;    $bassheadcount = 0;    $basscabcount = 0;    $basscombocount = 0;    $drumkitcount = 0;    $cymbalscount = 0;    $otherbookings = Booking::where('Room_id', '!=', $bookinginfo->Room_id)        ->where(function ($query) use ($begin, $end) {            $query->where(function ($q) use ($begin, $end) {                $q->where('Booking_start', '>=', $begin)                ->where('Booking_start', '<', $end);            })->orWhere(function ($q) use ($begin, $end) {                $q->where('Booking_start', '<=', $begin)                ->where('Booking_end', '>', $end);            })->orWhere(function ($q) use ($begin, $end) {                $q->where('Booking_end', '>', $begin)                ->where('Booking_end', '<=', $end);            })->orWhere(function ($q) use ($begin, $end) {                $q->where('Booking_start', '>=', $begin)                ->where('Booking_end', '<=', $end);            });    })->get();    }然后,如果計數(shù)最終大于庫存量,我使用單獨的 if 語句來重定向。實際錯誤的一個示例是:2 套鼓有庫存。預(yù)訂一個下午 1-2 點的房間……然后在同一房間預(yù)訂另一個下午 2-3 點的房間。兩者都需要鼓組。如果我隨后嘗試在下午 1 點到 3 點之間在不同的空間進行預(yù)訂,即使一組鼓再次空閑(如果這有意義),計數(shù)也已經(jīng)是 2。我真的很困惑。我無法想象我是否需要:繼續(xù)“計數(shù)”,但生成一些東西,為與另一個(?)位于同一房間的每件物品扣除 1。我是否應(yīng)該完全放棄計數(shù)并為每個設(shè)備項目編寫單獨的查詢......以及我什至?xí)绾巫龅竭@一點!任何幫助將非常感激。
查看完整描述

2 回答

?
達令說

TA貢獻1821條經(jīng)驗 獲得超6個贊

盡管我之前的答案中的方法看起來很有希望......但隨著庫存量和相鄰預(yù)訂的增加,它開始出現(xiàn)無法修復(fù)的計數(shù)錯誤。


我重新思考并設(shè)計了更好的解決方案。無論如何,用戶只能預(yù)訂至少 30 分鐘的時段。


因此,使用 do/while 循環(huán),對于用戶選擇的時間段每增加 30 分鐘,它將執(zhí)行一次庫存檢查。


我確信敲打服務(wù)器并不是一件好事,但至少在預(yù)訂期間會有固定的時間來查詢它。


///STOCK CHECK


    $stockcheckbegin = $begin;

    $stockcheckend = date("Y-m-d H:i", strtotime('+30 minutes',strtotime($begin)));


    $tempguitarheadcount = 0;

    $tempguitarcabcount = 0;

    $tempguitarcombocount = 0;

    $tempbassheadcount = 0;

    $tempbasscabcount = 0;

    $tempbasscombocount = 0;

    $tempdrumkitcount = 0;

    $tempcymbalscount = 0;


    do {

        $otherbookings = Booking::orderby('Booking_start', 'ASC')

        ->where(function ($query) use ($stockcheckbegin, $stockcheckend) {

            $query->where(function ($q) use ($stockcheckbegin, $stockcheckend) {

                $q->where('Booking_start', '>=', $stockcheckbegin)

                ->where('Booking_start', '<', $stockcheckend);

            })->orWhere(function ($q) use ($stockcheckbegin, $stockcheckend) {

                $q->where('Booking_start', '<=', $stockcheckbegin)

                ->where('Booking_end', '>', $stockcheckend);

            })->orWhere(function ($q) use ($stockcheckbegin, $stockcheckend) {

                $q->where('Booking_end', '>', $stockcheckbegin)

                ->where('Booking_end', '<=', $stockcheckend);

            })->orWhere(function ($q) use ($stockcheckbegin, $stockcheckend) {

                $q->where('Booking_start', '>=', $stockcheckbegin)

                ->where('Booking_end', '<=', $stockcheckend);

            });

        })->get();


        foreach($otherbookings as $other){


            $tempguitarheadcount = $tempguitarheadcount + $other->Equip->guitarheadamount;

            $tempguitarcabcount = $tempguitarcabcount + $other->Equip->guitarcabamount;

            $tempguitarcombocount = $tempguitarcombocount + $other->Equip->guitarcomboamount;

            $tempbassheadcount = $tempbassheadcount + $other->Equip->bassheadamount;

            $tempbasscabcount = $tempbasscabcount + $other->Equip->basscabamount;

            $tempbasscombocount = $tempbasscombocount + $other->Equip->basscomboamount;

            $tempdrumkitcount = $tempdrumkitcount + $other->Equip->drumkitamount;

            $tempcymbalscount = $tempcymbalscount + $other->Equip->cymbalsamount;


            if(($currenthireprices->guitarheadstock - ($guitarheadamount + $tempguitarheadcount)) < 0){

                return redirect()->back()->withInput()->with('Booking_query_error', "Sorry! Our 'Guitar Head' stock will run out during the course of this booking. (Between $stockcheckbegin and $stockcheckend)");

            }

            if(($currenthireprices->guitarcabstock - ($guitarcabamount + $tempguitarcabcount)) < 0){

                return redirect()->back()->withInput()->with('Booking_query_error', "Sorry! Our 'Guitar Cab' stock will run out during the course of this booking. (Between $stockcheckbegin and $stockcheckend)");

            }

            if(($currenthireprices->guitarcombostock - ($guitarcomboamount + $tempguitarcombocount)) < 0){

                return redirect()->back()->withInput()->with('Booking_query_error', "Sorry! Our 'Guitar Combo' stock will run out during the course of this booking. (Between $stockcheckbegin and $stockcheckend)");

            }

            if(($currenthireprices->bassheadstock - ($bassheadamount + $tempbassheadcount)) < 0){

                return redirect()->back()->withInput()->with('Booking_query_error', "Sorry! Our 'Bass Head' stock will run out during the course of this booking. (Between $stockcheckbegin and $stockcheckend)");

            }

            if(($currenthireprices->basscabstock - ($basscabamount + $tempbasscabcount)) < 0){

                return redirect()->back()->withInput()->with('Booking_query_error', "Sorry! Our 'Bass Cab' stock will run out during the course of this booking. (Between $stockcheckbegin and $stockcheckend)");

            }

            if(($currenthireprices->basscombostock - ($basscomboamount + $tempbasscombocount)) < 0){

                return redirect()->back()->withInput()->with('Booking_query_error', "Sorry! Our 'Bass Combo' stock will run out during the course of this booking. (Between $stockcheckbegin and $stockcheckend)");

            }

            if(($currenthireprices->drumkitstock - ($drumkitamount + $tempdrumkitcount)) < 0){

                return redirect()->back()->withInput()->with('Booking_query_error', "Sorry! Our 'Drum kit' stock will run out during the course of this booking. (Between $stockcheckbegin and $stockcheckend)");

            }

            if(($currenthireprices->cymbalsstock - ($cymbalsamount + $tempcymbalscount)) < 0){

                return redirect()->back()->withInput()->with('Booking_query_error', "Sorry! Our sets of 'Cymbals' stock will run out during the course of this booking. (Between $stockcheckbegin and $stockcheckend)");

            }

        }


            $tempguitarheadcount = 0;

            $tempguitarcabcount = 0;

            $tempguitarcombocount = 0;

            $tempbassheadcount = 0;

            $tempbasscabcount = 0;

            $tempbasscombocount = 0;

            $tempdrumkitcount = 0;

            $tempcymbalscount = 0;


            $stockcheckbegin = date("Y-m-d H:i", strtotime('+30 minutes',strtotime($stockcheckbegin)));

            $stockcheckend = date("Y-m-d H:i", strtotime('+30 minutes',strtotime($stockcheckend)));


    } while ($stockcheckbegin != $end);


    if(($currenthireprices->guitarheadstock - ($guitarheadamount + $guitarheadcount)) < 0){

        return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $guitarheadamount guitar heads available between $timestart and $timeend. There's $currenthireprices->guitarheadstock in stock and $guitarheadcount in use.");

    }

    if(($currenthireprices->guitarcabstock - ($guitarcabamount + $guitarcabcount)) < 0){

        return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $guitarcabamount 'Guitar cabs' available between $timestart and $timeend. There's $currenthireprices->guitarcabstock in stock and $guitarcabcount in use.");

    }

    if(($currenthireprices->guitarcombostock - ($guitarcomboamount + $guitarcombocount)) < 0){

        return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $guitarcomboamount 'Guitar combos' available between $timestart and $timeend. There's $currenthireprices->guitarcombostock in stock and $guitarcombocount in use.");

    }

    if(($currenthireprices->bassheadstock - ($bassheadamount + $bassheadcount)) < 0) {

        return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $bassheadamount 'Bass heads' available between $timestart and $timeend. There's $currenthireprices->bassheadstock in stock and $bassheadcount in use.");

    }

    if(($currenthireprices->basscabstock - ($basscabamount + $basscabcount)) < 0) {

        return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $basscabamount 'Bass cabs' available between $timestart and $timeend. There's $currenthireprices->basscabstock in stock and $basscabcount in use.");

    }

    if(($currenthireprices->basscombostock - ($basscomboamount + $basscombocount)) < 0){

        return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $basscomboamount 'Bass combos' available between $timestart and $timeend. There's $currenthireprices->basscombostock in stock and $basscombocount in use.");

    }

    if(($currenthireprices->drumkitstock - ($drumkitamount + $drumkitcount)) < 0){

        return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $drumkitamount 'Drum kits' available between $timestart and $timeend. There's $currenthireprices->drumkitstock in stock and $drumkitcount in use.");

    }

    if(($currenthireprices->cymbalsstock - ($cymbalsamount + $cymbalscount)) < 0){

        return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $cymbalsamount 'sets of cymbals' available between $timestart and $timeend. There's $currenthireprices->cymbalsstock in stock and $cymbalscount in use.");

    }


    //----- END OF STOCK CHECK



查看完整回答
反對 回復(fù) 2023-09-22
?
慕娘9325324

TA貢獻1783條經(jīng)驗 獲得超4個贊

我將進一步測試這一點,但我想我可能已經(jīng)找到了解決方案。


我已經(jīng)擁有的:


一種在選定時間范圍內(nèi)獲取所有沖突預(yù)訂的機制。它可以提供集合中包含的所有項目的計數(shù)。它不“知道”的是在預(yù)訂過程中,庫存是否會被用完。


解決方案(到目前為止,早期測試正在發(fā)揮作用)。


我使用 orderBy 按開始時間對原始查詢結(jié)果進行排序。


我使用 foreach 來循環(huán)遍歷它們。


我在循環(huán)之外定義了幾個數(shù)組,可以使用它們將先前循環(huán)的屬性傳遞回下一個循環(huán)。如果沒有發(fā)現(xiàn)計數(shù)錯誤,則在最后覆蓋。


然后我創(chuàng)建了一些 if 語句來檢查下一個預(yù)訂與上一個預(yù)訂。


如果下一個開始是在上一個結(jié)束之前,那么我會創(chuàng)建另一個數(shù)組來將當(dāng)前值傳遞到其中,并在 if 內(nèi)為每個數(shù)組啟動另一個數(shù)組,然后重新計算該時間范圍內(nèi)的所有預(yù)訂。如果計數(shù)再次超過該時間內(nèi)的可用庫存,它就會爆發(fā)并重定向。


當(dāng)該循環(huán)完成后,我們繼續(xù)前一個循環(huán)。


對意大利面條代碼表示歉意。


$first = $otherbookings->first();


    if ($first == null){



    }else{

       $previous = [];

    $previous ['id'] = $first->id;

    $previous ['Booking_end'] = $first->Booking_end;

    }


    $tempdrumkitcount = 0;


    foreach($otherbookings as $other){


        if($previous ['id'] == $other->id){


            $drumkitcount = (int)$first->Equip->drumkitamount;

            //check

            if(($currenthireprices->drumkitstock - ($other->drumkitamount + $drumkitcount)) < 0){

                return redirect()->back()->withInput()->with('Booking_query_error', "Check 1 error");

            }

        }

        else{

            if($previous ['Booking_end'] > $other->Booking_start){


                $current ['id'] = $other->id;

                $current ['Booking_start'] = $other->Booking_start;

                $current ['Booking_end'] = $other->Booking_end;


                foreach($otherbookings as $newother){


                    if($newother->id != $current ['id']){


                        if(($newother->Booking_start < $current ['Booking_start']) && ($newother->Booking_end > $current ['Booking_start'] )){

                            $tempdrumkitcount = $tempdrumkitcount + $newother->Equip->drumkitamount;

                        }

                        if(($newother->Booking_start > $current ['Booking_start']) && ($newother->Booking_end < $current ['Booking_end'] )){

                            $tempdrumkitcount = $tempdrumkitcount + $newother->Equip->drumkitamount;

                        }

                        if(($currenthireprices->drumkitstock - ($drumkitamount + $tempdrumkitcount)) < 0){

                            return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $drumkitamount 'Drum kits' available between $timestart and $timeend to complete your booking. (Error- 100 [Cummalative Check]).");

                        }

                    }


                }

                $drumkitcount = $other->Equip->drumkitamount + $drumkitcount;


                if(($currenthireprices->drumkitstock - ($drumkitamount + $drumkitcount)) < 0){

                    return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $drumkitamount 'Drum kits' available between $timestart and $timeend to complete your booking. (Error- 150 [Non-Cummalative Check]).");

                }

                $drumkitcount =  $drumkitcount - $previous ['drumkitamount'];

            }

            if($previous ['Booking_end'] <= $other->Booking_start){

                $drumkitcount =  $drumkitcount - $previous ['drumkitamount'];

                $drumkitcount = $drumkitcount + $other->Equip->drumkitamount;


                if(($currenthireprices->drumkitstock - ($drumkitamount + $drumkitcount)) < 0){

                    return redirect()->back()->withInput()->with('Booking_query_error', "Unfortunatly there aren't $drumkitamount 'Drum kits' available between $timestart and $timeend to complete your booking. (Error- 200 [Non-overlap main check]).");

                }

            }

        }


        $previous ['id'] = $other->id;

        $previous ['Booking_end'] = $other->Booking_end;

        $previous ['drumkitamount'] = $other->Equip->drumkitamount;

    }



查看完整回答
反對 回復(fù) 2023-09-22
  • 2 回答
  • 0 關(guān)注
  • 161 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號