123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- <?php
- /**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 16/8/17
- * Time: 下午3:49
- */
- namespace activity;
- use Log;
- use StatesHelper;
- class full_item
- {
- private $mStart;
- private $mEnd;
- private $mName;
- private $mRules;
- public function __construct($start,$end,$name)
- {
- $this->mStart = $start;
- $this->mEnd = $end;
- $this->mName = $name;
- $this->mRules = [];
- }
- public function add_rule($title)
- {
- $this->mRules[] = $title;
- }
- public function is_runing()
- {
- $cur = time();
- return ($cur >= $this->mStart && $cur < $this->mEnd);
- }
- public function rules() {
- return $this->mRules;
- }
- }
- class full_sent
- {
- const MANSONG_STATE_NORMAL = 1;
- const MANSONG_STATE_CLOSE = 2;
- const MANSONG_STATE_CANCEL = 3;
- const STORE_ID = 6;
- static private $stInstance = null;
- private $mItem;
- private $mFreePrice;
- private function __construct()
- {
- }
- static public function instance()
- {
- if(self::$stInstance == null) {
- self::$stInstance = new full_sent();
- }
- if(StatesHelper::fetch_state('full_sent')) {
- Log::record("full_sent reinit data.",Log::DEBUG);
- self::$stInstance->init();
- }
- return self::$stInstance;
- }
- public function rules()
- {
- if(is_null($this->mItem) == false && $this->mItem->is_runing()) {
- return $this->mItem->rules();
- }
- else {
- return array();
- }
- }
- public function free_price()
- {
- if($this->mFreePrice > 0) {
- $val = $this->mFreePrice / 100;
- return "天猫价满{$val}元(除抢购商品外)包邮";
- } else {
- return false;
- }
- }
- private function init()
- {
- $store_list = Model('store')->getStoreOnlineList(array('store_id' => 6),null,'','store_free_price');
- if(empty($store_list)) {
- $this->mFreePrice = 0;
- } else {
- $this->mFreePrice = intval($store_list[0]['store_free_price'] * 100 + 0.5);
- }
- $mod = Model('p_mansong');
- $value = $mod->getMansongInfoByStoreID(self::STORE_ID);
- if(empty($value)) {
- $this->mItem = null;
- }
- else
- {
- $start = intval($value['start_time']);
- $end = intval($value['end_time']);
- $name = $value['mansong_name'];
- $this->mItem = new full_item($start,$end,$name);
- $rules = $value['rules'];
- foreach ($rules as $rule)
- {
- $val = $this->filter($rule);
- if($val != false) {
- $this->mItem->add_rule($val);
- }
- }
- }
- }
- private function filter($rule)
- {
- $discount = doubleval($rule['discount']) * 100 + 0.5;
- $discount = intval($discount);
- if($discount > 0) {
- $discount = $discount / 100;
- $desc = "减{$discount}";
- } else {
- $desc = "";
- }
- $goods_id = intval($rule['goods_id']);
- if($goods_id > 0) {
- $goods_name = $rule['mansong_goods_name'];
- $name = "赠{$goods_name}";
- } else {
- $name = '';
- }
- if(empty($desc) && empty($name)) {
- return false;
- }
- $price = $rule['price'];
- if(empty($desc)) {
- $title = "满{$price}{$name}";
- }
- elseif(empty($name)) {
- $title = "满{$price}{$desc}";
- }
- else {
- $title = "满{$price}{$desc},{$name}";
- }
- return $title;
- }
- }
|