dever %!s(int64=4) %!d(string=hai) anos
pai
achega
c45cbd53ea

+ 43 - 2
app/collection/lib/Core.php

@@ -8,6 +8,8 @@ class Core
 {
 	protected $token;
 	protected $uid;
+    protected $id;
+    protected $id_code;
     protected $share_uid = 0;
     protected $user;
 	protected $year;
@@ -51,13 +53,47 @@ class Core
     # 检查内容
     protected function checkInfo()
     {
-        $this->info = Dever::db('collection/info')->one($this->id);
+        $this->info = $this->get($this->id);
         if (!$this->info) {
             Dever::alert('内容还没有准备好');
         }
         return $this->info;
     }
 
+    # 获取内容
+    protected function get($id)
+    {
+        $info = Dever::load('collection/lib/info')->num($id);
+        if ($info) {
+            $this->handle($info);
+        }
+        
+        return $info;
+    }
+
+    protected function handle(&$info)
+    {
+        # 过滤一些不用的信息
+        unset($info['num_buy']);
+        unset($info['num_ratio_buy']);
+        unset($info['num_add_buy']);
+        unset($info['num_add_view']);
+        unset($info['num_view']);
+        unset($info['buy_price']);
+        unset($info['audit']);
+        unset($info['status']);
+        unset($info['reorder']);
+        unset($info['admin_founder']);
+        unset($info['admin_editor']);
+        unset($info['udate']);
+        unset($info['state']);
+        unset($info['cdate']);
+        unset($info['score_id']);
+        unset($info['score_type']);
+        unset($info['score_name']);
+        $info['id_code'] = Dever::encode($info['id'], $this->key);
+    }
+
     # 检查是否可以查看
     protected function checkView()
     {
@@ -97,7 +133,12 @@ class Core
             }
             
         } else {
-            $this->id = Dever::input('id');
+            $this->id_code = Dever::input('id');
+            if ($this->id_code == -1) {
+                $this->id = $this->id_code;
+            } else {
+                $this->id = Dever::decode($this->id_code, $this->key);
+            }
         }
     }
 

+ 36 - 0
app/collection/lib/Info.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace Collection\Lib;
+
+use Dever;
+
+class Info
+{
+	# 获取内容
+    protected function get($id)
+    {
+        $info = Dever::db('collection/info')->one($id);
+        
+        return $info;
+    }
+
+	public function num($data)
+    {
+    	if (is_numeric($data)) {
+    		$data = $this->get($data);
+    		if (!$data) {
+    			return array();
+    		}
+    	}
+        $data['num_buy_total'] = $data['num_buy'];
+        if (isset($data['num_add_buy']) && isset($data['num_ratio_buy'])) {
+            $data['num_buy_total'] = round(($data['num_buy_total']+$data['num_add_buy'])*$data['num_ratio_buy']);
+        }
+
+        if (isset($data['num_view']) && isset($data['num_add_view'])) {
+            $data['num_view_total'] = round(($data['num_view']+$data['num_add_view']));
+        }
+
+        return $data;
+    }
+}

+ 5 - 19
app/collection/lib/Manage.php

@@ -24,30 +24,21 @@ class Manage
     public function num($id)
     {
         $data = Dever::db('collection/info')->one($id);
-        $data = Dever::load('collection/api')->ding($data);
+        $data = Dever::load('collection/lib/info')->num($data);
 
         $cate = Dever::db('collection/cate')->one($data['cate_id']);
         $html = '《' . $cate['name'] . '》<br />';
 
-        $num_buy = $data['num_buy'];
-        $num_add_buy = $data['num_add_buy'];
-        $num_ratio_buy = $data['num_ratio_buy'];
-        $num_buy_total = $data['num_buy_total'];
-
         if ($data['buy'] == 1) {
             $html .= '<font style="color:red">收费</font><br />';
         } else {
             $html .= '<font style="color:blue">免费</font><br />';
         }
         
-        $html .= '购买数:('.$num_buy.'+'.$num_add_buy.')*'.$num_ratio_buy.'='.$num_buy_total;
-
-        $num_view = $data['num_view'];
-        $num_add_view = $data['num_add_view'];
-        $num_view_total = $num_view + $num_add_view;
+        $html .= '购买数:('.$data['num_buy'].'+'.$data['num_add_buy'].')*'.$data['num_ratio_buy'].'='.$data['num_buy_total'];
 
         
-        $html .= '<br />阅读数:'.$num_view.'+'.$num_add_view.'='.$num_view_total;
+        $html .= '<br />阅读数:'.$data['num_view'].'+'.$data['num_add_view'].'='.$data['num_view_total'];
         
         return $html;
     }
@@ -56,14 +47,9 @@ class Manage
     public function objectNum($id)
     {
         $data = Dever::db('collection/object')->one($id);
-        $data = Dever::load('collection/api')->ding($data);
-
-        $num_buy = $data['num_buy'];
-        $num_add_buy = $data['num_add_buy'];
-        $num_ratio_buy = $data['num_ratio_buy'];
-        $num_buy_total = $data['num_buy_total'];
+        $data = Dever::load('collection/lib/info')->num($data);
 
-        $html = '购买数:('.$num_buy.'+'.$num_add_buy.')*'.$num_ratio_buy.'='.$num_buy_total;
+        $html = '购买数:('.$data['num_buy'].'+'.$data['num_add_buy'].')*'.$data['num_ratio_buy'].'='.$data['num_buy_total'];
         
         return $html;
     }

+ 15 - 10
app/collection/src/Api.php

@@ -41,6 +41,21 @@ class Api extends Core
         return $file['url'];
     }
 
+    # home首页
+    public function home()
+    {
+        # 获取我拥有的合集
+        $data['info'] = array();
+        $collection = Dever::load('user/lib/collection')->getList($this->uid);
+        if ($collection) {
+            foreach ($collection as $k => $v) {
+                $data['info'][] = $this->get($v['info_id']);
+            }
+        }
+
+        return $data;
+    }
+
     public function getUrl($url)
     {
         # 转成短域名
@@ -376,16 +391,6 @@ class Api extends Core
         Dever::alert('error');
     }
 
-    public function ding($data)
-    {
-        $data['num_buy_total'] = $data['num_buy'];
-        if (isset($data['num_add_buy']) && isset($data['num_ratio_buy'])) {
-            $data['num_buy_total'] = round(($data['num_buy_total']+$data['num_add_buy'])*$data['num_ratio_buy']);
-        }
-
-        return $data;
-    }
-
     # 获取功能
     private function getFunc()
     {

+ 14 - 1
app/user/database/collection.php

@@ -118,6 +118,19 @@ return array
 
     'request' => array
     (
-        
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'info_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'page' => array(10, 'list'),
+            'col' => 'info_id,num',
+        ),
     ),
 );

+ 9 - 0
app/user/lib/Collection.php

@@ -40,4 +40,13 @@ class Collection
 
         return $info;
     }
+
+    # 获取用户拥有的合集
+    public function getList($uid)
+    {
+        $where['uid'] = $uid;
+        $info = Dever::db('user/collection')->getAll($where);
+
+        return $info;
+    }
 }