Browse Source

add first order present

stanley-king 7 years ago
parent
commit
299642d136

+ 120 - 0
helper/fcode/present_manager.php

@@ -0,0 +1,120 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2017/5/9
+ * Time: 下午10:35
+ */
+
+namespace fcode;
+
+require_once (BASE_ROOT_PATH . '/helper/message/msgutil.php');
+require_once (BASE_ROOT_PATH . '/helper/special_helper.php');
+
+
+use StatesHelper;
+use Log;
+use special_manager;
+use commonid_helper;
+use algorithm;
+
+class present_manager
+{
+    public static $stInstance;
+
+    private $mFcodes;
+    private $mCidBcodes;
+
+    private function __construct()
+    {
+    }
+
+    static public function instance()
+    {
+        if(self::$stInstance == null) {
+            self::$stInstance = new present_manager();
+        }
+
+        if(StatesHelper::fetch_state('fcode')) {
+            Log::record("present_manager reinit data.",Log::DEBUG);
+            self::$stInstance->init();
+        }
+
+        return self::$stInstance;
+    }
+
+    private function init()
+    {
+        global $config;
+        $special_id = $config['autosend_fcodes']['order_present'];
+        if($special_id <= 0) return false;
+
+        $blocks = special_manager::instance()->special($special_id,$goods_ids);
+
+        if(empty($blocks)) return false;
+
+        $fcodes = [];
+        $cid_bcodes = [];
+        foreach ($blocks as $block)
+        {
+            $item_type  = $block['item_type'];
+            if($item_type == 'home1')
+            {
+                $items = $block['items'];
+                if(empty($items)) continue;
+
+                $item = $items[0];
+                $batch_code = $item['title'];
+                if(empty($batch_code)) continue;
+                $goods_id = intval($item['data']);
+                $cid = commonid_helper::instance()->common_id($goods_id);
+                if($cid > 0) {
+                    $fcodes[$cid] = $batch_code;
+                    $cid_bcodes[] = "{$cid}.{$batch_code}";
+                }
+            }
+        }
+        $this->mFcodes = $fcodes;
+        sort($cid_bcodes);
+        $this->mCidBcodes = $cid_bcodes;
+
+        return true;
+    }
+
+    public function fetch($mobile)
+    {
+        if(empty($mobile) || $this->can_send($mobile) == false)
+            return false;
+
+        foreach ($this->mFcodes as $commonid => $batch_code)
+        {
+            $oper = new operator($commonid,$batch_code);
+
+            if($oper->grabed()) continue;
+            $fcode = $oper->grab();
+            if($fcode != false) {
+                return ['fcode' => $fcode,'common_id' => $commonid,'batch_code' => $batch_code];
+            }
+        }
+        return false;
+    }
+
+    private function can_send($mobile)
+    {
+        $mod_fcode = Model('goods_fcode');
+        $codes = $mod_fcode->getFcodeList(['mobile' => $mobile]);
+
+        $user_fcodes = [];
+        foreach ($codes as $item)
+        {
+            $fcoder = new mfcode($item);
+            $cid   = $fcoder->commonid();
+            $bcode = $fcoder->batch_code();
+            $user_fcodes[] = "{$cid}.{$bcode}";
+        }
+        sort($user_fcodes);
+
+        $out = algorithm::set_intersection($user_fcodes,$this->mCidBcodes);
+        return empty($out) ? true : false;
+    }
+}

+ 0 - 98
helper/fcode/turn_manager.php

@@ -1,98 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: stanley-king
- * Date: 2017/5/9
- * Time: 下午10:35
- */
-
-namespace fcode;
-
-require_once (BASE_ROOT_PATH . '/helper/message/msgutil.php');
-require_once (BASE_ROOT_PATH . '/helper/special_helper.php');
-
-
-use StatesHelper;
-use Log;
-use special_manager;
-use special_formater;
-
-
-class turn_manager
-{
-    public static $stInstance;
-    private $mGoodsBlock;
-    private $mAmountGoods;
-
-    private function __construct()
-    {
-    }
-
-    static public function instance()
-    {
-        if(self::$stInstance == null) {
-            self::$stInstance = new turn_manager();
-        }
-
-//        if(StatesHelper::fetch_state('fcode')) {
-//            Log::record("fcode reinit data.",Log::DEBUG);
-//            self::$stInstance->init();
-//        }
-        self::$stInstance->init();
-
-        return self::$stInstance;
-    }
-
-    private function init()
-    {
-        $this->mAmountGoods = [];
-        $this->mGoodsBlock  = [];
-        //$blocks = special_manager::instance()->special(62,$goods_ids);
-        $formater = new special_formater(62,false);
-        $blocks = $formater->format($goods_ids);
-
-        foreach ($blocks as $block)
-        {
-            $item_type  = $block['item_type'];
-            $item_title = $block['item_title'];
-            $amount = intval($item_title);
-            if($item_type == 'home_goods' && $amount > 0)
-            {
-                $items = $block['items'];
-                foreach ($items as $item) {
-                    $this->add($amount,$item);
-                }
-            }
-        }
-
-        krsort($this->mAmountGoods);
-    }
-
-    private function add($amount,$item)
-    {
-        $goods_id = intval($item['data']);
-        if($goods_id <= 0) return;
-
-        if(array_key_exists($amount,$this->mAmountGoods) == false) {
-            $this->mAmountGoods[$amount] = [];
-        }
-        $this->mAmountGoods[$amount][] = $goods_id;
-        $this->mGoodsBlock[$goods_id] = $item;
-    }
-
-    public function fetch($amount,$count)
-    {
-        $amount = intval($amount);
-        if($amount <=0) return false;
-
-        $gids = [];
-        foreach ($this->mAmountGoods as $key => $val)
-        {
-            if($key <= $amount) {
-                $gids = array_merge($gids,$val);
-            }
-        }
-
-        return $gids;
-    }
-}

+ 25 - 0
helper/session_helper.php

@@ -322,4 +322,29 @@ class session_helper
         $thief = new bonus\thief_vilator($fromid);
         return $thief->thief($err);
     }
+
+    static public function first_order()
+    {
+        if (array_key_exists('order_num', $_SESSION)) {
+            $order_num = $_SESSION['order_num'];
+        }
+        else
+        {
+            $mod_member = Model('member');
+            $minfo = $mod_member->getMemberInfoByID(self::memberid());
+            if(empty($minfo)) return false;
+
+            $order_num = intval($minfo['order_num']);
+            if($order_num > 0) {
+                $_SESSION['order_num'] = $order_num;
+            }
+        }
+
+        if($order_num == 0) {
+            return true;
+        }
+        else {
+            return false;
+        }
+    }
 }

+ 3 - 3
helper/special_helper.php

@@ -753,9 +753,9 @@ class special_manager
 
     public function special($special_id,&$goods_ids)
     {
-        if(StatesHelper::fetch_state('special')) {
-            $this->mContents = [];
-        }
+//        if(StatesHelper::fetch_state('special')) {
+//            $this->mContents = [];
+//        }
 
         $special_id = intval($special_id);
         if(array_key_exists($special_id,$this->mContents)) {

+ 43 - 4
mobile/control/bonusex.php

@@ -21,7 +21,8 @@ require_once(BASE_ROOT_PATH . '/helper/search_param.php');
 require_once(BASE_ROOT_PATH . '/helper/goods_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/session_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/login_helper.php');
-require_once (BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
+require_once(BASE_ROOT_PATH . '/helper/third_author/wxauthor.php');
+require_once(BASE_ROOT_PATH . '/helper/fcode/present_manager.php');
 
 
 class bonusexControl extends mobileControl
@@ -673,6 +674,43 @@ function bonus_output_type($output)
     echo '</div>';
 }
 
+function bonus_output_present($output)
+{
+    if(session_helper::first_order() == false) return;
+
+    $fcode = fcode\present_manager::instance()->fetch($_SESSION['member_mobile']);
+    if($fcode == false) return;
+
+    $common_id  = $fcode['common_id'];
+    $batch_code = $fcode['batch_code'];
+    $fcode_url = BASE_SITE_URL . "/mobile/index.php?act=fcode&op=index&common_id={$common_id}&batch_code={$batch_code}";
+
+    $model_goods = Model('goods');
+    $items = $model_goods->getGoodsListByColorDistinct(array('goods_commonid' => $common_id),goods_helper::fieldstr,'','');
+    if(empty($items)) return;
+
+    $helper = new goods_helper();
+    $ret = $helper->summary($items,$related_goods);
+    $summary = $ret['summary'][0];
+
+    $str = "<div class=\"prompt text_left\">
+                <p class=\"prompt pro\">丽人亲友首单福利</p>
+            </div>";
+
+    $str.= "<div class=\"first_goods_box overflow_h text_left\">
+                <div class=\"first_goods_img f_left\">
+                    <img src=\"{$summary['goods_image_url']}\">
+                </div>
+                <div class=\"first_goods_msg f_right\">
+                    <p class=\"p first_goods_name\">{$summary['goods_mobile_name']}</p>
+                    <p class=\"p first_goods_desc\">{$summary['goods_jingle']}</p>
+                    <p class=\"p first_goods_price bonus_price\"><span class=\"bonus_icon\"></span>{$summary['goods_promotion_price']}元<span class=\"desc\">专柜价 {$summary['goods_price']}</span></p>
+                    <p><a href=\"{$fcode_url}\" class=\"center\">查看详情</a></p>
+                </div>
+            </div>";
+    echo $str;
+}
+
 function bonus_output_mine($output)
 {
     if($_SESSION['is_app']) {
@@ -681,12 +719,13 @@ function bonus_output_mine($output)
         $show_down = true;
     }
     $relay_id = intval($output['relay_id']);
-
     $mine_bonus = $output['mine_bonus'];
-    if(!empty($mine_bonus)) {
+    if(!empty($mine_bonus))
+    {
+        $mshop_url = BASE_SITE_URL . "/mshop";
         $bonus = \bonus\user_bonus::create_by_param($mine_bonus);
         echo('<div class="price">');
-        echo('<p><span>' . $bonus->bonus_value() . '</span>元</p>');
+        echo('<p><span>' . $bonus->bonus_value() . "</span>元<a class=\"link_mshop\" href=\"{$mshop_url}\"></a ></p>");
         echo('</div>');
         echo('<input type="hidden" id="mine_bonus" value=' ."{$bonus->bonus_sn()}>");
         echo('<input type="hidden" id="relay_id" value=' ."{$relay_id}>");

+ 1 - 1
mobile/control/control.php

@@ -270,7 +270,7 @@ class mbMemberControl extends mobileControl
 
 function bonus_version()
 {
-    return "v=2017062301";
+    return "v=2017070401";
 }
 function shop_version()
 {

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

@@ -27,11 +27,13 @@
 
     <?php bonus_output_type($output); ?>
     <?php bonus_output_mine($output); ?>
+    <?php bonus_output_present($output); ?>
     <?php bonus_output_bindedinfo($output); ?>
     <?php bonnus_out_goods($output); ?>
     <?php bonus_out_rule(); ?>
     <?php bonus_out_download(); ?>
 </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>
 <script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/mobile/bonus/js/zepto.min.js?<?php echo bonus_version(); ?>"></script>

+ 2 - 3
test/TestFcode.php

@@ -12,7 +12,7 @@ require_once(BASE_ROOT_PATH . '/fooder.php');
 require_once(BASE_ROOT_PATH . '/helper/fcode/generator.php');
 require_once(BASE_ROOT_PATH . '/helper/fcode/operator.php');
 require_once(BASE_ROOT_PATH . '/helper/fcode/mfcode.php');
-require_once(BASE_ROOT_PATH . '/helper/fcode/turn_manager.php');
+require_once(BASE_ROOT_PATH . '/helper/fcode/present_manager.php');
 require_once(BASE_ROOT_PATH . '/helper/fcode/send_manager.php');
 
 
@@ -25,8 +25,7 @@ class TestFcode extends PHPUnit_Framework_TestCase
 
     public function testManager()
     {
-        $manager = fcode\turn_manager::instance();
-        $manager->fetch(600,10);
+        $manager = fcode\present_manager::instance();
     }
 
     public function testSendManager()