full_sent.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/8/17
  6. * Time: 下午3:49
  7. */
  8. namespace activity;
  9. class full_item
  10. {
  11. private $mStart;
  12. private $mEnd;
  13. private $mName;
  14. private $mRules;
  15. public function __construct($start,$end,$name)
  16. {
  17. $this->mStart = $start;
  18. $this->mEnd = $end;
  19. $this->mName = $name;
  20. $this->mRules = [];
  21. }
  22. public function add_rule($title)
  23. {
  24. $this->mRules[] = $title;
  25. }
  26. public function is_runing()
  27. {
  28. $cur = time();
  29. return ($cur >= $this->mStart && $cur < $this->mEnd);
  30. }
  31. public function rules() {
  32. return $this->mRules;
  33. }
  34. }
  35. class full_sent
  36. {
  37. const MANSONG_STATE_NORMAL = 1;
  38. const MANSONG_STATE_CLOSE = 2;
  39. const MANSONG_STATE_CANCEL = 3;
  40. const STORE_ID = 6;
  41. static private $stInstance = null;
  42. private $verchecker;
  43. private $mItem;
  44. private $mFreePrice;
  45. private function __construct()
  46. {
  47. $this->verchecker = new version_checker('activity_version_fullsent');
  48. }
  49. static public function instance()
  50. {
  51. if(self::$stInstance == null) {
  52. self::$stInstance = new full_sent();
  53. }
  54. if(self::$stInstance->verchecker->need_init()) {
  55. self::$stInstance->init();
  56. }
  57. return self::$stInstance;
  58. }
  59. public function rules()
  60. {
  61. if(is_null($this->mItem) == false && $this->mItem->is_runing()) {
  62. return $this->mItem->rules();
  63. }
  64. else {
  65. return array();
  66. }
  67. }
  68. public function free_price()
  69. {
  70. if($this->mFreePrice > 0) {
  71. $val = $this->mFreePrice / 100;
  72. return "满{$val}元(专柜价)包邮";
  73. } else {
  74. return false;
  75. }
  76. }
  77. private function init()
  78. {
  79. $store_list = Model('store')->getStoreOnlineList(array('store_id' => 6),null,'','store_free_price');
  80. if(empty($store_list)) {
  81. $this->mFreePrice = 0;
  82. } else {
  83. $this->mFreePrice = intval($store_list[0]['store_free_price'] * 100 + 0.5);
  84. }
  85. $mod = Model('p_mansong');
  86. $value = $mod->getMansongInfoByStoreID(self::STORE_ID);
  87. if(empty($value)) {
  88. $this->mItem = null;
  89. }
  90. else
  91. {
  92. $start = intval($value['start_time']);
  93. $end = intval($value['end_time']);
  94. $name = $value['mansong_name'];
  95. $this->mItem = new full_item($start,$end,$name);
  96. $rules = $value['rules'];
  97. foreach ($rules as $rule)
  98. {
  99. $val = $this->filter($rule);
  100. if($val != false) {
  101. $this->mItem->add_rule($val);
  102. }
  103. }
  104. }
  105. }
  106. private function filter($rule)
  107. {
  108. $discount = doubleval($rule['discount']) * 100 + 0.5;
  109. $discount = intval($discount);
  110. if($discount > 0) {
  111. $discount = $discount / 100;
  112. $desc = "减{$discount}";
  113. } else {
  114. $desc = "";
  115. }
  116. $goods_id = intval($rule['goods_id']);
  117. if($goods_id > 0) {
  118. $goods_name = $rule['mansong_goods_name'];
  119. $name = "赠{$goods_name}";
  120. } else {
  121. $name = '';
  122. }
  123. if(empty($desc) && empty($name)) {
  124. return false;
  125. }
  126. $price = $rule['price'];
  127. if(empty($desc)) {
  128. $title = "满{$price}{$name}";
  129. }
  130. elseif(empty($name)) {
  131. $title = "满{$price}{$desc}";
  132. }
  133. else {
  134. $title = "满{$price}{$desc},{$name}";
  135. }
  136. return $title;
  137. }
  138. }