public function actionSearch() { set_time_limit(0); while (1) { $array_subs = Subscription::model()->with('userSubscriptions')->findALl(); //$array_subs = Subscription::model()->with('userSubscriptions')->findAllByAttributes(array('ID'=>57)); foreach ($array_subs as $tiSubs) { //delete all flights of subs $this->deleteOldFlights($tiSubs); $lowestPrice = new D_LowestPrice(); $this->_price = $lowestPrice->searchFlight($tiSubs); //date backward //search fail if ((int) $this->_price == 0) { continue; } $this->createHistoryPrice($tiSubs, (int) $this->_price); $this->addFlightsOfSubscription($tiSubs, $lowestPrice); $isModified = $this->modifyPriceOfSubscription($tiSubs); if ($isModified) { echo "subscription is modified \n"; $array_user_subs = $tiSubs->userSubscriptions; print_r($array_user_subs); foreach ($array_user_subs as $user_tiSubs) { $tiUser = $user_tiSubs->iDUser; if (!$tiUser->Pushable) { continue; } echo "user is pushable\n"; if ((int) $this->_price < (int) $user_tiSubs->PriceLimit || $user_tiSubs->PriceLimit == NULL) { $user_devices = $tiUser->userDevices; foreach ($user_devices as $user_device) { $this->_deviceToken = $user_device->Device_token; $this->_id = $tiSubs->ID; //$this->_deviceToken = "70a10324b2a2e4e6daaa8eee74a30c8bb196db31be43043cc94cb149d117aeb7"; //$this->_message = "asdf"; $this->_message = "您订阅的{$tiSubs->DepartCity}至{$tiSubs->ArriveCity}价格已更新至{$this->_price}"; echo "start to push\n"; $this->actionIndex(); } } } } sleep(1); } sleep(2); } }
public function actionIndex($subs_id) { $subs = \Subscription::model()->findByAttributes(array('ID' => $subs_id)); $lowestPrice = new \D_LowestPrice(); $subs->CurrentPrice = (int) $lowestPrice->searchFlight($subs); echo "now subs " . $subs_id . " current price is " . $subs->CurrentPrice . "\n"; try { if (!$subs->save()) { new \Error(5, null, json_encode($subs->getErrors())); } } catch (Exception $e) { new \Error(5, null, $e->getMessage()); } $date = new \DateGenerater(); $date = $date->getDateYMD("-"); $price = $subs->CurrentPrice; $history_price = \HistoryPrice::model()->findAllByAttributes(array('ID_subscription' => $subs->ID, 'Date' => $date)); if ($history_price == NULL || count($history_price) == 0) { $history_price = new HistoryPrice(); $history_price->ID_subscription = $subs->ID; $history_price->Price = $price; $history_price->Date = $date; try { $history_price->save(); } catch (Exception $e) { new \Error(5, NULL, $e->getMessage()); } } else { //var_dump($history_price); $history_price = $history_price[0]; if ($history_price->Price == $price) { return; } $history_price->Price = $price < $history_price->Price ? $price : $history_price; try { $history_price->save(); } catch (Exception $e) { new \Error(5, NULL, $e->getMessage()); } } }
public function actionSearch() { //echo dirname(__FILE__); set_time_limit(0); while (1) { $array_subs = Subscription::model()->with('userSubscriptions')->findALl(); var_dump($array_subs); foreach ($array_subs as $tiSubs) { //echo var_dump($tiSubs); //echo "xxxxxxxxxxxxxxxx<br>"; $lowestPrice = new D_LowestPrice(); $this->_price = $lowestPrice->searchFlight($tiSubs); $this->_date = $lowestPrice->date; $this->createHistoryPrice($tiSubs, (int) $this->_price); $isModified = $this->modifySubscription($tiSubs, (int) $this->_price); if ($isModified) { $array_user_subs = $tiSubs->userSubscriptions; foreach ($array_user_subs as $user_tiSubs) { $tiUser = $user_tiSubs->iDUser; if (!$tiUser->Pushable) { continue; } if ($this->_price < $user_tiSubs->PriceLimit || $user_tiSubs->PriceLimit == NULL) { $user_devices = $tiUser->userDevices; foreach ($user_devices as $user_device) { $this->_deviceToken = $user_device->Device_token; //$this->_deviceToken = "70a10324b2a2e4e6daaa8eee74a30c8bb196db31be43043cc94cb149d117aeb7"; //$this->_message = "asdf"; $this->_message = "您订阅的{$tiSubs->DepartCity}至{$tiSubs->ArriveCity}价格已更新至{$this->_price}"; $this->actionIndex(); } } } } } sleep(300); } }