duanmao1319 2019-01-25 16:18
浏览 43

动态定价和许多变量的数据库模式 - 预订系统

I got stuck with the following problem: For my booking system I want to save the prices for all possible combinations at night, so I don't have to calculate them on the fly. I choose for this solution to improve performance and for the fact that these prices only change one time per day, at night. My first try was going to be to save all possible combinations to the DB. But I quickly found out that this isn't efficient.

A booking can vary from 1 adult to 9 adults and 9 children with each child having a varying age between 0 and 17.

When a user searches for 1 adult I need to be able to return a price and also when a user searches for 2 adults and 3 children with the age of 2,10 and 15 I need to be able to return a price.

This was my first approach, without considering the age of the children:

//Amount adults
        for($a = 1; $a <= static::MAX_ADULTS; $a++) {
            //Amount children
            for($c = 0; $c <= static::MAX_CHILDREN; $c++) {
                $cheapestPriceObj = null;
                //Add 1 day to arrival per iteration
                    for($i = 0; $i < $dDiff->days; $i++) {
                        $arrival = strtotime(" + $i days",$this->_arrival);
                        $travelCompany = array(array('amount_adults' => $a, 'amount_children' => $c));
                        $priceInfo = $this->_curAcco->getListerPriceInfo($arrival, static::DEFAULT_DURATION,$travelCompany);
                        if($priceInfo) {
                            if(is_null($cheapestPriceObj)) {
                                $cheapestPriceObj = $priceInfo;
                            } else if($priceInfo['price'] < $cheapestPriceObj['price']) {
                                $cheapestPriceObj = $priceInfo;
                            }
                        }   
                    }
                    //Save cheapest price and date for travelcompany
                    if($cheapestPriceObj && $cheapestPriceObj['price'] > 0) {
                        $default = new AccommodationRoomDefaultPrice;
                        $default->fkItemRoom = $cheapestPriceObj['rooms'][0]['itemRoom'];
                        $default->arrival_date = $cheapestPriceObj['arrival_date'];
                        $default->duration = $cheapestPriceObj['duration'];
                        $default->amount_adults = $a;
                        $default->amount_children = $c;
                        $default->price = $cheapestPriceObj['price'];
                        $default->save();
                    }
            }
        }

The Database schema is as follows:

id-fkItemRoom-arrival_date-duration-amount_adults-amount_children-price

But this misses the "age" part. And prices are also depending on the age.

How do I solve this problem? I'm not just looking for an "answer". I would like to educate myself on how I solve big data challenges like this in general.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)