function setbonus() { $userbonus = $_REQUEST["userbonus"]; $bonussumm = $_REQUEST["bonussumm"]; $factpaid = $_REQUEST["factpaid"]; $deliverysum = $_REQUEST["deliverysum"]; $session = JFactory::getSession(); $session->set('userbonus', $userbonus, 'jbzoo'); $session->set('bonussumm', $bonussumm, 'jbzoo'); $session->set('factpaid', $factpaid, 'jbzoo'); $session->set('deliverysum', $deliverysum, 'jbzoo'); }
public function AddBonusToUsers() { $app = JFactory::getApplication('site'); $componentParams = $app->getParams('com_bonussystem'); $birthdaybonus = $componentParams->get('birthdaybonus', 200); $curday = date("d"); $curmonth = date("m"); $db = JFactory::getDBO(); $query = $db->getQuery(true); $query->select("user_id, profile_value"); $query->from('#__user_profiles'); $query->where("profile_key = 'profile.dob'"); $db->setQuery((string)$query); $results = $db->loadObjectList(); if ($results) { foreach($results as $result) { $birthdate = $result->profile_value; $birthdate = str_replace('"', '', $birthdate); $birthdate = explode("-",$birthdate); $birthday = $birthdate[2]; $birthmonth = $birthdate[1]; if (($birthday == $curday) AND ($birthmonth == $curmonth)) { $query = $db->getQuery(true); $query = "INSERT INTO #__user_bonus (user_id, order_id, bonus, bonusminus, factpaid, event, bonus_date, active) VALUES ('".$result->user_id."', '0', '".$birthdaybonus."', '0', '0', '".$birthdaybonus." бонусов на День Рождения', '".date('Y-m-d')."', '1')"; $db->setQuery((string)$query); $db->query(); } } }
$query = $db->getQuery(true); $query->select("bonus, event, bonusday, bonusmonth"); $query->from('#__user_bonus_rules'); $query->where("((bonusday = '".(int)$curday."') AND (bonusmonth = '".(int)$curmonth."'))"); $db->setQuery((string)$query); $result = $db->loadObject(); if ($result) { $query = $db->getQuery(true); $bonus = $result->bonus; $event = $result->event; $query = $db->getQuery(true); $query->select("user_id"); $query->from('#__user_profiles'); $query->where("user_id != '452'"); $db->setQuery((string)$query); $results = $db->loadObjectList(); if ($results) { foreach($results as $result) { $query = "INSERT INTO #__user_bonus (user_id, order_id, bonus, bonusminus, factpaid, event, bonus_date, active) VALUES ('".$result->user_id."', '0', '".$bonus."', '0', '0', '".$event."', '".date('Y-m-d')."', '1')"; $db->setQuery((string)$query); $db->query(); } } } echo "Начисление бонусов успешно завершено!"; }
$db = JFactory::getDBO(); $order_id = $this->orderId; if ($order_id > 0) { $query = $db->getQuery(true); $query->select("id"); $query->from('#__user_bonus'); $query->where("order_id = '".$order_id."'"); $db->setQuery((string)$query); $orderid = $db->loadObject(); $query = $db->getQuery(true); $query->select("elements, created_by"); $query->from('#__zoo_item'); $query->where("id = '".$order_id."'"); $db->setQuery((string)$query); $user_id = $db->loadObject(); $elements = json_decode($user_id->elements); $query = $db->getQuery(true); $query->select("SUM(factpaid) as totalfactpaid"); $query->from('#__user_bonus'); $query->where("((user_id = '".$user_id->created_by."') AND (active = '1'))"); $db->setQuery((string)$query); $result = $db->loadObject(); $totalfactpaid = $result->totalfactpaid; $userbonus = $elements->{"1af7e792-bcff-4a6c-9bdb-dd5023b0251a"}->userbonus; $bonussumm = $elements->{"1af7e792-bcff-4a6c-9bdb-dd5023b0251a"}->bonussumm; $factpaid = $elements->{"1af7e792-bcff-4a6c-9bdb-dd5023b0251a"}->factpaid; $deliverysum = $elements->{"1af7e792-bcff-4a6c-9bdb-dd5023b0251a"}->deliverysum; if ($bonussumm < $factpaid) $bonuscanuse = $bonussumm; else $bonuscanuse = $factpaid; if ($totalfactpaid > 15000) $bonuscanuse = intval($bonuscanuse / 1000) * 100; elseif ($totalfactpaid > 10000) $bonuscanuse = intval($bonuscanuse / 1000) * 70; elseif ($totalfactpaid > 5000) $bonuscanuse = intval($bonuscanuse / 1000) * 50; else $bonuscanuse = intval($bonuscanuse / 1000) * 30; }
if ($orderid) { $query = $db->getQuery(true); $query = "UPDATE #__user_bonus SET bonus_date = '".date('Y-m-d')."', active = '1' WHERE id = '".$orderid->id."'"; $db->setQuery((string)$query); $db->query(); } else { $query = $db->getQuery(true); $query = "INSERT INTO #__user_bonus (user_id, order_id, bonus, bonusminus, factpaid, event, bonus_date, active) VALUES ('".$user_id->created_by."', '".$order_id."', '".$bonuscanuse."', '".$userbonus."', '".$factpaid."', 'Оплата заказа №".$order_id."', '".date('Y-m-d')."', '1')"; $db->setQuery((string)$query); $db->query(); }
$("#bonuscheckbox").removeAttr("checked"); countbonus(); userbonus = 0; applybonus(); else $totalsumm = $this->orderDetails->getTotalPrice();
$session = JFactory::getSession(); $userbonusarr = $session->get('items-' . $this->getItem()->id . '-' . $this->identifier, '0', 'ElementJBBasketItems'); $userbonus = $userbonusarr["userbonus"]; $deliverysum = $userbonusarr["deliverysum"];
4.1 замена строки return round($summa, 2); на return round($summa - $userbonus + $deliverysum, 2);
$db = JFactory::getDBO(); $order_id = $this->getItem()->id; if ($order_id > 0) { $query = $db->getQuery(true); $query->select("id"); $query->from('#__user_bonus'); $query->where("order_id = '".$order_id."'"); $db->setQuery((string)$query); $orderid = $db->loadObject(); $query = $db->getQuery(true); $query->select("elements, created_by"); $query->from('#__zoo_item'); $query->where("id = '".$order_id."'"); $db->setQuery((string)$query); $user_id = $db->loadObject(); $elements = json_decode($user_id->elements); $query = $db->getQuery(true); $query->select("SUM(factpaid) as totalfactpaid"); $query->from('#__user_bonus'); $query->where("((user_id = '".$user_id->created_by."') AND (active = '1'))"); $db->setQuery((string)$query); $result = $db->loadObject(); $totalfactpaid = $result->totalfactpaid; $userbonus = $elements->{"1af7e792-bcff-4a6c-9bdb-dd5023b0251a"}->userbonus; $bonussumm = $elements->{"1af7e792-bcff-4a6c-9bdb-dd5023b0251a"}->bonussumm; $factpaid = $elements->{"1af7e792-bcff-4a6c-9bdb-dd5023b0251a"}->factpaid; //$deliverysum = $elements->{"1af7e792-bcff-4a6c-9bdb-dd5023b0251a"}->deliverysum; if ($bonussumm < $factpaid) $bonuscanuse = $bonussumm; else $bonuscanuse = $factpaid; if ($totalfactpaid > 15000) $bonuscanuse = intval($bonuscanuse / 1000) * 100; elseif ($totalfactpaid > 10000) $bonuscanuse = intval($bonuscanuse / 1000) * 70; elseif ($totalfactpaid > 5000) $bonuscanuse = intval($bonuscanuse / 1000) * 50; else $bonuscanuse = intval($bonuscanuse / 1000) * 30; if ($orderInfo["status"] == "paid") { if ($orderid) { $query = $db->getQuery(true); $query = "UPDATE #__user_bonus SET bonus_date = '".date('Y-m-d')."', active = '1' WHERE id = '".$orderid->id."'"; $db->setQuery((string)$query); $db->query(); } else { $query = $db->getQuery(true); $query = "INSERT INTO #__user_bonus (user_id, order_id, bonus, bonusminus, factpaid, event, bonus_date, active) VALUES ('".$user_id->created_by."', '".$order_id."', '".$bonuscanuse."', '".$userbonus."', '".$factpaid."', 'Оплата заказа №".$this->getItem()->id."', '".date('Y-m-d')."', '1')"; $db->setQuery((string)$query); $db->query(); } } else { if ($orderid) { $query = $db->getQuery(true); $query = "UPDATE #__user_bonus SET active = '0' WHERE order_id = '".$order_id."'"; $db->setQuery((string)$query); $db->query(); } else { $query = $db->getQuery(true); $query = "INSERT INTO #__user_bonus (user_id, order_id, bonus, bonusminus, factpaid, event, bonus_date, active) VALUES ('".$user_id->created_by."', '".$order_id."', '".$bonuscanuse."', '".$userbonus."', '".$factpaid."', 'Оплата заказа №".$this->getItem()->id."', '".date('Y-m-d')."', '0')"; $db->setQuery((string)$query); $db->query(); } } }
$session = JFactory::getSession(); $userbonus = $session->get('userbonus', '0', 'jbzoo'); $bonussumm = $session->get('bonussumm', '0', 'jbzoo'); $factpaid = $session->get('factpaid', '0', 'jbzoo'); $deliverysum = $session->get('deliverysum', '0', 'jbzoo'); if ($userbonus > 0) $saveData["userbonus"] = $userbonus; if ($bonussumm > 0) $saveData["bonussumm"] = $bonussumm; if ($factpaid > 0) $saveData["factpaid"] = $factpaid; if ($deliverysum > 0) $saveData["deliverysum"] = $deliverysum;
$db = JFactory::getDBO(); $curuser =& JFactory::getUser(); $session = JFactory::getSession(); $userbonusarr = $session->get('items-' . $this->getItem()->id . '-' . $this->identifier, '0', 'ElementJBBasketItems'); $userbonus = $userbonusarr["userbonus"]; $deliverysum = $userbonusarr["deliverysum"]; if ($userbonus == "") $userbonus = 0; $query = $db->getQuery(true); $query->select("SUM(bonus) as bonus"); $query->from('#__user_bonus'); $query->where("((user_id = '".$curuser->id."') AND (bonus_date < '".date('Y-m-d')."') AND (active = '1'))"); $db->setQuery((string)$query); $result = $db->loadObject(); $totalbonus = $result->bonus; $query = $db->getQuery(true); $query->select("SUM(bonusminus) as bonusminus"); $query->from('#__user_bonus'); $query->where("((user_id = '".$curuser->id."') AND (active = '1'))"); $db->setQuery((string)$query); $result = $db->loadObject(); $totalbonus -= $result->bonusminus;
<tfoot> <tr id="trbonus"> <td colspan="4"> </td> <td colspan="2">Использовано <?php echo $userbonus ?> бонусов</td> </tr> <tr> <td colspan="3"> </td> <td><strong><?php echo JText::_('JBZOO_CART_TOTAL'); ?>:</strong></td> <td class="jsTotalCount"><?php echo $count; ?></td> <td class="jsTotalPrice"><?php echo $this->app->jbmoney->toFormat($summa, $currency); ?></td> </tr> <tr> <td colspan="3"> </td> <td colspan="2"><strong>Стоимость доставки:</strong></td> <td><?php echo $this->app->jbmoney->toFormat($deliverysum, $currency); ?></td> </tr> <tr id="tritogo"> <td colspan="3"> </td> <td colspan="2"><strong>ИТОГО:</strong></td> <td><?php echo $this->app->jbmoney->toFormat($summa - $userbonus + $deliverysum, $currency); ?></td> </tr> </tfoot>
6. zoo/jbuniversal/templates/catalog/render/basket/_default.php
?> <script type="text/javascript"> var elweightarr = []; </script><?php $db = JFactory::getDBO(); $curuser =& JFactory::getUser(); $session = JFactory::getSession(); $userbonus = $session->get('userbonus', '0', 'jbzoo'); $query = $db->getQuery(true); $query->select("SUM(bonus) as bonus"); $query->from('#__user_bonus'); $query->where("((user_id = '".$curuser->id."') AND (bonus_date < '".date('Y-m-d')."') AND (active = '1'))"); $db->setQuery((string)$query); $result = $db->loadObject(); $totalbonus = $result->bonus; $query = $db->getQuery(true); $query->select("SUM(bonusminus) as bonusminus"); $query->from('#__user_bonus'); $query->where("((user_id = '".$curuser->id."') AND (active = '1'))"); $db->setQuery((string)$query); $result = $db->loadObject(); $totalbonus -= $result->bonusminus; $bonuscanuse = 0;
$curelement = $item->getElement('b0d2b218-87a9-4573-85b7-350d2eec1061'); $data = (array)$curelement->data(); if ($data['basic']['discount'] == 0) $bonusclass = "hasbonus"; else $bonusclass = ""; $elementweight = $item->getElement('1a81724a-b570-4f7f-9bca-27781a86013b'); $data2 = (array)$elementweight->data(); $weight = $data2['0']['value']; $totalweight += $weight * $basketItem['quantity']; ?> <script type="text/javascript"> elweightarr[<?php echo $i ?>] = <?php echo $weight ?>; </script> <?php
$summa20 = $summa * 0.2; if ($summa20 > 10) { if ($summa20 >= $totalbonus) $bonuscanuse = $totalbonus; else { $bonuscanuse = intval($summa20 / 10) * 10; } }
6.6
<tr> <td colspan="4"> </td> <td id="tdbonuscanuse" colspan="3"><strong>Использовать <?php echo $bonuscanuse ?> бонусов</strong></td> <td><center><input type="checkbox" id="bonuscheckbox" name="bonuscheckbox" onclick="applybonus()" <?php if ($userbonus > 0) {echo "checked=\"checked\"";} ?>/></center></td> </tr> <tr> <td colspan="4"> </td> <td id="tddeliverytext" colspan="2"><strong>Стоимость доставки</strong></td> <td id="tddelivery" colspan="2">0 р.</td> </tr> <tr> <td colspan="4"> </td> <td colspan="2"><strong>Общий вес (кг)</strong></td> <td id="tdweight" colspan="2"><?php echo $totalweight ?></td> </tr> <tr> <td colspan="4"> </td> <td id="tdbonuscanuse" colspan="2"><strong>ИТОГО</strong></td> <td id="tditogo" colspan="2"><?php echo $this->app->jbmoney->toFormat($summa, $currencyConvert); ?></td> </tr>
6.7
var userbonus = <?php echo $userbonus ?>; var totalbonus = <?php echo $totalbonus ?>; var summa20 = 0; var bonuscanuse = 0; var totalsum = 0; var newtotalsum = 0; var factpaid = 0; var bonussumm = 0; var deliverytype1 = ""; var deliverytype2 = ""; var itogo = 0; var delivery = 0; var weight = 0; var emsstat = ""; var emsprice = 0; var emsmin = 0; var emsmax = 0; function countbonus() { totalsum = parseFloat(jQuery("#jbzoo td.jsTotalPrice").html().replace(/ р./, '').replace(/,/, '.').replace(/ /, '')); summa20 = round(totalsum * 0.2,2); bonuscanuse = 0; if (summa20 > 10) { if (summa20 >= totalbonus) bonuscanuse = totalbonus; else { bonuscanuse = parseInt(summa20 / 10) * 10; } } jQuery("#tdbonuscanuse").html("<strong>Использовать " + bonuscanuse + " бонусов</strong>"); return bonuscanuse; } function applybonus() { weight = 0; jQuery('.hasbonus').each(function(i, el) { bonussumm += parseFloat(jQuery(el).html().replace(/ р./, '').replace(/,/, '.').replace(/ /, '')); }); jQuery('#jbzoo input.input-quantity').each(function(i, el) { weight += round(elweightarr[i] * parseFloat(jQuery(el).val()),3); }); deliverytype1 = jQuery('select[name="elements[37d3a0c7-9446-48ff-a0a1-7476aef328b8][0][list-0]"] option:selected').val(); deliverytype2 = jQuery('select[name="elements[37d3a0c7-9446-48ff-a0a1-7476aef328b8][0][list-1]"] option:selected').val(); if (jQuery("#bonuscheckbox").prop("checked")) { userbonus = countbonus(); newtotalsum = round(totalsum - bonuscanuse,2); } else { totalsum = parseFloat(jQuery("#jbzoo td.jsTotalPrice").html().replace(/ р./, '').replace(/,/, '.').replace(/ /, '')); newtotalsum = totalsum; userbonus = 0; } switch (deliverytype1) { case "Самовывоз" : {jQuery("#tddelivery").html("0 р."); delivery = 0; jQuery("#tddeliverytext").html("<strong>Стоимость доставки</strong>"); break;} case "Доставка курьером" : {jQuery("#tddeliverytext").html("<strong>Стоимость доставки</strong>"); switch (deliverytype2) { case "Доставка по г. Самара" : { if (newtotalsum > 2000) {jQuery("#tddelivery").html("0 р."); delivery = 0;} else {jQuery("#tddelivery").html("150 р."); delivery = 150;}; break;} case "п.Запанской, п.Мясокомбинат,Зубчаниновка от ул.Магистральной до поста ДПС" : {jQuery("#tddelivery").html("200 р."); delivery = 200; break;} case "п.Красная Глинка, п.Сухая Самарка, п.Мехзавод, п.Управленческий, 116-й км, п.Смышляевка" : {jQuery("#tddelivery").html("350 р."); delivery = 350; break;} case "с.Красный Яр, с.Малая Царевщина, п.Волжский" : {jQuery("#tddelivery").html("680 р."); delivery = 680; break;} case "г.Кинель, с.Курумоч" : {jQuery("#tddelivery").html("765 р."); delivery = 765; break;} case "г.Тольятти" : {jQuery("#tddelivery").html("1 400 р."); delivery = 1400; break;} case "г.Отрадный, г.Жигулевск" : {jQuery("#tddelivery").html("1 600 р."); delivery = 1600; break;} case "г.Нефтегорск" : {jQuery("#tddelivery").html("1 760 р."); delivery = 1760; break;} case "г.Сергиевск" : {jQuery("#tddelivery").html("2 050 р."); delivery = 2050; break;} case "г.Сызрань" : {jQuery("#tddelivery").html("2 900 р."); delivery = 2900; break;} default : {jQuery("#tddelivery").html("0 р."); delivery = 0; break;} }; break;} case "Доставка почтой ЕМС" : {delivery = 0; applyems(weight); break;} default : {jQuery("#tddelivery").html("0 р."); delivery = 0; break;} }; itogo = newtotalsum + delivery; jQuery("#tditogo").html(itogo + " р."); jQuery("#tdweight").html(round(weight,3)); jQuery.ajax({ type: "POST", url: "index.php?option=com_zoo&controller=basket&task=setbonus", data: "userbonus=" + userbonus + "&bonussumm=" + bonussumm + "&factpaid=" + newtotalsum + "&deliverysum=" + delivery, dataType: 'html', async: false }); } function round(a,b) { b=b || 0; return Math.round(a*Math.pow(10,b))/Math.pow(10,b); } function applyems(weight) { if (deliverytype1 == "Доставка почтой ЕМС") { from = "city--samara"; to = "city--" + jQuery('select[name="elements[fe492a91-951e-4e06-9054-3df8af796f8a][option][]"] option:selected').val(); jQuery.ajax({ type: "GET", url: "http://emspost.ru/api/rest?method=ems.calculate&from=" + from + "&to=" + to + "&weight=" + weight + "", dataType: 'jsonp', crossDomain: true, async: false, success: function(data){ emsstat = data.rsp.stat; if (emsstat == "ok") { emsprice = data.rsp.price; emsmin = data.rsp.term.min; emsmax = data.rsp.term.max; jQuery("#tddeliverytext").html("<strong>Стоимость доставки</strong><br />от " + emsmin + " до " + emsmax + " дней"); jQuery("#tddelivery").html(emsprice + " р."); itogo = parseFloat(newtotalsum) + parseFloat(emsprice); jQuery("#tditogo").html(itogo + " р."); jQuery.ajax({ type: "POST", url: "index.php?option=com_zoo&controller=basket&task=setbonus", data: "userbonus=" + userbonus + "&bonussumm=" + bonussumm + "&factpaid=" + newtotalsum + "&deliverysum=" + emsprice, dataType: 'html', async: false }); } else { alert("При обращении к серверу EMS произошла ошибка! (" + data.rsp.err.code + "): " + data.rsp.err.msg); } } }); } } jQuery(document).ready(function () { applybonus(); jQuery('select[name="elements[37d3a0c7-9446-48ff-a0a1-7476aef328b8][0][list-1]"]').change(function(){ applybonus(); }); jQuery('select[name="elements[fe492a91-951e-4e06-9054-3df8af796f8a][option][]"]').change(function(){ applyems(weight); }); });
7. components/com_users/models/registration.php
Что делаем - Начисление бонусов за регистрацию
$app = JFactory::getApplication('site'); $componentParams = $app->getParams('com_bonussystem'); $bonus = $componentParams->get('birthdaybonus', 200); $query = "INSERT INTO #__user_bonus (user_id, order_id, bonus, bonusminus, factpaid, event, bonus_date, active) VALUES ('".$userId."', '0', '".$bonus."', '0', '0', '".$bonus." бонусов за регистрацию', '".date('Y-m-d')."', '1')"; $db->setQuery((string)$query); $db->query();
Пояснение по используемым id
Прикрепленные файлы
Сообщение отредактировал Giadastar: 15 May 2014 - 20:25