|
@@ -0,0 +1,200 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * Created by PhpStorm.
|
|
|
+ * User: stanley-king
|
|
|
+ * Date: 2018/1/19
|
|
|
+ * Time: 下午12:17
|
|
|
+ */
|
|
|
+
|
|
|
+namespace activity;
|
|
|
+use Log;
|
|
|
+use StatesHelper;
|
|
|
+use Exception;
|
|
|
+
|
|
|
+
|
|
|
+class bargain_item
|
|
|
+{
|
|
|
+ private $mGoodsId;
|
|
|
+ private $mStartTime;
|
|
|
+ private $mUsableDays;
|
|
|
+ private $mLowestPrice;
|
|
|
+ private $mRandom;
|
|
|
+ private $mTotalNum;
|
|
|
+
|
|
|
+ public function __construct($goods_id,$params)
|
|
|
+ {
|
|
|
+ $this->mGoodsId = $goods_id;
|
|
|
+ $this->mStartTime = $params['start_time'];
|
|
|
+ $this->mUsableDays = $params['usable_days'];
|
|
|
+ $this->mLowestPrice = $params['lowest_price'];
|
|
|
+ $this->mRandom = $params['type'];
|
|
|
+ $this->mTotalNum = $params['total_num'];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function format()
|
|
|
+ {
|
|
|
+ $result = [];
|
|
|
+ $result['goods_id'] = $this->goods_id();
|
|
|
+ $result['start_time'] = $this->start_time();
|
|
|
+ $result['over_time'] = $this->over_time();
|
|
|
+ $result['lowest_price'] = $this->lowest_price();
|
|
|
+ $result['random'] = $this->random();
|
|
|
+ $result['total_num'] = $this->total_num();
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+ public function goods_id() {
|
|
|
+ return $this->mGoodsId;
|
|
|
+ }
|
|
|
+ public function start_time() {
|
|
|
+ return $this->mStartTime;
|
|
|
+ }
|
|
|
+ public function over_time() {
|
|
|
+ return $this->mStartTime + 86400 * $this->mUsableDays;
|
|
|
+ }
|
|
|
+ public function lowest_price() {
|
|
|
+ return $this->mLowestPrice;
|
|
|
+ }
|
|
|
+ public function random() {
|
|
|
+ return $this->mRandom == 1;
|
|
|
+ }
|
|
|
+ public function total_num() {
|
|
|
+ return $this->mTotalNum;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+class bargain_goods
|
|
|
+{
|
|
|
+ private $mGoodsItems;
|
|
|
+ private $mSpecials;
|
|
|
+
|
|
|
+ static private $stInstance = null;
|
|
|
+
|
|
|
+ static public function instance()
|
|
|
+ {
|
|
|
+ if (self::$stInstance == null) {
|
|
|
+ self::$stInstance = new bargain_goods();
|
|
|
+ }
|
|
|
+ if (StatesHelper::fetch_state('bargain_goods')) {
|
|
|
+ Log::record("bargain reinit data.", Log::DEBUG);
|
|
|
+ self::$stInstance->init();
|
|
|
+ }
|
|
|
+ return self::$stInstance;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function isTakepart($goods_id,&$act_id)
|
|
|
+ {
|
|
|
+ $gid = intval($goods_id);
|
|
|
+ if(array_key_exists($gid,$this->mGoodsItems)) {
|
|
|
+ $act_id = $gid;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function get_info($act_id)
|
|
|
+ {
|
|
|
+ $gid = intval($act_id);
|
|
|
+ if(array_key_exists($gid,$this->mGoodsItems)) {
|
|
|
+ $item = $this->mGoodsItems[$gid];
|
|
|
+ return $item->format();
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function init()
|
|
|
+ {
|
|
|
+ global $config;
|
|
|
+ $spids = $config['bargain_goods']['special_ids'];
|
|
|
+ if (empty($spids)) return true;
|
|
|
+
|
|
|
+ $this->mOpgroups = [];
|
|
|
+ $this->mAllGoods = [];
|
|
|
+ $this->mSpecials = [];
|
|
|
+ $this->mErrGoods = [];
|
|
|
+
|
|
|
+ $this->mSpecials = array_unique($spids);
|
|
|
+ foreach ($this->mSpecials as $special_id) {
|
|
|
+ $this->add_special($special_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function add_special($special_id)
|
|
|
+ {
|
|
|
+ $mod_special = Model('mb_special');
|
|
|
+ $ret = $mod_special->getMbSpecialItemUsableListByID($special_id);
|
|
|
+ $blocks = $ret['blocks'];
|
|
|
+
|
|
|
+ $cur_group = null;
|
|
|
+ foreach ($blocks as $block)
|
|
|
+ {
|
|
|
+ $type = $block['item_type'];
|
|
|
+ if ($type == 'home1') {
|
|
|
+ $this->add_goods($block);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function add_goods($block)
|
|
|
+ {
|
|
|
+ $items = $block['items'];
|
|
|
+ if (empty($items)) return;
|
|
|
+
|
|
|
+ $type = $items['type'];
|
|
|
+ $show_type = $items['show_type'];
|
|
|
+
|
|
|
+ if($type == 'goods' && $show_type == 'goods_bargain')
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //'start=20180119 10#days=3#lowest=20#random=0#num=10';
|
|
|
+ $params = $this->parse($items['reserved']);
|
|
|
+ $good_id = intval($items['data']);
|
|
|
+ $item = new bargain_item($good_id,$params);
|
|
|
+ $this->mGoodsItems[$good_id] = $item;
|
|
|
+ }
|
|
|
+ catch (Exception $ex) {
|
|
|
+ Log::record(__METHOD__ . " bargain goods special fail.",Log::ERR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function parse($reserved)
|
|
|
+ {
|
|
|
+ //'start=20180119 10:00:00#days=3#lowest=20#random=0#num=10';
|
|
|
+ $result = explode("#",$reserved);
|
|
|
+ $params = [];
|
|
|
+ foreach($result as $val)
|
|
|
+ {
|
|
|
+ $kv = preg_split('/=/',$val);
|
|
|
+ if(!empty($kv))
|
|
|
+ {
|
|
|
+ $k = trim($kv[0]);
|
|
|
+ $v = trim($kv[1]);
|
|
|
+ if(!empty($k))
|
|
|
+ {
|
|
|
+ if($k == 'days') {
|
|
|
+ $params['usable_days'] = intval($v);
|
|
|
+ }
|
|
|
+ elseif($k == 'start') {
|
|
|
+ $params['start_time'] = strtotime($v);
|
|
|
+ }
|
|
|
+ elseif($k == 'lowest') {
|
|
|
+ $params['lowest_price'] = intval($v*100 + 0.5) / 100;
|
|
|
+ }
|
|
|
+ elseif($k == 'random') {
|
|
|
+ $params['type'] = intval($v);
|
|
|
+ }
|
|
|
+ elseif($k == 'num') {
|
|
|
+ $params['total_num'] = intval($v);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+}
|