dever 6 년 전
부모
커밋
88524c36f8

+ 0 - 7
act/lib/Pay.php

@@ -67,13 +67,6 @@ class Pay
 
                 Dever::db('act/order')->update($update);
 
-                if ($order['type'] != 1) {
-                    //return;
-                }
-
-                # 订阅
-                Dever::load('act/lib/subscribe')->submit($uid, $order['product_id'], 1);
-
                 $score = false;
                 $num = false;
                 $journal = Dever::load('act/order')->getJournal($order['product_id']);

+ 2 - 2
act/src/Order.php

@@ -167,7 +167,7 @@ class Order extends Core
         if (isset($buy['price']) && $buy['price'] && $buy['price'] > 0) {
             $order_data['cash'] = $buy['price'];
         } else {
-            $order_data['cash'] = $journal['cash'] * $order_data['num'];
+            $order_data['cash'] = $journal['cash'] * $order_data['buy_num'];
         }
 
         $source = Dever::input('source');
@@ -289,7 +289,7 @@ class Order extends Core
         return 'ok';
     }
 
-    private function createOrder($prefix = 'JC')
+    public function createOrder($prefix = 'JP')
     {
         $order = Dever::order($prefix);
 

+ 1 - 1
buy/assets/mobile/codedetail.html

@@ -16,7 +16,7 @@
     <div class="btn-wrap">
         <a href="javascript:;" node-act="read" class="button black">阅读电子刊</a>
     </div>
-    <div class="code-list">
+    <div class="code-list pages">
         <dl>
             <dd>
                 <p><i class="ico-code"></i>兑换码:675386834</p>

+ 5 - 1
buy/assets/mobile/list.html

@@ -14,7 +14,7 @@
         <a class="li active"><span>预购杂志</span></a>
         <a class="li"><span>兑换码</span></a>
     </div>
-    <div class="list" node-id="list">
+    <div class="list pages" node-id="list">
         <div class="item">
             <img src="images/mag.png" class="default" />
             <div class="info">
@@ -70,6 +70,10 @@
             $('#layer').show();
         })
 
+        $('[node-act="pay"]').on('click',function(){
+            pay($(this).data('src'));
+        })
+
         $('#close').on('click',function(){
             $('#layer').hide();
         });

+ 10 - 2
buy/assets/mobile/pay.html

@@ -43,14 +43,15 @@
 
     <div class="mask fn-hide" id="pay-layer">
         <div class="layer buy-result">
-            <h3 class="title">购买说明</h3>
-            <div class="res">您已成功购买1000本电子刊</div>
+            <h3 class="title">购买提示</h3>
+            <div class="res" id="buyyes">您已成功购买1000本电子刊</div>
             <div class="btn-wrapper">
                 <a href="codedetail.html" class="button">查看兑换码</a>
                 <div class="button" node-act="close">继续购买</div>
             </div>
         </div>
     </div>
+    <div id="pay"></div>
 <script type="text/javascript" src="js/global.js?v=3f8cf811"></script><script type="text/javascript" src="js/pay.js?v=3f8cf811"></script></body>
 <script>
     
@@ -67,5 +68,12 @@
         $(this).closest('.mask').hide();
     });
 
+    function pay(url)
+    {
+        $.get(url, function(t) {
+            $("#pay").html(t);
+        })
+    }
+
 </script>
 </html>

+ 4 - 14
buy/src/Base.php

@@ -78,7 +78,7 @@ class Base
 
             $cate['logotxt'] = '<img src="'.$cate['logo'].'" />' . $cate['name'];
 
-            $url = urlencode($this->url('list_code'));
+            $url = urlencode($this->url('list'));
             $cate['login'] = 'location.href=\'' . Dever::url('request.auth?account='.$this->account.'&source='.$this->source.'&refer=' . $url, 'oauth') . '\'';
 
             $info = Dever::db('journal/info')->getOne($cate['journal_id']);
@@ -87,7 +87,7 @@ class Base
                 $cate['cover'] = $info['pic_gd'];
             }
 
-            $cate['list_link'] = $this->url('list_code');
+            $cate['list_link'] = $this->url('list');
             $cate['my_link'] = $this->url('my_code');
 
             Dever::cache($key, $cate);
@@ -120,18 +120,8 @@ class Base
     	return Dever::location($this->url($uri, $param, $project));
     }
 
-    protected function createOrder($prefix = 'JC')
+    protected function createOrder($prefix = 'JP')
     {
-        $order = Dever::order($prefix);
-
-        //$order = Dever::rand(2, 2) . Dever::rand(6, 0);
-
-        $info = Dever::db('journal/order')->one(array('order_id' => $order));
-
-        if ($info) {
-            return $this->createOrder($prefix);
-        }
-
-        return $order;
+        return Dever::load('act/order')->createOrder($prefix);
     }
 }

+ 62 - 86
buy/src/Buy.php

@@ -37,9 +37,18 @@ class Buy extends Base
 
                 //$data[$k]['ding'] = '销量:' . $v['num_ding'];
 
-                $data[$k]['pay_url'] = $this->url('pay', array('id' => $v['id']));
-
                 $data[$k]['pic_gd'] .= '?imageView2/2/w/375';
+
+                if ($v['buy'] == 1) {
+                    $data[$k]['button'] = '订阅';
+                    $data[$k]['act'] = 'pay';
+                    $data[$k]['code'] = $this->url('pay', array('id' => $v['id']));
+                } else {
+                    $data[$k]['act'] = 'read';
+                    # 小刊阅读码
+                    $data[$k]['code'] = $this->create_code($v['id']);
+                    $data[$k]['button'] = '阅读';
+                }
             }
         }
 
@@ -51,32 +60,25 @@ class Buy extends Base
     {
         $where['cate_id'] = $this->cate;
         $where['create_uid'] = $this->user['id'];
-        //$where['type'] = 3;
+        $where['order_id'] = Dever::input('order_id');
+        if (!$where['order_id']) {
+            Dever::alert('错误的订单');
+        }
         $where['type'] = 4;
         $data = Dever::db('code/info')->getAll($where);
 
         if ($data) {
             foreach ($data as $k => $v) {
-                $info = Dever::db('journal/info')->one($v['product_id']);
-
-                $data[$k]['code'] = str_replace("\n", '', trim($v['code']));
-
-                $data[$k]['code_string'] = '阅读码:' . trim($v['code']);
-
-                if ($v['type'] == 3) {
-                    $data[$k]['code_string'] .= ' 已兑换';
+                $data[$k]['code'] = '<i class="ico-code"></i>兑换码:'.$v['id'];
+                if ($v['type'] == 1) {
+                    $data[$k]['txt'] = '未使用';
+                    $data[$k]['class'] = '';
+                    $data[$k]['copy'] = '<a href="javascript:;" class="button" node-id="copy" data-clipboard-text="'.$v['id'].'">复制</a>';
                 } else {
-                    $data[$k]['code_string'] .= ' <font style="color:red">未兑换</font>';
+                    $data[$k]['txt'] = '已使用';
+                    $data[$k]['class'] = 'used';
+                    $data[$k]['copy'] = '<a href="javascript:;" class="button disabled">复制</a>';
                 }
-
-                $data[$k]['name'] = $info['name'];
-
-                $data[$k]['pic_gd'] = $info['pic_gd'] ? $info['pic_gd'] : $info['pic_view_cover'];
-
-                $data[$k]['pic_gd'] .= '?imageView2/2/w/375';
-
-                //$data[$k]['code_pic'] = '';
-                $data[$k]['code_pic'] = $this->create_code($info['id']);
             }
         }
 
@@ -114,6 +116,14 @@ class Buy extends Base
         }
 
         $info['buy_notices'] = str_replace("\n", '<br />', $info['buy_notices']);
+
+        $result['buy_class'] = 'mask fn-hide';
+        $config['buy_code'] = '';
+        $result['buy_yes'] = '';
+        $buy_num = Dever::input('buy_num');
+        if ($buy_num > 0) {
+            $info += $this->success();
+        }
         
         return $info;
     }
@@ -146,64 +156,32 @@ class Buy extends Base
     # 小刊购买成功
     public function success()
     {
-        $config = Dever::db('main/config')->one(1);
-
         $id = Dever::input('id');
         $buy_id = Dever::input('buy');
-        $config['list'] = $this->url('list');
-        $config['buy'] = $this->url('pay', array('id' => $id));
-
+        
         $order_id = Dever::input('order_id');
-        $order = Dever::db('journal/order')->one($order_id);
-
-        if ($order['uid'] != $this->user['id']) {
-            $this->location('list');
-        }
+        $create = Dever::input('create');
+        if ($order_id && $create == 1) {
+            $order = Dever::db('journal/order')->one($order_id);
 
-        $uid = $this->user['id'];
+            if ($order['uid'] != $this->user['id']) {
+                $this->location('list');
+            }
 
-        $code = Dever::load('code/lib/core')->createCodeByOrder($order);
-        if ($code) {
-            $update['where_id'] = $order['id'];
-            $order['code'] = $update['code'] = $code;
-            Dever::db('journal/order')->update($update);
-        }
+            $uid = $this->user['id'];
 
-        $config['code_show'] = 'display:none;';
-        $config['button'] = '继续购买';
-        $config['button_node'] = '';
-        $config['button_span'] = '';
-        $config['reload'] = 1;
-        if ($order && $order['type'] == 3) {
-            $config['code_show'] = '';
-            $config['button_node'] = 'copy';
-            $order['code'] = str_replace("\n", '', trim($order['code']));
-            $config['button_span'] = $order['code'];
-            if (!$order['code']) {
-                $order['code'] = '生成中...';
-                $config['reload'] = 2;
-                $config['button_node'] = 'refresh';
-                $config['button_span'] = '';
-                $config['button'] = '刷新';
-                //$this->location('success', array('id' => $id, 'buy' => $buy_id, 'order_id' => $order_id));
-            } else {
-                $config['button'] = '继续购买<span>'.$order['code'].'</span>';
-            }
-            
-            $config['code'] = '<p class="single"><span>'.$order['code'].'</span></p>';
-            $buy = Dever::db('journal/buy_num')->one($buy_id);
-            if ($buy && $buy['code'] > 1) {
-                $uid = $this->user['id'];
-                $code = Dever::db('code/info')->state(array('create_uid' => $uid, 'order_id' => $order['order_id']));
-                $config['code'] = '<p>';
-                foreach ($code as $k => $v) {
-                    $config['code'] .= '<span>'.$v['code'].'</span>';
-                }
-                $config['code'] .= '</p>';
+            $code = Dever::load('code/lib/core')->createCodeByOrder($order, -1);
+            if ($code) {
+                $update['where_id'] = $order['id'];
+                $update['code'] = $code;
+                Dever::db('journal/order')->update($update);
             }
         }
 
-        return $config;
+        $config['buy_code'] = $this->url('codedetail', array('order_id' => $order_id, 'id' => $id));
+        $result['buy_yes'] = '您已成功购买' . Dever::input('buy_num') . '本电子刊';
+        $result['buy_class'] = 'mask';
+        return $result;
     }
 
     # 小刊购买 一个兑换码的
@@ -277,17 +255,13 @@ class Buy extends Base
             Dever::alert('请传入正确的小刊ID');
         }
 
-        $info = Dever::db('journal/info')->one($journal_id);
-        $buy = Dever::db('journal/buy_num')->one($buy_id);
+        $info = Dever::load('act/order')->getJournal($journal_id);
+        $buy = Dever::load('act/order')->getBuy($buy_id);
 
         if (!$buy || !$info) {
             Dever::alert('请传入正确的小刊ID');
         }
 
-        if (!$buy['name']) {
-            $buy['name'] = '购买' . $buy['num'] . '本';
-        }
-
         $user = Dever::db('passport/user')->one($uid);
         $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 2));
 
@@ -301,12 +275,12 @@ class Buy extends Base
         $order_data['type'] = 3;
         $order_data['status'] = 1;
         $order_data['name'] = $info['name'] . '-' . $buy['name'];
-        //$order_data['num'] = Dever::input('num', 1);
-        $order_data['num'] = $buy['num'];
+        $order_data['buy_num'] = $buy['num'];
+
         if (isset($buy['price']) && $buy['price'] && $buy['price'] > 0) {
             $order_data['cash'] = $buy['price'];
         } else {
-            $order_data['cash'] = $info['cash'] * $order_data['num'];
+            $order_data['cash'] = $info['cash'] * $order_data['buy_num'];
         }
 
         $order_data['system'] = 2;
@@ -318,11 +292,6 @@ class Buy extends Base
             $order_data['seller_id'] = $this->seller;
         }
 
-        if ($this->type == 2) {
-            # 购买兑换码
-            $order_data['type'] = 3;
-        }
-
         $id = Dever::db('journal/order')->insert($order_data);
 
         if (!$id) {
@@ -330,7 +299,14 @@ class Buy extends Base
         }
 
         //$param参数
-        $refer = $this->url('success', array('id' => $journal_id, 'buy' => $buy_id, 'order_id' => $id));
+        $param['id'] = $journal_id;
+        $parma['buy'] = $buy_id;
+        $param['buy_num'] = $order_data['buy_num'];
+        $param['order_id'] = $id;
+        # 立刻创建兑换码
+        //$param['create'] = 1;
+        $refer = $this->url('pay', $param);
+        //$refer = 'callback.success';
         $param = array
         (
             'account_id' => 2,
@@ -339,7 +315,7 @@ class Buy extends Base
             'username' => $user['username'],
             'name' => $order_data['name'],
             'cash' => $order_data['cash'],
-            //'cash' => '0.01',
+            'cash' => '0.01',
             'openid' => $wechat['openid'],
             'product_id' => $journal_id . '-' . $buy_id,
             'order_id' => $order_id,

+ 32 - 0
buy/template/mobile/codedetail.php

@@ -0,0 +1,32 @@
+<?php
+
+$view
+
+->set('name', 'codedetail')
+
+->import('inc/head')
+
+->fetch('#code@src', 'buy/buy.code')
+
+->loop
+(
+    '.code-list',
+    'buy/buy.lists_code',
+    array
+    (
+        'p' => '$v.code',
+        'span' => array
+        (
+            'class' => '$v.class',
+            'html' => '$v.txt',
+        ),
+        'dt' => '$v.copy',
+    )
+)
+
+# 暂无记录
+->append('body', '<div id="page" dever-page-link="<{Dever::pageInfo()["link"]}>" dever-page-list=".pages"></div>')
+
+->import('inc/foot')
+
+->display();

+ 3 - 1
buy/template/mobile/list.php

@@ -30,7 +30,9 @@ $view
 
         '.button' => array
         (
-            'onclick' => 'pay(\'<{$v.pay_url}>\')',
+            'node-act' => '$v.act',
+            'data-src' => '$v.code',
+            'html' => '$v.button'
         )
         
     )

+ 11 - 11
buy/template/mobile/my_code.php

@@ -10,8 +10,8 @@ $view
 
 ->fetch('.info-txt', 'buy/base.config#desc')
 
-->fetch(array('.tab .li@href', 0), 'service/base.config#list_link')
-->fetch(array('.tab .li@href', 1), 'service/base.config#my_link')
+->fetch(array('.tab .li@href', 0), 'buy/base.config#list_link')
+->fetch(array('.tab .li@href', 1), 'buy/base.config#my_link')
 
 ->loop
 (
@@ -19,19 +19,19 @@ $view
     'buy/buy.lists_code',
     array
     (
-        'img' => array
+        '.order-info' => array
         (
-            'src' => '$v.pic_gd',
+            'p' => '$v.cdate',
+            'a' => array
+            (
+                'href' => '$v.link',
+            )
         ),
-        'h2' => '$v.name',
-        '.code' => '$v.code_string',
-
-        '.opposite' => array
+        '.mag-info' => array
         (
-            'node-pic' => '$v.code_pic',
+            'p' => '$v.name',
+            'span' => '$v.desc',
         ),
-
-        'span' => '$v.code',
         
     )
 )

+ 8 - 6
buy/template/mobile/pay.php

@@ -6,18 +6,20 @@ $view
 
 ->import('inc/head')
 
-->fetch('.h1', 'service/buy.info#buy')
+->fetch('.h1', 'buy/buy.info#buy')
 
-->fetch('.richtext', 'service/buy.info#buy_desc')
+->fetch('.richtext', 'buy/buy.info#buy_desc')
 
-->fetch('#notice', 'service/buy.info#buy_notice')
-->fetch('#notices', 'service/buy.info#buy_notices')
+//->fetch('#notice', 'buy/buy.info#buy_notice')
+//->fetch('#notices', 'buy/buy.info#buy_notices')
+->fetch('#buyyes', 'buy/buy.info#buy_yes')
+->fetch('#pay-layer', 'buy/buy.info#buy_class')
 
 # 循环
 ->loop
 (
     '.code',
-    'service/buy.buy',
+    'buy/buy.buy',
     array
     (
         'p|0' => '$v.name',
@@ -35,7 +37,7 @@ $view
 ->loop
 (
     '.codes',
-    'service/buy.buys',
+    'buy/buy.buys',
     array
     (
         'p|0' => '$v.name',

+ 4 - 0
code/lib/Core.php

@@ -36,10 +36,14 @@ class Core
                 $product_num = intval($product_num/$code_num);
 
                 if ($num < 0) {
+                    # 订阅
+                    Dever::load('act/lib/subscribe')->submit($order['uid'], $order['product_id'], 1);
                 	$code = $this->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $order['uid'], $order['order_id'], 0, 3, 1);
                 }
                 $this->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $order['uid'], $order['order_id'], 0, 1, $code_num + $num);
             } else {
+                # 订阅
+                Dever::load('act/lib/subscribe')->submit($order['uid'], $order['product_id'], 1);
                 $code = $this->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $order['uid'], $order['order_id'], 0, 3);
             }
         }