public function sendEmail($email) { $text = ''; $cart = json_decode($this->itemslist); $mailArr = []; $mailArr[] = Yii::$app->params['adminEmail']; if (!empty($this->email)) { $mailArr[] = $this->email; } if (count($cart) > 0) { foreach ($cart as $item) { $ebayItem = Item::findOne(['ebay_item_id' => $item[0]]); $text .= '<tr>' . ' <td>' . $ebayItem['ebay_item_id'] . '</td> ' . '<td>' . $ebayItem['title'] . '</td>' . ' <td>' . $ebayItem['current_price_value'] . '</td>' . '<td>' . $item[3] . '</td>>' . '<td>' . $ebayItem['current_price_value'] * $item[3] . '</td><td>' . $ebayItem['viewItemURL'] . '</td>></tr>'; } return Yii::$app->mailer->compose('order-link', ['user' => Yii::$app->user->identity, 'name' => $this->name, 'email' => $this->email, 'phone' => $this->phone, 'text' => $text])->setTo($mailArr)->setFrom(Yii::$app->params['supportEmail'])->setSubject($this->subject)->send(); } else { return false; } }
private function addToBD($ebayResponse) { date_default_timezone_set('Europe/Moscow'); $today = date("YmdHis"); $hash = new Hash(); $hash->hash = $this->queryHash; $hash->life_time = $today; $hash->page_count = $this->pageCount; $hash->page = $this->queryPage; $hash->save(); $hashID = $hash->id; foreach ($ebayResponse['searchResult']['item'] as $itemEbay) { $ebay_item = Item::findOne(['ebay_item_id' => $itemEbay['itemId']]); if (!empty($ebay_item->ebay_item_id)) { continue; } $item = new Item(); $item->ebay_item_id = $itemEbay['itemId']; $item->title = $itemEbay['title']; $item->categoryId = $itemEbay['primaryCategory']['categoryId']; $item->categoryName = $itemEbay['primaryCategory']['categoryName']; if (isset($itemEbay['galleryURL'])) { $item->galleryURL = $itemEbay['galleryURL']; } $item->viewItemURL = $itemEbay['viewItemURL']; $item->sellingState = $itemEbay['sellingStatus']['sellingState']; $item->timeLeft = $itemEbay['sellingStatus']['timeLeft']; $item->current_price_value = $itemEbay['sellingStatus']['convertedCurrentPrice']['value']; $item->condition_id = $itemEbay['condition']['conditionId']; $item->condition_display_name = $itemEbay['condition']['conditionDisplayName']; $item->shipping_service_cost = $this->calculateShipping($itemEbay); $item->price_shipping_sum = $this->calculateValidPrice($itemEbay, $item->shipping_service_cost); $item->save(); $itemID = $item->id; $links = new Links(); $links->itemId = $itemID; $links->hashId = $hashID; $links->save(); } }
public static function addVote($entity, $id, $voteAdd) { $user = User::thisUser(); $vote = Vote::findOne(['entity' => $entity, 'entity_id' => $id, 'user_id' => $user->id]); if (empty($vote)) { $vote = new Vote(); $vote->entity = $entity; $vote->entity_id = $id; $vote->user_id = $user->id; } /** @var VoteModel $model */ $model = null; if ($entity == self::ENTITY_ITEM) { $model = Item::findOne($id); if ($user->reputation < Item::MIN_REPUTATION_ITEM_VOTE) { // Если только пользователь не отменяет свои дизлайки if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) { return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')]; } } } else { if ($entity == self::ENTITY_EVENT) { $model = Event::findOne($id); if ($user->reputation < Event::MIN_REPUTATION_EVENT_VOTE) { // Если только пользователь не отменяет свои дизлайки if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) { return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')]; } } } else { if ($entity == self::ENTITY_SCHOOL) { $model = School::findOne($id); if ($user->reputation < School::MIN_REPUTATION_SCHOOL_VOTE) { // Если только пользователь не отменяет свои дизлайки if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) { return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')]; } } } else { if ($entity == self::ENTITY_COMMENT) { $model = Comment::findOne($id); if ($user->reputation < Comment::MIN_REPUTATION_COMMENT_VOTE) { // Если только пользователь не отменяет свои дизлайки if (!($vote->vote == self::VOTE_DOWN && $voteAdd == self::VOTE_DOWN)) { return ['vote' => 0, 'count' => $model->getVoteCount(), 'error' => Lang::t('ajax', 'noReputationVote')]; } } } } } } if (!empty($model)) { if ($vote->vote == self::VOTE_UP) { if ($voteAdd == self::VOTE_UP) { // убираем up $vote->vote = self::VOTE_NONE; $model->addVote(-1); $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP); } else { // ставим down $vote->vote = self::VOTE_DOWN; $model->addVote(-2); $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_UP); $model->addReputation(VoteModel::ADD_REPUTATION_DOWN); } } elseif ($vote->vote == self::VOTE_DOWN) { if ($voteAdd == self::VOTE_UP) { // ставим up $vote->vote = self::VOTE_UP; $model->addVote(2); $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN); $model->addReputation(VoteModel::ADD_REPUTATION_UP); } else { // убираем down $vote->vote = self::VOTE_NONE; $model->addVote(1); $model->addReputation(VoteModel::ADD_REPUTATION_CANCEL_DOWN); } } else { if ($voteAdd == self::VOTE_UP) { // ставим up $vote->vote = self::VOTE_UP; $model->addVote(1); $model->addReputation(VoteModel::ADD_REPUTATION_UP); } else { // ставим down $vote->vote = self::VOTE_DOWN; $model->addVote(-1); $model->addReputation(VoteModel::ADD_REPUTATION_DOWN); } } } if ($vote->save()) { if (!empty($model)) { $model->save(); } } return ['vote' => $vote->vote, 'count' => $model->getVoteCount()]; }
public function getEntityModel() { if ($this->entity == self::ENTITY_ITEM) { return Item::findOne(['id' => $this->entity_id]); } }
public function actionAlarm() { $id = Yii::$app->request->post('id'); $msg = Yii::$app->request->post('msg'); $item = Item::findOne($id); if ($item && !empty($msg)) { if (Alarm::addAlarm(Alarm::ENTITY_ITEM, $item->id, $msg)) { $resultMsg = Lang::t('main/dialogs', 'modalAlarm_msgAlarmResultTrue'); Yii::$app->session->setFlash('success', $resultMsg); } else { $resultMsg = Lang::t('main/dialogs', 'modalAlarm_msgAlarmResultFalse'); Yii::$app->session->setFlash('success', $resultMsg); } return json_encode(['msg' => $resultMsg]); } }
/** * Finds the Item model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Item the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Item::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }