Example #1
0
 public function saveBaoJia($hotelid, $roomid, $arr)
 {
     //$pricerule,$starttime,$endtime,$hotelid,$roomid,$basicprice,$profit,$description
     $pricerule = Arr::get($arr, 'pricerule');
     $starttime = Arr::get($arr, 'starttime');
     $endtime = Arr::get($arr, 'endtime');
     $basicprice = Arr::get($arr, 'basicprice') ? Arr::get($arr, 'basicprice') : 0;
     $profit = Arr::get($arr, 'profit') ? Arr::get($arr, 'profit') : 0;
     $description = Arr::get($arr, 'description');
     $monthval = Arr::get($arr, 'monthval');
     $weekval = Arr::get($arr, 'weekval');
     $number = Arr::get($arr, 'number');
     if (empty($starttime) || empty($endtime)) {
         return false;
     }
     $stime = strtotime($starttime);
     $etime = strtotime($endtime);
     $price = (int) $basicprice + (int) $profit;
     //按日期范围报价
     if ($pricerule == 'all') {
         $begintime = $stime;
         while (true) {
             $model = ORM::factory('hotel_room_price')->where("suitid={$roomid} and day='{$begintime}'")->find();
             $data_arr = array();
             $data_arr['hotelid'] = $hotelid;
             $data_arr['suitid'] = $roomid;
             $data_arr['basicprice'] = $basicprice;
             $data_arr['profit'] = $profit;
             $data_arr['description'] = $description;
             $data_arr['price'] = $price;
             $data_arr['day'] = $begintime;
             $data_arr['number'] = $number;
             if ($model->suitid) {
                 $query = DB::update('hotel_room_price')->set($data_arr)->where("suitid={$roomid} and day='{$begintime}'");
                 $query->execute();
             } else {
                 foreach ($data_arr as $k => $v) {
                     $model->{$k} = $v;
                 }
                 $model->save();
             }
             $begintime = $begintime + 86400;
             if ($begintime > $etime) {
                 break;
             }
         }
     } else {
         if ($pricerule == 'month') {
             $syear = date('Y', $stime);
             $smonth = date('m', $stime);
             $sday = date('d', $stime);
             $eyear = date('Y', $etime);
             $emonth = date('m', $etime);
             $eday = date('d', $etime);
             $beginyear = $syear;
             $beginmonth = $smonth;
             while (true) {
                 $daynum = date('t', strtotime($beginyear . '-' . $beginmonth . '-' . '01'));
                 foreach ($monthval as $v) {
                     if ((int) $v < 10) {
                         $v = '0' . $v;
                     }
                     $newtime = strtotime($beginyear . '-' . $beginmonth . '-' . $v);
                     if ((int) $v > (int) $daynum || $newtime < $stime || $newtime > $etime) {
                         continue;
                     }
                     $model = ORM::factory('hotel_room_price')->where("suitid={$roomid} and day='{$newtime}'")->find();
                     $data_arr = array();
                     $data_arr['hotelid'] = $hotelid;
                     $data_arr['suitid'] = $roomid;
                     $data_arr['basicprice'] = $basicprice;
                     $data_arr['profit'] = $profit;
                     $data_arr['description'] = $description;
                     $data_arr['price'] = $price;
                     $data_arr['day'] = $newtime;
                     $data_arr['number'] = $number;
                     if ($model->suitid) {
                         $query = DB::update('hotel_room_price')->set($data_arr)->where("suitid={$roomid} and day='{$newtime}'");
                         $query->execute();
                     } else {
                         foreach ($data_arr as $k => $v) {
                             $model->{$k} = $v;
                         }
                         $model->save();
                     }
                 }
                 $beginmonth = (int) $beginmonth + 1;
                 if ($beginmonth > 12) {
                     $beginmonth = $beginmonth - 12;
                     $beginyear++;
                 }
                 if ($beginmonth > $emonth && $beginyear >= $eyear || $beginmonth <= $emonth && $beginyear > $eyear) {
                     break;
                 }
                 $beginmonth = $beginmonth < 10 ? '0' . $beginmonth : $beginmonth;
             }
         } else {
             if ($pricerule == 'week') {
                 $begintime = $stime;
                 while (true) {
                     $cur_week = date('w', $begintime);
                     $cur_week = $cur_week == 0 ? 7 : $cur_week;
                     if (in_array($cur_week, $weekval)) {
                         $model = ORM::factory('hotel_room_price')->where("suitid={$roomid} and day='{$begintime}'")->find();
                         $data_arr = array();
                         $data_arr['hotelid'] = $hotelid;
                         $data_arr['suitid'] = $roomid;
                         $data_arr['basicprice'] = $basicprice;
                         $data_arr['profit'] = $profit;
                         $data_arr['description'] = $description;
                         $data_arr['price'] = $price;
                         $data_arr['day'] = $begintime;
                         $data_arr['number'] = $number;
                         if ($model->suitid) {
                             $query = DB::update('hotel_room_price')->set($data_arr)->where("suitid={$roomid} and day='{$begintime}'");
                             $query->execute();
                         } else {
                             foreach ($data_arr as $k => $v) {
                                 $model->{$k} = $v;
                             }
                             $model->save();
                         }
                     }
                     $begintime = $begintime + 86400;
                     if ($begintime > $etime) {
                         break;
                     }
                 }
             }
         }
     }
     Model_Hotel::updateMinPrice($hotelid);
 }
Example #2
0
 public function action_ajax_addprice()
 {
     /* $typeid = Arr::get($_POST,'typeid');
        $basicprice = Arr::get($_POST,'basicprice') ?  Arr::get($_POST,'basicprice') : 0;
        $profit = Arr::get($_POST,'profit') ? Arr::get($_POST,'profit') : 0;
        $day = Arr::get($_POST,'day');
        $suitid = Arr::get($_POST,'suitid');
        $productid = Arr::get($_POST,'productid');
        $price = (int)$basicprice+(int)$profit;*/
     $typeid = Arr::get($_POST, 'typeid');
     $productid = Arr::get($_POST, 'productid');
     $suitid = Arr::get($_POST, 'suitid');
     $basicprice = Arr::get($_POST, 'basicprice') ? Arr::get($_POST, 'basicprice') : 0;
     $profit = Arr::get($_POST, 'profit') ? Arr::get($_POST, 'profit') : 0;
     $child_basicprice = Arr::get($_POST, 'child_basicprice') ? Arr::get($_POST, 'child_basicprice') : 0;
     $child_profit = Arr::get($_POST, 'child_profit') ? Arr::get($_POST, 'child_profit') : 0;
     $old_basicprice = Arr::get($_POST, 'old_basicprice') ? Arr::get($_POST, 'old_basicprice') : 0;
     $old_profit = Arr::get($_POST, 'old_profit') ? Arr::get($_POST, 'old_profit') : 0;
     $number = $_POST['number'] == '' ? -1 : $_POST['number'];
     $number = (string) $number == '不限' ? -1 : $number;
     $roombalance = empty($_POST['roombalance']) ? 0 : $_POST['roombalance'];
     $day = Arr::get($_POST, 'day');
     $price = (int) $basicprice + (int) $profit;
     $child_price = (int) $child_basicprice + (int) $child_profit;
     $old_price = (int) $old_basicprice + (int) $old_profit;
     $table = self::$priceTableArr[$typeid];
     switch ($typeid) {
         case 1:
             $arr = array('lineid' => $productid, 'suitid' => $suitid, 'adultbasicprice' => $basicprice, 'adultprofit' => $profit, 'adultprice' => $price, 'day' => $day, 'childbasicprice' => $child_basicprice, 'childprofit' => $child_profit, 'childprice' => $child_price, 'oldbasicprice' => $old_basicprice, 'oldprofit' => $old_profit, 'oldprice' => $old_price, 'roombalance' => $roombalance);
             //$field = 'lineid,suitid,adultbasicprice,adultprofit,adultprice,day';
             break;
         case 2:
             $arr = array('hotelid' => $productid, 'suitid' => $suitid, 'basicprice' => $basicprice, 'profit' => $profit, 'price' => $price, 'day' => $day);
             //$field = 'hotelid,suitid,basicprice,profit,price,day';
             break;
         case 3:
             $arr = array('carid' => $productid, 'suitid' => $suitid, 'adultbasicprice' => $basicprice, 'adultprofit' => $profit, 'adultprice' => $price, 'day' => $day);
             // $field = 'carid,suitid,adultbasicprice,adultprofit,adultprice,day';
             break;
     }
     $flag = false;
     if ($price != 0) {
         $sql_key = $sql_value = '';
         $sql = "INSERT INTO sline_{$table} (";
         $sql2 = "VALUES ( ";
         foreach ($arr as $key => $value) {
             $sql_key .= "`" . $key . "`,";
             $sql_value .= "'" . $value . "',";
         }
         $sql_key = substr($sql_key, 0, -1) . ")";
         $sql_value = substr($sql_value, 0, -1) . ")";
         $sql = $sql . $sql_key . $sql2 . $sql_value . ";";
         //$sql = "insert into sline_{$table} ($field) values(";
         //$sql.= "'{$productid}','{$suitid}','{$basicprice}','{$profit}','{$price}','{$day}')";
         $result = DB::query(Database::INSERT, $sql)->execute();
         if ($result) {
             $flag = true;
         }
     }
     $out = array();
     if ($flag) {
         $out['status'] = true;
         $out['price'] = $price;
         $out['basicprice'] = $basicprice;
         $out['profit'] = $profit;
         $out['child_price'] = $child_price;
         $out['child_basicprice'] = $child_basicprice;
         $out['child_profit'] = $child_profit;
         $out['old_price'] = $old_price;
         $out['old_basicprice'] = $old_basicprice;
         $out['old_profit'] = $old_profit;
         $out['roombalance'] = $roombalance;
         $out['number'] = $number == -1 ? '不限' : $number;
         switch ($typeid) {
             case 1:
                 Model_Line::updateMinPrice($productid);
                 break;
             case 2:
                 Model_Hotel::updateMinPrice($productid);
                 break;
             case 3:
                 Model_Car::updateMinPrice($productid);
                 break;
         }
     } else {
         $out['status'] = false;
     }
     echo json_encode($out);
     exit;
 }