dever 4 years ago
parent
commit
05a2933b91

+ 26 - 1
app/collection/lib/Core.php

@@ -15,6 +15,7 @@ class Core
     protected $day = 0;
     protected $parent_page_id;
     protected $page_id;
+    protected $info;
     protected $key = 'dreamland1985';
     /*
     # 定义全局的系统类型
@@ -41,16 +42,39 @@ class Core
         $this->system_source = Dever::input('system_source', 1);
     }
 
+    # 获取用户信息
     protected function getUser($uid, $collection_id)
     {
         return Dever::load('user/lib/info')->get($uid, $collection_id);
     }
 
+    # 检查内容
     protected function checkInfo()
     {
-        return Dever::db('collection/info')->one($this->id);
+        $this->info = Dever::db('collection/info')->one($this->id);
+        if (!$this->info) {
+            Dever::alert('内容还没有准备好');
+        }
+        return $this->info;
+    }
+
+    # 检查是否购买
+    protected function checkBuy()
+    {
+        if (!$this->info) {
+            $this->checkInfo();
+        }
+        if ($this->info['buy'] == 1) {
+            # 收费 从订单中读取是否已经购买
+            $this->info['buy_data'] = Dever::load('user/lib/collection')->one($this->uid, $this->info['id']);
+            return $this->info['buy_data'] ? true : false;
+        } else {
+            # 免费
+            return true;
+        }
     }
 
+    # 检测邀请码
     protected function checkCode()
     {
         $this->code = Dever::input('code');
@@ -77,6 +101,7 @@ class Core
         }
     }
 
+    # 获取邀请码
     protected function getCode($id, $parent_page_id, $page_id, $index, $times_id, $day = 0, $uid = 0)
     {
         if (Dever::project('invite')) {

+ 18 - 25
app/collection/src/Api.php

@@ -168,33 +168,24 @@ class Api extends Core
     # 获取合集内容
     public function getInfo()
     {
-        # 是否已经购买
-        $data['is_buy'] = false;
-        
         $data['info'] = $this->checkInfo();
-        if ($data['info']) {
-            $data['info']['user'] = array();
-            if ($data['info']['uid'] > 0) {
-                $data['info']['user'] = $this->getUser($data['info']['uid'], $data['info']['id']);
-            }
-            $data['info']['pic_bg'] = explode(',', $data['info']['pic_bg']);
-
-            if ($data['info']['buy'] == 1) {
-                # 收费 从订单中读取是否已经购买
-                $data['is_buy'] = false;
-            } else {
-                # 免费
-                $data['is_buy'] = true;
-            }
-
-            # 获取按钮样式
-            $data['button'] = $this->button($data['info']);
+        $data['info']['user'] = array();
+        if ($data['info']['uid'] > 0) {
+            $data['info']['user'] = $this->getUser($data['info']['uid'], $data['info']['id']);
+        }
+        $data['info']['pic_bg'] = explode(',', $data['info']['pic_bg']);
 
-            # 获取code
-            $data['code'] = $this->getInfoCode();
-        } else {
-            Dever::alert('内容还没有准备好');
+        $data['is_buy'] = $this->checkBuy();
+        $data['buy_data'] = array();
+        if ($data['is_buy']) {
+            $data['buy_data'] = $this->info['buy_data'];
         }
+        
+        # 获取按钮样式
+        $data['button'] = $this->button($data['info']);
+
+        # 获取code
+        $data['code'] = $this->getInfoCode();
 
         return $data;
     }
@@ -210,10 +201,12 @@ class Api extends Core
         # 获取用户信息
         $data['user'] = $this->user;
         $data['info'] = $this->checkInfo();
+
         # 获取按钮样式
         $data['info']['button'] = $this->button($data['info']);
         # 是否可以看
-        $data['show'] = true;
+        $data['show'] = $this->checkBuy();
+
         # 获取每个模块
         $data['items'] = Dever::load('collection/lib/content')->getList($this->id, $this->page_id);
         # 滑动到多少时,加载下一页

+ 20 - 0
app/user/database/collection.php

@@ -61,6 +61,26 @@ return array
             'update'    => 'text',
         ),
 
+        'share_num'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '分享数量',
+            'default'   => '0',
+            'desc'      => '分享数量',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+        ),
+
+        'use_num'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '使用数量',
+            'default'   => '0',
+            'desc'      => '使用数量',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',

+ 1 - 1
app/user/lib/Collection.php

@@ -14,7 +14,7 @@ class Collection
         $info = Dever::db('user/collection')->one($where);
         if (!$info) {
             $where['num'] = $num;
-            Dever::db('user/collection')->insert($update);
+            Dever::db('user/collection')->insert($where);
         } else {
             $update['where_id'] = $info['id'];
             $update['num'] = $info['num'] + $num;

+ 3 - 21
app/user/lib/Ticket.php

@@ -105,8 +105,7 @@ class Ticket
         $status = $send['pay_status'];
         $msg = $send['pay_msg'];
 
-        $order = Dever::db('user/ticket_order')->one(array('order_id' => $order_id));
-
+        $order = Dever::db('user/ticket_order')->one(array('order_id' => $order_id, 'time' => time()));
         if ($order && $order['status'] == 1) {
             if ($status == 2) {
 
@@ -127,7 +126,7 @@ class Ticket
             }
 
             $update['status'] = $status;
-            $update['id'] = $order['id'];
+            $update['where_id'] = $order['id'];
             Dever::db('user/ticket_order')->update($update);
         }
 
@@ -137,7 +136,7 @@ class Ticket
     # 生成订单号
     public function getOrderId()
     {
-        $where['order_id'] = $this->createOrderId();
+        $where['order_id'] = Dever::order('T');
         $state = Dever::db('user/ticket_order')->one($where);
         if (!$state) {
             return $where['order_id'];
@@ -146,23 +145,6 @@ class Ticket
         }
     }
 
-    # 生成订单号
-    public function createOrderId()
-    {   
-        if (function_exists('session_create_id')) {
-            return strtoupper(session_create_id());
-        } else {
-            $charid = strtoupper(md5(uniqid(mt_rand(), true)));
-            return substr($charid, 0, 8) . substr($charid, 8, 4) . substr($charid, 12, 4) . substr($charid, 16, 4) . substr($charid, 20, 12);
-        }
-    }
-
-    # 临时订单号 无用
-    public function createTmpOrderId($prefix = '')
-    {
-        return $prefix . (strtotime(date('YmdHis', time()))) . substr(microtime(), 2, 6) . sprintf('%03d', rand(0, 999));
-    }
-
     public function getOrderIdAndId($order_id, $id)
     {
     	if ($order_id) {