stanley-king 7 years ago
parent
commit
da3ca5e66b

+ 4 - 0
admin/control/cache.php

@@ -112,6 +112,7 @@ class cacheControl extends SystemControl
             $this->mPublisher->modify_activity();
             $this->mPublisher->modify_activity_optional_goods();
             $this->mPublisher->modify_activity_goods_sampler();
+            $this->mPublisher->modify_activity_bargain_goods();
         }
         else
         {
@@ -198,6 +199,9 @@ class cacheControl extends SystemControl
             if(in_array('goods_sampler',$todo)) {
                 $this->mPublisher->modify_activity_goods_sampler();
             }
+            if(in_array('bargain_goods',$todo)) {
+                $this->mPublisher->modify_activity_bargain_goods();
+            }
         }
 
         $this->log(L('cache_cls_operate'));

+ 1 - 0
admin/language/zh/cache.php

@@ -27,6 +27,7 @@ $lang['cache_cls_searcher']	    = '搜索引擎重新加载数据';
 $lang['cache_cls_payfcode']	    = '支付后F码商品';
 $lang['cache_cls_optionalgoods']= '任选专区信息';
 $lang['cache_cls_goodssampler'] = '红包内推荐商品';
+$lang['cache_cls_bargaingoods'] = '砍价商品';
 
 
 

+ 1 - 0
admin/language/zh_cn/cache.php

@@ -27,6 +27,7 @@ $lang['cache_cls_searcher']	    = '搜索引擎重新加载数据';
 $lang['cache_cls_payfcode']	    = '支付后F码商品';
 $lang['cache_cls_optionalgoods']= '任选专区信息';
 $lang['cache_cls_goodssampler'] = '红包内推荐商品';
+$lang['cache_cls_bargaingoods'] = '砍价商品';
 
 $lang['cache_cls_salelist']	    = '手机品牌相关缓存';
 $lang['cache_cls_appversion']	= 'Andrid手机版本信息缓存';

+ 7 - 0
admin/templates/default/cache.clear.php

@@ -177,6 +177,13 @@
                                             &nbsp;<?php echo $lang['cache_cls_goodssampler'] ?>
                                         </label>
                                     </li>
+                                    <li class="left w18pre">
+                                        <label>
+                                            <input type="checkbox" name="cache[]" id="bargain_goods"
+                                                   value="bargain_goods">
+                                            &nbsp;<?php echo $lang['cache_cls_bargaingoods'] ?>
+                                        </label>
+                                    </li>
                                 </ul>
                             </td>
                         </tr>

+ 2 - 1
admin/templates/default/mb_special_item.edit.php

@@ -77,6 +77,7 @@
                     <option value="image">图片</option>
                     <option value="goods">商品(红包价 + 专柜价)</option>
                     <option value="goods_simple">商品(红包价)</option>
+                    <option value="goods_bargain">商品(砍价)</option>
                     <option value="goods_top">商品榜单</option>
                     <option value="webview">网络页面</option>
                     <option value="video">外部视频链接</option>
@@ -106,7 +107,7 @@
             </div>
         </div>
         <h4 class="dialog-handle-title">保留数据:</h4>
-        <input id="dialog_item_image_reserved" type="text" class="txt w200 marginright marginbot vatop"><br/>
+        <input id="dialog_item_image_reserved" type="text" class="txt w400 marginright marginbot vatop"><br/>
         <a id="btn_save_item" class="btn" href="javascript:;"><span>保存</span></a>
     </form>
 </div>

+ 3 - 0
data/model/room_bargain.model.php

@@ -32,4 +32,7 @@ class room_bargainModel extends Model
     public function getBargainByUserGoods($user_id,$goods_id,$lock=false) {
         return $this->where(['user_id' => $user_id,'goods_id' => $goods_id])->lock($lock)->find();
     }
+    public function getBargainList($condition, $field = '*', $page = 0 , $order = 'bargain_id desc', $limit = 0) {
+        return $this->where($condition)->field($field)->order($order)->page($page)->limit($limit)->select();
+    }
 }

+ 4 - 0
helper/account_helper.php

@@ -558,6 +558,10 @@ class account_helper
         }
     }
 
+    public static function onAsyncBargainComplete($bargain_id)
+    {
+    }
+
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static function onAsyncFollow($user,$follow)
     {

+ 0 - 12
helper/activity/bargain.php

@@ -1,12 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2018/1/19
- * Time: 下午12:17
- */
-
-class bargain
-{
-
-}

+ 200 - 0
helper/activity/bargain_goods.php

@@ -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;
+    }
+}

+ 1 - 1
helper/activity/groupbuy.php

@@ -223,7 +223,7 @@ class groupbuy
             foreach ($group_ids as $gid)
             {
                 $start  = intval($this->group_list[$gid]['start_time']);
-                $end    =  intval($this->group_list[$gid]['end_time']);
+                $end    = intval($this->group_list[$gid]['end_time']);
 
                 $cur = time();
                 if($cur >= intval($start) && $cur < intval($end)) {

+ 2 - 0
helper/activity_helper.php

@@ -16,6 +16,8 @@ require_once (BASE_ROOT_PATH . '/helper/activity/recommend_goods.php');
 require_once (BASE_ROOT_PATH . '/helper/activity/goods_gift.php');
 require_once (BASE_ROOT_PATH . '/helper/activity/optional_goods.php');
 require_once (BASE_ROOT_PATH . '/helper/activity/goods_sampler.php');
+require_once (BASE_ROOT_PATH . '/helper/activity/bargain_goods.php');
+
 require_once (BASE_ROOT_PATH . '/helper/algorithm.php');
 require_once (BASE_ROOT_PATH . '/helper/message/msgutil.php');
 require_once (BASE_ROOT_PATH . '/helper/activity_helper.php');

+ 10 - 0
helper/goods_helper.php

@@ -200,6 +200,16 @@ class goods_helper
             array_push($ret['bundling'],$val);
         }
 
+        $ret['bargain'] = [];
+        foreach ($goods_list as $goods)
+        {
+            $gid = intval($goods['goods_id']);
+            $item = activity\bargain_goods::instance()->get_info($gid);
+            if($item != false) {
+                $ret['bargain'][] = $item;
+            }
+        }
+
         return $ret;
     }
 

+ 3 - 0
helper/message/msgutil.php

@@ -74,6 +74,9 @@ class StatesHelper
         elseif($type == 'goods_sampler') {
             $states['goods_sampler'] = true;
         }
+        elseif($type == 'bargain_goods') {
+            $states['bargain_goods'] = true;
+        }
     }
 
     static public function onSearcher($states,$msg)

+ 6 - 0
helper/message/publisher.php

@@ -134,6 +134,12 @@ class publisher
             $this->mRedis->publish('activity',serialize(array('type'=>'goods_sampler','value' => 0)));
         }
     }
+    public function modify_activity_bargain_goods()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('activity',serialize(array('type'=>'bargain_goods','value' => 0)));
+        }
+    }
 
     public function modify_activity()
     {

+ 1 - 1
helper/room/access_client.php

@@ -43,7 +43,7 @@ class access_client extends tcp_client
 
     public function join($room,$room_key)
     {
-        $param = ["act" => 'factory','op' => 'create', "type" => 'bargain','params' => ['goods_id' => $goods_id,'user' => $user]];
+        $param = ["act" => 'factory','op' => 'create', "type" => 'bargain_goods','params' => ['goods_id' => $goods_id,'user' => $user]];
 
         $result = $this->request($param);
         if(empty($result)) return false;

+ 7 - 2
helper/room/bargain_room.php

@@ -16,6 +16,11 @@ class bargain
     public function __construct($params) {
         $this->mParams = $params;
     }
+
+    public function format() {
+        $result = [];
+        return $result;
+    }
     public function bargain_id() {
         return intval($this->mParams['bargain_id']);
     }
@@ -61,7 +66,7 @@ class bargain_room extends base_room
     public function __construct($cinfos, $roomkeys = [])
     {
         parent::__construct($cinfos,$roomkeys);
-        $this->mRoomType = 'bargain';
+        $this->mRoomType = 'bargain_goods';
         $this->init();
     }
 
@@ -85,7 +90,7 @@ class bargain_room extends base_room
         $ret = $this->bargain($room_key);
         if($ret !== false) {
             $this->add_return([$room_key],'ret_bargain',['value' => $ret]);
-            $this->add_broad('bargain',['value' => $ret]);
+            $this->add_broad('bargain_goods',['value' => $ret]);
             return true;
         }
         else {

+ 1 - 1
helper/room/factory.php

@@ -65,7 +65,7 @@ class factory
     private function create_bargain($params)
     {
         global $config;
-        $usable_days = intval($config['bargain']['usable_days']);
+        $usable_days = intval($config['bargain_goods']['usable_days']);
         $usable_days = $usable_days > 0 ? $usable_days : 3;
 
         $creator = intval($params['creator']);

+ 1 - 1
helper/room/factory_client.php

@@ -45,7 +45,7 @@ class factory_client extends tcp_client
 
     public function create_bargain($goods_id,$user)
     {
-        $param = ["act" => 'factory','op' => 'create', "type" => 'bargain','params' => ['goods_id' => $goods_id,'user' => $user]];
+        $param = ["act" => 'factory','op' => 'create', "type" => 'bargain_goods','params' => ['goods_id' => $goods_id,'user' => $user]];
 
         $result = $this->request($param);
         if(empty($result)) return false;

+ 1 - 1
helper/room/proto_type.php

@@ -13,7 +13,7 @@ class proto_type
 {
     const act_factory = 'factory';
 
-    const act_bargain  = 'bargain';
+    const act_bargain  = 'bargain_goods';
     const room_bargain = 1;
 
     const act_group    = 'group';

+ 19 - 0
helper/special_helper.php

@@ -320,6 +320,25 @@ class special_formater
         return $result;
     }
 
+    public static function format_bargain($bargains, $title='')
+    {
+        $result = [];
+
+        $result['item_title'] = $title;
+        $result['item_type'] = 'home_bargain';
+
+        foreach ($bargains as $bargain_id) {
+            $item['image'] = "";
+            $item['type'] = 'bargain_type';
+            $item['data'] = $bargain_id;
+            $item['title'] = '';
+
+            $result['items'][] = $item;
+        }
+
+        return $result;
+    }
+
     public static function format_goods($goods_ids,$title,$sort_summary)
     {
         $result = [];

+ 78 - 2
mobile/control/bargain.php

@@ -14,13 +14,20 @@ require_once(BASE_ROOT_PATH . '/helper/url_helper.php');
 
 class bargainControl extends mobileControl
 {
-
     public function __construct()
     {
         parent::__construct();
     }
 
-    public function open_bargainOp()
+    public function createOp()
+    {
+        if (!session_helper::logined()) {
+            throw new UnloginException();
+        }
+
+    }
+
+    public function openOp()
     {
         $bargain_id = intval($_GET['bargain_id']);
         if(session_helper::need_wechat_author())
@@ -39,6 +46,75 @@ class bargainControl extends mobileControl
         }
     }
 
+    public function mine_listOp()
+    {
+        if (!session_helper::logined()) {
+            throw new UnloginException();
+        }
+
+        $mod_bargain = Model('room_bargain');
+        $items  = $mod_bargain->getBargainList(['member_id' => session_helper::memberid()], '*', $this->page_size);
+        $page_count = $mod_bargain->gettotalpage();
+
+        $gids = [];
+        $bargains = [];
+        $details = [];
+        foreach ($items as $item)
+        {
+            $gid = intval($item['goods_id']);
+            $bid = intval($item['bargain_id']);
+
+            if($bid > 0 && $gid > 0) {
+                $gids[] = $gid;
+                $bargains[] = $bid;
+                $bargain = new room\bargain($item);
+                $details[] = $bargain->format();
+            }
+        }
+
+        if(empty($gids))
+        {
+            return self::outsuccess(['special_list' => null,
+                'summary'  => null,
+                'groupbuy' => null,
+                'limitime' => null,
+                'bundling' => null,
+                'bargain_detail' => null,
+                'mobile_page' => mobile_page($page_count)]);
+        }
+        else
+        {
+            $helper = new goods_helper();
+            $ret = $helper->online_summary($gids,$related_goods);
+            $block = special_formater::format_bargain($bargains,'我的砍价');
+            $blocks[] = $block;
+
+            return self::outsuccess(['special_list' => $blocks,
+                'summary'  => $ret['summary'],
+                'groupbuy' => $ret['groupbuy'],
+                'limitime' => $ret['limitime'],
+                'bundling' => $ret['bundling'],
+                'bargain'  => $ret['bargain'],
+                'bargain_detail' => null,
+                'mobile_page' => mobile_page($page_count)]);
+        }
+    }
+
+    public function detailOp()
+    {
+        if (!session_helper::logined()) {
+            throw new UnloginException();
+        }
+
+        $bargain_id = intval($_GET['bargain_id']);
+        if(!$this->validate($bargain_id)) {
+            return self::outerr(errcode::ErrParamter);
+        }
+        else {
+            return self::outsuccess(['tpl' => new tpl_bargain($bargain_id)],'game/bargain');
+        }
+    }
+
     private function validate($bargain_id)
     {
         if($bargain_id <= 0) return false;

+ 1 - 1
mobile/control/control.php

@@ -292,7 +292,7 @@ class mbMemberControl extends mobileControl
     {
         parent::__construct();
 
-        if ($_SESSION['is_login'] != 1) {
+        if (!session_helper::logined()) {
             throw new UnloginException();
         }
     }

+ 1 - 0
mobile/control/special.php

@@ -117,6 +117,7 @@ class specialControl extends mobileHomeControl
                 'groupbuy' => $goodsex['groupbuy'],
                 'limitime' => $goodsex['limitime'],
                 'bundling' => $goodsex['bundling'],
+                'bargain' => $goodsex['bargain'],
                 'mobile_page' => mobile_page(1));
         }
         else

+ 0 - 1
shop/control/store_account.php

@@ -221,5 +221,4 @@ class store_accountControl extends BaseSellerControl {
         Tpl::output('member_menu', $menu_array);
         Tpl::output('menu_key', $menu_key);
     }
-
 }

+ 6 - 0
test/TestActivity.php

@@ -21,6 +21,12 @@ class TestActivity extends PHPUnit_Framework_TestCase
     {
         Base::run_util();
     }
+
+    public function testBargainGoods()
+    {
+        $instance = activity\bargain_goods::instance();
+
+    }
     public function testOptionalGoods()
     {
         $instance = activity\optional_goods::instance();

+ 36 - 0
test/TestRegex.php

@@ -35,4 +35,40 @@ class TestRegex extends PHPUnit_Framework_TestCase
         }
 
     }
+    public function testBargainReserved()
+    {
+        $src = 'start=20180119 10:00:00#days=3#lowest=20#random=0#num=10';
+        $result = explode("#",$src);
+
+        $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'] = 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['numbers'] = intval($v);
+                    }
+                }
+            }
+        }
+
+        return $params;
+    }
 }

+ 2 - 2
test/TestRoomFactory.php

@@ -63,7 +63,7 @@ class TestRoomFactory extends PHPUnit_Framework_TestCase
     {
         $factory = new room\factory();
         $creator = 36429;
-        $parms = ["act" => 'factory','op' => 'create', "type" => 'bargain','creator' => $creator,'goods_id' => 4831,'cost_price' => 20, 'lowest_price' => 10];
+        $parms = ["act" => 'factory','op' => 'create', "type" => 'bargain_goods','creator' => $creator,'goods_id' => 4831,'cost_price' => 20, 'lowest_price' => 10];
         $factory->create($parms);
     }
     public function testFactoryBuildBargain()
@@ -76,7 +76,7 @@ class TestRoomFactory extends PHPUnit_Framework_TestCase
     {
         $processor = new room\factory_processor();
         $creator = 36429;
-        $ret = $processor->onRequest(0,json_encode(["act" => 'factory','op' => 'create', "type" => 'bargain','creator' => $creator,'goods_id' => 4831,'cost_price' => 20, 'lowest_price' => 10]));
+        $ret = $processor->onRequest(0,json_encode(["act" => 'factory','op' => 'create', "type" => 'bargain_goods','creator' => $creator,'goods_id' => 4831,'cost_price' => 20, 'lowest_price' => 10]));
     }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////