dever 6 years ago
parent
commit
530ea84622

+ 11 - 0
act/lib/Subscribe.php

@@ -21,6 +21,17 @@ class Subscribe
             return 2;
         }
     }
+
+    public function getInfo($id, $uid, $type = 4)
+    {
+        $where['uid'] = $uid;
+        $where['type'] = $type;
+        $where['data_id'] = $id;
+        $where['state'] = 1;
+        $data = Dever::db('act/subscribe')->one($where);
+
+        return $data;
+    }
     
     # 获取小刊订阅列表
     public function getList($id, $type = 4)

+ 13 - 2
journal/database/buy.php

@@ -63,11 +63,22 @@ return array
         'buy_notice'      => array
         (
             'type'      => 'varchar-800',
-            'name'      => '购买小刊提示-h5页面购买兑换码时的提示语',
+            'name'      => '购买一个兑换码提示-h5页面购买兑换码时的提示语',
             'default'   => '一次购买多本将生成一个兑换码用于兑换,如需多个兑换码,请多次购买。',
             'desc'      => '购买小刊提示',
             'match'     => 'is_string',
-            'update'    => 'text',
+            'update'    => 'textarea',
+        ),
+
+        'buy_notices'      => array
+        (
+            'type'      => 'varchar-800',
+            'name'      => '购买多个兑换码提示-h5页面购买兑换码时的提示语',
+            'default'   => '购买兑换码赠送好友:点击下方购买后,将生成多个兑换码。
+积分规则:使用兑换码兑换后,使用人获得积分,购买人不增加积分。',
+            'desc'      => '购买小刊提示',
+            'match'     => 'is_string',
+            'update'    => 'textarea',
         ),
 
         'buy_desc'      => array

+ 28 - 0
journal/database/buy_num.php

@@ -179,5 +179,33 @@ return array
             'order' => array('cash' => 'asc','reorder' => 'desc', 'cdate' => 'desc'),
             'col' => '*',
         ),
+
+        'getAllCode' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'info_id' => 'yes',
+                'code' => 1,
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'cdate' => 'desc'),
+            'col' => '*',
+        ),
+
+        'getAllCodes' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'info_id' => 'yes',
+                'code' => array(1, '>'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'cdate' => 'desc'),
+            'col' => '*',
+        ),
     ),
 );

+ 5 - 0
main/src/Journal.php

@@ -253,6 +253,11 @@ class Journal extends Core
             $this->setButton('read', 1, '开始阅读');
             $this->setButton('code', 2, '再次购买');
 
+            $subscribeInfo = Dever::load('act/lib/subscribe')->getInfo($info['id'], $uid, 4);
+            if (isset($subscribeInfo['source']) && $subscribeInfo['source'] == 2) {
+                $this->setButton('code', 1, '兑换码阅读');
+            }
+
             if (checkVersion()->journal_buy == 2) {
                 $this->setButton('code', 1, '兑换码阅读');
                 $this->setButton('share', -1);

+ 8 - 3
service/assets/mobile/pay.html

@@ -13,9 +13,14 @@
             <div class="h1">正在购买《xxxx》</div>
             <div style="font-size:10px;color:red;margin-top:-15px;margin-bottom:10px;" id="notice">一次购买多本将生成一个兑换码用于兑换,如需多个兑换码,请多次购买。</div>
             <div class="list">
-                <a  class="item" bind-id="item" href="#"><p>购买10本</p><p>¥6</p></a>
-                <a  class="item" bind-id="item" href="#"><p>购买10本</p><p>¥6</p></a>
-                <a  class="item" bind-id="item" href="#"><p>购买10本</p><p>¥6</p></a>
+                <a  class="item code" bind-id="item" href="#"><p>购买10本</p><p>¥6</p></a>
+                <a  class="item code" bind-id="item" href="#"><p>购买10本</p><p>¥6</p></a>
+                <a  class="item code" bind-id="item" href="#"><p>购买10本</p><p>¥6</p></a>
+            </div>
+
+            <div style="font-size:10px;color:red;margin-top:-15px;margin-bottom:10px;" id="notices">一次购买多本将生成一个兑换码用于兑换,如需多个兑换码,请多次购买。</div>
+            <div class="list">
+                <a  class="item codes" bind-id="item" href="#"><p>购买10本</p><p>¥6</p></a>
             </div>
         </div>
         <div class='buytip' id="open"><p>购买说明</p></div> 

+ 40 - 6
service/src/Buy.php

@@ -95,12 +95,18 @@ class Buy extends Base
 
         $buy = Dever::db('journal/buy')->one(array('id' => $id));
 
+        $info['buy_desc'] = '';
+        $info['buy_notice'] = '一次购买多本将生成一个兑换码用于兑换,如需多个兑换码,请多次购买。';
+        $info['buy_notices'] = '购买兑换码赠送好友:点击下方购买后,将生成多个兑换码。
+积分规则:使用兑换码兑换后,使用人获得积分,购买人不增加积分。';
         if ($buy) {
             $info['buy_desc'] = $buy['buy_content'];
-            $info['buy_notice'] = $buy['buy_notice'];
-        } else {
-            $info['buy_desc'] = '';
-            $info['buy_notice'] = '一次购买多本将生成一个兑换码用于兑换,如需多个兑换码,请多次购买。';
+            if ($buy['buy_notice']) {
+                $info['buy_notice'] = $buy['buy_notice'];
+            }
+            if ($buy['buy_notices']) {
+                $info['buy_notices'] = $buy['buy_notices'];
+            }
         }
         
         return $info;
@@ -179,11 +185,39 @@ class Buy extends Base
         return $config;
     }
 
-    # 小刊购买
+    # 小刊购买 一个兑换码的
     public function buy()
     {
         $id = Dever::input('id');
-        $data = Dever::db('journal/buy_num')->getAll(array('info_id' => $id));
+        $data = Dever::db('journal/buy_num')->getAllCode(array('info_id' => $id));
+        $info = Dever::db('journal/info')->one($id);
+
+        if ($data) {
+            foreach ($data as $k => $v) {
+                if ($v['price'] > 0) {
+                    $data[$k]['price'] = '¥' . number_format($v['price'], 2);
+                } elseif ($info['cash'] > 0) {
+                    $data[$k]['price'] = '¥' . number_format($info['cash'] * $v['num'], 2);
+                } else {
+                    $data[$k]['price'] = '免费';
+                }
+
+                if (!$v['name']) {
+                    $data[$k]['name'] = '购买' . $v['num'] . '本';
+                }
+                $data[$k]['cate'] = $info['cate_id'];
+
+                $data[$k]['pay_url'] = $this->url('buy.pay', array('buy_id' => $v['id'], 'journal_id' => $v['info_id']));
+            }
+        }
+        return $data;
+    }
+
+    # 小刊购买 多个兑换码的
+    public function buys()
+    {
+        $id = Dever::input('id');
+        $data = Dever::db('journal/buy_num')->getAllCodes(array('info_id' => $id));
         $info = Dever::db('journal/info')->one($id);
 
         if ($data) {

+ 20 - 1
service/template/mobile/pay.php

@@ -11,11 +11,12 @@ $view
 ->fetch('.richtext', 'service/buy.info#buy_desc')
 
 ->fetch('#notice', 'service/buy.info#buy_notice')
+->fetch('#notices', 'service/buy.info#buy_notices')
 
 # 循环
 ->loop
 (
-    '.item',
+    '.code',
     'service/buy.buy',
     array
     (
@@ -30,6 +31,24 @@ $view
     )
 )
 
+# 循环
+->loop
+(
+    '.codes',
+    'service/buy.buys',
+    array
+    (
+        'p|0' => '$v.name',
+        'p|1' => '$v.price',
+
+        'self' => array
+        (
+            'href' => 'javascript:;',
+            'onclick' => 'pay(\'<{$v.pay_url}>\')',
+        ),
+    )
+)
+
 ->fetch(array('script@src', 0),     Dever::assets('global.js'))