Guest User

Untitled

a guest
Nov 17th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. <?
  2. set_time_limit(99999);
  3. include "../../php/connect.php";
  4. include "../../config.php";
  5. ?>
  6. <script>
  7. alert("Запускаю проверку наличия товаров из прайса в каталоге.");
  8. </script>
  9. <?
  10. $test_left_q = mysqli_query($conn, "
  11. SELECT
  12. goods_update.art AS art_update,goods_update.brand AS brand_update,goods_update.name AS name_update,
  13. goods_update.price AS price_update,goods_update.sklad AS sklad_update,goods_update.id AS id_update,
  14. newgoods.art AS art_sklad,newgoods.brand AS brand_sklad,newgoods.sklad AS sklad_sklad,
  15. IF(newgoods.art IS NULL, 'false', 'true') AS test_sklad
  16. FROM goods_update
  17. LEFT OUTER JOIN newgoods ON goods_update.art = newgoods.art AND goods_update.sklad = newgoods.sklad
  18. ");
  19. $count_goods = 0;
  20. $count_deactive = 0;
  21. $count_active = 0;
  22. $count_roz_nal = 0;
  23. $count_price = 0;
  24. ?>
  25. <script>
  26. alert("Добавляю в каталог новый товар");
  27. </script>
  28. <?
  29. while ($test_left = mysqli_fetch_assoc($test_left_q)) {
  30. if ($test_left['test_sklad'] == "false") {
  31. $count_goods++;
  32. mysqli_query($conn, "
  33. INSERT INTO newgoods (name,brand,art,price,sklad,nal,price_date,roz_date,roz,active)
  34. SELECT name,brand,art,price,sklad,nal,CURDATE(),CURDATE(),CEIL(price*1.3),1
  35. FROM goods_update
  36. WHERE id = ". $test_left['id_update'] ."
  37. ");
  38.  
  39. }
  40. }
  41.  
  42. ?>
  43. <script>
  44. alert("Запускаю проверку наличия товаров из каталога в прайсе.");
  45. </script>
  46. <?
  47. $test_right_q = mysqli_query($conn, "
  48. SELECT
  49. goods_update.art AS art_update,goods_update.brand AS brand_update,goods_update.price AS price_update,
  50. newgoods.art AS art_sklad,newgoods.brand AS brand_sklad,newgoods.id AS id_sklad,newgoods.nal AS nal_sklad,
  51. IF(goods_update.art IS NULL, 'false', 'true') AS test_update
  52. FROM goods_update
  53. RIGHT OUTER JOIN newgoods ON goods_update.art = newgoods.art AND goods_update.sklad = newgoods.sklad
  54. ");
  55. ?>
  56. <script>
  57. alert("Запускаю обновление информацию о товаре.");
  58. </script>
  59. <?
  60. while ($test_right = mysqli_fetch_assoc($test_right_q)) {
  61. if ($test_right['test_update'] == "false" && $test_right['nal_sklad'] == 0) {
  62. $count_deactive++;
  63. mysqli_query($conn, "UPDATE newgoods SET active = 0 WHERE id = " . $test_right['id_sklad']);
  64. } else if ($test_right['test_update'] == "true") {
  65. if ($test_right['nal_sklad'] > 0) {
  66. $count_roz_nal++;
  67. mysqli_query($conn, "UPDATE newgoods SET roz = CEIL(".$test_right['price_update']."*1.3), roz_date = CURDATE() WHERE id = " . $test_right['id_sklad']);
  68. } else {
  69. $count_active++;
  70. $count_price++;
  71. mysqli_query($conn, "
  72. UPDATE newgoods
  73. SET price = ".$test_right['price_update'].",
  74. price_date = CURDATE(),
  75. roz = CEIL(".$test_right['price_update']."*1.3),
  76. roz_date = CURDATE(),
  77. active = 1
  78. WHERE id = " . $test_right['id_sklad']
  79. );
  80. }
  81. }
  82. }
  83. ?>
  84. <script>
  85. alert("Запускаю проверку актуальности каталога товаров.");
  86. </script>
  87. <?
  88. $test_roz_date_q = mysqli_query($conn, "SELECT id,roz_date,CURDATE() AS curdate FROM newgoods");
  89. ?>
  90. <script>
  91. alert("Обновление активности товара.");
  92. </script>
  93. <?
  94. while ($test_roz_date = mysqli_fetch_assoc($test_roz_date_q)) {
  95. $test_date = date_diff(new DateTime(), new DateTime($test_roz_date['roz_date']))->days;
  96. if ($test_date > 6) {
  97. $count_deactive++;
  98. mysqli_query($conn, "UPDATE newgoods SET active = 0 WHERE id = " . $test_roz_date['id']);
  99. }
  100. }
  101. echo "Добавил " . $count_goods . " карточек. n";
  102. echo "Деактивировал " . $count_deactive . " карточек. n";
  103. echo "Активировал " . $count_active . " карточек. n";
  104. echo "Обновил " . $count_roz_nal . " розничных цен. n";
  105. echo "Обновил " . $count_price . " закупочных цен. n";
  106. ?>
Add Comment
Please, Sign In to add comment