public function getChannelList()
 {
     for ($j = 1; $j <= 12; $j++) {
         $url = 'http://www.app-echo.com/channel/list?&page=' . $j . '&per-page=16';
         $result = API::RequestWithCookie($url);
         $rule = '/<h3>(.+)<\\/h3>|<a href\\=\\"(.+)\\"><\\/a>/';
         preg_match_all($rule, $result, $preg);
         $rule = '/\\/channel\\/\\d+/';
         $obj = M('Channel');
         $list = [];
         for ($i = 0; $i < 32; $i++) {
             if ($i % 2) {
                 $temp['url'] = $preg[2][$i];
                 if (preg_match($rule, $temp['url'])) {
                     array_push($list, $temp);
                 }
                 $temp = null;
             } else {
                 $temp['title'] = $preg[1][$i];
             }
         }
         $obj->addAll($list);
         echo 'page ' . $j . ' finish<br />';
         ob_flush();
         flush();
     }
 }
 public function queryPlaceCalendarRange()
 {
     $jsonData = json_decode($_POST['json_data'], true);
     $placeCalendar = M('PlaceCalendar');
     $map['place_id'] = $jsonData['placeId'];
     $endDay = $placeCalendar->where($map)->max('date');
     if ($endDay === false) {
         $ret['retcode'] = '-1';
         $ret['retmsg'] = 'Query place calendar range error.';
     } else {
         $startDay = date('Y-m-d');
         $diff = API::dateDiff($startDay, $endDay);
         $dateRange = array('diff' => $diff, 'startDay' => $startDay, 'endDay' => $endDay);
         $ret['retcode'] = '1';
         $ret['retmsg'] = 'success.';
         $ret['retdata'] = $dateRange;
     }
     echo json_encode($ret, JSON_UNESCAPED_UNICODE);
 }
 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;
 }