function changeConsumerRank($uid) { //consumer information if (!isset($this->consumer)) { $this->consumer = new Consumer(); } $this->consumerData = $this->consumer->fetchRow('id = ' . $uid); //total points $this->rewardPointTransactionRecord = new RewardPointTransactionRecord(); $rewardData = $this->rewardPointTransactionRecord->fetchAll('consumer_id=' . $uid . ' and transaction_id !=4'); $rewardDataArray = $rewardData->toArray(); $total = 0; if (count($rewardDataArray)) { foreach ($rewardDataArray as $val) { $total += $val['point_amount']; } } //participated campaigns $campaign = new CampaignInvitation(); $campaignData = $campaign->fetchAll('state = "ACCEPTED" and consumer_id =' . $uid); $campaginNum = count($campaignData); //rank information $rank = $this->fetchRow('campaign_number<=' . $campaginNum . ' and point_total<=' . $total, 'point_total desc'); if (count($rank)) { if ($this->consumerData->rank == $rank->id) { return; } else { $this->consumerData->rank = $rank->id; $this->consumerData->save(); // add notification $notificationModel = new Notification(); $notificationModel->createRecord("RANK_UPGRADE", $uid); $row = $this->rewardPointTransactionRecord->createRow(); $row->consumer_id = $uid; $row->date = date("Y-m-d H:i:s"); $row->transaction_id = 7; $row->point_amount = $rank->point_bonus; $row->save(); $this->changeConsumerRank($uid); } } else { return; } }
function redeemAction() { $this->view->title = $this->view->translate("Wildfire") . " - " . $this->view->translate("GIFT_REDEEM"); if ($this->_request->isPost()) { $formData = $this->_request->getPost(); $cartNamespace = new Zend_Session_Namespace('Cart'); if ($cartNamespace->list == null) { $this->_redirect('gift/list'); return; } // validate consumer info $consumerModel = new Consumer(); $consumer = $consumerModel->fetchRow("email = '" . $this->_currentUser->email . "' and password = MD5('" . $formData['password'] . "')"); if ($consumer == null) { $this->_flashMessenger->addMessage($this->view->translate("Gift_consumer_info_incorrect")); $this->_flashMessenger->addMessage(true); $this->_redirect('gift/confirmcart'); return; } // check redeem condition $db = Zend_Registry::get('db'); $selectTotalCompletedCampaign = $db->select(); $selectTotalCompletedCampaign->from('campaign_participation', 'count(*)')->join('campaign_invitation', 'campaign_participation.campaign_invitation_id = campaign_invitation.id', null)->where('campaign_invitation.consumer_id = ?', $this->_currentUser->id); $this->view->completedCampaignAmount = $db->fetchOne($selectTotalCompletedCampaign); // $selectTotalSubmittedReport = $db->select(); // $selectTotalSubmittedReport->from('report', 'count(*)') // ->where('state = "APPROVED"') // ->where('consumer_id = ?', $this->_currentUser->id); // $this->view->submittedReportAmount = $db->fetchOne($selectTotalSubmittedReport); if ($this->view->completedCampaignAmount < 1 || $this->_currentUser->pest != null && $this->_currentUser->pest == 1) { $this->_flashMessenger->addMessage($this->view->translate("Gift_can_not_redeem_gift")); $this->_flashMessenger->addMessage(true); $this->_redirect('gift/confirmcart'); return; } // check the point $selectUsablePoints = $db->select(); $selectUsablePoints->from('reward_point_transaction_record', 'SUM(point_amount)')->where("consumer_id = ?", $this->_currentUser->id); $usablePoints = (int) $db->fetchOne($selectUsablePoints); $amountSelectedProductPoint = 0; foreach ($cartNamespace->list as $product) { $selectSelectedProductPoint = $db->select(); $selectSelectedProductPoint->from('product', 'point')->where("id = " . $product['id']); $selectedProductPoint = (int) $db->fetchOne($selectSelectedProductPoint); $amountSelectedProductPoint += $product['amount'] * $selectedProductPoint; } if ($amountSelectedProductPoint > $usablePoints) { $this->_flashMessenger->addMessage($this->view->translate("Gift_have_no_enough_point")); $this->_flashMessenger->addMessage(true); $this->_redirect('gift/confirmcart'); return; } // save shipping info $consumerModel = new Consumer(); $id = $this->_currentUser->id; $consumer = $consumerModel->find($id)->current(); $consumer->recipients_name = $formData['recipients_name']; $consumer->phone = $formData['phone']; $consumer->address1 = $formData['address1']; $consumer->postalcode = $formData['postalcode']; if ($formData['city'] != null && $formData['province'] != null) { $consumer->city = $formData['city']; $consumer->province = $formData['province']; } if ($formData['englishcity'] != null) { $consumer->city = $formData['englishcity']; $consumer->province = null; } if ($formData['province'] == '' && $formData['englishcity'] == null) { $consumer->city = null; $consumer->province = null; } $consumer->save(); // save exchange records $currentTime = date("Y-m-d H:i:s"); $rewardPointTransactionRecordModel = new RewardPointTransactionRecord(); $prodcutOrderModel = new ProductOrder(); $notificationModel = new Notification(); $total_redeem_point = 0; foreach ($cartNamespace->list as $product) { // add records to reward_point_transaction_record table $rewardPointTransactionRecord = array("consumer_id" => $this->_currentUser->id, "DATE" => $currentTime, "transaction_id" => '4', "point_amount" => -$product['amount'] * $product['point']); $transactionRecordId = $rewardPointTransactionRecordModel->insert($rewardPointTransactionRecord); // add records to product_order table $prodcutOrder = array('consumer_id' => $this->_currentUser->id, 'product_id' => $product['id'], 'create_date' => $currentTime, 'state' => 'NEW', 'reward_point_transaction_record_id' => $transactionRecordId, 'amount' => $product['amount']); $prodcutOrderId = $prodcutOrderModel->insert($prodcutOrder); // roll back if an exception occurred // ... $total_redeem_point += $product['amount'] * $product['point']; } // add notification $notificationModel->createRecord("REDEEM_POINT", $this->_currentUser->id, $total_redeem_point); $this->paidGifts = $cartNamespace->list; $cartNamespace->list = null; // show redeem.phtml with "... Successfully" $this->_flashMessenger->addMessage("Gift_submit_orders_successfully"); $this->_flashMessenger->addMessage(false); $this->_flashMessenger->addMessage($this->paidGifts); $this->_redirect('gift/thankyou'); } else { $this->_redirect('gift/list'); } }
function adminprofilesurveyAction() { $profileSurvey = $this->_request->getParam('profileSurvey'); $consumerId = $this->_request->getParam('id'); $consumerArray = explode(',', $consumerId); $profileSurveyInvitation = new ProfileSurveyInvitation(); $notificationModel = new Notification(); foreach ($consumerArray as $consumer) { if ($consumer != '') { $invitation = $profileSurveyInvitation->fetchRow('consumer_id = ' . $consumer . ' and profile_id = ' . $profileSurvey); if (!count($invitation)) { $currentTime = date("Y-m-d H:i:s"); $row = $profileSurveyInvitation->createRow(); $row->consumer_id = $consumer; $row->profile_id = $profileSurvey; $row->date = $currentTime; $row->save(); // add notification $notificationModel->createRecord("PROFILE_SURVEY", $consumer, $profileSurvey); } } } $this->_helper->json('Success'); }