Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     use \Functions\Functions;
  3.     $incomes = new CasesIncomes();
  4.     $incomes = $incomes->data;
  5. ?>
  6. <h2>Предметы на складе (Цены: 100% от площадки Steam)</h2>
  7.  
  8. <div class="row" id="stock">
  9.     <?php
  10.         $paid_for_skins_total = 0;
  11.         foreach ($model->cases as $key => $case):
  12.         if (count($case['items']) == 0) continue;
  13.         $income = $incomes[$case['id']];
  14.     ?>
  15.         <form method="POST" action="">
  16.         <div class="row case">
  17.             <input type="hidden" name="case_id" value="<?=$case['id']?>">
  18.             <div class="col-lg-22">
  19.  
  20.             <h2 id="<?=$case['static_name']?>"><button class="items-toggler"> - </button>&nbsp<?=$case['name_en']?> - $<?=$case['price_usd']?> USD
  21.                 <span class="case-info">[Предметов в кейсе: <div class="case-items-count inline-div"><?=$case['current_count']?></div>, маржа: <div class="case-percentage inline-div"><?=Functions::format_number($income['percentage'])?></div>%]</span>
  22.             </h2>
  23.             <div class="items">
  24.             <?php foreach ($case['items'] as $key => $item): ?>
  25.             <?php
  26.                 $paid_for_skins_total += $item['price']/* * 0.8*/;
  27.                 //$item_data = $case['case']->get_item_data($item['market_hash_name']);
  28.                 $item_data = array();
  29.             ?>
  30.             <div class="row item" style="font-size: 150%">
  31.                 <div class="col-lg-2 text-right item-count-div"><?=$item['count']?></div>
  32.                 <div class="col-lg-2 text-center">
  33.                     <div class="row">
  34.                     <img src="http://steamcommunity-a.akamaihd.net/economy/image/<?php echo $item['img']; ?>/64fx64f" title="<?php echo $item['firstname']; ?> | <?php echo $item['secondname']; ?>" alt="<?php echo $item['market_hash_name']; ?>" class="<?php echo $item['rarity']; ?>">
  35.                     </div>
  36.                     <div class="row price">
  37.                         $<?=Functions::format_number($item['price']/* * 0.8*/)?> USD
  38.                     </div>
  39.                 </div>
  40.                 <div class="col-lg-9 col-lg-push-1 text-left">
  41.                     <div class="row market_hash_name"><?php echo $item['market_hash_name']; ?></div>
  42.                     <!--
  43.                         <div class="row">В кейсе: <?=$item_data['cnt']?> шт. Шанс: <?=$item_data['percentage']?>%</div>
  44.                     -->
  45.                 </div>
  46.                 <div class="col-lg-6">
  47.                     <input type="number" min="0" max="<?=$item['count']?>" value=0 name="skins[<?=$item['market_hash_name']?>]"> <span class="select-all-label">Все</span>
  48.                 </div>
  49.             </div>
  50.             <?php endforeach; ?>
  51.             <a href="#<?=$case['static_name']?>" class="a-top">В начало <?=$case['name_en']?></a>
  52.             </div>
  53.             </div>
  54.             <div class="col-lg-8 to-case-box">
  55.                 <div class="row text-center">
  56.                     <button class="btn btn-primary btn-lg btn-to-case">Отправить в кейс</button>
  57.                 </div>             
  58.                 <div class="row text-center">
  59.                     <span class="case-name" name="<?=$case['static_name']?>"><?=$case['name_en']?></span>
  60.                 </div>
  61.                 <?php if ($member_id->user_id == 1 || $member_id->user_id == 2): ?>
  62.                 <div class="row text-center">
  63.                     <a onclick="select_all(this); return false;" href="#">ALL</a>
  64.                 </div>
  65.                 <?php endif; ?>
  66.             </div>
  67.         </div>
  68.         </form>
  69.     <?php endforeach; ?>
  70. </div>
  71. <div class="paid_total_amount" style="margin: 30px 0">
  72.     <div class="row">
  73.         <div class="col-lg-30 text-center">
  74.             <span style="font-size: 160%">Цена всех предметов на складе: $<?=Functions::format_number($paid_for_skins_total/* * 0.7*/)?> USD
  75.             </span>
  76.         </div>
  77.     </div>
  78. </div>
  79.  
  80. <div class="cases-bottom-list case">
  81.     <div class="items">
  82.         <?php foreach ($model->cases as $key => $case):?>
  83.             <?php if (count($case['items']) == 0) continue; ?>
  84.             <a href="#<?=$case['static_name']?>"><?=$case['name_en']?></a>
  85.         <?php endforeach; ?>
  86.     </div>
  87.     <div style="padding:10px;">
  88.         <button class="to_top btn btn-primary btn-lg" style="width:100%; margin-bottom:3px">Наверх</button>
  89.         <button class="to_bot btn btn-primary btn-lg" style="width:100%">Вниз</button>
  90.         <!--<button class="items-toggler btn btn-primary btn-lg">-</button>!-->
  91.     </div>
  92. </div>
  93.  
  94. <script>
  95.    
  96.     $( document ).ready(function() {
  97.  
  98.  
  99.     function select_all(el) {
  100.         var inputs = $(el).parent().parent().prev().find('input[type=number]');
  101.         $(inputs).each(function(index, item) {
  102.             $(item).val($(item).attr('max'));
  103.         });
  104.     }
  105.  
  106.  
  107.     $('.select-all-label').on('click', function() {
  108.         $(this).prev().val($(this).prev().attr('max'));
  109.     });
  110.    
  111.  
  112.     $('.btn-to-case').on('click', function() {
  113.  
  114.         var MAX_COUNT_TO_SEND = 10;
  115.  
  116.         var send_count = 1;
  117.  
  118.         $('#loading_bg').addClass('active');
  119.  
  120.         var form = $(this).closest('form');
  121.         var prev_form = form.prev();
  122.         var skins = [];
  123.  
  124.         var items = form.find('.items > .item');
  125.         items.each(function(item) {
  126.             if ($(this).find('input[type="number"]').val() > 0) {
  127.                 skins.push({'market_hash_name' : $(this).find('.market_hash_name').text(),
  128.                         'count' : $(this).find('input[type="number"]').val()});
  129.             }
  130.         });
  131.  
  132.         var case_id = parseInt(form.find('input[name="case_id"]').val());
  133.  
  134.         var partsArr = [];
  135.         var parts_count = Math.ceil(skins.length / MAX_COUNT_TO_SEND);
  136.         //console.log('parts_count : ' + parts_count);
  137.         //console.log('parts_count : ' + parts_count);
  138.         partsArr = array_chunk(skins, MAX_COUNT_TO_SEND); // разбиваем массив на 10 частей
  139.         partsArr.forEach(function(item, i, partsArr) {
  140.             sendItems(item, case_id, parts_count);
  141.         });
  142.  
  143.         return false;
  144.  
  145.         function sendItems(skins, case_id, _count, small_count) {
  146.  
  147.             $.ajax({
  148.               url: '<?=$this->router->generate('stock_test')?>?drop_to_inventory',
  149.               type: 'POST',
  150.               dataType: 'json',
  151.               data: {
  152.                 'skins': skins,
  153.                 'case_id': case_id,
  154.               },
  155.  
  156.               success: function(data) {
  157.  
  158.                 /*
  159.                 console.log('skins : ' + skins);
  160.                 console.log('i : ' + send_count);
  161.                 console.log('count : ' + _count);
  162.                 */
  163.  
  164.                 $('#loading_bg p').text('Отправлено: ' + send_count + ' из ' + _count);
  165.  
  166.                 form.find('.case-items-count').text(data.current_count);
  167.                 var items = form.find('.items > .item');
  168.                 form.find('.case-percentage').text(data.percentage);
  169.                 items.each(function() {
  170.                     var input = $(this).find('input[type="number"]');
  171.                     var count = input.val();
  172.                     var new_count = input.attr('max') - count;
  173.                     input.attr('max', new_count);
  174.                     $(this).find('.col-lg-2.text-right').text(new_count);
  175.                     input.val(0);
  176.  
  177.                     var our_items = $('input[name="'+input.attr('name')+'"]');
  178.  
  179.                     our_items.each(function(){
  180.                         $(this).attr('max', new_count);
  181.                         $(this).val(0);
  182.                         $(this).closest('.item').find('.item-count-div').text(new_count);
  183.                         if (new_count == 0)
  184.                             $(this).closest('.item').remove();
  185.                         var _form = $(this).closest('form');
  186.                         if (_form.find('.items > .item').length < 1) {
  187.                             _form.remove();
  188.                             $('.cases-bottom-list a[href="#'+_form.find('h2').attr('id')+'"]').remove();
  189.                         }
  190.                     });
  191.                     if (new_count == 0)
  192.                         $(this).remove();
  193.  
  194.                 });
  195.  
  196.                 if (form.find('.items > .item').length < 1) {
  197.                     form.remove();
  198.                     $('.cases-bottom-list a[href="#'+form.find('h2').attr('id')+'"]').remove();
  199.                     $("html, body").scrollTop(prev_form.find('h2').offset().top-60);
  200.                 }
  201.                
  202.                 $("html, body").scrollTop(form.find('h2').offset().top-60);
  203.  
  204.                 if (send_count == _count) {
  205.                     setTimeout(function() {
  206.                         $('#loading_bg').removeClass('active');
  207.                         $('#loading_bg p').text('');
  208.                         getNotification('send-item');
  209.                     }, 5000);
  210.                 }
  211.  
  212.                 send_count++;
  213.  
  214.               },
  215.  
  216.               error: function(name, xhr) {
  217.                 alert('Unexpected error. Please check your console.');
  218.                 console.log(name, xhr);
  219.                 if (send_count == _count) {
  220.                     $('#loading_bg').removeClass('active');
  221.                     $('#loading_bg p').text('');
  222.                 }
  223.               }
  224.  
  225.             });
  226.         }
  227.  
  228.     });
  229.  
  230.     function array_chunk(input, size) {  
  231.         for(var x, i = 0, c = -1, l = input.length, n = []; i < l; i++) {
  232.             (x = i % size) ? n[c][x] = input[i] : n[++c] = [input[i]];
  233.         }
  234.         return n;
  235.     }
  236.  
  237. });
  238.  
  239.  
  240. </script>
  241.  
  242.  
  243.  
  244. <div class="notification_box success" id="notification-send-item-box">
  245.     <div class="head">
  246.         <i class="icon icon-success-white"></i>
  247.         <h3>Готово!</h3>
  248.     </div>
  249.     <p>Предметы успешно отправлены в кейс</p>
  250. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement