소스 검색

增加抢购活动列表

stanley-king 8 년 전
부모
커밋
8a300362c6
5개의 변경된 파일355개의 추가작업 그리고 38개의 파일을 삭제
  1. 59 30
      helper/activity/groupbuy.php
  2. 64 2
      helper/activity/limitime.php
  3. 92 6
      helper/activity_helper.php
  4. 124 0
      mobile/control/activity.php
  5. 16 0
      test/activity_helperTest.php

+ 59 - 30
helper/activity/groupbuy.php

@@ -11,30 +11,6 @@ namespace activity;
 
 class group_item
 {
-//"groupbuy_id": "11",
-//"groupbuy_name": "新品上架,超低价购",
-//"start_time": "1471874040",
-//"end_time": "1472572800",
-//"goods_id": "4127",
-//"goods_commonid": "2582",
-//"goods_name": "雅漾舒缓特护洁面乳200ml 200ml",
-//"store_id": "6",
-//"store_name": "熊猫美妆",
-//"goods_price": "295.00",
-//"groupbuy_price": "100.00",
-//"groupbuy_rebate": "3.39",
-//"virtual_quantity": "100",
-//"upper_limit": "2",
-//"buyer_count": "0",
-//"buy_quantity": "0",
-//"groupbuy_intro": "",
-//"state": "20",
-//"recommended": "0",
-//"views": "0",
-//"groupbuy_image": "6_05252180202959484.jpg",
-//"groupbuy_image1": "6_05252180208131012.jpg",
-//"remark": "好玩"
-
     private $mParam;
     public function __construct($param)
     {
@@ -51,12 +27,12 @@ class group_item
 
     public function to_array()
     {
-        $info['groupbuy_id']   = intval($this->mParam['groupbuy_id']);
-        $info['groupbuy_name'] = $this->mParam['groupbuy_name'];
-        $info['remark']        = $this->mParam['remark'];
-        $info['start_time']    = intval($this->mParam['start_time']);
-        $info['end_time']      = intval($this->mParam['end_time']);
-        $info['goods_id']      = intval($this->mParam['goods_id']);
+        $info['groupbuy_id']     = intval($this->mParam['groupbuy_id']);
+        $info['groupbuy_name']   = $this->mParam['groupbuy_name'];
+        $info['remark']          = $this->mParam['remark'];
+        $info['start_time']      = intval($this->mParam['start_time']);
+        $info['end_time']        = intval($this->mParam['end_time']);
+        $info['goods_id']        = intval($this->mParam['goods_id']);
         $info['promotion_price'] = floatval($this->mParam['groupbuy_price']);
         $info['rebate']          = floatval($this->mParam['groupbuy_rebate']);
         $info['quantity']        = intval($this->mParam['virtual_quantity']);
@@ -135,6 +111,59 @@ class groupbuy
         return $groupbuy;
     }
 
+    public function acting()
+    {
+        $groups = [];
+        $curtm = time();
+        foreach ($this->group_list as $group)
+        {
+            $start = intval($group['start_time']);
+            $end = intval($group['end_time']);
+            if($curtm >= $start && $curtm < $end) {
+                $groups[] = $group;
+            }
+        }
+
+        $result = [];
+        foreach ($groups as $val) {
+            $item = new group_item($val);
+            $result[] = $item->to_array();
+        }
+
+        return $result;
+    }
+
+    public function unstart()
+    {
+        $groups = [];
+        $curtm = time();
+        foreach ($this->group_list as $group)
+        {
+            $start = intval($group['start_time']);
+            if($curtm < $start) {
+                $groups[] = $group;
+            }
+        }
+
+        $result = [];
+        foreach ($groups as $val) {
+            $item = new group_item($val);
+            $result[] = $item->to_array();
+        }
+
+        return $result;
+    }
+
+    public function goods($group_id)
+    {
+        if(array_key_exists($group_id,$this->group_list)) {
+            $goods_id = intval($this->group_list[$group_id]['goods_id']);
+            return array($goods_id);
+        } else {
+            return array();
+        }
+    }
+
     public function isTakepart($goods_id,&$act_id)
     {
         if(array_key_exists(intval($goods_id),$this->goodsid_gid))

+ 64 - 2
helper/activity/limitime.php

@@ -26,10 +26,11 @@ class limit_item
         $info['xianshi_name']    = $this->mParam['xianshi_name'];
         $info['xianshi_title']   = $this->mParam['xianshi_title'];
         $info['xianshi_explain'] = $this->mParam['xianshi_explain'];
-        $info['start_time'] = intval($this->mParam['start_time']);
-        $info['end_time']   = intval($this->mParam['end_time']);
+        $info['start_time']  = intval($this->mParam['start_time']);
+        $info['end_time']    = intval($this->mParam['end_time']);
         $info['lower_limit'] = intval($this->mParam['lower_limit']);
         $info['state']       = intval($this->mParam['state']);
+        //$info['goods_list']  = $this->mParam['goods_list'];
 
         return $info;
     }
@@ -46,6 +47,7 @@ class limitime
     static private $stInstance = null;
     private $limit_list;
     private $goodsid_limit;
+    private $mLimitGoods;
 
     private $verchecker;
 
@@ -74,17 +76,25 @@ class limitime
 
         $this->limit_list = array();
         $this->goodsid_limit = array();
+        $this->mLimitGoods = [];
 
         $list = $mod->getXianshiList($condition);
         foreach ($list as $val)
         {
             $xianshi_id = intval($val['xianshi_id']);
             $this->limit_list[$xianshi_id] = $val;
+            $this->mLimitGoods[$xianshi_id] = [];
+
+            $gids = [];
             $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']);
                 $this->goodsid_limit[$goods_id] = $xianshi_goods;
+                $gids[] = $goods_id;
             }
+            $this->mLimitGoods[$xianshi_id] = $gids;
+            $this->limit_list[$xianshi_id]['goods_list'] = $gids;
+
         }
     }
 
@@ -121,4 +131,56 @@ class limitime
             return false;
         }
     }
+
+    public function goods($limit_id)
+    {
+        if(array_key_exists($limit_id,$this->limit_list)) {
+            return $this->mLimitGoods[$limit_id];
+        } else {
+            return array();
+        }
+    }
+
+    public function acting()
+    {
+        $limits = [];
+        $curtm = time();
+        foreach ($this->limit_list as $limit)
+        {
+            $start = intval($limit['start_time']);
+            $end = intval($limit['end_time']);
+            if($curtm >= $start && $curtm < $end) {
+                $limits[] = $limit;
+            }
+        }
+
+        $result = [];
+        foreach ($limits as $val) {
+            $item = new limit_item($val);
+            $result[] = $item->format();
+        }
+
+        return $result;
+    }
+
+    public function unstart()
+    {
+        $limits = [];
+        $curtm = time();
+        foreach ($this->limit_list as $limit)
+        {
+            $start = intval($limit['start_time']);
+            if($curtm < $start) {
+                $limits[] = $limit;
+            }
+        }
+
+        $result = [];
+        foreach ($limits as $val) {
+            $item = new limit_item($val);
+            $result[] = $item->format();
+        }
+
+        return $result;
+    }
 }

+ 92 - 6
helper/activity_helper.php

@@ -18,6 +18,39 @@ require_once (BASE_ROOT_PATH . '/helper/activity/version_checker.php');
 
 require_once (BASE_ROOT_PATH . '/helper/algorithm.php');
 
+function less_endtime($left,$right)
+{
+    $l_end = intval($left['end_time']);
+    $r_end = intval($right['end_time']);
+
+    if($l_end > $r_end) {
+        return 1;
+    }
+    elseif($l_end == $r_end) {
+        return 0;
+    }
+    else {
+        return -1;
+    }
+}
+
+function less_startime($left,$right)
+{
+    $l_start = intval($left['start_time']);
+    $r_start = intval($right['start_time']);
+
+    if($l_start > $r_start) {
+        return 1;
+    }
+    elseif($l_start == $r_start) {
+        return 0;
+    }
+    else {
+        return -1;
+    }
+}
+
+
 //抢,限,推,套装,三个信息会出现在商品的summary 中,其余的出现在商品的详细信息中
 class activity_helper
 {
@@ -41,7 +74,6 @@ class activity_helper
             return false;
         }
     }
-
     public static function have_recommend($goods_id)
     {
         if (activity\recommend_goods::instance()->isTakepart($goods_id)) {
@@ -50,15 +82,12 @@ class activity_helper
             return false;
         }
     }
-
     public static function have_bundling($goods_id) {
         return activity\bundling::instance()->have_bundling($goods_id);
     }
-
     public static function bundling_goods($bl_id) {
         return activity\bundling::instance()->bundling_goods($bl_id);
     }
-
     //赠品信息
     public static function have_gift($goods_id) {
         return activity\goods_gift::instance()->have_gift($goods_id);
@@ -86,10 +115,67 @@ class activity_helper
     public static function free_ship() {
         return activity\full_sent::instance()->free_price();
     }
-
     //推荐商品列表
     public static function recomoned_goodsids()
     {
-        return \activity\recommend_goods::instance()->goods_ids();
+        return activity\recommend_goods::instance()->goods_ids();
+    }
+
+    public static function limit_goods($limit_id)
+    {
+        return activity\limitime::instance()->goods($limit_id);
+    }
+    public static function groupbuy_goods($group_id)
+    {
+        return activity\groupbuy::instance()->goods($group_id);
+    }
+
+    public static function acting()
+    {
+        $limits = activity\limitime::instance()->acting();
+        $groupbuys = activity\groupbuy::instance()->acting();
+
+        $values = [];
+        foreach ($limits as $val) {
+            $values[] = $val;
+        }
+        foreach ($groupbuys as $val) {
+            $values[] = $val;
+        }
+
+        $result = [];
+        if(!empty($values))
+        {
+            uasort($values,'less_endtime');
+            foreach ($values as $value) {
+                $result[] = $value;
+            }
+        }
+
+        return $result;
+    }
+    public static function unstart()
+    {
+        $limits = activity\limitime::instance()->unstart();
+        $groupbuys = activity\groupbuy::instance()->unstart();
+
+        $values = [];
+        foreach ($limits as $val) {
+            $values[] = $val;
+        }
+        foreach ($groupbuys as $val) {
+            $values[] = $val;
+        }
+
+        $result = [];
+        if(!empty($values))
+        {
+            uasort($values,'less_startime');
+            foreach ($values as $value) {
+                $result[] = $value;
+            }
+        }
+
+        return $result;
     }
 }

+ 124 - 0
mobile/control/activity.php

@@ -6,6 +6,113 @@
  * Time: 下午4:45
  */
 
+require_once(BASE_ROOT_PATH . '/helper/activity_helper.php');
+require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
+
+class act_formater
+{
+    private $mActivities;
+
+    public function __construct($activities)
+    {
+        $this->mActivities = $activities;
+    }
+
+    public function format()
+    {
+        $specials = [];
+        $goods_ids = [];
+        foreach ($this->mActivities as $act)
+        {
+            if(array_key_exists('xianshi_id',$act))
+            {
+                $specials[] = $this->format_limit($act,$gids);
+                self::array_copy($goods_ids,$gids);
+            }
+            elseif(array_key_exists('groupbuy_id',$act))
+            {
+                $specials[] = $this->format_groupbuy($act,$gids);
+                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);
+
+            return array('special_list' => $specials,
+                'summary' => $ret['summary'],
+                'groupbuy' => $ret['groupbuy'],
+                'limitime' => $ret['limitime'],
+                'bundling' => $ret['bundling'],
+                'mobile_page' => mobile_page(1));
+        }
+        else {
+            return array('special_list' => null,
+                'summary' => null,
+                'groupbuy' => null,
+                'limitime' => null,
+                'bundling' => null,
+                'mobile_page' => mobile_page(1));
+        }
+
+    }
+
+    private function format_limit($limt,&$gids)
+    {
+        $result =[];
+
+        $limt_id = intval($limt['xianshi_id']);
+        $result['item_title'] = strval($limt_id);
+        $result['item_type'] = 'home_limit';
+
+        $gids = activity_helper::limit_goods($limt_id);
+        if(empty($gids)) return array();
+        foreach ($gids as $gid) {
+            $item['type'] = 'goods';
+            $item['data'] = strval($gid);
+            $item['image'] = '';
+            $item['title'] = '';
+
+            $result['items'][] = $item;
+        }
+
+        return $result;
+    }
+
+    private function format_groupbuy($group, &$gids)
+    {
+        $result =[];
+
+        $act_id = intval($group['groupbuy_id']);
+        $result['item_title'] = strval($act_id);
+        $result['item_type'] = 'home_group';
+
+        $gids = activity_helper::groupbuy_goods($act_id);
+        if(empty($gids)) return array();
+        foreach ($gids as $gid) {
+            $item['type'] = 'goods';
+            $item['data'] = strval($gid);
+            $item['image'] = '';
+            $item['title'] = '';
+
+            $result['items'][] = $item;
+        }
+
+        return $result;
+    }
+
+    private static function array_copy(&$dest,$src)
+    {
+        if(empty($src)) return $dest;
+        foreach ($src as $value) {
+            array_push($dest,$value);
+        }
+        return $dest;
+    }
+}
+
 class activityControl extends mobileControl
 {
     public function __construct()
@@ -13,6 +120,23 @@ class activityControl extends mobileControl
         parent::__construct();
     }
 
+    public function actingOp()
+    {
+        $actings = activity_helper::acting();
+        $formater = new act_formater($actings);
+        $result = $formater->format();
+
+        return self::outsuccess($result);
+    }
+    public function unstartOp()
+    {
+        $actings = activity_helper::unstart();
+        $formater = new act_formater($actings);
+        $result = $formater->format();
+
+        return self::outsuccess($result);
+    }
+
     public function limit_entraOp()
     {
         $_SESSION['client_type'] = "wap";

+ 16 - 0
test/activity_helperTest.php

@@ -41,4 +41,20 @@ class activity_helperTest extends PHPUnit_Framework_TestCase
         $helper = new goods_helper();
         $ret = $helper->get_spu(2629,4182,$err);
     }
+
+    public function testFull()
+    {
+        $contents = activity\full_sent::instance()->rules();
+        $store_list = Model('store')->getStoreOnlineList(array('store_id' => 6),null,'','store_free_price');
+    }
+    public function testActivity()
+    {
+        $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();
+    }
 }