activity_helper.php 5.2 KB

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