activity_helper.php 6.1 KB

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