public function queryPlaceCalendar()
 {
     $jsonData = json_decode($_POST['json_data'], true);
     $day = $jsonData['month'] . '-01';
     // 判断月份第一天是星期几,0 代表周日
     // 时间往前移,到该天是周日
     $diff = date('w', strtotime($day));
     $startDay = date('Y-m-d', strtotime('-' . $diff . ' day', strtotime($day)));
     // 时间前移之后共有几天
     $number = API::daysInMonth($jsonData['month']) + $diff;
     // 时间往后移,到该天是周六
     $number = $number + (7 - $number % 7);
     $endDay = date('Y-m-d', strtotime('+' . ($number - 1) . ' day', strtotime($startDay)));
     $placeCalendar = M('PlaceCalendar');
     //这里做日期检查更新
     $map['date'] = array('LT', date('Y-m-d'));
     $map['state'] = '1';
     $map['place_id'] = $jsonData['placeId'];
     $data['state'] = '3';
     $result = $placeCalendar->where($map)->save($data);
     if ($result === false) {
         $ret['retcode'] = '-1';
         $ret['retmsg'] = 'Checks and update place calendar error.';
     } else {
         // 日期检查更新通过,做查询
         $map = null;
         $map['place_id'] = $jsonData['placeId'];
         $map['date'] = array('BETWEEN', array($startDay, $endDay));
         $result = $placeCalendar->where($map)->select();
         if ($result === false) {
             $ret['retcode'] = '-1';
             $ret['retmsg'] = 'Query place calendar error.';
         } else {
             $list = [];
             $temp = [null, null, null, null, null, null, null];
             foreach ($result as $key => $value) {
                 $obj['id'] = $value['id'];
                 $obj['placeId'] = $value['place_id'];
                 $obj['date'] = $value['date'];
                 $obj['month'] = $value['month'];
                 $obj['day'] = substr($value['date'], -2);
                 $obj['price'] = $value['price'] / 100;
                 $obj['state'] = $value['state'];
                 $obj['thisMonth'] = $value['month'] == $jsonData['month'] ? true : false;
                 switch (date('w', strtotime($value['date']))) {
                     case 0:
                         $obj['dayIs'] = 'sunday';
                         $temp[0] = $obj;
                         break;
                     case 1:
                         $obj['dayIs'] = 'monday';
                         $temp[1] = $obj;
                         break;
                     case 2:
                         $obj['dayIs'] = 'tuesday';
                         $temp[2] = $obj;
                         break;
                     case 3:
                         $obj['dayIs'] = 'wednesday';
                         $temp[3] = $obj;
                         break;
                     case 4:
                         $obj['dayIs'] = 'thursday';
                         $temp[4] = $obj;
                         break;
                     case 5:
                         $obj['dayIs'] = 'friday';
                         $temp[5] = $obj;
                         break;
                     case 6:
                         $obj['dayIs'] = 'saturday';
                         $temp[6] = $obj;
                         break;
                 }
                 if ($temp[6] != null) {
                     array_push($list, $temp);
                     $temp = [null, null, null, null, null, null, null];
                 } else {
                     if (!$result[$key + 1]) {
                         array_push($list, $temp);
                         $temp = [null, null, null, null, null, null, null];
                     }
                 }
             }
             $ret['retcode'] = '1';
             $ret['retmsg'] = 'success.';
             $ret['retdata'] = array('list' => $list, 'month' => date('F Y', strtotime($jsonData['month'])));
         }
     }
     echo json_encode($ret, JSON_UNESCAPED_UNICODE);
 }
Пример #2
0
 private function __addPlaceCalendar($placeId)
 {
     $map['place_id'] = $placeId;
     $price = M('Place')->where($map)->getField('default_price');
     $placeCalendar = M('PlaceCalendar');
     $result = $placeCalendar->where($map)->max('date');
     if (!$result) {
         // 查不到日期,从当前时间开始初始化,一个月
         $mouth = date('Y-m');
     } else {
         // 查到日期,接着日期后面初始化,一个月
         $mouth = date('Y-m', strtotime('+1 day', strtotime($result)));
     }
     $number = API::daysInMonth($mouth);
     $today = $mouth . '-01';
     $dataList = [];
     for ($i = 0; $i < $number; $i++) {
         $temp = null;
         $temp['place_id'] = $placeId;
         $temp['month'] = $mouth;
         $temp['date'] = date('Y-m-d', strtotime('+' . $i . ' day', strtotime($today)));
         $temp['price'] = $price;
         $temp['state'] = '1';
         array_push($dataList, $temp);
     }
     $result = $placeCalendar->addAll($dataList);
     return $result;
 }