浏览代码

Merge branch 'bonus_manager' of 121.43.114.153:/home/git/repositories/shopnc into bonus_manager

james 8 年之前
父节点
当前提交
d5adc539b6
共有 40 个文件被更改,包括 1107 次插入182 次删除
  1. 0 5
      admin/control/mb_special.php
  2. 10 0
      data/model/goods.model.php
  3. 142 7
      data/resource/mobile/bonus/css/content_rem.css
  4. 二进制
      data/resource/mobile/bonus/imgaes/small_bonus_icon.png
  5. 1 1
      data/resource/mobile/fcode/css/main.css
  6. 5 4
      helper/activity/groupbuy.php
  7. 4 2
      helper/activity/limitime.php
  8. 31 3
      helper/activity_helper.php
  9. 147 0
      helper/bonus/scaler.php
  10. 8 0
      helper/bonus_helper.php
  11. 1 1
      helper/buy_first.php
  12. 12 15
      helper/goods_helper.php
  13. 1 1
      helper/model/goods_summary.php
  14. 3 1
      helper/order_helper.php
  15. 12 1
      helper/predeposit_helper.php
  16. 7 0
      helper/search/processor.php
  17. 201 3
      helper/search/searcher.php
  18. 0 2
      helper/search/server.php
  19. 26 40
      helper/search/tcp_client.php
  20. 65 0
      helper/search/util.php
  21. 26 1
      helper/search_param.php
  22. 8 0
      helper/session_helper.php
  23. 90 17
      mobile/control/activity.php
  24. 152 21
      mobile/control/bonusex.php
  25. 1 1
      mobile/control/control.php
  26. 1 1
      mobile/control/index.php
  27. 83 0
      mobile/control/member_bonus.php
  28. 1 1
      mobile/control/member_favorites.php
  29. 10 1
      mobile/control/member_fcode.php
  30. 1 1
      mobile/control/member_notice.php
  31. 20 35
      mobile/control/search.php
  32. 1 1
      mobile/control/special.php
  33. 2 2
      mobile/templates/default/bonus/bind.php
  34. 2 2
      mobile/templates/default/bonus/content.php
  35. 4 2
      mobile/templates/default/bonus/detail.php
  36. 1 0
      mobile/templates/default/fcode/bind.php
  37. 2 1
      shop/control/member_message.php
  38. 12 8
      shop/templates/default/seller/store_promotion_xianshi.add.php
  39. 7 1
      test/TestSearch.php
  40. 7 0
      test/bonus_helperTest.php

+ 0 - 5
admin/control/mb_special.php

@@ -439,11 +439,6 @@ class mb_specialControl extends SystemControl
      */
     public function goods_listOp()
     {
-        //$model_goods = Model('goods');
-//        $condition = array();
-//        $condition['goods_name'] = array('like', '%' . $_REQUEST['keyword'] . '%');
-//        $goods_list = $model_goods->getGoodsOnlineList($condition, 'goods_id,goods_name,goods_promotion_price,goods_image,goods_storage', 10);
-
         $p['keyword'] = urlencode($_REQUEST['keyword']);
         $param = new search_param($p);
         $params = $param->format();

+ 10 - 0
data/model/goods.model.php

@@ -1575,4 +1575,14 @@ class goodsModel extends Model
         return $common_info;
     }
 
+    public function click_goods($goods_id,$goods_info)
+    {
+        $goods_info['goods_click'] = intval($goods_info['goods_click']) + 1;
+        if (C('cache_open')) {
+            $this->_wGoodsCache($goods_id, array('goods_click' => $goods_info['goods_click']));
+            wcache('updateRedisDate', array($goods_id => $goods_info['goods_click']), 'goodsClick');
+        } else {
+            $this->editGoodsById(array('goods_click' => array('exp', 'goods_click + 1')), $goods_id);
+        }
+    }
 }

+ 142 - 7
data/resource/mobile/bonus/css/content_rem.css

@@ -97,7 +97,6 @@ div.link a{
     height: 0;
 }
 .pro {
-    margin-top: 0.67rem;
     position: relative;
 }
 .pro:after {
@@ -219,6 +218,7 @@ p.p_name {
     height: 1.2rem;
     line-height: 1.2rem;
     margin-top: 15px;
+    margin-bottom: 0.67rem;
     font-size: 0.48rem;
 }
 .tel_pro {
@@ -240,8 +240,9 @@ input,button {
 }
 .tel input {
     height: 0.96rem;
-    width: 98%;
+    width: 7.5rem;
     display: inline-block;
+    background: transparent;
 }
 .yanz {
     margin-top: 2%;
@@ -255,13 +256,14 @@ input,button {
     width: 56%;
     height:0.96rem;
 }
-.yanz input {
+/*.yanz input {
     width: 100%;
-}
+}*/
 .yanz button {
     width: 42%;
     display: inline-block;
     border-left: 1px solid #e3e3e3;
+    background: transparent;
 }
 
 @-webkit-keyframes link {
@@ -403,13 +405,13 @@ input,button {
     margin: 0;
 }
 .list {
-    margin-bottom: -0.67rem;
+    margin-bottom: -0.27rem;
 }
 .name .prompt {
     padding: 0 0.4rem;
 }
 .briefing {
-    padding: 0.4rem 0.4rem 0.2rem;
+    padding: 0.4rem 0.4rem;
     margin-bottom: -0.67rem;
 }
 .briefing p {
@@ -495,5 +497,138 @@ input,button {
     padding-left: 0.1rem;
     color: #317DD6;
 }
-
+.goods_items {
+    display: flex;
+    flex-flow: row wrap;
+    color: #000;
+}
+.goods_box {
+    width: 4.61rem;
+    position: relative;
+    margin-top: 0.26rem;
+    background: #fff;
+    margin-left: 0.26rem
+}
+.goods .conserve {
+    background: #FF4E4E;
+    color: #fff;
+    font-size: 9px;
+    padding: 0.06rem;
+    border-bottom-right-radius: 10px;
+    border-bottom-left-radius: 10px;
+}
+[data-dpr = "2"] .goods .conserve {
+    font-size: 18px;
+}
+[data-dpr = "3"] .goods .conserve {
+    font-size: 27px;
+}
+.null_r_margin {
+    margin-right: 0;
+}
+.goods .discounts {
+    font-size: 16px;
+    color: #FF4E4E;
+    vertical-align: middle;
+    line-height: 1.3;
+}
+[data-dpr = "2"] .goods .discounts {
+    font-size: 32px;
+}
+[data-dpr = "3"] .goods .discounts {
+    font-size: 48px;
+}
+.goods .discounts_box {
+    font-size: 9px;
+    color: #FF4E4E;;
+}
+[data-dpr = "2"] .discounts_box {
+    font-size: 18px;
+}
+[data-dpr = "3"] .discounts_box {
+    font-size: 27px;
+}
+.goods .goods_msg {
+    padding: 0.17rem;
+}
+.goods .discount {
+    border: 1px solid #FF4E4E;
+    border-radius: 10px;
+    margin-right: 0.05rem;
+}
+.price_box {
+    margin-top: 0.35rem;
+    overflow: hidden;
+}
+.goods .badge {
+    position: absolute;
+    top: 0.26rem;
+    right: 0.26rem;
+    border-radius: 50px;
+    padding:0.06rem 0.18rem;
+    color: #fff;
+    font-size: 11px;
+}
+[data-dpr = "2"] .goods .badge {
+    font-size: 22px;
+}
+[data-dpr = "3"] .goods .badge {
+    font-size: 33px;
+}
+.goods_name {
+    font-size: 11px;
+    white-space:nowrap;
+    text-overflow:ellipsis;
+    -o-text-overflow:ellipsis;
+    overflow:hidden;
+}
+[data-dpr = "2"] .goods_name {
+    font-size: 22px;
+}
+[data-dpr = "3"] .goods_name {
+    font-size: 33px;
+}
+.desc {
+    font-size: 10px;
+    white-space:nowrap;
+    text-overflow:ellipsis;
+    -o-text-overflow:ellipsis;
+    overflow:hidden;
+    color: #7E7E7E;
+}
+[data-dpr = "2"] .desc {
+    font-size: 22px;
+}
+[data-dpr = "3"] .desc {
+    font-size: 33px;
+}
+.f_left {
+    float: left;
+}
+.f_right {
+    float: right;
+}
+.goods img {
+    width: 100%;
+}
+.bonus_icon {
+    display: inline-block;
+    width: 0.37rem;
+    height: 0.48rem;
+    background: url("../imgaes/small_bonus_icon.png") no-repeat;
+    background-size: 100%;
+}
+.bonus_price {
+    font-size: 22px;
+    color: #FF4E4E;
+}
+[data-dpr = "2"] .bonus_price {
+    font-size: 44px;
+}
+[data-dpr = "3"] .bonus_price {
+    font-size: 66px;
+}
+.link {
+    margin-bottom: 0.67rem;
+}
 

二进制
data/resource/mobile/bonus/imgaes/small_bonus_icon.png


+ 1 - 1
data/resource/mobile/fcode/css/main.css

@@ -213,7 +213,7 @@ input,button,.btn {
     margin-top: 0.21rem;
 }
 .prompt_text ul {
-    width: 6.23rem;
+    width: 8rem;
 }
 .advert {
     border-top: 1px solid #DADADA;

+ 5 - 4
helper/activity/groupbuy.php

@@ -29,10 +29,11 @@ class group_item
         return cthumb($value, 360, $store_id);
     }
 
-    public function to_array()
+    public function format()
     {
         $info['groupbuy_id']     = intval($this->mParam['groupbuy_id']);
         $info['groupbuy_name']   = $this->mParam['groupbuy_name'];
+        $info['groupbuy_type']   = intval($this->mParam['groupbuy_type']);
         $info['remark']          = $this->mParam['remark'];
         $info['start_time']      = intval($this->mParam['start_time']);
         $info['end_time']        = intval($this->mParam['end_time']);
@@ -165,7 +166,7 @@ class groupbuy
         $result = [];
         foreach ($groups as $val) {
             $item = new group_item($val);
-            $result[] = $item->to_array();
+            $result[] = $item->format();
         }
 
         return $result;
@@ -186,7 +187,7 @@ class groupbuy
         $result = [];
         foreach ($groups as $val) {
             $item = new group_item($val);
-            $result[] = $item->to_array();
+            $result[] = $item->format();
         }
 
         return $result;
@@ -243,7 +244,7 @@ class groupbuy
         if(isset($act_id,$this->group_list[$act_id])) {
             $param = $this->group_list[$act_id];
             $item = new group_item($param);
-            return $item->to_array();
+            return $item->format();
         } else {
             return false;
         }

+ 4 - 2
helper/activity/limitime.php

@@ -33,6 +33,7 @@ class limit_item
         $info['end_time']    = intval($this->mParam['end_time']);
         $info['lower_limit'] = intval($this->mParam['lower_limit']);
         $info['state']       = intval($this->mParam['state']);
+        $info['xianshi_type']       = intval($this->mParam['xianshi_type']);
 
         return $info;
     }
@@ -95,15 +96,16 @@ class limitime
         $condition['store_id'] = self::STORE_ID;
         $condition['state'] = self::XIANSHI_STATE_NORMAL;
 
-        $list = $mod->getXianshiList($condition);
+        $list = $mod->getXianshiList($condition,null,'xianshi_type asc');
         foreach ($list as $val)
         {
             $xianshi_id = intval($val['xianshi_id']);
             $limit_list[$xianshi_id] = $val;
             $limitGoods[$xianshi_id] = [];
 
+
             $gids = [];
-            $goods_list = Model('p_xianshi_goods')->getXianshiGoodsList(array('xianshi_id' => $xianshi_id),null,'xianshi_type asc');
+            $goods_list = Model('p_xianshi_goods')->getXianshiGoodsList(array('xianshi_id' => $xianshi_id));
             foreach ($goods_list as $xianshi_goods) {
                 $goods_id = intval($xianshi_goods['goods_id']);
                 self::add_limitgoods($goodsidLimitGoods,$goods_id,$xianshi_goods);

+ 31 - 3
helper/activity_helper.php

@@ -20,12 +20,24 @@ function less_endtime($left,$right)
 {
     $l_end = intval($left['end_time']);
     $r_end = intval($right['end_time']);
+    $l_type = intval($left['time_type']);
+    $r_type = intval($right['time_type']);
+    $l_actype = $left['act_type'];
+    $r_actype = $left['act_type'];
 
     if($l_end > $r_end) {
         return 1;
     }
-    elseif($l_end == $r_end) {
-        return 0;
+    elseif($l_end == $r_end)
+    {
+        if($l_type > $r_type) return 1;
+        elseif($l_type < $r_type) return -1;
+        else
+        {
+            if($l_actype > $r_actype) return 1;
+            elseif($l_actype < $r_actype) return -1;
+            else return 0;
+        }
     }
     else {
         return -1;
@@ -36,12 +48,23 @@ function less_startime($left,$right)
 {
     $l_start = intval($left['start_time']);
     $r_start = intval($right['start_time']);
+    $l_type = intval($left['time_type']);
+    $r_type = intval($right['time_type']);
+    $l_actype = $left['act_type'];
+    $r_actype = $left['act_type'];
 
     if($l_start > $r_start) {
         return 1;
     }
     elseif($l_start == $r_start) {
-        return 0;
+        if($l_type > $r_type) return 1;
+        elseif($l_type < $r_type) return -1;
+        else
+        {
+            if($l_actype > $r_actype) return 1;
+            elseif($l_actype < $r_actype) return -1;
+            else return 0;
+        }
     }
     else {
         return -1;
@@ -134,9 +157,14 @@ class activity_helper
 
         $values = [];
         foreach ($limits as $val) {
+            $val['time_type'] = $val['xianshi_type'];
+            $val['act_type'] = 1;
             $values[] = $val;
         }
+
         foreach ($groupbuys as $val) {
+            $val['time_type'] = $val['groupbuy_type'];
+            $val['act_type'] = 2;
             $values[] = $val;
         }
 

+ 147 - 0
helper/bonus/scaler.php

@@ -0,0 +1,147 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2017/4/20
+ * Time: 下午5:12
+ */
+
+namespace bonus;
+
+
+class scaler
+{
+    const match_rate = 30;
+
+    private $mMoneys;
+    private $mMatchMoney;
+
+    public function __construct($rates_moneys)
+    {
+        $this->mMatchMoney = 0;
+
+        $moneys = [];
+        foreach ($rates_moneys as $rate => $money)
+        {
+            if($rate == self::match_rate) {
+                $this->mMatchMoney += $money;
+            }
+            else {
+                $val = [];
+                $val['rate'] = $rate;
+                $val['amount'] = $money;
+
+                $moneys[] = $val;
+            }
+        }
+        uasort($moneys,['\bonus\scaler','rate_desc']);
+
+        $this->mMoneys = [];
+        foreach ($moneys as $item) {
+            $this->mMoneys[] = $item;
+        }
+    }
+    private function match_money() {
+        return $this->mMatchMoney * 100 / self::match_rate;
+    }
+
+    public function calc()
+    {
+        $total = $this->match_money();
+
+        $count = count($this->mMoneys);
+        if($count == 0) {
+            return $this->format($total);
+        }
+        $max_rate = $this->mMoneys[0]['rate'];
+        if($max_rate < self::match_rate) {
+            return $this->format($total);
+        }
+
+        for($pos = $count - 1; $pos >= 0;)
+        {
+            $ret = $this->_calc($pos);
+            if($ret == false) {
+                $pos--;
+            } else {
+                $total += $ret;
+                $total = intval($total * 100 + 0.5) / 100;
+                return $this->format($total);
+            }
+        }
+        return $this->format($total);
+    }
+
+    private function format($total)
+    {
+        $total = intval($total * 100 + 0.5);
+        if($total == 0) {
+            return false;
+        }
+        else {
+            return $total / 100;
+        }
+    }
+
+    private function _calc($pos)
+    {
+        $rate   = $this->mMoneys[$pos]['rate'];
+        $amount = $this->mMoneys[$pos]['amount'];
+        $y = intval($amount * 100 + 0.5);
+
+        if($rate > self::match_rate)
+        {   //满足条件,用0折扣红包抵扣
+            $this->_calc_AB($pos + 1,$A,$B);
+            return $B + ($A* 100 - self::match_rate * $B)  / (self::match_rate);
+        }
+        else
+        {
+            $this->_calc_AB($pos,$A,$B);
+            $need_amount = ($A * 100 - self::match_rate * $B) * $rate / ((self::match_rate - $rate) * 100);
+            $x = intval($need_amount * 100 + 0.5);
+
+            if($x < 0) { //此时达不到匹配的折扣率
+                return false;
+            }
+            elseif($x == 0) { //前一个恰好抵扣
+                return $B;
+            }
+            else
+            {
+                if($x <= $y) { //当前不满足全部抵扣
+                    return $B + ($x / $rate);
+                }
+                else { //当前还需要用0折扣红包抵扣
+                    $this->_calc_AB($pos + 1,$A,$B);
+                    return $B + ($A * 100 - self::match_rate * $B)  / (self::match_rate);
+                }
+            }
+        }
+    }
+
+    private function _calc_AB($pos,&$A,&$B)
+    {
+        $A = 0;
+        for ($i = 0; $i < $pos; $i++) {
+            $amount = $this->mMoneys[$i]['amount'];
+            $A += $amount;
+        }
+
+        $B = 0;
+        for ($i = 0; $i < $pos; $i++) {
+            $amount = $this->mMoneys[$i]['amount'];
+            $rate = $this->mMoneys[$i]['rate'];
+            $B += $amount * 100 / $rate;
+        }
+    }
+
+    static public function rate_desc($left,$right)
+    {
+        $t_l = intval($left['rate']);
+        $t_r = intval($right['rate']);
+
+        if($t_l > $t_r) return -1;
+        elseif($t_l < $t_r) return 1;
+        else return 0;
+    }
+}

+ 8 - 0
helper/bonus_helper.php

@@ -22,6 +22,7 @@ require_once (BASE_ROOT_PATH . '/helper/bonus/shaker.php');
 require_once (BASE_ROOT_PATH . '/helper/bonus/allocator.php');
 require_once (BASE_ROOT_PATH . '/helper/bonus/witholder.php');
 require_once (BASE_ROOT_PATH . '/helper/bonus/open_sharer.php');
+require_once (BASE_ROOT_PATH . '/helper/bonus/scaler.php');
 
 
 class bonus_helper
@@ -324,4 +325,11 @@ class bonus_helper
             return (empty($items) == true);
         }
     }
+
+    static public function match_price($rate_moneys)
+    {
+        if(empty($rate_moneys)) return false;
+        $scaler = new \bonus\scaler($rate_moneys);
+        return $scaler->calc();
+    }
 }

+ 1 - 1
helper/buy_first.php

@@ -202,7 +202,7 @@ class buy_first
         $goods_ids = $this->goods_ids();
 
         $helper = new goods_helper();
-        $summaries = $helper->get_summary($goods_ids,$related_goods);
+        $summaries = $helper->online_summary($goods_ids,$related_goods);
         $summary_list = $summaries['summary'];
         if(!empty($related_goods)) {
             $related_summary = $helper->cart_summary($related_goods,$x);

+ 12 - 15
helper/goods_helper.php

@@ -25,11 +25,6 @@ class goods_helper
 
     }
 
-    static function common_id($goods_id)
-    {
-        return commonid_helper::instance()->common_id($goods_id);
-    }
-
     public function get_distinct($goods_commonids)
     {
         $goods_list = Model('goods')->cls()->getGoodsListByColorDistinct(array('goods_commonid' => array('in', $goods_commonids)),self::fieldstr);
@@ -63,15 +58,19 @@ class goods_helper
             return false;
         }
 
+        foreach ($goods_list as $goods_info) {
+            $mod->click_goods($goods_info['goods_id'],$goods_info);
+        }
+
         $ret = array();
         $gcommon = new goods_common($common_info,$goods_list,$show_gid);
         $ret['common_info'] = $gcommon->format();
 
-        $ret_summary = $this->get_summaryex($goods_list,$related_goods);
+        $ret_summary = $this->summary($goods_list,$related_goods);
         $summary = $ret_summary['summary'];
 
         if(!empty($related_goods)) {
-            $ret_related = $this->get_summary($related_goods,$x);
+            $ret_related = $this->online_summary($related_goods,$x);
             $summary = array_merge($summary,$ret_related['summary']);
         }
 
@@ -91,11 +90,9 @@ class goods_helper
         return $ret;
     }
 
-    public function get_distinct_summary($common_ids,&$goods_ids,&$related_goods)
+    public function common_summary($common_ids, &$goods_ids, &$related_goods)
     {
         $mod = Model('goods');
-        $mod->cls();
-
         $goods_list = $mod->getGoodsListByColorDistinct(array('goods_commonid' => array('in', $common_ids)),self::fieldstr);
 
         $goods_ids = array();
@@ -103,10 +100,10 @@ class goods_helper
             $goods_ids[] = intval($goods['goods_id']);
         }
 
-        return $this->get_summaryex($goods_list,$related_goods);
+        return $this->summary($goods_list,$related_goods);
     }
 
-    public function get_summary(&$goods_ids,&$related_goods)
+    public function online_summary(&$goods_ids, &$related_goods)
     {
         $goods_list = Model('goods')->cls()->getGoodsOnlineList(array('goods_id' => array('in', $goods_ids)),self::fieldstr);
         $goods_ids = array();
@@ -115,7 +112,7 @@ class goods_helper
             $goods_ids[] = $goods_id;
         }
         $goods_ids = array_unique($goods_ids);
-        $ret = $this->get_summaryex($goods_list,$related_goods);
+        $ret = $this->summary($goods_list,$related_goods);
 
         return $ret;
     }
@@ -123,10 +120,10 @@ class goods_helper
     public function cart_summary($goods_ids,&$related_goods)
     {
         $goods_list = Model('goods')->cls()->getGoodsList(array('goods_id' => array('in', $goods_ids)),self::fieldstr);
-        return $this->get_summaryex($goods_list,$related_goods);
+        return $this->summary($goods_list,$related_goods);
     }
 
-    public function get_summaryex($goods_list, &$related_goods)
+    public function summary($goods_list, &$related_goods)
     {
         $related_goods = [];
         $summary_list = [];

+ 1 - 1
helper/model/goods_summary.php

@@ -155,7 +155,7 @@ class goods_summary
         global $config;
         if($act_id == false) // && empty($this->bundles)
         {
-            $summary['bonus_price']  = predeposit_helper::bonus_price($this->goods_info['goods_price'],$rates);
+            $summary['bonus_price']  = predeposit_helper::login_bonus_price($this->goods_info['goods_price'],$rates);
             $gap = predeposit_helper::discount_gap($summary['bonus_price'],$this->goods_info['goods_price']);
             $summary['discount_gap'] = $gap;
             $summary['gap_show'] = true;

+ 3 - 1
helper/order_helper.php

@@ -8,6 +8,8 @@
  */
 require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/account_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/goods/commonid_helper.php');
+
 
 class refund_item
 {
@@ -744,7 +746,7 @@ class order_helper
             $goods["rec_id"] = intval($val["rec_id"]);
             $goods["order_id"] = intval($val["order_id"]);
             $goods["goods_id"] = intval($val["goods_id"]);
-            $commonid = goods_helper::common_id($goods["goods_id"]);
+            $commonid = commonid_helper::instance()->common_id($goods["goods_id"]);
             if($commonid == false) {
                 continue;
             }

+ 12 - 1
helper/predeposit_helper.php

@@ -294,7 +294,7 @@ class predeposit_helper
         return $bonus_rate->calc_money($goods_amount,$rates);
     }
 
-    static public function bonus_price($goods_price,&$rates)
+    static public function login_bonus_price($goods_price, &$rates)
     {
         if(session_helper::isLogin())
         {
@@ -312,6 +312,17 @@ class predeposit_helper
             return $goods_price;
         }
     }
+
+    static public function unlogin_bonus_price($goods_price,$rate_moneys,&$rates)
+    {
+        if(!empty($rate_moneys)) {
+            $bonus_rate = new RateMoney($rate_moneys);
+            return $bonus_rate->calc_price($goods_price,$rates);
+        } else {
+            return $goods_price;
+        }
+    }
+
     static public function discount_gap($bonus_price,$goods_price)
     {
         $bonus_price = intval($bonus_price* 100 + 0.5);

+ 7 - 0
helper/search/processor.php

@@ -20,6 +20,8 @@ class processor implements IProcessor
 {
     const GetRelatedWord = 1;
     const SearchReasult  = 2;
+    const MatchPrice     = 3;
+
     const ValidateArea   = 20;
 
     public function handle_input($body)
@@ -43,6 +45,11 @@ class processor implements IProcessor
             $result = searcher::instance()->get_result($params);
             return serialize($result);
         }
+        elseif($type == self::MatchPrice) {
+            $params = $body['params'];
+            $result = searcher::instance()->match_price($params);
+            return serialize($result);
+        }
         elseif ($type == self::ValidateArea) {
             $params = $body['params'];
             $area_id = $params['area_id'];

+ 201 - 3
helper/search/searcher.php

@@ -11,6 +11,7 @@ namespace search;
 use algorithm;
 use brand_helper;
 use category_helper;
+use Log;
 
 function mb_str_split( $string ) {
     return preg_split('/(?<!^)(?!$)/u', $string );
@@ -209,9 +210,88 @@ class goods_dict extends words
     }
 }
 
+class goods_info
+{
+    private $mGoods;
+    public function __construct()
+    {
+        $this->mGoods = [];
+    }
+
+    public function add($commonid, $price, $click, $salenum)
+    {
+        $commonid = intval($commonid);
+        if(!array_key_exists($commonid,$this->mGoods)) {
+            $this->mGoods[$commonid]['price'] = intval($price * 100 + 0.5);
+            $this->mGoods[$commonid]['click'] = intval($click);
+            $this->mGoods[$commonid]['salenum'] = intval($salenum);
+        }
+    }
+    public function goods($commonid)
+    {
+        return $this->mGoods[$commonid];
+    }
+
+    static public function click_asc($left,$right)
+    {
+        $t_l = intval($left['click']);
+        $t_r = intval($right['click']);
+
+        if($t_l > $t_r) return 1;
+        elseif($t_l < $t_r) return -1;
+        else return 0;
+    }
+    static public function click_desc($left,$right)
+    {
+        $t_l = intval($left['click']);
+        $t_r = intval($right['click']);
+
+        if($t_l > $t_r) return -1;
+        elseif($t_l < $t_r) return 1;
+        else return 0;
+    }
+
+    static public function salenum_asc($left,$right)
+    {
+        $t_l = intval($left['salenum']);
+        $t_r = intval($right['salenum']);
+
+        if($t_l > $t_r) return 1;
+        elseif($t_l < $t_r) return -1;
+        else return 0;
+    }
+    static public function salenum_desc($left,$right)
+    {
+        $t_l = intval($left['salenum']);
+        $t_r = intval($right['salenum']);
+
+        if($t_l > $t_r) return -1;
+        elseif($t_l < $t_r) return 1;
+        else return 0;
+    }
+    static public function price_asc($left,$right)
+    {
+        $t_l = intval($left['price']);
+        $t_r = intval($right['price']);
+
+        if($t_l > $t_r) return 1;
+        elseif($t_l < $t_r) return -1;
+        else return 0;
+    }
+    static public function price_desc($left,$right)
+    {
+        $t_l = intval($left['price']);
+        $t_r = intval($right['price']);
+
+        if($t_l > $t_r) return -1;
+        elseif($t_l < $t_r) return 1;
+        else return 0;
+    }
+}
+
 class searcher
 {
-    const filter = "goods_commonid,gc_id,brand_id,goods_mobile_name,goods_jingle,goods_spec";
+    const filter = "goods_commonid,gc_id,brand_id,goods_mobile_name,goods_jingle,goods_spec,goods_click,goods_salenum,goods_price";
 
     private $name_dict;
     private $jingle_dict;
@@ -221,6 +301,9 @@ class searcher
     private $category_dict;
     private $goods_dict;
 
+    private $goods_info;
+    private $price_cids;
+
     private static $stInstance;
 
     public static function instance()
@@ -255,6 +338,8 @@ class searcher
         $this->jingle_dict = new words();
         $this->spec_dict = new words();
         $this->goods_dict = new goods_dict();
+        $this->goods_info = new goods_info();
+        $this->price_cids = new valtokey();
 
         $mod_goods = Model('goods');
         $items = $mod_goods->getGoodsOnlineList(array(), self::filter, '', '', false);
@@ -280,7 +365,11 @@ class searcher
             $this->brand_dict->add_brand($brand_id,$common_id,$hot_id);
             $this->goods_dict->add_goods($common_id,$brand_id,$hot_id);
             $this->category_dict->add_hot($hot_id,$brand_id,$common_id);
+
+            $this->goods_info->add($common_id,$item['goods_price'],$item['goods_click'],$item['goods_salenum']);
+            $this->price_cids->add($common_id,intval($item['goods_price'] * 100 + 0.5));
         }
+        $this->price_cids->finish();
     }
 
     private function get_name($dict, $words)
@@ -486,10 +575,119 @@ class searcher
         }
 
         if(isset($keyword) && !empty($keyword)) {
-            return $this->keyword_serarch($keyword,$hot,$brand);
+            $result = $this->keyword_serarch($keyword,$hot,$brand);
         } else {
-            return $this->hb_search($hot,$brand);
+            $result = $this->hb_search($hot,$brand);
+        }
+
+        if(!empty($result))
+        {
+            $order = $params['order'];
+            $sort  = $params['sort'];
+
+            $page_count = 1;
+            if(!isset($params['page_no'])) {
+                $page_no = null;
+            } else {
+                $page_no = $params['page_no'];
+            }
+
+            if(!isset($params['page_size'])) {
+                $page_size = null;
+            } else {
+                $page_size = intval($params['page_size']);
+                $page_size = $page_size <= 0 ? 10 : $page_size;
+                $page_count = intval(count($result['cids']) / $page_size) + ((count($result['cids']) % $page_size) == 0 ? 0 : 1);
+            }
+
+            $cids = $this->sort_goods($result['cids'],$order,$sort,$page_no,$page_size);
+            $result['cids'] = $cids;
+            $result['page_count'] = $page_count;
+        }
+
+        return $result;
+    }
+
+    private function sort_goods($cids,$order,$sort,$page_no,$page_size)
+    {
+        $goods = [];
+        foreach ($cids as $cid) {
+            $val = $this->goods_info->goods($cid);
+            $val['cid'] = $cid;
+            $goods[] = $val;
+        }
+
+        if($sort == 'asc')
+        {
+            if($order == 'click') {
+                uasort($goods,['\search\goods_info','click_asc']);
+            }
+            elseif($order == 'salenum') {
+                uasort($goods,['\search\goods_info','salenum_asc']);
+            }
+            elseif($order == 'price') {
+                uasort($goods,['\search\goods_info','price_asc']);
+            }
+            else {
+                Log::record("searcher sort_goods not order param");
+            }
+        }
+        else
+        {
+            if($order == 'click') {
+                uasort($goods,['\search\goods_info','click_desc']);
+            }
+            elseif($order == 'salenum') {
+                uasort($goods,['\search\goods_info','salenum_desc']);
+            }
+            elseif($order == 'price') {
+                uasort($goods,['\search\goods_info','price_desc']);
+            }
+            else {
+                Log::record("searcher sort_goods not order param");
+            }
         }
+
+        $tmp = [];
+        foreach ($goods as $val) {
+            $tmp[] = $val;
+        }
+        $goods = $tmp;
+
+        $count = count($goods);
+        $result = [];
+        if($page_no == null || $page_size == null)
+        {
+            foreach ($goods as $val) {
+                $result[] = $val['cid'];
+            }
+        }
+        else
+        {
+            $page_no = $page_no <= 0 ? 1 : $page_no;
+            for ($start = ($page_no -1) * $page_size; $page_size > 0 && $start < $count; $page_size--,$start++) {
+                $result[] = $goods[$start]['cid'];
+            }
+        }
+
+        return $result;
+    }
+
+    public function match_price($params)
+    {
+        $price = $params['price'];
+        $page_no   = intval($params['page_no']);
+        $page_size = intval($params['page_size']);
+
+        if($page_no <= 0 || $page_size <= 0) {
+            return false;
+        }
+        $start = ($page_no - 1) * $page_size;
+
+        $result = $this->price_cids->findless(intval($price * 100 + 0.5),$start,$page_size);
+        $result['page_count'] = intval($result['total'] / $page_size) + ($result['total'] % $page_size == 0 ? 0 : 1);
+
+        return $result;
     }
 
     private function get_ids($dict, $words)

+ 0 - 2
helper/search/server.php

@@ -53,7 +53,6 @@ class CentraHelper
 
     public function run_loop($sockfd)
     {
-        //$this->mListenSocket = stream_socket_server ($this->remote_addr(), $errno, $errstr);
         $this->mListenSocket = $sockfd;
         Log::record("stream_set_blocking",Log::DEBUG);
         if(stream_set_blocking($this->mListenSocket, 0) == false) {
@@ -100,7 +99,6 @@ class CentraHelper
         if($buffer == false) {
             fclose($stream);
             Log::record("event_buffer_new return false pid={$pid} socket_fd={$socket}",Log::DEBUG);
-
             return;
         }
 

+ 26 - 40
helper/search/tcp_client.php

@@ -14,6 +14,7 @@ class tcp_client
 {
     const GetRelatedWord = 1;
     const SearchReasult  = 2;
+    const MatchPrice     = 3;
 
     const ValidateArea   = 20;
 
@@ -44,6 +45,29 @@ class tcp_client
 
     public function get_words($word)
     {
+        $param = array("type" => self::GetRelatedWord, "keyword" => $word);
+        return $this->request($param);
+    }
+
+    public function get_result($params)
+    {
+        $param = array("type" => self::SearchReasult, "params" => $params);
+        return $this->request($param);
+    }
+    public function match_price($params)
+    {
+        $param = array("type" => self::MatchPrice, "params" => $params);
+        return $this->request($param);
+    }
+
+    public function get_area($area_id)
+    {
+        $param = array("type" => self::ValidateArea, "params" => array('area_id' => $area_id));
+        return $this->request($param);
+    }
+
+    private function request($param)
+    {
         $times = 0;
         do
         {
@@ -51,7 +75,6 @@ class tcp_client
                 return false;
             }
 
-            $param = array("type" => self::GetRelatedWord, "keyword" => $word);
             $ret = $this->write_param($param);
             if($ret === false) {
                 $this->fini_socket();
@@ -65,48 +88,11 @@ class tcp_client
                 return unserialize($body);
             }
         }
-        $this->fini_socket();
-        return false;
-    }
-
-    public function get_result($params)
-    {
-        if($this->init_socket() == false) {
-            return false;
-        }
-
-        $param = array("type" => self::SearchReasult, "params" => $params);
-        $ret = $this->write_param($param);
-
-        if($ret == true)
+        else
         {
-            $body = $this->read_body();
-            if($body != false) {
-                return unserialize($body);
-            }
-        }
-        $this->fini_socket();
-        return false;
-    }
-
-    public function get_area($area_id)
-    {
-        if($this->init_socket() == false) {
+            $this->fini_socket();
             return false;
         }
-
-        $param = array("type" => self::ValidateArea, "params" => array('area_id' => $area_id));
-        $ret = $this->write_param($param);
-
-        if($ret == true)
-        {
-            $body = $this->read_body();
-            if($body != false) {
-                return unserialize($body);
-            }
-        }
-        $this->fini_socket();
-        return false;
     }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

+ 65 - 0
helper/search/util.php

@@ -225,3 +225,68 @@ class array_tree
         return $this->mTree[$hot]['subids'];
     }
 }
+
+class valtokey
+{
+    private $mKeys;
+    private $mValMap;
+    private $mKeyMap;
+    private $mCount;
+
+    public function __construct()
+    {
+        $this->mKeys   = [];
+        $this->mValMap = [];
+        $this->mKeyMap = [];
+        $this->mCount = 0;
+    }
+
+    public function add($key,$val)
+    {
+        if(algorithm::binary_search($this->mKeyMap,$key) == true) {
+            return false;
+        } else {
+            $pos = algorithm::lower_bonud($this->mKeyMap,$key);
+            algorithm::array_insert($this->mKeyMap,$pos,$key);
+        }
+
+        $pos = algorithm::lower_bonud($this->mValMap,$val);
+        algorithm::array_insert($this->mValMap,$pos,$val);
+        algorithm::array_insert($this->mKeys,$pos,$key);
+
+        return true;
+    }
+    public function finish() {
+        $this->mKeyMap = [];
+        $this->mCount = count($this->mKeys);
+    }
+
+    public function findless($val,$start,$length)
+    {
+        $pos = algorithm::upper_bound($this->mValMap,$val);
+        if($pos < 0) {
+            return false;
+        }
+        elseif ($pos >= $this->mCount) {
+            $pos = $this->mCount - 1;
+        }
+        else {
+            $data = $this->mValMap[$pos];
+            if($data > $val) {
+                $pos -= 1;
+            }
+        }
+
+        $pos = $pos - $start;
+        if($pos < 0) {
+            return false;
+        }
+
+        $result = [];
+        for ($i = $pos; $i >= 0 && $length > 0; $i--,$length--) {
+            $result[] = $this->mKeys[$i];
+        }
+
+        return array('total' => $pos + 1,'cids' => $result);
+    }
+}

+ 26 - 1
helper/search_param.php

@@ -12,6 +12,8 @@ class search_param
     private $mKeyWord;
     private $mBrandId;
     private $mHotId;
+    private $mOrder;
+    private $mSort;
 
     public function __construct($param)
     {
@@ -33,9 +35,28 @@ class search_param
         if (!empty(trim($param['hot_id']))) {
             $this->mHotId = intval($param['hot_id']);
         }
+
+        //下面两个参数和客户端定义反了
+        $this->mOrder = 'click';
+        if (!empty($param['sort']))
+        {
+            $order = strtolower(trim($param['sort']));
+            if(in_array($order,array('click','salenum','price'))) {
+                $this->mOrder = $order;
+            }
+        }
+
+        $this->mSort = 'desc';
+        if (!empty($param['order']))
+        {
+            $sort = strtolower(trim($param['order']));
+            if(in_array($sort,array('asc','desc'))) {
+                $this->mSort = $sort;
+            }
+        }
     }
 
-    public function format()
+    public function format($page_no = null,$page_size = null)
     {
         if (empty($this->mKeyWord) && $this->mBrandId == 0 && $this->mHotId == 0) {
             return false;
@@ -44,6 +65,10 @@ class search_param
             $result['keyword'] = $this->mKeyWord;
             $result['brand_id'] = $this->mBrandId;
             $result['hot_id'] = $this->mHotId;
+            $result['order'] = $this->mOrder;
+            $result['sort'] = $this->mSort;
+            $result['page_no'] = $page_no;
+            $result['page_size'] = $page_size;
 
             return $result;
         }

+ 8 - 0
helper/session_helper.php

@@ -69,6 +69,14 @@ class session_helper
     {
         return ($_SESSION['is_login'] == 1);
     }
+    static public function isapp()
+    {
+        if(isset($_SESSION['is_app'])) {
+            return ($_SESSION['is_app'] == true);
+        } else {
+            return false;
+        }
+    }
 
     static public function isVerfiyMobile()
     {

+ 90 - 17
mobile/control/activity.php

@@ -8,6 +8,7 @@
 
 require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
+require_once(BASE_ROOT_PATH . '/helper/special_helper.php');
 
 class act_formater
 {
@@ -25,31 +26,58 @@ class act_formater
         $specials = [];
         $goods_ids = [];
 
+        $cur_type = -1;
         foreach ($this->mActivities as $act)
         {
             $gids =[];
+            $block = false;
+
             if(array_key_exists('xianshi_id',$act))
             {
                 $block = $this->format_limit($act,$gids);
                 if($block != false) {
-                    $specials[]= $block;
-                    self::array_copy($goods_ids,$gids);
+                    $time_type = intval($act['xianshi_type']);
                 }
             }
             elseif(array_key_exists('groupbuy_id',$act))
             {
                 $block = $this->format_groupbuy($act,$gids);
                 if($block != false) {
-                    $specials[]= $block;
-                    self::array_copy($goods_ids,$gids);
+                    $time_type = intval($act['groupbuy_type']);
                 }
             }
+            else {
+                $time_type = false;
+                Log::record("an error activity.",Log::ERR);
+            }
+
+            if($block != false)
+            {
+                if($time_type !== false)
+                {
+                    if($cur_type != $time_type)
+                    {
+                        $banners = $this->type_banner($time_type);
+                        if(!empty($banners))
+                        {
+                            foreach ($banners as $banner) {
+                                $specials[] = $banner;
+                            }
+                        }
+                        $cur_type = $time_type;
+                    }
+                }
+
+                $specials[]= $block;
+                self::array_copy($goods_ids,$gids);
+            }
         }
+
         $goods_ids = array_unique($goods_ids);
         if(!empty($goods_ids))
         {
             $helper = new goods_helper();
-            $ret = $helper->get_summary($goods_ids,$related);
+            $ret = $helper->online_summary($goods_ids,$related);
 
             return array('special_list' => $specials,
                 'summary' => $ret['summary'],
@@ -76,16 +104,17 @@ class act_formater
         $group_ids = [];
         $limit_ids = [];
 
+        $cur_type = -1;
         foreach ($this->mActivities as $act)
         {
             $gids = [];
+            $block = false;
             if(array_key_exists('xianshi_id',$act))
             {
                 $block = $this->format_limit($act,$gids);
                 if($block != false) {
                     $limit_ids[] = intval($act['xianshi_id']);
-                    $specials[]= $block;
-                    self::array_copy($goods_ids,$gids);
+                    $time_type = intval($act['xianshi_type']);
                 }
             }
             elseif(array_key_exists('groupbuy_id',$act))
@@ -93,20 +122,41 @@ class act_formater
                 $block = $this->format_groupbuy($act,$gids);
                 if($block != false) {
                     $group_ids[] = intval($act['groupbuy_id']);
-                    $specials[]= $block;
-                    self::array_copy($goods_ids,$gids);
+                    $time_type = intval($act['groupbuy_type']);
                 }
             }
             else {
+                $time_type = false;
                 Log::record("an error activity.",Log::ERR);
             }
+
+            if($block != false)
+            {
+                if($time_type !== false)
+                {
+                    if($cur_type != $time_type)
+                    {
+                        $banners = $this->type_banner($time_type);
+                        if(!empty($banners))
+                        {
+                            foreach ($banners as $banner) {
+                                $specials[] = $banner;
+                            }
+                        }
+                        $cur_type = $time_type;
+                    }
+                }
+
+                $specials[]= $block;
+                self::array_copy($goods_ids,$gids);
+            }
         }
 
         $goods_ids = array_unique($goods_ids);
         if(!empty($goods_ids))
         {
             $helper = new goods_helper();
-            $ret = $helper->get_summary($goods_ids,$related);
+            $ret = $helper->online_summary($goods_ids,$related);
 
             $summarys = $ret['summary'];
             foreach ($summarys as &$summary)
@@ -157,7 +207,8 @@ class act_formater
                 'bundling' => $ret['bundling'],
                 'mobile_page' => mobile_page(1));
         }
-        else {
+        else
+        {
             return array('special_list' => null,
                 'summary' => null,
                 'groupbuy' => null,
@@ -167,6 +218,22 @@ class act_formater
         }
     }
 
+    private function type_banner($time_type)
+    {
+        static $stTimeBanner = array(12 => 345,20 => 347,24 => 348);
+        //static $stTimeBanner = array(12 => 60);
+
+        if(array_key_exists($time_type,$stTimeBanner))
+        {
+            $banners = special_manager::instance()->special($stTimeBanner[$time_type],$gids);
+            if(empty($banners))
+                return null;
+            else
+                return $banners;
+        }
+        return null;
+    }
+
     private function format_limit($limt, &$goods_ids)
     {
         $result =[];
@@ -262,10 +329,11 @@ class limit_outer
 
         $act_id = $act['xianshi_id'];
         $gids = activity_helper::limit_goods($act_id);
-        $goods_ids = array($gids[0]);
+        if(empty($gids)) return false;
 
+        $goods_ids = array($gids[0]);
         $helper = new goods_helper();
-        $ret = $helper->get_summary($goods_ids,$related);
+        $ret = $helper->online_summary($goods_ids,$related);
 
         if(!empty($ret['summary']))
         {
@@ -296,10 +364,11 @@ class limit_outer
         $act = $this->mAct;
         $act_id = $act['groupbuy_id'];
         $gids = activity_helper::groupbuy_goods($act_id);
-        $goods_ids = array($gids[0]);
+        if(empty($gids)) return false;
 
+        $goods_ids = array($gids[0]);
         $helper = new goods_helper();
-        $ret = $helper->get_summary($goods_ids,$related);
+        $ret = $helper->online_summary($goods_ids,$related);
 
         if(!empty($ret['summary']))
         {
@@ -358,7 +427,9 @@ class activityControl extends mobileControl
             $act = $acts[0];
             $outer = new limit_outer(limit_outer::WAIT_END,$act);
             $result = $outer->format();
-            return self::outsuccess($result,"activity/limit_entra");
+            if($result != false) {
+                return self::outsuccess($result,"activity/limit_entra");
+            }
         }
 
         $unstarts = activity_helper::unstart();
@@ -366,7 +437,9 @@ class activityControl extends mobileControl
             $act = $unstarts[0];
             $outer = new limit_outer(limit_outer::WAIT_START,$act);
             $result = $outer->format();
-            return self::outsuccess($result,"activity/limit_entra");
+            if($result != false) {
+                return self::outsuccess($result,"activity/limit_entra");
+            }
         }
 
         return self::outsuccess(null,"activity/limit_entra");

+ 152 - 21
mobile/control/bonusex.php

@@ -15,6 +15,10 @@ require_once (BASE_ROOT_PATH . '/helper/sms_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/model_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/category_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/brand_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/search/tcp_client.php');
+require_once (BASE_ROOT_PATH . '/helper/search/util.php');
+require_once (BASE_ROOT_PATH . '/helper/search_param.php');
+require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
 
 class bonusexControl extends mobileControl
 {
@@ -84,9 +88,16 @@ class bonusexControl extends mobileControl
                     $mine_bonus = bonus_helper::get_mine_by_bonussn($new_sn);
                 }
             }
-            $data = array('type_info' => $type_info, 'mine_bonus' => $mine_bonus,'binded_info' => $binded_info,'avatars' => $avatars,'relay_id' =>$relay_id);
+
+            $summarys = $this->matched_goods($mine_bonus);
+            $data = array('type_info' => $type_info,
+                'mine_bonus' => $mine_bonus,
+                'binded_info' => $binded_info,
+                'avatars' => $avatars,
+                'summarys' => $summarys,
+                'relay_id' =>$relay_id);
             if($bonus->isBinded() || $isMineType) {
-                return self::outsuccess($data,"bonus/content");
+                return self::outsuccess($data,"bonus/detail");
             }
             else
             {
@@ -117,9 +128,11 @@ class bonusexControl extends mobileControl
             else
             {
                 if($type->isEnd() || $type->binded_over()) {
+                    $summarys = $this->matched_goods($mine_bonus);
                     return self::outsuccess(array('type_info' => $type_info,
                         'binded_info' => $binded_info,
-                        'avatars' => $avatars),
+                        'avatars' => $avatars,
+                        'summarys' => $summarys),
                         'bonus/detail');
                 }
                 else {
@@ -151,10 +164,12 @@ class bonusexControl extends mobileControl
             $mine_bonus = bonus_helper::filter_bonus($mine_bonus);
         }
 
+        $summarys = $this->matched_goods($mine_bonus);
         return self::outsuccess(array('type_info' => $type_info,
             'mine_bonus' => $mine_bonus,
             'binded_info' => $binded_info,
-            'avatars' => $avatars),
+            'avatars' => $avatars,
+            'summarys' => $summarys),
             'bonus/detail');
     }
 
@@ -186,11 +201,13 @@ class bonusexControl extends mobileControl
             $mine_bonus = bonus_helper::filter_bonus($mine_bonus);
 
             if($bonus_obj->isBinded()) {
+                $summarys = $this->matched_goods($mine_bonus);
                 return self::outsuccess(array('type_info' => $type_info,
                     'mine_bonus' => $mine_bonus,
                     'binded_info' => $binded_info,
-                    'avatars' => $avatars),
-                    "bonus/content");
+                    'avatars' => $avatars,
+                    'summarys' => $summarys),
+                    "bonus/detail");
             }
             elseif($type->isEnd()) {
                  return self::outsuccess(array('type_info' => $type_info),"bonus/end");
@@ -206,11 +223,13 @@ class bonusexControl extends mobileControl
                     $ret = bonus_helper::bind_bonus($bonus_obj->bonus_sn(),$_SESSION['MPHPSESSID'],session_helper::cur_mobile(),$new_sn);
                     if($ret == true) {
                         $mine_bonus = bonus_helper::get_mine_by_bonussn($new_sn);
+                        $summarys = $this->matched_goods($mine_bonus);
                         return self::outsuccess(array('type_info' => $type_info,
                             'mine_bonus' => $mine_bonus,
                             'binded_info' => $binded_info,
-                            'avatars' => $avatars),
-                            "bonus/content");
+                            'avatars' => $avatars,
+                            'summarys' => $summarys),
+                            "bonus/detail");
                     } else {
                         return self::outsuccess(array('type_info' => $type_info,
                             'mine_bonus' => $mine_bonus,'binded_info' => $binded_info,
@@ -250,11 +269,14 @@ class bonusexControl extends mobileControl
                             return self::outerr(errcode::ErrBonus,"无此红包.");
                         }
                         $this->fileter_typeinfos($type_infos,$type_info,$binded_info,$avatars);
+                        $summarys = $this->matched_goods($mine_bonus);
                         $data = array('type_info' => $type_info,
                             'mine_bonus' => $mine_bonus,
                             'binded_info' => $binded_info,
-                            'avatars' => $avatars,'relay_id' =>$relay_id);
-                        return self::outsuccess($data,"bonus/content");
+                            'avatars' => $avatars,
+                            'summarys' => $summarys,
+                            'relay_id' =>$relay_id);
+                        return self::outsuccess($data,"bonus/detail");
                     } else {
                         $data = array('type_info' => $type_info, 'mine_bonus' => $mine_bonus,'binded_info' => $binded_info,'avatars' => $avatars,'relay_id' =>$relay_id);
                         return self::outsuccess($data,"bonus/bind");
@@ -281,7 +303,13 @@ class bonusexControl extends mobileControl
             $type_infos = bonus_helper::get_typeinfo($type_sn);
             $this->fileter_typeinfos($type_infos,$type_info,$binded_info,$avatars);
             $mine_bonus = bonus_helper::filter_bonus($mine_bonus);
-            return self::outsuccess(array('type_info' => $type_info, 'mine_bonus' => $mine_bonus,'binded_info' => $binded_info,'avatars' => $avatars),"bonus/content");
+            $summarys = $this->matched_goods($mine_bonus);
+            return self::outsuccess(array('type_info' => $type_info,
+                'mine_bonus' => $mine_bonus,
+                'binded_info' => $binded_info,
+                'avatars' => $avatars,
+                'summarys' => $summarys),
+                "bonus/detail");
         }
 
         $type_sn = $bonus_obj->type_sn();
@@ -338,7 +366,10 @@ class bonusexControl extends mobileControl
                 $type_infos = bonus_helper::get_typeinfo($bonus_obj->type_sn());
                 $this->fileter_typeinfos($type_infos,$type_info,$binded_info,$avatars);
 
-                return self::outsuccess(array('type_info' => $type_info, 'mine_bonus' => $mine_bonus,'binded_info' => $binded_info,'avatars' => $avatars));
+                return self::outsuccess(array('type_info' => $type_info,
+                    'mine_bonus' => $mine_bonus,
+                    'binded_info' => $binded_info,
+                    'avatars' => $avatars));
             } else {
                 return self::outerr($ret['code'],$ret['msg']);
             }
@@ -397,8 +428,13 @@ class bonusexControl extends mobileControl
                     $bonus = bonus_helper::get_mine_by_bonussn($bonus_obj->bonus_sn());
                     $type_infos = bonus_helper::get_typeinfo($bonus_obj->type_sn());
                     $this->fileter_typeinfos($type_infos,$type_info,$binded_info,$avatars);
-
-                    return self::outsuccess(array('type_info' => $type_info,'mine_bonus' => $bonus,'binded_info' => $binded_info,'avatars' => $avatars),"bonus/content");
+                    $summarys = $this->matched_goods($mine_bonus);
+                    return self::outsuccess(array('type_info' => $type_info,
+                        'mine_bonus' => $bonus,
+                        'binded_info' => $binded_info,
+                        'avatars' => $avatars,
+                        'summarys' => $summarys),
+                        "bonus/detail");
                 } else {
                     return self::outsuccess(errcode::ErrBonus,"只有拼收起红包才可以摇哦~");
                 }
@@ -427,6 +463,63 @@ class bonusexControl extends mobileControl
             return self::outerr(errcode::ErrBonusComment,"留言失败.");
         }
     }
+
+    private function matched_goods($bonus)
+    {
+        if(session_helper::isapp())
+        {
+
+        }
+        else
+        {
+            if($bonus == false) return false;
+            $rate_moneys[intval($bonus['bonus_rate'])] = $bonus['bonus_value'];
+            $price = bonus_helper::match_price($rate_moneys);
+            if($price == false) {
+                return false;
+            }
+
+            $params = ['price' => $price,'page_no' => 1,'page_size' => 10];
+            $result = search\tcp_client::instance()->match_price($params);
+
+            $cids = $result['cids'];
+            $model_goods = Model('goods');
+            $items = $model_goods->getGoodsListByColorDistinct(array('goods_commonid' => array('in',$cids)),goods_helper::fieldstr,'','');
+
+            $tmp =[];
+            foreach ($items as $item) {
+                $commonid = intval($item['goods_commonid']);
+                $tmp[$commonid] = $item;
+            }
+
+            $summarys = [];
+            foreach ($cids as $cid)
+            {
+                if(array_key_exists($cid,$tmp)) {
+                    $summarys[] = $this->simple_summary($tmp[$cid],$rate_moneys);
+                }
+            }
+
+            return $summarys;
+        }
+    }
+
+    private function simple_summary($goods_info, $rate_moneys)
+    {
+        $summary['goods_image'] = cthumb($goods_info['goods_image'],1280,$goods_info['store_id']);
+        $summary['goods_name']  = $goods_info['goods_mobile_name'];
+        $summary['goods_jingle'] = $goods_info['goods_jingle'];
+        $summary['goods_price'] = intval($goods_info['goods_price'] * 100 + 0.5) / 100;
+
+        $bonus_price  = predeposit_helper::unlogin_bonus_price($goods_info['goods_price'],$rate_moneys,$rates);
+        $summary['bonus_price'] = intval($bonus_price * 100 + 0.5) / 100;
+
+        $discount = intval($summary['bonus_price'] * 100 / $goods_info['goods_price'] + 0.5) / 100;
+        $summary['discount'] = $discount * 10;
+        $summary['price_diff'] = $goods_info['goods_price'] - $summary['bonus_price'];
+
+        return $summary;
+    }
 }
 
 function bonus_output_unstart($output)
@@ -769,13 +862,51 @@ function share_image($output)
     return $share['img_url'];
 }
 
-function bonus_rule()
+function bonnus_out_goods($output)
+{
+    $summarys = $output['summarys'];
+    if($summarys == false) return;
+
+
+    echo '<div class="prompt text_left"> 
+            <p class="pro">已达内买价的商品(去APP内部查看详情)</p>
+          </div>';
+
+    echo '<div class="goods_items">';
+    foreach ($summarys as $summary)
+    {
+        echo
+        "<div class='goods_box'>
+            <div class='goods'>
+                <div>
+                    <img src=\"{$summary['goods_image']}\">
+                </div>
+                <div class=\"goods_msg\">
+                    <p class=\"text_left goods_name\">{$summary['goods_name']}</p>
+                    <p class=\"text_left desc\">{$summary['goods_jingle']}</p>
+                    <div class=\"price_box\">
+                        <div class=\"f_left\">
+                            <p class=\"text_left desc\">专柜价{$summary['goods_price']}元</p>
+                            <p class=\"text_left bonus_price\"><span class=\"bonus_icon\"></span>{$summary['bonus_price']}</p>
+                        </div>
+                        <div class=\"f_right discount\">
+                            <p class=\"discounts_box\"><span class=\"discounts\">{$summary['discount']}</span>折</p>
+                            <p class=\"conserve\">立省{$summary['price_diff']}元</p>
+                        </div>
+                    </div>
+                    <div class=\"badge\" style=\"background:#3CB638;\">新品</div>
+                </div>
+            </div>
+        </div>";
+    }
+
+    echo '</div>';
+}
+
+function bonus_out_rule()
 {
-    //todo 等一段时间之后,红包界面APP内部不现实这些规则
-//    if($_SESSION['is_app'])
-//        return '';
-//    else
-        return '<div class="prompt text_left">
+    echo
+    '<div class="prompt text_left">
         <p class="pro">红包细则</p>
     </div>
     <div class="briefing text_left">
@@ -790,7 +921,7 @@ function bonus_rule()
     </div>';
 }
 
-function bonus_brands()
+function bonus_out_brands()
 {
     if($_SESSION['is_app']) {
         return;

+ 1 - 1
mobile/control/control.php

@@ -272,7 +272,7 @@ class mbMemberControl extends mobileControl
 
 function bonus_version()
 {
-    return "v=20170411";
+    return "v=2017042101";
 }
 function shop_version()
 {

+ 1 - 1
mobile/control/index.php

@@ -81,7 +81,7 @@ class indexControl extends specialControl
             $goods_ids = $ret[$page_no - 1];
 
             $helper = new goods_helper();
-            $ret = $helper->get_summary($goods_ids,$other_goods);
+            $ret = $helper->online_summary($goods_ids,$other_goods);
 
             $blocks = [];
             $blocks[] = special_formater::format_goods($goods_ids,"热门推荐",$ret['sort_summary']);

+ 83 - 0
mobile/control/member_bonus.php

@@ -13,6 +13,11 @@ require_once (BASE_ROOT_PATH . '/helper/shaker_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/ranklist_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/special_helper.php');
 require_once (BASE_ROOT_PATH . '/helper/util_helper.php');
+require_once (BASE_ROOT_PATH . '/helper/search/tcp_client.php');
+require_once (BASE_ROOT_PATH . '/helper/search/util.php');
+require_once (BASE_ROOT_PATH . '/helper/search_param.php');
+require_once (BASE_ROOT_PATH . '/helper/goods_helper.php');
+
 
 class member_bonusControl extends mbMemberControl
 {
@@ -115,6 +120,82 @@ class member_bonusControl extends mbMemberControl
         }
     }
 
+    public function match_goodsOp()
+    {
+        $bonus_rate = $this->mPred->bonus_rate();
+        $rate_moneys = $bonus_rate->format();
+        $price = bonus_helper::match_price($rate_moneys);
+
+        if($price == false)
+        {
+            return self::outsuccess(array('special_list' => null,
+                'summary'  => null,
+                'groupbuy' => null,
+                'limitime' => null,
+                'bundling' => null,
+                'mobile_page' => mobile_page(0)));
+        }
+        else
+        {
+            $params = ['price' => $price,'page_no' => $this->page_no(),'page_size' => $this->page_size()];
+            $result = search\tcp_client::instance()->match_price($params);
+
+            $cids = $result['cids'];
+            $model_goods = Model('goods');
+            $items = $model_goods->getGoodsListByColorDistinct(array('goods_commonid' => array('in',$cids)),goods_helper::fieldstr,'','');
+            $page_count = $result['page_count'];
+
+            if(empty($items))
+            {
+                return self::outsuccess(array('special_list' => null,
+                    'summary'  => null,
+                    'groupbuy' => null,
+                    'limitime' => null,
+                    'bundling' => null,
+                    'mobile_page' => mobile_page($page_count)));
+            }
+            else
+            {
+                $tmp =[];
+                foreach ($items as $item) {
+                    $commonid = intval($item['goods_commonid']);
+                    $tmp[$commonid] = $item;
+                }
+
+                $goods_list = [];
+                foreach ($cids as $cid)
+                {
+                    if(array_key_exists($cid,$tmp)) {
+                        $goods_list[] = $tmp[$cid];
+                    }
+                }
+
+                $blocks = [];
+                if($this->page_no() == 1)
+                {
+                }
+
+                foreach ($goods_list as $goods) {
+                    $goods_id = intval($goods['goods_id']);
+                    $goods_ids[] = $goods_id;
+                }
+
+                $helper = new goods_helper();
+                $ret = $helper->summary($goods_list,$related_goods);
+
+                $block = special_formater::format_goods($goods_ids,"",$ret['sort_summary']);
+                $blocks[] = $block;
+
+                return self::outsuccess(array('special_list' => $blocks,
+                    'summary'  => $ret['summary'],
+                    'groupbuy' => $ret['groupbuy'],
+                    'limitime' => $ret['limitime'],
+                    'bundling' => $ret['bundling'],
+                    'mobile_page' => mobile_page($page_count)));
+            }
+        }
+    }
+
     public function makeby_bonusOp()
     {
         if(!isset($_GET['bonus_sn']) || empty($_GET['bonus_sn'])) {
@@ -793,6 +874,8 @@ class member_bonusControl extends mbMemberControl
         $pages = $this->pages($count);
         return $type_infos;
     }
+
+
 }
 
 class tpl_invite

+ 1 - 1
mobile/control/member_favorites.php

@@ -56,7 +56,7 @@ class member_favoritesControl extends mbMemberControl
         }
 
         $helper = new goods_helper();
-        $ret = $helper->get_summary($gids,$related_goods);
+        $ret = $helper->online_summary($gids,$related_goods);
         $block = special_formater::format_goods($gids,'我的商品',$ret['sort_summary']);
         $blocks[] = $block;
 

+ 10 - 1
mobile/control/member_fcode.php

@@ -55,7 +55,16 @@ class member_fcodeControl extends mbMemberControl
         }
         else
         {
-            $blocks = $this->format($fcodes);
+            if($this->page_no() == 1 && is_publish())
+            {
+                $blocks = special_manager::instance()->special(343,$unused_gids);
+                $items = $this->format($fcodes);
+                $blocks = array_merge($blocks,$items);
+            }
+            else {
+                $blocks = $this->format($fcodes);
+            }
+
             $helper = new goods_helper();
             $ret = $helper->cart_summary($gids,$related_goods);
 

+ 1 - 1
mobile/control/member_notice.php

@@ -36,7 +36,7 @@ class member_noticeControl extends mbMemberControl
             $page_count = $mod_anotice->gettotalpage();
 
             $helper = new goods_helper();
-            $ret = $helper->get_summaryex($goods_list,$related_goods);
+            $ret = $helper->summary($goods_list,$related_goods);
 
             $block = special_formater::format_goods($gids,"",$ret['sort_summary']);
             $blocks[] = $block;

+ 20 - 35
mobile/control/search.php

@@ -28,7 +28,7 @@ class searchControl extends mobileHomeControl
     public function indexOp()
     {
         $param = new search_param($_GET);
-        $params = $param->format();
+        $params = $param->format($this->page_no(),$this->page_size());
 
         if($params == false) {
             return self::outsuccess(array('special_list' => null,
@@ -52,15 +52,11 @@ class searchControl extends mobileHomeControl
         }
 
         $cids = $result['cids'];
-        $order = $this->order($_GET['sort'], $_GET['order']);
-
         $model_goods = Model('goods');
-        $goods_list = $model_goods->getGoodsListByColorDistinct(array('goods_commonid' => array('in',$cids)),
-            goods_helper::fieldstr, $order, $this->page_size());
-        $page_count = $model_goods->gettotalpage();
-        $model_goods->cls();
+        $items = $model_goods->getGoodsListByColorDistinct(array('goods_commonid' => array('in',$cids)),goods_helper::fieldstr,'','');
+        $page_count = $result['page_count'];
 
-        if(empty($goods_list))
+        if(empty($items))
         {
             return self::outsuccess(array('special_list' => null,
                 'summary'  => null,
@@ -71,6 +67,20 @@ class searchControl extends mobileHomeControl
         }
         else
         {
+            $tmp =[];
+            foreach ($items as $item) {
+                $commonid = intval($item['goods_commonid']);
+                $tmp[$commonid] = $item;
+            }
+
+            $goods_list = [];
+            foreach ($cids as $cid)
+            {
+                if(array_key_exists($cid,$tmp)) {
+                    $goods_list[] = $tmp[$cid];
+                }
+            }
+
             $blocks = [];
             if($this->page_no() == 1)
             {
@@ -113,7 +123,7 @@ class searchControl extends mobileHomeControl
             }
 
             $helper = new goods_helper();
-            $ret = $helper->get_summaryex($goods_list,$related_goods);
+            $ret = $helper->summary($goods_list,$related_goods);
 
             $block = special_formater::format_goods($goods_ids,"",$ret['sort_summary']);
             $blocks[] = $block;
@@ -127,31 +137,6 @@ class searchControl extends mobileHomeControl
         }
     }
 
-    private function order($field, $order)
-    {
-        if(empty($field)) {
-            return 'is_own_shop desc,goods_click desc';
-        }
-        else
-        {
-            if(empty($order)) {
-                $order = 'desc';
-            } elseif($order == 'desc') {
-                $order = 'desc';
-            } else {
-                $order = 'asc';
-            }
-
-            if ($field == 'salenum') {
-                return 'goods_salenum desc';
-            } elseif($field == 'price') {
-                return 'goods_price ' . $order;
-            } else {
-                return 'goods_click desc';
-            }
-        }
-    }
-
     public function suggest_wordsOp()
     {
         $keyword = $_GET['keyword'];
@@ -291,7 +276,7 @@ class searchControl extends mobileHomeControl
             }
 
             $helper = new goods_helper();
-            $ret = $helper->get_summary($gids,$related_goods);
+            $ret = $helper->online_summary($gids,$related_goods);
             $block = special_formater::format_goods($gids,"猜你喜欢",$ret['sort_summary']);
 
             return array('special_list' => array($block),

+ 1 - 1
mobile/control/special.php

@@ -39,7 +39,7 @@ class specialControl extends mobileHomeControl
         if (!empty($goods_ids))
         {
             $helper = new goods_helper();
-            $goodsex = $helper->get_summary($goods_ids, $related_goods);
+            $goodsex = $helper->online_summary($goods_ids, $related_goods);
 
             return array('special_list' => $specials,
                 'summary' => $goodsex['summary'],

+ 2 - 2
mobile/templates/default/bonus/bind.php

@@ -50,8 +50,8 @@
     </div>
 
     <?php bonus_output_bindedinfo($output); ?>
-    <?php echo bonus_rule(); ?>
-    <?php bonus_brands(); ?>
+    <?php echo bonus_out_rule(); ?>
+    <?php bonus_out_brands(); ?>
 </div>
 <script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/mobile/bonus/js/zepto.min.js?<?php echo bonus_version(); ?>"></script>
 <script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/mobile/bonus/js/tel.js?<?php echo bonus_version(); ?>"></script>

+ 2 - 2
mobile/templates/default/bonus/content.php

@@ -29,8 +29,8 @@
     <?php bonus_output_type($output); ?>
     <?php bonus_output_mine($output); ?>
     <?php bonus_output_bindedinfo($output); ?>
-    <?php echo bonus_rule(); ?>
-    <?php bonus_brands(); ?>
+    <?php echo bonus_out_rule(); ?>
+    <?php bonus_out_brands(); ?>
 </div>
 <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js?<?php echo bonus_version(); ?>"></script>
 <script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/mobile/comm/wx_share.js?<?php echo bonus_version(); ?>"></script>

+ 4 - 2
mobile/templates/default/bonus/detail.php

@@ -26,11 +26,13 @@
             <img src="<?php echo bonus_output_sender_header($output); ?>"/>
         </div>
     </div>
+
     <?php bonus_output_type($output); ?>
     <?php bonus_output_mine($output); ?>
     <?php bonus_output_bindedinfo($output); ?>
-    <?php echo bonus_rule(); ?>
-    <?php bonus_brands(); ?>
+    <?php bonnus_out_goods($output); ?>
+    <?php bonus_out_rule(); ?>
+    <?php bonus_out_brands(); ?>
 </div>
 <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js?<?php echo bonus_version(); ?>"></script>
 <script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/mobile/comm/wx_share.js?<?php echo bonus_version(); ?>"></script>

+ 1 - 0
mobile/templates/default/fcode/bind.php

@@ -17,6 +17,7 @@
             <li>1.领取后进入APP“F码专区”购买</li>
             <li>2.请注意F码使用有效期</li>
             <li>3.商品退货后F码不退</li>
+            <li>4.可以继续分享该链接给好友领取F码</li>
         </ul>
     </div>
     <div class="bind_tel_box p_absolute bg_write">

+ 2 - 1
shop/control/member_message.php

@@ -6,7 +6,8 @@
 
 defined('InShopNC') or exit('Access Invalid!');
 
-class member_messageControl extends BaseMemberControl {
+class member_messageControl extends BaseMemberControl
+{
     public function __construct() {
         parent::__construct();
 		//读取语言包

+ 12 - 8
shop/templates/default/seller/store_promotion_xianshi.add.php

@@ -29,7 +29,7 @@
         <dl>
             <dt>活动类型<?php echo $lang['nc_colon'];?></dt>
             <dd>
-                <select name="xianshi_type">
+                <select id="xianshi_type" name="xianshi_type">
                     <option value="24">普通抢</option>
                     <option value="10">10点抢</option>
                     <option value="12">午休抢</option>
@@ -87,17 +87,21 @@
 <script src="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js"></script>
 <link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_SITE_URL;?>/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css"  />
 <script>
-$(document).ready(function(){
+$(document).ready(function()
+{
     <?php if(empty($output['xianshi_info'])) { ?>
-    $('#start_time').datetimepicker({
-        controlType: 'select'
-    });
+        $('#start_time').datetimepicker({
+            controlType: 'select'
+        });
 
-    $('#end_time').datetimepicker({
-        controlType: 'select'
-    });
+        $('#end_time').datetimepicker({
+            controlType: 'select'
+        });
     <?php } ?>
 
+    var xianshi_type = "<?php echo empty($output['xianshi_info'])  ?  '':$output['xianshi_info']['xianshi_type'];?>";
+    $('#xianshi_type').val(xianshi_type);
+
     jQuery.validator.methods.greaterThanDate = function(value, element, param) {
         var date1 = new Date(Date.parse(param.replace(/-/g, "/")));
         var date2 = new Date(Date.parse(value.replace(/-/g, "/")));

+ 7 - 1
test/TestSearch.php

@@ -48,9 +48,15 @@ class TestSearch extends PHPUnit_Framework_TestCase
     public function testSearcher()
     {
         $searcher = new search\searcher();
-        $result = $searcher->get_result(array('keyword' => '相宜本草'));
+        $searcher->init();
+        $result = $searcher->get_result(array('keyword' => '妮维雅','order' =>'price','sort' => 'desc','page_no' => 1,'page_size' => 10));
+
+
+        $result = $searcher->match_price(array('price' => 9.27,'page_no' => 1,'page_size' => 10));
+        $x = 100;
     }
 
+
     public function testRequest()
     {
         for($i = 0; $i < 1000; ++$i) {

+ 7 - 0
test/bonus_helperTest.php

@@ -23,6 +23,13 @@ class bonus_helperTest extends PHPUnit_Framework_TestCase
         Base::run_util();
     }
 
+    public function testScaler()
+    {
+        //$scaler = new \bonus\scaler([10 => 10,100 => 100,50 => 50, 30 => 30]);
+        //$scaler = new \bonus\scaler([10 => 10,50 => 50, 20 => 60,100 => 100]);
+        $scaler = new \bonus\scaler([30 => 0.62,100 => 1.26]);
+        $ret = $scaler->calc();
+    }
     public function testModel()
     {
         $item = Model('user_bonus')->field('*')->where(array('type_id' => 105,'bonus_id' => 2491))->select();