full_sent.php 3.6 KB

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