/** * Add feedback * * @param mixed $writerID * @param mixed $score * @param mixed $feedback * @param mixed $activityID * @param mixed $activityType * @return int|null|string|void */ public function addFeedback($writerID, $score, $feedback, $activityID, $activityType = BuckysFeedback::ACTIVITY_TYPE_TRADE) { global $db; if (!is_numeric($activityID) || !is_numeric($writerID) || !is_numeric($score) || $feedback == '') { return; } // failed //If you left feedback already, then return if ($this->hasFeedback($writerID, $activityID, $activityType)) { return; } //exists $param = ['activityID' => $activityID, 'activityType' => $activityType, 'writerID' => $writerID, 'score' => $score, 'comment' => $feedback, 'createdDate' => date('Y-m-d H:i:s')]; $otherUserID = null; switch ($activityType) { case BuckysFeedback::ACTIVITY_TYPE_TRADE: $tradeIns = new BuckysTrade(); $tradeData = $tradeIns->getTradeByID($activityID); if (!$tradeData) { return; } //no such trade if ($tradeData['sellerID'] == $writerID) { $otherUserID = $param['receiverID'] = $tradeData['buyerID']; $param['itemID'] = $tradeData['buyerItemID']; } else { if ($tradeData['buyerID'] == $writerID) { $otherUserID = $param['receiverID'] = $tradeData['sellerID']; $param['itemID'] = $tradeData['sellerItemID']; } else { return; //no rights } } break; case BuckysFeedback::ACTIVITY_TYPE_SHOP: $shopOrderIns = new BuckysShopOrder(); $orderData = $shopOrderIns->getOrderByID($activityID); if (!$orderData || $orderData['buyerID'] != $writerID) { return; } //no such trade $otherUserID = $param['receiverID'] = $orderData['sellerID']; $param['itemID'] = $orderData['productID']; break; default: return; //no such cases break; } $newID = $db->insertFromArray(TABLE_FEEDBACK, $param); if ($newID && $otherUserID) { //Update TradeUser Table for rating calculation $this->_updateRanking($otherUserID); } //Create notification $tradeNotificationIns = new BuckysTradeNotification(); $tradeNotificationIns->createNotification($otherUserID, $writerID, BuckysTradeNotification::ACTION_TYPE_FEEDBACK, $newID); return $newID; }
/** * Add feedback * * @param integer $tradeID * @param integer $userID * @param integer $score : one of this two value, 1 & -1 * @param string $feedback * @return int */ public function addFeedback($tradeID, $userID, $score, $feedback) { global $db; if (!is_numeric($tradeID) || !is_numeric($userID) || !is_numeric($score) || $feedback == '') { return; } // failed if ($this->getFeedbackByTradeID($tradeID)) { return; } //exists //Add $tradeIns = new BuckysTrade(); $tradeData = $tradeIns->getTradeByID($tradeID); $otherUserID = null; if (!$tradeData) { return; } //no such trade if ($tradeData['sellerID'] == $userID) { $param = ['tradeID' => $tradeID, 'sellerID' => $tradeData['sellerID'], 'buyerID' => $tradeData['buyerID'], 'sellerToBuyerScore' => $score, 'sellerToBuyerFeedback' => $feedback, 'sellerToBuyerFeedbackCreatedAt' => date('Y-m-d H:i:s')]; $otherUserID = $tradeData['buyerID']; } else { if ($tradeData['buyerID'] == $userID) { $param = ['tradeID' => $tradeID, 'sellerID' => $tradeData['sellerID'], 'buyerID' => $tradeData['buyerID'], 'buyerToSellerScore' => $score, 'buyerToSellerFeedback' => $feedback, 'buyerToSellerFeedbackCreatedAt' => date('Y-m-d H:i:s')]; $otherUserID = $tradeData['sellerID']; } else { return; //no rights } } $newID = $db->insertFromArray(TABLE_TRADE_FEEDBACK, $param); if ($newID && $otherUserID) { //Update TradeUser Table for rating calculation $this->_updateRanking($otherUserID); } //Create notification $tradeNotificationIns = new BuckysTradeNotification(); $tradeNotificationIns->createNotification($otherUserID, $userID, BuckysTradeNotification::ACTION_TYPE_FEEDBACK, $newID); return $newID; }
/** * Update shipping Info * It has 2 logic in it. Update your own shipping info, and update already created trade records which has no shipping info. * * @param integer $userID * @param array $data */ public function updateShippingInfo($userID, $data) { if (!is_numeric($userID) || $data['shippingAddress'] == '' || $data['shippingCity'] == '' || $data['shippingState'] == '' || $data['shippingZip'] == '' || $data['shippingCountryID'] == '' || !is_numeric($data['shippingCountryID'])) { return false; } //Update my shipping info global $db; $query = sprintf('UPDATE %s SET ', TABLE_TRADE_USERS); $query = $db->prepare($query . 'shippingAddress=%s, shippingCity=%s, shippingState=%s, shippingZip=%s, shippingCountryID=%d WHERE userID=' . $userID, $data['shippingAddress'], $data['shippingCity'], $data['shippingState'], $data['shippingZip'], $data['shippingCountryID']); $db->query($query); //Update trade table which has no shipping info with this info. //It will check trade table, and create records in trade_shipping_info $tradeIns = new BuckysTrade(); $tradeShippingInfoIns = new BuckysTradeShippingInfo(); //---------------- Update for seller ----------------------// $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'seller'); if (!empty($requiredList) && count($requiredList) > 0) { foreach ($requiredList as $tradeData) { //Add shipping info $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID); if (!empty($shippingRecID) && is_numeric($shippingRecID)) { //update trade table $tradeIns->updateTrade($tradeData['tradeID'], array('sellerShippingID' => $shippingRecID)); } } } //---------------- Update for buyer ----------------------// $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'buyer'); if (!empty($requiredList) && count($requiredList) > 0) { foreach ($requiredList as $tradeData) { //Add shipping info $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID); if (!empty($shippingRecID) && is_numeric($shippingRecID)) { //update trade table $tradeIns->updateTrade($tradeData['tradeID'], array('buyerShippingID' => $shippingRecID)); } } } return true; }
/** * Save Tracking number */ function saveTrackingNumber() { $userID = buckys_is_logged_in(); if (!$userID) { //You should be logged in return; } else { $tradeIns = new BuckysTrade(); $tradeID = buckys_escape_query_integer($_REQUEST['tradeID']); $trackingNo = buckys_escape_query_string($_REQUEST['trackingNo']); $tradeData = $tradeIns->getTradeByID($tradeID); if (empty($tradeData) || $tradeData['sellerID'] != $userID && $tradeData['buyerID'] != $userID) { //error, no permission echo json_encode(['success' => 0, 'msg' => "You do not have permission."]); } else { if ($tradeData['sellerID'] == $userID) { $tradeIns->updateTrade($tradeID, ['sellerTrackingNo' => $trackingNo]); } else { $tradeIns->updateTrade($tradeID, ['buyerTrackingNo' => $trackingNo]); } echo json_encode(['success' => 1, 'msg' => "You have saved tracking number successfully."]); } } }
} buckys_enqueue_stylesheet('trade.css'); buckys_enqueue_javascript('trade.js'); $BUCKYS_GLOBALS['content'] = 'trade/traded'; $BUCKYS_GLOBALS['headerType'] = 'trade'; $paramCurrentPage = get_secure_integer($_REQUEST['page']); $paramType = get_secure_string($_REQUEST['type']); $view = array(); $baseURL = '/trade/traded.php'; if ($paramType == 'history') { $baseURL .= '?type=' . $paramType; } else { $paramType = 'completed'; } //Get offer_received info $tradeIns = new BuckysTrade(); $countryIns = new BuckysCountry(); $view['trades'] = $tradeIns->getTradesByUserID($userID, $paramType); $view['trades'] = buckys_trade_pagination($view['trades'], $baseURL, $paramCurrentPage, TRADE_ROWS_PER_PAGE); $view['myID'] = $userID; switch ($paramType) { case 'history': $view['pagetitle'] = 'Trade History'; break; case 'completed': default: $view['pagetitle'] = 'Completed Trades'; //Mark the activity (offer received) as read $tradeNotificationIns = new BuckysTradeNotification(); $tradeNotificationIns->markAsRead($userID, BuckysTradeNotification::ACTION_TYPE_OFFER_ACCEPTED); break;
/** * Accept offer * * @param integer $offerID * @return bool|int */ public function acceptOffer($offerID) { if (!is_numeric($offerID)) { return false; } //Get related info for this offer $tradeItemIns = new BuckysTradeItem(); $offerInfo = $this->getOfferByID($offerID); if (empty($offerInfo)) { return false; } $sellerData = $tradeItemIns->getItemById($offerInfo['targetItemID']); $buyerData = $tradeItemIns->getItemById($offerInfo['offeredItemID']); if (empty($buyerData) || empty($sellerData)) { return false; } $offerInfo['sellerID'] = $sellerData['userID']; $offerInfo['buyerID'] = $buyerData['userID']; //Add trade $tradeIns = new BuckysTrade(); $newTradeID = $tradeIns->addTrade($offerInfo['sellerID'], $offerInfo['buyerID'], $offerInfo['targetItemID'], $offerInfo['offeredItemID']); //Change trade Item status to "traded" $tradeItemIns->updateItem($offerInfo['targetItemID'], ['status' => BuckysTradeItem::STATUS_ITEM_TRADED]); $tradeItemIns->updateItem($offerInfo['offeredItemID'], ['status' => BuckysTradeItem::STATUS_ITEM_TRADED]); //Remove all offered made by these 2 items $this->deleteOffersByItemID($offerInfo['targetItemID']); $this->deleteOffersByItemID($offerInfo['offeredItemID']); //After processing accept (creating record in trade table), then you should remove the offer record from the table //$this->deleteOffer($offerID); // Meaningless code since it should be deleted by deleteOffersByItemID (2 commands above this) //Create notification $tradeNotificationIns = new BuckysTradeNotification(); $tradeNotificationIns->createNotification($offerInfo['buyerID'], $offerInfo['sellerID'], BuckysTradeNotification::ACTION_TYPE_OFFER_ACCEPTED, $newTradeID); return $newTradeID; }
/** * Update shipping Info * It has 2 logic in it. Update your own shipping info, and update already created trade records which has no shipping info. * * @param integer $userID * @param array $data * @return bool */ public function updateShippingInfo($userID, $data) { if (!is_numeric($userID) || $data['shippingAddress'] == '' || $data['shippingCity'] == '' || $data['shippingState'] == '' || $data['shippingZip'] == '' || $data['shippingCountryID'] == '' || !is_numeric($data['shippingCountryID'])) { return false; } //Update my shipping info global $db; $db->updateFromArray(TABLE_TRADE_USERS, $data, ['userID' => $userID]); //Update trade table which has no shipping info with this info. //It will check trade table, and create records in trade_shipping_info $tradeIns = new BuckysTrade(); $tradeShippingInfoIns = new BuckysTradeShippingInfo(); //---------------- Update for seller ----------------------// $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'seller'); if (!empty($requiredList) && count($requiredList) > 0) { foreach ($requiredList as $tradeData) { //Add shipping info $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID); if (!empty($shippingRecID) && is_numeric($shippingRecID)) { //update trade table $tradeIns->updateTrade($tradeData['tradeID'], ['sellerShippingID' => $shippingRecID]); } } } //---------------- Update for buyer ----------------------// $requiredList = $tradeIns->getShippingInfoRequiredTrade($userID, 'buyer'); if (!empty($requiredList) && count($requiredList) > 0) { foreach ($requiredList as $tradeData) { //Add shipping info $shippingRecID = $tradeShippingInfoIns->addTradeShippingInfo($userID); if (!empty($shippingRecID) && is_numeric($shippingRecID)) { //update trade table $tradeIns->updateTrade($tradeData['tradeID'], ['buyerShippingID' => $shippingRecID]); } } } //-------------------- Update Buyer Shipping Info -----------------------// $tradeShippingInfoIns->updateTradeShippingInfo($userID, $data); return true; }
/** * Save Tracking number * */ function saveTrackingNumber() { $userID = buckys_is_logged_in(); if (!$userID) { //You should be logged in echo json_encode(array('success' => 0, 'msg' => "Please sign in to save tracking number.")); } else { $tradeIns = new BuckysTrade(); $tradeID = get_secure_integer($_REQUEST['tradeID']); $trackingNo = get_secure_string($_REQUEST['trackingNo']); $tradeData = $tradeIns->getTradeByID($tradeID); if (empty($tradeData) || $tradeData['sellerID'] != $userID && $tradeData['buyerID'] != $userID) { //error, no permission echo json_encode(array('success' => 0, 'msg' => "You do not have permission.")); } else { if ($tradeData['sellerID'] == $userID) { $tradeIns->updateTrade($tradeID, array('sellerTrackingNo' => $trackingNo)); } else { $tradeIns->updateTrade($tradeID, array('buyerTrackingNo' => $trackingNo)); } echo json_encode(array('success' => 1, 'msg' => "You have saved tracking number successfully.")); } } }