public function displayMain() { global $smarty, $link, $cookie; if (!$cookie->logged) { Tools::redirect($link->getPage('LoginView')); } $user = new User((int) $cookie->id_user); $errors = array(); $success = false; //添加feedback //1.添加创建对象 if (Tools::isSubmit('submit')) { $feedback = new Feedback(); $feedback->copyFromPost(); if ($feedback->rating <= 0 && $feedback->rating > 5) { $feedback->rating = 4; } $data = explode("-", base64_decode(Tools::getRequest("data"))); $feedback->id_product = (int) $data[0]; $feedback->unit_price = (double) $data[2]; $feedback->quantity = (int) $data[3]; $feedback->md5_key = md5(Tools::getRequest("data")); $feedback->name = substr($user->first_name, 0, 1) . "***" . substr($user->last_name, -1, 1); $feedback->id_user = $user->id; if ($feedback->add()) { $success = true; } else { $errors = $feedback->_errors; } } //2.获取用户评论过的MD5KEY $proids = Feedback::haveFeedbackWithUser($user->id); //3.获取用户购买过的产品 $products = array(); if ($result = $user->getPaymentedProduct()) { foreach ($result as &$row) { if (!in_array($row['md5_key'], $proids)) { $products[] = $row; } } } $smarty->assign(array('success' => $success, 'errors' => $errors, 'products' => $products, 'DISPLAY_LEFT' => Module::hookBlock(array('myaccount')))); return $smarty->fetch('my-feedback.tpl'); }
} else { $response = 'response'; } if (isset($_POST['mark'])) { $mark = htmlspecialchars(trim($_POST['mark'])); } else { $mark = ''; } if (isset($_POST['good'])) { $good = htmlspecialchars(trim($_POST['good'])); } else { $good = ''; } if (isset($_POST['better'])) { $better = htmlspecialchars(trim($_POST['better'])); } else { $better = ''; } $auth = new Auth(); if (isset($_POST['send'])) { $auth->setSession(); } //hasSession проверяет существует ли $_SESSION['resp']==1 и увеличивает её на 1 if ($auth->hasSession()) { $feed = new Feedback(); $arr = $feed->add($name, $email, $response, $shotdate, $mark, $good, $better); include __DIR__ . '/views/single.php'; } else { header('Location: ./'); } }
continue; } $id_product = array_rand($productids); $feedback = new Feedback(); $feedback->id_product = (int) $id_product; $feedback->unit_price = (double) $productids[$id_product]; $feedback->quantity = (int) $feed->quantity; $feedback->md5_key = md5(time()); $feedback->flag_code = strtolower($feed->countryCode); $feedback->name = substr($feed->name, 0, 1) . "***" . substr($feed->name, -2, 2); $feedback->feedback = pSQL($feed->buyerFeedback); $feedback->id_user = 0; $feedback->rating = (int) $feed->star; $feedback->active = 1; $feedback->add_date = rand_time(Tools::getRequest('from_date')); if ($feedback->add()) { $field = pSQL($rating_fields[$feed->star - 1]); if ($feedback->feedbackStateExists($id_product)) { Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'feedback_state SET times=times+1,total_rating=total_rating+' . (int) $feedback->rating . ",`" . $field . "`=`" . $field . "`+1 \n\t\t\t\tWHERE id_product=" . intval($id_product)); } else { Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'feedback_state SET id_product=' . intval($id_product) . ',times=1,total_rating=' . (int) $feedback->rating . ",`" . $field . "`=`" . $field . "`+1"); } Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product SET orders=orders+' . rand(3, 5) . ' WHERE id_product=' . (int) $id_product); } } } function getCurlData($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);