stanley-king il y a 7 ans
Parent
commit
b3d101c99c

+ 4 - 0
admin/control/cache.php

@@ -110,6 +110,7 @@ class cacheControl extends SystemControl
 
             $this->mPublisher->modify_index_brands();
             $this->mPublisher->modify_activity();
+            $this->mPublisher->modify_index_optional_goods();
         }
         else
         {
@@ -190,6 +191,9 @@ class cacheControl extends SystemControl
                 $this->mPublisher->modify_index_payfcode();
                 $this->mPublisher->modify_index_presentfcode();
             }
+            if(in_array('optional_goods',$todo)) {
+                $this->mPublisher->modify_index_optional_goods();
+            }
         }
 
         $this->log(L('cache_cls_operate'));

+ 48 - 3
admin/control/mb_special.php

@@ -20,6 +20,7 @@ require_once (BASE_ROOT_PATH . '/helper/search_param.php');
 require_once (BASE_ROOT_PATH . '/helper/area_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/ugc_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/activity_helper.php');
 
 class mb_specialControl extends SystemControl
 {
@@ -404,16 +405,60 @@ class mb_specialControl extends SystemControl
         $updata = array('item_data' => $item_data,'bg_type' => $bg_type,'bg_data' => $bg_data,'bg_image' => $_POST['bg_image_name'],'has_margin' => $has_margin);
         $result = $model_mb_special->editMbSpecialItemByID($updata, $_POST['item_id'], $_POST['special_id']);
 
-        if($result) {
+        if($result)
+        {
             if($_POST['special_id'] == $model_mb_special::INDEX_SPECIAL_ID) {
                 showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'index_edit'));
-            } else {
-                showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id'])));
+            }
+            else
+            {
+                $ret = $this->other_check($_POST['special_id'],$err);
+                if($ret) {
+                    showMessage(L('nc_common_save_succ'), urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id'])));
+                } else {
+                    showMessage($err, urlAdmin('mb_special', 'special_edit', array('special_id' => $_POST['special_id'])));
+                }
             }
         } else {
             showMessage(L('nc_common_save_succ'), '');
         }
     }
+    private function other_check($special_id,&$err)
+    {
+        $special_id = intval($special_id);
+
+        global $config;
+        $opids = $config['optional_goods'];
+        if(in_array($special_id,$opids))
+        {
+            $layerror = \activity\optional_goods::instance()->layout_error();
+            if($layerror != false) {
+                $gids = implode(",",$layerror);
+                $err = "下列商品 {$gids} 布局错误或者重复添加";
+                return false;
+            }
+
+            $all_goods = activity\optional_goods::instance()->all_goods();
+            $err_goods = [];
+            foreach ($all_goods as $gid)
+            {
+                $ret = activity_helper::optional_goods_check($gid,$erret);
+                if($ret == false) {
+                    $err_goods[] = $gid;
+                }
+            }
+
+            if(!empty($err_goods)) {
+                $gids = implode(",",$err_goods);
+                $err = "下列商品 {$gids} 已经参与了其它活动,不能添加,请处理";
+                return false;
+            }
+            return true;
+        }
+        else {
+            return true;
+        }
+    }
 
     /**
      * 图片上传

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

@@ -25,6 +25,7 @@ $lang['cache_cls_discovery']	= '手机发现页相关缓存';
 $lang['cache_cls_goods']	    = '商品相关缓存';
 $lang['cache_cls_searcher']	    = '搜索引擎重新加载数据';
 $lang['cache_cls_payfcode']	    = '支付后F码商品';
+$lang['cache_cls_optionalgoods']= '任选专区信息';
 
 
 

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

@@ -25,6 +25,8 @@ $lang['cache_cls_discovery']	= '手机发现页相关缓存';
 $lang['cache_cls_goods']	    = '商品相关缓存';
 $lang['cache_cls_searcher']	    = '搜索引擎重新加载数据';
 $lang['cache_cls_payfcode']	    = '支付后F码商品';
+$lang['cache_cls_optionalgoods']= '任选专区信息';
+
 
 $lang['cache_cls_salelist']	    = '手机品牌相关缓存';
 $lang['cache_cls_appversion']	= 'Andrid手机版本信息缓存';

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

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

+ 4 - 3
admin/templates/default/layout/msg_layout.php

@@ -30,12 +30,13 @@
           <?php } ?>
           <script type="text/javascript"> window.setTimeout("javascript:location.href='<?php echo $output['url'][0]['url'];?>'", <?php echo $time;?>); </script>
           <?php }else { if ($output['url'] != ''){ ?>
-          <a href="<?php echo $output['url'];?>" class="btns"><span><?php echo $lang['nc_back_to_pre_page'];?></span></a> 
+          <a href="<?php echo $output['url'];?>" class="btns"><span><?php echo $lang['nc_back_to_pre_page'];?></span></a>
           <script type="text/javascript"> window.setTimeout("javascript:location.href='<?php echo $output['url'];?>'", <?php echo $time;?>); </script>
           <?php }else { ?>
-          <a href="javascript:history.back()" class="btns"><span><?php echo $lang['nc_back_to_pre_page'];?></span></a> 
+          <a href="javascript:history.back()" class="btns"><span><?php echo $lang['nc_back_to_pre_page'];?></span></a>
           <script type="text/javascript"> window.setTimeout("javascript:history.back()", <?php echo $time;?>); </script>
-          <?php } } ?></td>
+          <?php } } ?>
+        </td>
       </tr>
       <?php } ?>
     </tbody>

+ 27 - 0
crontab/control/date.php

@@ -1131,4 +1131,31 @@ class dateControl extends BaseCronControl
     {
 
     }
+    public function update_voteOp()
+    {
+        $mod_special = Model('mb_special');
+        $items = $mod_special->field('*')->where(['from_user' => 1])->limit(false)->select();
+        foreach ($items as $item)
+        {
+            $spid = intval($item['special_id']);
+            $params      = $item['params'];
+            $vote_result = $item['vote_result'];
+
+            if(!empty($params) && !empty($vote_result))
+            {
+                $params      = unserialize($params);
+                $vresult = unserialize($vote_result);
+                $vote = $params['vote'];
+                if(!empty($vote))
+                {
+                    $params['vote'] = [];
+                    $params['vote'][] = $vote;
+                    $vote_result = [];
+                    $vote_result[] = $vresult;
+
+                    $mod_special->editUserSpecial($spid,['special_id' =>$spid],['params' => serialize($params),'vote_result' => serialize($vote_result)]);
+                }
+            }
+        }
+    }
 }

+ 21 - 5
data/logic/buy.logic.php

@@ -166,6 +166,11 @@ class buyLogic
 
         //重新计算优惠后(满即送)的店铺实际商品总金额
         $store_goods_total = $this->_logic_buy_1->reCalcGoodsTotal($store_goods_total,$store_mansong_rule_list,'mansong');
+
+        //取得店铺N元任选
+        $optional_goods = $this->_logic_buy_1->getOptionalGoods($store_cart_list);
+        $store_goods_total = $this->_logic_buy_1->reCalcGoodsTotal($store_goods_total,$optional_goods,'optional_goods');
+
         //返回店铺可用的代金券
         $store_voucher_list = $this->_logic_buy_1->getStoreAvailableVoucherList($store_goods_total, $member_id);
         $result['store_voucher_list'] = $store_voucher_list;
@@ -222,9 +227,11 @@ class buyLogic
         $result['inv_info'] = $inv_info;
 
         $buyer_info	= Model('member')->getMemberInfoByID($member_id);
+
         if (floatval($buyer_info['available_predeposit']) > 0) {
             $result['available_predeposit'] = $buyer_info['available_predeposit'];
         }
+
         if (floatval($buyer_info['available_rc_balance']) > 0) {
             $result['available_rc_balance'] = $buyer_info['available_rc_balance'];
         }
@@ -533,6 +540,11 @@ class buyLogic
         //重新计算店铺扣除满即送后商品实际支付金额
         $store_final_goods_total = $this->_logic_buy_1->reCalcGoodsTotal($store_goods_total,$store_mansong_rule_list,'mansong');
 
+        //取得店铺N元任选
+        $optional_goods = $this->_logic_buy_1->getOptionalGoods($store_cart_list);
+        $store_final_goods_total = $this->_logic_buy_1->reCalcGoodsTotal($store_final_goods_total,$optional_goods,'optional_goods');
+
+
         //得到有效的代金券
         $input_voucher_list = $this->_logic_buy_1->reParseVoucherList($input_voucher_list,$store_goods_total,$this->_member_info['member_id']);
 
@@ -574,6 +586,8 @@ class buyLogic
         $this->_order_data['store_cart_list'] = $store_cart_list;
         $this->_order_data['goods_buy_quantity'] = $goods_buy_quantity;
         $this->_order_data['input_voucher_list'] = $input_voucher_list;
+        $this->_order_data['input_voucher_list'] = $input_voucher_list;
+        $this->_order_data['optional_goods'] = $optional_goods;
     }
 
     /**
@@ -617,12 +631,15 @@ class buyLogic
         //收货人信息
         list($reciver_info,$reciver_name) = $this->_logic_buy_1->getReciverAddr($input_address_info);
 
-        foreach ($store_cart_list as $store_id => $goods_list) {
-    
+        foreach ($store_cart_list as $store_id => $goods_list)
+        {
             //取得本店优惠额度(后面用来计算每件商品实际支付金额,结算需要)
             $promotion_total = !empty($store_promotion_total[$store_id]) ? $store_promotion_total[$store_id] : 0;
+            $promotion_optotal = !empty($optional_goods[$store_id]) ? $optional_goods[$store_id]['discount'] : 0;
+            $promotion_total += $promotion_optotal;
+
             //本店总的优惠比例,保留3位小数
-            $should_goods_total = $store_final_order_total[$store_id]-$store_freight_total[$store_id]+$promotion_total;
+            $should_goods_total = $store_final_order_total[$store_id] - $store_freight_total[$store_id] + $promotion_total;
             $promotion_rate = abs(number_format($promotion_total/$should_goods_total,5));
             if ($promotion_rate <= 1) {
                 $promotion_rate = floatval(substr($promotion_rate,0,5));
@@ -652,8 +669,7 @@ class buyLogic
             $order['goods_amount'] = $order['order_amount'] - $order['shipping_fee'];
             $order['order_from'] = $order_from;
 			//中山小修改货到付款bug>>>
-			if( $order['payment_code']=="")
-			{
+			if( $order['payment_code']=="") {
 				$order['payment_code']="offline";
 			}
             $order_id = $model_order->addOrder($order);

+ 33 - 1
data/logic/buy_1.logic.php

@@ -5,6 +5,9 @@
  * by 33hao.com 好商城V3 运营版
  */
 defined('InShopNC') or exit('Access Invalid!');
+
+require_once (BASE_ROOT_PATH . '/helper/activity_helper.php');
+
 class buy_1Logic
 {
     /**
@@ -114,6 +117,28 @@ class buy_1Logic
         return array($premiums_list,$mansong_rule_list);
 	}
 
+	public function getOptionalGoods($store_cart_list)
+    {
+        $result = [];
+        foreach ($store_cart_list as $store_id => $cart_list)
+        {
+            if($store_id == 6)
+            {
+                $matcher = new optional_match($cart_list);
+                $op_result = $matcher->match();
+                if($op_result != false) {
+                    $result[$store_id] = $op_result;
+                } else {
+                    $result[$store_id] = array('discount' => 0,'goods_nums' => []);
+                }
+            }
+            else {
+                $result[$store_id] = array('discount' => 0,'goods_nums' => []);
+            }
+        }
+        return $result;
+    }
+
 	/**
 	 * 重新计算每个店铺最终商品总金额(最初计算金额减去各种优惠/加运费)
 	 * @param array $store_goods_total 店铺商品总金额
@@ -125,7 +150,8 @@ class buy_1Logic
 	    $deny = empty($store_goods_total) || !is_array($store_goods_total) || empty($preferential_array) || !is_array($preferential_array);
 	    if ($deny) return $store_goods_total;
 	
-	    switch ($preferential_type) {
+	    switch ($preferential_type)
+        {
 	    	case 'mansong':
 	    	    if (!C('promotion_allow')) return $store_goods_total;
 	    	    foreach ($preferential_array as $store_id => $rule_info) {
@@ -147,7 +173,13 @@ class buy_1Logic
 	    	        $store_goods_total[$store_id] += $freight_total;
 	    	    }
 	    	    break;
+            case 'optional_goods':
+                foreach ($preferential_array as $store_id => $value) {
+                    $store_goods_total[$store_id] -= $value['discount'];
+                }
+                break;
 	    }
+
 	    return $store_goods_total;
 	}
 

+ 7 - 1
data/model/buy.model.php

@@ -900,6 +900,9 @@ class buyModel {
         //重新计算优惠后(满即送)的店铺实际商品总金额
         $store_goods_total = $model_cart->reCalcGoodsTotal($store_goods_total,$store_mansong_rule_list,'mansong');
 
+        $optional_goods = $this->_logic_buy_1->getOptionalGoods($store_cart_list);
+        $store_goods_total = $this->_logic_buy_1->reCalcGoodsTotal($store_goods_total,$optional_goods,'optional_goods');
+
         //返回店铺可用的代金券
         $store_voucher_list = $model_cart->getStoreAvailableVoucherList($store_goods_total, $member_id);
         $result['store_voucher_list'] = $store_voucher_list;
@@ -1099,7 +1102,10 @@ class buyModel {
         list($store_premiums_list,$store_mansong_rule_list) = $model_cart->getMansongRuleCartListByTotal($store_goods_total);
 
         //重新计算店铺扣除满即送后商品实际支付金额
-        $store_final_goods_total = $model_cart->reCalcGoodsTotal($store_goods_total,$store_mansong_rule_list,'mansong');
+        $store_goods_total = $model_cart->reCalcGoodsTotal($store_goods_total,$store_mansong_rule_list,'mansong');
+
+        $optional_goods = $this->_logic_buy_1->getOptionalGoods($store_cart_list);
+        $store_final_goods_total = $this->_logic_buy_1->reCalcGoodsTotal($store_goods_total,$optional_goods,'optional_goods');
 
         //得到有效的代金券
         $input_voucher_list = $model_cart->reParseVoucherList($input_voucher_list,$store_goods_total,$member_id);

+ 0 - 62
data/model/mb_special.model.php

@@ -122,68 +122,6 @@ class mb_specialModel extends Model
         return $this->_getMbSpecialItemList($condition);
     }
 
-    /**
-     * 专题可用项目列表(用于前台显示仅显示可用项目)
-     * @param int $special_id
-     *
-     */
-    public function getMbSpecialItemUsableListByIDEx($special_id)
-    {
-        $prefix = 'mb_specialex';
-        $item_list = rcache($special_id, $prefix);
-        //缓存有效
-        if (!empty($item_list)) {
-            return unserialize($item_list['special']);
-        }
-
-        //缓存无效查库并缓存
-        $condition = array();
-        $condition['special_id'] = $special_id;
-        $condition['item_usable'] = self::SPECIAL_ITEM_USABLE;
-        $item_list = $this->_getMbSpecialItemList($condition);
-        if (!empty($item_list)) {
-            $pages = array();
-            foreach ($item_list as $value) {
-                //处理图片
-                $items = array();
-                $items['item_id'] = $value['item_id'];
-                $items['special_id'] = $value['item_id'];
-                $items['item_type'] = $value['item_type'];
-                $items['item_sort'] = $value['item_sort'];
-                $item_data = $this->_formatMbSpecialData($value['item_data'], $value['item_type']);
-
-                // add goods_price
-                if ($value['item_type'] === 'goods') {
-                    foreach ($item_data['item'] as &$item) {
-                        $model_goods = Model('goods');
-                        $goods_detail = $model_goods->getGoodsInfo(array('goods_id' => $item['goods_id']),
-                            'goods_price,goods_storage,goods_storage_alarm,goods_jingle,goods_marketprice');
-                        if (!empty($goods_detail)) {
-                            $item['goods_price'] = $goods_detail['goods_price'];
-                            $item['goods_storage'] = $goods_detail['goods_storage'];
-                            $item['goods_storage_alarm'] = $goods_detail['goods_storage_alarm'];
-                            $item['goods_jingle'] = $goods_detail['goods_jingle'];
-                            $item['goods_marketprice'] = $goods_detail['goods_marketprice'];
-                        } else {
-                            $item['goods_price'] = 0.0;
-                            $item['goods_storage'] = '0';
-                            $item['goods_storage_alarm'] = '0';
-                            $item['goods_jingle'] = '';
-                            $item['goods_marketprice'] = '0.00';
-                        }
-                    }
-                }
-
-                $items['item_data'] = $item_data;
-                array_push($pages, $items);
-            }
-            $item_list = $pages;
-        }
-        $cache = array('special' => serialize($item_list));
-        wcache($special_id, $cache, $prefix);
-        return $item_list;
-    }
-
     public function getMbSpecialItemUsableListByID($special_id)
     {
         $prefix = 'mb_special';

+ 300 - 0
helper/activity/optional_goods.php

@@ -0,0 +1,300 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2017/8/30
+ * Time: 下午9:14
+ */
+
+namespace activity;
+
+use algorithm;
+use StatesHelper;
+use Log;
+
+//M元买N件商品活动
+class opgroup
+{
+    private $mPrice;   //
+    private $mOptions;
+    private $mStartTm;
+    private $mEndTm;
+    private $mGoods;
+
+    public function __construct($price,$options,$start,$end)
+    {
+        $this->mPrice = $price;
+        $this->mOptions = $options;
+        $this->mStartTm = $start;
+        $this->mEndTm = $end;
+        $this->mGoods = [];
+    }
+    public function match($gids)
+    {
+        if($this->acting() == false) return false;
+
+        $set = algorithm::set_intersection($this->mGoods,$gids);
+        if(count($set) >= $this->mOptions) {
+            return ['gids' => $set,'price' => $this->mPrice,'options' => $this->mOptions];
+        } else {
+            return false;
+        }
+    }
+
+    public function add_goods($gid)
+    {
+        $gid = intval($gid);
+        if($gid <= 0) return false;
+
+        if(algorithm::binary_search($this->mGoods,$gid)) {
+            return false;
+        } else {
+            $pos = algorithm::lower_bonud($this->mGoods,$gid);
+            algorithm::array_insert($this->mGoods,$pos,$gid);
+            return true;
+        }
+    }
+    public function acting() {
+        $cur_tm = time();
+        return ($cur_tm >= $this->mStartTm && $cur_tm < $this->mEndTm);
+    }
+    public function equal($price,$options) {
+        return ($this->mPrice == $price && $this->mOptions == $options);
+    }
+}
+
+class optional_goods
+{
+    private $mAllGoods;
+    private $mOpgroups;
+    private $mSpecials;
+    private $mErrGoods;
+
+    static private $stInstance = null;
+
+    private function __construct() {
+        $this->mOpgroups = [];
+        $this->mAllGoods = [];
+        $this->mSpecials = [];
+        $this->mErrGoods = [];
+    }
+
+    static public function instance()
+    {
+        if(self::$stInstance == null) {
+            self::$stInstance = new optional_goods();
+        }
+        if(StatesHelper::fetch_state('optional_goods')) {
+            Log::record("optional_goods reinit data.",Log::DEBUG);
+            self::$stInstance->init();
+        }
+        return self::$stInstance;
+    }
+    public function layout_error()
+    {
+        if(empty($this->mErrGoods)) {
+            return false;
+        }
+        else {
+            return $this->mErrGoods;
+        }
+    }
+    public function all_goods() {
+        return $this->mAllGoods;
+    }
+
+    public function exist_goods($gid)
+    {
+        $gid = intval($gid);
+        if($gid <= 0) return false;
+
+        if(algorithm::binary_search($this->mAllGoods,$gid)) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    public function match($gidnums)
+    {
+        $input_goods = $this->input_goods($gidnums);
+        $match_goods = algorithm::set_intersection($this->mAllGoods,$input_goods);
+        if(empty($match_goods)) return false;
+
+        $parts = $this->parse($gidnums);
+        if(empty($parts)) return false;
+
+        $result = [];
+        foreach ($parts as $part)
+        {
+            $part_goods = algorithm::set_intersection($this->mAllGoods,$part);
+            $groups = $this->domatch($part_goods);
+            foreach ($groups as $val) {
+                $result[] = $val;
+            }
+        }
+
+        return $result;
+    }
+    private function domatch($part_goods)
+    {
+        $result = [];
+        foreach ($this->mOpgroups as $opgroup) {
+            $part = $opgroup->match($part_goods);
+            if($part != false) {
+                $result[] = $part;
+            }
+        }
+        return $result;
+    }
+
+    private function input_goods($gidnums)
+    {
+        $result = [];
+        foreach ($gidnums as $gid => $num) {
+            if($num > 0) {
+                $result[] = $gid;
+            }
+        }
+        sort($result);
+        return $result;
+    }
+
+    private function parse($gid_nums)
+    {
+        $result = [];
+        while (true)
+        {
+            $item = [];
+            foreach ($gid_nums as $gid => &$num) {
+                if($num > 0) {
+                    $item[] = $gid;
+                    $num--;
+                }
+            }
+            if(!empty($item)) {
+                sort($item);
+                $result[] = $item;
+            }
+            else {
+                break;
+            }
+        }
+
+        return $result;
+    }
+
+    private function init()
+    {
+        global $config;
+        $opids = $config['optional_goods'];
+        if(empty($opids)) return true;
+        $this->mSpecials = array_unique($opids);
+
+        foreach($this->mSpecials as $special_id) {
+            $this->add_special($special_id);
+        }
+        sort($this->mErrGoods);
+    }
+    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')
+            {
+                $tmp_group = $this->add_group($block);
+                if($tmp_group != null) {
+                    $cur_group = $tmp_group;
+                    $this->mOpgroups[] = $cur_group;
+                }
+            }
+            else
+            {
+                $this->add_goods($cur_group,$block);
+            }
+        }
+    }
+    private function add_goods($group,$block)
+    {
+        $items = $block['items'];
+        if(empty($items)) return;
+
+        foreach ($items as $item)
+        {
+            if(array_key_exists('type',$item) && $item['type'] == 'goods')
+            {
+                $goods_id = intval($item['data']);
+                if($group != null && $goods_id > 0 && $this->exist_goods($goods_id) == false)
+                {
+                    if($group->add_goods($goods_id)) {
+                        $this->addgoods($goods_id);
+                    }
+                }
+                else {
+                    $this->mErrGoods[] = $goods_id;
+                }
+            }
+        }
+    }
+
+    private function add_group($block)
+    {
+        $items = $block['items'];
+        if(empty($items)) return null;
+
+        $reserved = $items['reserved'];
+        $params = preg_split("/#/",$reserved);
+        if(count($params) == 4)
+        {
+            $price   = intval($params[0] * 100 + 0.5);
+            $options = intval($params[1]);
+            $startm  = strtotime($params[2]);
+            $hours   = intval($params[3]);
+
+            if($price > 0 && $options > 1)
+            {
+                $group = $this->find($price,$options);
+                if($group == null)
+                {
+                    if($startm > 0 && $hours > 0 && $startm + 3600 * $hours >  time()) {
+                        $group = new opgroup($price,$options,$startm,$startm + 3600 * $hours);
+                    }
+                }
+                return $group;
+            }
+            else {
+                return null;
+            }
+        }
+    }
+
+    private function find($price,$options)
+    {
+        foreach ($this->mOpgroups as $item)
+        {
+            if($item->equal($price,$options)) {
+                return $item;
+            }
+        }
+        return null;
+    }
+    private function addgoods($gid)
+    {
+        $gid = intval($gid);
+        if($gid <= 0) return false;
+
+        if(algorithm::binary_search($this->mAllGoods,$gid)) {
+            return false;
+        } else {
+            $pos = algorithm::lower_bonud($this->mAllGoods,$gid);
+            algorithm::array_insert($this->mAllGoods,$pos,$gid);
+            return true;
+        }
+    }
+}

+ 132 - 0
helper/activity_helper.php

@@ -14,7 +14,10 @@ require_once (BASE_ROOT_PATH . '/helper/activity/recommend_combo.php');
 require_once (BASE_ROOT_PATH . '/helper/activity/full_sent.php');
 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/algorithm.php');
+require_once (BASE_ROOT_PATH . '/helper/message/msgutil.php');
+require_once (BASE_ROOT_PATH . '/helper/activity_helper.php');
 
 function less_endtime($left,$right)
 {
@@ -213,4 +216,133 @@ class activity_helper
 
         return $result;
     }
+
+    public static function optional_goods_check($goods_id,&$err)
+    {
+        if(self::take_parted($goods_id,$type)) {
+            $err['msg'] = '该商品已经参加其它活动';
+            return false;
+        }
+        elseif(self::have_bundling($goods_id)) {
+            $err['msg'] = '该商品已经参加套装活动';
+            return false;
+        }
+        return true;
+    }
+
+    public static function optional_goods_match($gids)
+    {
+        $result = activity\optional_goods::instance()->match($gids);
+        return $result;
+    }
+}
+
+class optional_match
+{
+    private $mPregids;
+    private $mAllGoods;
+
+    public function __construct($cart_list)
+    {
+        $this->mPregids = [];
+        $this->mAllGoods = [];
+
+
+        foreach ($cart_list as $cart)
+        {
+            $bl_id = intval($cart['bl_id']);
+            $goods_id = intval($cart['goods_id']);
+            $goods_num = intval($cart['goods_num']);
+            if($bl_id == 0 && $goods_id > 0)
+            {
+                $this->mPregids[$goods_id] = $goods_num;
+                $this->mAllGoods[$goods_id] = $cart;
+            }
+        }
+    }
+
+    public function match()
+    {
+        if(!empty($this->mPregids))  {
+            $matchs = activity\optional_goods::instance()->match($this->mPregids);
+        }
+        else {
+            return false;
+        }
+
+        $discount_cent = 0;
+        $goods_nums = [];
+
+        foreach ($matchs as $item)
+        {
+            $gids = $item['gids'];
+            $options = $item['options'];
+            $price = $item['price'];
+
+            $num = count($gids);
+            $times = intval($num / $options);
+            $count = $options * $times;
+
+            if($num % $options == 0) {
+                $match_goods = $gids;
+            } else {
+                $match_goods = $this->find_goods($gids,$count);
+            }
+            $total_price = $this->total_price_cent($match_goods);
+            $discount_cent += ($total_price - $price * $times);
+
+            foreach ($match_goods as $gid)
+            {
+                if(array_key_exists($gid,$goods_nums)) {
+                    $goods_nums[$gid] += 1;
+                } else {
+                    $goods_nums[$gid] = 1;
+                }
+            }
+        }
+
+        return ['discount' => $discount_cent / 100, 'goods_nums' => $goods_nums];
+    }
+    private function find_goods($gids,$count)
+    {
+        $goods_list = [];
+        foreach ($gids as $gid) {
+            $goods_list[] = $this->mAllGoods[$gid];
+        }
+        usort($goods_list,['optional_match','price_desc']);
+
+        $match_goods = [];
+        $index = 0;
+        foreach ($goods_list as $goods)
+        {
+            if($index < $count) {
+                $gid = intval($goods['goods_id']);
+                $match_goods[] = $gid;
+                $index++;
+            } else {
+                break;
+            }
+        }
+
+        return $match_goods;
+    }
+
+    private function total_price_cent($gids)
+    {
+        $total_price = 0;
+        foreach ($gids as $gid) {
+            $total_price += intval($this->mAllGoods[$gid]['goods_price'] * 100 + 0.5);
+        }
+        return $total_price;
+    }
+
+    public static function price_desc($left,$right)
+    {
+        $l_price = intval($left['goods_price'] * 100  + 0.5);
+        $r_price = intval($right['goods_price'] * 100 + 0.5);
+
+        if($l_price > $r_price) return -1;
+        elseif($l_price < $r_price) return 1;
+        else return 0;
+    }
 }

+ 57 - 9
helper/buy_first.php

@@ -60,6 +60,7 @@ class buy_first
 
         //红包信息
         $result['total_pred'] = doubleval($this->mLogicOut['available_predeposit']);
+        $result['opgoods_discount'] = $this->optional_goods();
         $result['available_pred']  = $this->available_pred($goods_amount,$full_discount,$result['total_pred'],$rates,$discount_gap,$gap_show);
         $result['discount_gap'] = $discount_gap;
         $result['bonus_rates'] = $this->formate_rates($rates);
@@ -89,6 +90,32 @@ class buy_first
 
         return $result;
     }
+    private function optional_goods()
+    {
+        $discount = 0;
+        $result = [];
+        $store_cart_list = $this->mLogicOut['store_cart_list'];
+        foreach ($store_cart_list as $store_id => $cart_list)
+        {
+            if($store_id == 6)
+            {
+                $matcher = new optional_match($cart_list);
+                $op_result = $matcher->match();
+                if($op_result != false) {
+                    $result[$store_id] = $op_result;
+                    $discount += $op_result['discount'];
+                } else {
+                    $result[$store_id] = array('discount' => 0,'goods_nums' => []);
+                }
+            }
+            else {
+                $result[$store_id] = array('discount' => 0,'goods_nums' => []);
+            }
+        }
+        $this->mLogicOut['optional_goods'] = $result;
+
+        return $discount;
+    }
 
     private function formate_rates($rates)
     {
@@ -282,20 +309,41 @@ class buy_first
     private function pred_goods_amount()
     {
         $pred_amount = 0.00;
-        $cart_list = $this->mLogicOut['store_cart_list'];
-        foreach ($cart_list as $store => $cart)
+        $store_cart_list = $this->mLogicOut['store_cart_list'];
+        foreach ($store_cart_list as $store_id => $cart_list)
         {
-            foreach ($cart as $item)
+            $opgoods = $this->mLogicOut['optional_goods'][$store_id];
+
+            foreach ($cart_list as $cart)
             {
-                $goods_total = $item['goods_total'];
-                if(intval($item['bl_id']) > 0) {
+                $goods_total = $cart['goods_total'];
+                if(intval($cart['bl_id']) > 0) {
                 }
-                elseif(!empty($item['groupbuy_info'])) {
+                elseif(!empty($cart['groupbuy_info'])) {
                 }
-                elseif(!empty($item['xianshi_info'])) {
+                elseif(!empty($cart['xianshi_info'])) {
                 }
-                else {
-                    $pred_amount += $goods_total;
+                else
+                {
+                    if(empty($opgoods)) {
+                        $pred_amount += $goods_total;
+                    }
+                    else
+                    {
+                        $goods_id    = intval($cart['goods_id']);
+                        if(array_key_exists($goods_id,$opgoods['goods_nums']))
+                        {
+                            $goods_price = $cart['goods_price'];
+                            $goods_num = intval($cart['goods_num']);
+                            $opnum = $opgoods['goods_nums'][$goods_id];
+                            if($goods_num > $opnum) {
+                                $pred_amount += $goods_price * ($goods_num - $opnum);
+                            }
+                        }
+                        else {
+                            $pred_amount += $goods_total;
+                        }
+                    }
                 }
             }
         }

+ 3 - 3
helper/fcode/mfcode.php

@@ -65,10 +65,10 @@ class mfcode
         $result = [];
         $result['fcode_id'] = $this->fc_id();
 
-        $goods_id = commonid_helper::instance()->one_goods($this->commonid());
-        if($goods_id == false) return;
+        $gid = commonid_helper::instance()->one_goods($this->commonid());
+        if($gid == false) return false;
 
-        $result['goods_id'] = $goods_id;
+        $result['goods_id'] = $gid;
         $result['fcode']    = $this->fcode();
         $result['key']      = $this->user_key();
         $result['usable_time'] = $this->usable_time();

+ 4 - 0
helper/message/msgutil.php

@@ -74,6 +74,10 @@ class StatesHelper
         global $gMessageStates;
         global $gMessageLock;
 
+        if(empty($gMessageLock) || empty($gMessageStates)) {
+            return true;
+        }
+
         $finded = false;
         Mutex::lock($gMessageLock);
         foreach ($gMessageStates as $key => $val)

+ 6 - 0
helper/message/publisher.php

@@ -60,6 +60,12 @@ class publisher
             $this->mRedis->publish('ch_index',serialize(array('type'=>'present_fcode','value' => 0)));
         }
     }
+    public function modify_index_optional_goods()
+    {
+        if($this->mConnected) {
+            $this->mRedis->publish('ch_index',serialize(array('type'=>'optional_goods','value' => 0)));
+        }
+    }
     public function modify_index_special()
     {
         if($this->mConnected) {

+ 4 - 0
helper/special/block_filter.php

@@ -130,6 +130,10 @@ class block_filter
                 return $reserved;
             }
         }
+        else {
+            if(empty($reserved)) return "";
+            return $reserved;
+        }
     }
 
     protected function topimages($level)

+ 20 - 8
helper/ugc/answer.php

@@ -155,29 +155,41 @@ class special_vote
         $this->special_id = $special_id;
     }
 
-    public function vote($options)
+    public function vote($options,&$num)
     {
         try
         {
             $trans = new trans_wapper($this->mod_special,"special_vote");
             $special_info = $this->mod_special->getMbSpecialByID($this->special_id,'*',true);
             $special = new special($special_info);
-            $result = $special->vote_result();
-            if($result != false)
+            $vote_result = $special->vote_result();
+
+            $num = 0;
+            if($vote_result != false)
             {
+                $count = count($vote_result);
                 foreach ($options as $val)
                 {
-                    $val = intval($val);
-                    if(array_key_exists($val,$result)) {
-                        $result[$val] += 1;
+                    $index = intval($val['index']);
+                    $answer = $val['answer'];
+                    if($index >= $count) continue;
+
+                    $result = &$vote_result[$index];
+                    foreach ($answer as $item)
+                    {
+                        $opval = intval($item);
+                        if(array_key_exists($opval,$result)) {
+                            $result[$opval] += 1;
+                            $num++;
+                        }
                     }
                 }
             }
 
-            $this->mod_special->table('mb_special')->where(['special_id' => $this->special_id])->update(['vote_result' => serialize($result)]);
+            $this->mod_special->table('mb_special')->where(['special_id' => $this->special_id])->update(['vote_result' => serialize($vote_result)]);
             $trans->commit();
 
-            return $result;
+            return $vote_result;
         }
         catch (Exception $ex) {
             $trans->rollback();

+ 4 - 2
helper/ugc/content.php

@@ -206,13 +206,15 @@ class vote_item extends UGContent
     private $mOptions;
     private $mType;
     private $mSingle;
+    private $mVotekey;
 
-    public function __construct($content)
+    public function __construct($content,$vote_key)
     {
         parent::__construct($content);
         $this->mTitle = $content['title'];
         $this->mDeadline = intval($content['deadline']);
         $this->mType = intval($content['vote_type']);
+        $this->mVotekey = $vote_key;
 
         if(isset($content['vote_single'])) {
             $this->mSingle = boolval($content['vote_single']);
@@ -247,7 +249,7 @@ class vote_item extends UGContent
         $data = json_encode($options,JSON_UNESCAPED_UNICODE);
 
         $params = $this->base_info();
-        $reserved = "vote_type={$this->mType}";
+        $reserved = "vote_type={$this->mType}"; //#vote_key={$this->mVotekey}
         $params['item_data'] = $this->item_data('vote','',$this->mTitle,'vote',$data,$reserved);
         return $params;
     }

+ 15 - 4
helper/ugc/generator.php

@@ -78,8 +78,8 @@ class special_object
             }
             elseif($cur_type == 'vote')
             {
-                $vote_result = $item->vote_result();
-                $vote = $item->vote_param();
+                $vote_result[] = $item->vote_result();
+                $vote[] = $item->vote_param();
             }
             elseif ($cur_type == 'question')
             {
@@ -156,7 +156,16 @@ class special_object
 
 class generator
 {
-    public static function crate_special($data,&$err)
+    private $mVotePos;
+    private $mQuestionPos;
+
+    public function __construct()
+    {
+        $this->mVotePos = 0;
+        $this->mQuestionPos = 0;
+    }
+
+    public function crate_special($data,&$err)
     {
         if(empty($data)) {
             $err = ['code' => errcode::ErrParamter,'msg' => "参数不能为空"];
@@ -193,10 +202,12 @@ class generator
                     $obj_item = new goods_item($item);
                 }
                 elseif($type == 'vote') {
-                    $obj_item = new vote_item($item);
+                    $obj_item = new vote_item($item,$this->mVotePos);
+                    $this->mVotePos++;
                 }
                 elseif($type == 'question') {
                     $obj_item = new question_item($item);
+                    $this->mQuestionPos++;
                 }
                 else {
                     continue;

+ 5 - 3
helper/ugc_helper.php

@@ -30,7 +30,8 @@ class ugc_helper
 {
     public static function crate_special($data,&$err)
     {
-        $special = ugc\generator::crate_special($data,$err);
+        $generator = new ugc\generator();
+        $special = $generator->crate_special($data,$err);
         return $special;
     }
 
@@ -129,11 +130,12 @@ class ugc_helper
             if($special->has_vote() && $vote != false)
             {
                 $voter = new special_vote($special->special_id());
-                $vote_result = $voter->vote($vote);
+                $vote_result = $voter->vote($vote,$vote_num);
+
                 if($vote_result == false) {
                     return false;
                 } else {
-                    $num++;
+                    $num += $vote_num;
                     $bonus_type = 0;
                 }
             }

+ 7 - 3
mobile/control/cart.php

@@ -205,11 +205,15 @@ class cartControl extends mobileControl
         $fcodes = [];
         $gids = [];
 
-        foreach ($items as $item) {
+        foreach ($items as $item)
+        {
             $fcoder = new fcode\mfcode($item);
             $fcode = $fcoder->format();
-            $gids[] = intval($fcode['goods_id']);
-            $fcodes[] = $fcode;
+            if($fcode != false)
+            {
+                $gids[] = intval($fcode['goods_id']);
+                $fcodes[] = $fcode;
+            }
         }
 
         if(empty($fcodes))

+ 0 - 1
mobile/control/control.php

@@ -38,7 +38,6 @@ class mobileControl
 
         if (is_numeric($_GET['curpage']) && intval(trim($_GET['curpage'])) > 0) {
             $this->cur_page = intval(trim($_GET['curpage']));
-
         } else {
             $this->cur_page = 1;
         }

+ 0 - 248
mobile/control/index.php

@@ -106,254 +106,6 @@ class indexControl extends specialControl
             }
         }
     }
-
-    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    public function homeOp()
-    {
-        if($this->cur_page == 1) {
-            $start = microtime(true);
-            $ret = $this->pub_special(self::HomeSpecialID);
-            $ret['mobile_page'] = mobile_page(2);
-            perfor_period("home",$start,"index");
-
-            return self::outsuccess($ret,"shop/home");
-        }
-        else
-        {
-            $goods_ids = activity_helper::recomoned_goodsids();
-
-            $ret = array_chunk($goods_ids,$this->page_size());
-            $pages = count($ret);
-            $page_no = $pages >= $this->page_no() ? $this->page_no() : $pages;
-            $goods_ids = $ret[$page_no - 1];
-
-            $helper = new goods_helper();
-            $ret = $helper->online_summary($goods_ids,$other_goods);
-
-            $blocks = [];
-            $blocks[] = special_formater::format_goods($goods_ids,"热门推荐",$ret['sort_summary']);
-
-            self::outsuccess(array('special_list' => $blocks,
-                'summary' => $ret['summary'],
-                'groupbuy' => $ret['groupbuy'],
-                'limitime' => $ret['limitime'],
-                'bundling' => $ret['bundling'],
-                'mobile_page' => mobile_page($pages + 1)));
-        }
-    }
-
-    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    private function old_homeid()
-    {
-        if(is_publish()) {
-            return 61;
-        } else {
-            return 36;
-        }
-    }
-    public function indexOp()
-    {
-        $mb_special = Model('mb_special');
-        $special_list = $mb_special->getMbSpecialItemUsableListByIDEx($this->old_homeid());
-        $sale_list = $this->sale_list();
-        return self::outsuccess(array('special_list' => $special_list, 'sale_list' => $sale_list));
-    }
-
-    public function indexexOp()
-    {
-        $helper = new special_formater($this->old_homeid());
-        $ret = $helper->format($goods_ids);
-        $sale_list = $this->sale_list();
-        $helper = new goods_helper();
-        $goods_list = $helper->get_infos($goods_ids);
-        return self::outsuccess(array('special_list' => $ret,'goods_list' =>$goods_list, 'sale_list' => $sale_list));
-    }
-
-    /**
-     * 专题
-     */
-    public function specialOp()
-    {
-        if(!isset($_GET['special_id']) || empty($_GET['special_id'])) {
-            return self::outerr(errcode::ErrParamter);
-        }
-        $mb_special = Model('mb_special');
-        $special_list = $mb_special->getMbSpecialItemUsableListByIDEx($_GET['special_id']);
-        return self::outsuccess(array('special_list' => $special_list));
-    }
-
-    public function specialexOp()
-    {
-        if(!isset($_GET['special_id']) || empty($_GET['special_id'])) {
-            return self::outerr(errcode::ErrParamter);
-        }
-        $special_id = intval($_GET['special_id']);
-
-        $helper = new special_formater($special_id);
-        $ret = $helper->format($goods_ids);
-
-        $mod_goods = Model('goods');
-        $items = $mod_goods->field('goods_commonid')->where(array('goods_id' => array('in',$goods_ids)))->limit(false)->select();
-        $goods_commonids = array();
-        foreach ($items as $val) {
-            array_push($goods_commonids,intval($val['goods_commonid']));
-        }
-        $helper = new goods_helper();
-        $goods_list = $helper->get_distinct($goods_commonids);
-        return self::outsuccess(array('special_list' => $ret,'goods_list' =>$goods_list));
-    }
-
-    static private function validate_type($type, $data)
-    {
-        $types = array('keyword', 'special', 'goods', 'url');
-        if (empty($type) || !in_array($type, $types)) {
-            return array('code' => errcode::ErrSpecial, 'msg' => '错误的参数.');
-        }
-        $validator = new Validator();
-        if ($type === 'special') {
-            $validator->setValidate(Validator::verify_number($data, 'special data error.'));
-        } elseif ($type === 'keyword') {
-
-        } elseif ($type === 'goods') {
-
-        } else {
-
-        }
-
-        $err = $validator->validate();
-        if ($err != '') {
-            return array('code' => errcode::ErrSpecial,'msg' => $err);
-        } else {
-            return true;
-        }
-    }
-
-    public function advOp()
-    {
-        $type = $_GET['type'];
-        $data = $_GET['data'];
-        $ret = self::validate_type($type, $data);
-        if ($ret != true) {
-            return self::outerr($ret['code'],$ret['msg']);
-        }
-
-        if ($type === 'special') {
-            $mb_special = Model('mb_special');
-            $ret = $mb_special->getMbSpecialItemUsableListByID($data);
-        } elseif ($type === 'keyword') {
-
-        } elseif ($type === 'goods') {
-
-        } else {
-
-        }
-
-        self::outsuccess($ret);
-    }
-
-    /**
-     * 获取打赏接口数据
-     */
-    private function sale_list()
-    {
-        $prefix = 'mb_salelist';
-        $codeid = 122;
-
-        $ret = rcache($codeid, $prefix);
-        if (empty($ret))
-        {
-            $web_code = Model('web_code');
-            $result = $web_code->where(array('code_id' => 122, 'web_id' => 122))->select();
-            if (!empty($result)) {
-                $top = $result[0];
-                $tops = unserialize($top['code_info']);
-            }
-            if (empty($tops)) return array();
-
-            $ret = array();
-            foreach ($tops as $id => $val) {
-                $item = array();
-                $item['id'] = $id;
-                $img = $val['img_name'];
-                if (!empty($img)) {
-                    $item['image'] = UPLOAD_SITE_URL . DS . $img;
-                    $item['title'] = $val['recommend']['name'];
-                    array_push($ret, $item);
-                }
-            }
-            wcache($codeid, array("salelist" => serialize($ret)), $prefix);
-        } else {
-            $ret = unserialize($ret['salelist']);
-        }
-
-        return $ret;
-    }
-
-    public function sale_listOp()
-    {
-        $prefix = 'mb_salelist_content';
-        $codeid = 122;
-
-        $ret = rcache($codeid, $prefix);
-        if (empty($ret))
-        {
-            $web_code = Model('web_code');
-            $result = $web_code->where(array('code_id' => 122, 'web_id' => 122))->select();
-            if (!empty($result)) {
-                $top = $result[0];
-                $tops = unserialize($top['code_info']);
-            }
-            if (empty($tops)) return NULL;
-            $ret = array();
-            foreach ($tops as $id => $val) {
-                $item['id'] = $id;
-                $item['image'] = UPLOAD_SITE_URL . DS . $val['img_name'];
-                $item['title'] = $val['recommend']['name'];
-                $goods_list = $val['goods_list'];
-                $item['goods_list'] = array();
-                foreach ($goods_list as $goods_val) {
-                    $goods_val['goods_pic'] = UPLOAD_SITE_URL . DS . $goods_val['goods_pic'];
-                    array_push($item['goods_list'], $goods_val);
-                }
-                array_push($ret, $item);
-            }
-            wcache($codeid, array("salelist_content" => serialize($ret)), $prefix);
-        } else {
-            $ret = unserialize($ret['salelist_content']);
-        }
-
-        self::outsuccess(array('sale_list' => $ret));
-    }
-
-    /**
-     * android客户端版本号
-     */
-    public function apk_versionOp()
-    {
-        $version = C('mobile_apk_version');
-        $url = C('mobile_apk');
-        if (empty($version)) {
-            $version = '';
-        }
-        if (empty($url)) {
-            $url = '';
-        }
-
-        return self::outsuccess(array('version' => $version, 'url' => $url));
-    }
-
-    public function show_goodsOp()
-    {
-        $goods_ids = activity_helper::recomoned_goodsids();
-        $ret = array_chunk($goods_ids,$this->page_size());
-        $pages = count($ret);
-        $page_no = $pages >= $this->page_no() ? $this->page_no() : $pages;
-        $goods_ids = $ret[$page_no - 1];
-
-        $helper = new goods_helper();
-        $goods_list = $helper->get_infos($goods_ids);
-        self::outsuccess(array('goods_list' => $goods_list, 'mobile_page' => mobile_page($pages)));
-    }
 }
 
 class tpl_member

+ 2 - 3
mobile/control/member_buy.php

@@ -53,7 +53,7 @@ class member_buyControl extends mbMemberControl
         }
         else {
             $result = $buy_helper->format();
-            return self::outsuccess($result);
+                return self::outsuccess($result);
         }
     }
 
@@ -363,5 +363,4 @@ class member_buyControl extends mbMemberControl
             return $id_num;
         }
     }
-}
-
+}

+ 6 - 3
mobile/control/member_fcode.php

@@ -42,11 +42,14 @@ class member_fcodeControl extends mbMemberControl
         $fcodes = [];
         $gids = [];
 
-        foreach ($items as $item) {
+        foreach ($items as $item)
+        {
             $fcoder = new fcode\mfcode($item);
             $fcode = $fcoder->format();
-            $gids[] = intval($fcode['goods_id']);
-            $fcodes[] = $fcode;
+            if($fcode != false) {
+                $gids[] = intval($fcode['goods_id']);
+                $fcodes[] = $fcode;
+            }
         }
 
         if(empty($fcodes))

+ 9 - 3
mobile/control/special.php

@@ -166,11 +166,13 @@ class tpl_ugc
     private $mem_info;
     private $special;
     private $mQuestionIndex;
+    private $mVoteIndex;
     private $mAuthorRelation;
 
     public function __construct($output)
     {
         $this->mQuestionIndex = 0;
+        $this->mVoteIndex = 0;
         $this->spitem = $output['spitem'];
         $this->special_list = $output['special_list'];
         $this->summary = $output['summary'];
@@ -425,6 +427,7 @@ class tpl_ugc
                 } else {
                     $this->show_vote($item);
                 }
+                $this->mVoteIndex++;
             }
             elseif($show_type == 'question') {
                 $this->show_question($item);
@@ -577,9 +580,10 @@ class tpl_ugc
             $box = "checkbox";
         }
 
+        $index = $this->mVoteIndex + 1;
         $str = "<div class=\"vote\">
                     <div class=\"vote_pro\">
-                        <div class=\"vote_question\">{$title}</div>
+                        <div class=\"vote_question\">投票{$index}: {$title}</div>
                         <div class=\"vote_type\" data-type=\"{$vote_type}\">/{$svote_type}</div>
                     </div>
                     <div class=\"vote_options\">";
@@ -589,7 +593,7 @@ class tpl_ugc
             $option = $val['text'];
             $soption = "<div class=\"vote_option\">
                             <label>
-                                <input type=\"{$box}\" value=\"{$key}\" class=\"check\" name=\"submit_vote\">
+                                <input type=\"{$box}\" value=\"{$key}\" class=\"check\" name=\"vote{$this->mVoteIndex}\">
                                 <span class=\"label\">{$option}</span>
                             </label>
                         </div>";
@@ -637,7 +641,9 @@ class tpl_ugc
                     </div>";
 
         $str .=    '<div class="results">';
-        $result = $this->special->vote_result();
+        $vote_result = $this->special->vote_result();
+        $result = $vote_result[$this->mVoteIndex];
+
         $total = 0;
         foreach ($result as $key => $val) {
             $total += $val;

+ 13 - 10
test/activity_helperTest.php

@@ -12,13 +12,19 @@ define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
 require_once(BASE_ROOT_PATH . '/fooder.php');
 require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
+require_once(BASE_ROOT_PATH . '/helper/message/msgutil.php');
 
-class activity_helperTest extends PHPUnit_Framework_TestCase
+
+class TestActivity extends PHPUnit_Framework_TestCase
 {
     public static function setUpBeforeClass()
     {
         Base::run_util();
     }
+    public function testOptionalGoods()
+    {
+        $instance = activity\optional_goods::instance();
+    }
 
     public function testUrlencode()
     {
@@ -31,15 +37,12 @@ class activity_helperTest extends PHPUnit_Framework_TestCase
         $time = strftime("%Y-%m-%d %H:%M:%S",1474266342);
         $time = strftime("%Y-%m-%d %H:%M:%S",1474268695);
         $time = strftime("%Y-%m-%d %H:%M:%S",1474268698);
-
         $helper = new goods_helper();
-        //$helper->get_summary(array(4181),$related_goods);
     }
 
     public function testBundling()
     {
         $helper = new goods_helper();
-        //$ret = $helper->get_summary(array(2),$related_goods);
     }
 
     public function testSpu()
@@ -76,13 +79,13 @@ class activity_helperTest extends PHPUnit_Framework_TestCase
         $contents = activity\full_sent::instance()->rules();
         $store_list = Model('store')->getStoreOnlineList(array('store_id' => 6),null,'','store_free_price');
     }
-    public function testActivity()
+    public function testxActivity()
     {
-//        $acting = activity_helper::acting();
-//        $unstart = activity_helper::unstart();
-//        $acting  = activity\groupbuy::instance()->acting();
-//        $unstart = activity\groupbuy::instance()->unstart();
-//        $acting = activity\limitime::instance()->acting();
         $unstart = activity\limitime::instance()->unstart();
     }
+    public function testOpgoodsMatch()
+    {
+        $pregoods = array(1694 => 1,872 => 2,1708 => 1,4793 => 1);
+        activity_helper::optional_goods_match($pregoods);
+    }
 }

+ 11 - 0
test/TestTime.php

@@ -8,6 +8,17 @@
  */
 class TestTime extends PHPUnit_Framework_TestCase
 {
+    public function testS()
+    {
+        $tm = strtotime('2017-08-01 3:43:00');
+        $tm1 = strtotime('2017-8-01 3:43:00');
+        $tm2 = strtotime('2017-08-1 3:43:00');
+        $tm3 = strtotime('2017-8-1 3:43:00');
+
+        $tm3 = strtotime('2017-8-1 03:43:00');
+        $tm3 = strtotime('2017-8-1 3:43:00');
+        $tm3 = strtotime('2017-8-1  3:43');
+    }
     public function testDay()
     {
         $date = date('Y-m-d',time());

+ 32 - 0
test/TestUGC.php

@@ -177,6 +177,38 @@ class TestUGC extends PHPUnit_Framework_TestCase
         $y = iconv_get_encoding();
         $len = iconv_strlen($str,'UTF-8');
     }
+    public function testVoteResult()
+    {
+        $x = 'a:4:{i:0;i:0;i:1;i:0;i:2;i:0;i:3;i:0;}';
+        $y = unserialize($x);
+    }
+    public function testUpdatevote()
+    {
+        $mod_special = Model('mb_special');
+        $items = $mod_special->field('*')->where(['from_user' => 1])->limit(false)->select();
+        foreach ($items as $item)
+        {
+            $spid = intval($item['special_id']);
+            $params      = $item['params'];
+            $vote_result = $item['vote_result'];
+
+            if(!empty($params) && !empty($vote_result))
+            {
+                $params      = unserialize($params);
+                $vresult = unserialize($vote_result);
+                $vote = $params['vote'];
+                if(!empty($vote))
+                {
+                    $params['vote'] = [];
+                    $params['vote'][] = $vote;
+                    $vote_result = [];
+                    $vote_result[] = $vresult;
+
+                    $mod_special->editUserSpecial($spid,['special_id' =>$spid],['params' => serialize($params),'vote_result' => serialize($vote_result)]);
+                }
+            }
+        }
+    }
 }