Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. BEGIN
  2. DECLARE _payment VARCHAR(5) DEFAULT '';
  3. DECLARE _column_id INT DEFAULT 0;
  4. DECLARE _time INT DEFAULT 0;
  5. DECLARE _group_id INT DEFAULT 0;
  6. DECLARE _zone_id INT DEFAULT 0;
  7. DECLARE _notify_sms INT DEFAULT 0;
  8. DECLARE _is_important INT DEFAULT 0;
  9. DECLARE _with_driver INT DEFAULT 0;
  10. DECLARE _loaders_count INT DEFAULT 0;
  11. DECLARE _car_type INT DEFAULT 0;
  12. DECLARE _client_id INT DEFAULT 0;
  13. DECLARE _consider_curator INT DEFAULT 0;
  14. DECLARE _is_coordinator BOOLEAN DEFAULT FALSE;
  15. DECLARE _exist_user_coordinator BOOLEAN DEFAULT FALSE;
  16. DECLARE _result INT DEFAULT 0;
  17.  
  18. SELECT
  19. o.`payment`,
  20. o.`column_id`,
  21. o.`zone_id`,
  22. o.`notify_sms`,
  23. c.`is_important`,
  24. IF(o.`driver_id` > 0, 1, 0),
  25. o.`cargo_count`,
  26. o.`vehicle_type_id`,
  27. o.`client_id`
  28. INTO
  29. _payment,
  30. _column_id,
  31. _zone_id,
  32. _notify_sms,
  33. _is_important,
  34. _with_driver,
  35. _loaders_count,
  36. _car_type,
  37. _client_id
  38. FROM
  39. `orders` as o
  40. JOIN
  41. `clients` as c ON c.`id` = o.`client_id`
  42. WHERE
  43. o.`id` = order_id
  44. LIMIT 1;
  45.  
  46. SELECT
  47. u.`group_id`,
  48. u.`is_coordinator`
  49. INTO
  50. _group_id,
  51. _is_coordinator
  52. FROM
  53. `users` as u
  54. WHERE
  55. u.`id` = user_id
  56. LIMIT 1;
  57.  
  58. SELECT
  59. IF(time_type = 1,o.`time_visibility`,o.`time_assignment`),
  60. o.consider_curator
  61. INTO
  62. _time,
  63. _consider_curator
  64. FROM
  65. `orders_scopes` as o
  66. WHERE
  67. (o.`payment_types` LIKE CONCAT('%| ',_payment,' |%') OR o.`payment_types` LIKE '%-1%') AND
  68. (o.`column_ids` LIKE CONCAT('%| ',_column_id,' |%') OR o.`column_ids` LIKE '%-1%') AND
  69. (o.`group_ids` LIKE CONCAT('%| ',_group_id,' |%') OR o.`group_ids` LIKE '%-1%') AND
  70. (o.`zone_ids` LIKE CONCAT('%| ',_zone_id,' |%') OR o.`zone_ids` LIKE '%-1%') AND
  71. (o.`notify_sms` LIKE CONCAT('%| ',_notify_sms,' |%') OR o.`notify_sms` LIKE '%-1%') AND
  72. (o.`important_client` LIKE CONCAT('%| ',_is_important,' |%') OR o.`important_client` LIKE '%-1%') AND
  73. (o.`with_driver` LIKE CONCAT('%| ',_with_driver,' |%') OR o.`with_driver` LIKE '%-1%') AND
  74. (o.`loaders_count` LIKE CONCAT('%| ',_loaders_count,' |%') OR o.`loaders_count` LIKE '%-1%') AND
  75. (o.`car_types` LIKE CONCAT('%| ',_car_type,' |%') OR o.`car_types` LIKE '%-1%')
  76. ORDER BY
  77. o.`id` DESC
  78. LIMIT 1;
  79.  
  80. IF (_consider_curator = TRUE) THEN
  81. IF (_is_coordinator = TRUE) THEN
  82. SELECT EXISTS(
  83. SELECT 1 FROM client_user_coordinator
  84. WHERE `client_user_coordinator`.`client_id` = _client_id AND `client_user_coordinator`.`user_id` = user_id
  85. LIMIT 1
  86. )
  87. INTO
  88. _exist_user_coordinator;
  89. IF (_exist_user_coordinator = TRUE) THEN
  90. SET _result = _time;
  91. END IF;
  92. END IF;
  93. ELSE
  94. SET _result = _time;
  95. END IF;
  96.  
  97. RETURN _result;
  98. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement