activity_helper.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/8/14
  6. * Time: 下午5:27
  7. */
  8. require_once (BASE_ROOT_PATH . '/helper/activity/groupbuy.php');
  9. require_once (BASE_ROOT_PATH . '/helper/activity/limitime.php');
  10. require_once (BASE_ROOT_PATH . '/helper/activity/bundling.php');
  11. require_once (BASE_ROOT_PATH . '/helper/activity/recommend_combo.php');
  12. require_once (BASE_ROOT_PATH . '/helper/activity/full_sent.php');
  13. require_once (BASE_ROOT_PATH . '/helper/activity/recommend_goods.php');
  14. require_once (BASE_ROOT_PATH . '/helper/activity/goods_gift.php');
  15. require_once (BASE_ROOT_PATH . '/helper/activity/version_checker.php');
  16. require_once (BASE_ROOT_PATH . '/helper/algorithm.php');
  17. function less_endtime($left,$right)
  18. {
  19. $l_end = intval($left['end_time']);
  20. $r_end = intval($right['end_time']);
  21. if($l_end > $r_end) {
  22. return 1;
  23. }
  24. elseif($l_end == $r_end) {
  25. return 0;
  26. }
  27. else {
  28. return -1;
  29. }
  30. }
  31. function less_startime($left,$right)
  32. {
  33. $l_start = intval($left['start_time']);
  34. $r_start = intval($right['start_time']);
  35. if($l_start > $r_start) {
  36. return 1;
  37. }
  38. elseif($l_start == $r_start) {
  39. return 0;
  40. }
  41. else {
  42. return -1;
  43. }
  44. }
  45. //抢,限,推,套装,三个信息会出现在商品的summary 中,其余的出现在商品的详细信息中
  46. class activity_helper
  47. {
  48. const ACTIVITY_NONE = 0;
  49. const ACTIVITY_GROUPBUY = 1; //抢
  50. const ACTIVITY_LIMITTIME = 2; //限
  51. const ACTIVITY_BUNDLING = 3; //套装
  52. public static function take_parted($goods_id,&$act_type)
  53. {
  54. if(activity\groupbuy::instance()->isTakepart($goods_id,$act_id)) { //抢购
  55. $act_type = self::ACTIVITY_GROUPBUY;
  56. return $act_id;
  57. }
  58. elseif(activity\limitime::instance()->isTakepart($goods_id,$act_id)) { //
  59. $act_type = self::ACTIVITY_LIMITTIME;
  60. return $act_id;
  61. }
  62. else {
  63. $act_type = self::ACTIVITY_NONE;
  64. return false;
  65. }
  66. }
  67. public static function have_recommend($goods_id)
  68. {
  69. if (activity\recommend_goods::instance()->isTakepart($goods_id)) {
  70. return true;
  71. } else {
  72. return false;
  73. }
  74. }
  75. public static function have_bundling($goods_id) {
  76. return activity\bundling::instance()->have_bundling($goods_id);
  77. }
  78. public static function bundling_goods($bl_id) {
  79. return activity\bundling::instance()->bundling_goods($bl_id);
  80. }
  81. //赠品信息
  82. public static function have_gift($goods_id) {
  83. return activity\goods_gift::instance()->have_gift($goods_id);
  84. }
  85. public static function goods_gifts($goods_id) {
  86. return activity\goods_gift::instance()->gifts($goods_id);
  87. }
  88. public static function goods_giftids($goods_id) {
  89. return activity\goods_gift::instance()->goods_giftids($goods_id);
  90. }
  91. //商品组合
  92. public static function have_combo($goods_id) {
  93. return activity\recommend_combo::instance()->have_combo($goods_id);
  94. }
  95. public static function combo_goods($goods_id) {
  96. return activity\recommend_combo::instance()->combo_goods($goods_id);
  97. }
  98. //满赠活动
  99. public static function fullsent_rules() {
  100. return activity\full_sent::instance()->rules();
  101. }
  102. //包邮信息
  103. public static function free_ship() {
  104. return activity\full_sent::instance()->free_price();
  105. }
  106. //推荐商品列表
  107. public static function recomoned_goodsids()
  108. {
  109. return activity\recommend_goods::instance()->goods_ids();
  110. }
  111. public static function limit_goods($limit_id)
  112. {
  113. return activity\limitime::instance()->goods($limit_id);
  114. }
  115. public static function groupbuy_goods($group_id)
  116. {
  117. return activity\groupbuy::instance()->goods($group_id);
  118. }
  119. public static function acting()
  120. {
  121. $limits = activity\limitime::instance()->acting();
  122. $groupbuys = activity\groupbuy::instance()->acting();
  123. // $x = count($limits);
  124. // $y = count($groupbuys);
  125. // Log::record("activity_helper::acting limit = {$x} groupbuy = {$y}",Log::DEBUG);
  126. $values = [];
  127. foreach ($limits as $val) {
  128. $values[] = $val;
  129. }
  130. foreach ($groupbuys as $val) {
  131. $values[] = $val;
  132. }
  133. $result = [];
  134. if(!empty($values))
  135. {
  136. uasort($values,'less_endtime');
  137. foreach ($values as $value) {
  138. $result[] = $value;
  139. }
  140. }
  141. return $result;
  142. }
  143. public static function groupbuy_price($limit_id,&$price)
  144. {
  145. return activity\groupbuy::instance()->promotion_price($limit_id,$price);
  146. }
  147. public static function limit_price($limit_id,$goods_id,&$price)
  148. {
  149. return activity\limitime::instance()->promotion_price($limit_id,$goods_id,$price);
  150. }
  151. public static function unstart()
  152. {
  153. $limits = activity\limitime::instance()->unstart();
  154. $groupbuys = activity\groupbuy::instance()->unstart();
  155. $values = [];
  156. foreach ($limits as $val) {
  157. $values[] = $val;
  158. }
  159. foreach ($groupbuys as $val) {
  160. $values[] = $val;
  161. }
  162. $result = [];
  163. if(!empty($values))
  164. {
  165. uasort($values,'less_startime');
  166. foreach ($values as $value) {
  167. $result[] = $value;
  168. }
  169. }
  170. return $result;
  171. }
  172. }