dever 4 роки тому
батько
коміт
8b22a431c0

+ 21 - 0
app/collection/database/cate.php

@@ -4,6 +4,12 @@ $auth = Dever::tops();
 $status = Dever::config('base')->status;
 $type = Dever::db('collection/type')->state();
 
+$top = array
+(
+    1 => '推荐',
+    2 => '不推荐',
+);
+
 $list = array
 (
     # 匹配的正则或函数 选填项
@@ -144,6 +150,20 @@ return array
             'update'    => 'textarea',
         ),
 
+        'top'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '推荐',
+            'default'   => '2',
+            'desc'      => '推荐',
+            'match'     => 'is_numeric',
+            //'update'  => 'select',
+            'option'    => $top,
+            'search'    => 'select',
+            //'list'      => true,
+            //'edit'      => true,
+        ),
+
         'status'        => array
         (
             'type'      => 'int-11',
@@ -269,6 +289,7 @@ return array
             (
                 'ids' => array('yes-id', 'in'),
                 'id' => 'yes',
+                'top' => 'yes',
                 'status' => 1,
                 'state' => 1,
             ),

+ 5 - 4
app/collection/database/info.php

@@ -69,6 +69,7 @@ $config = array
         'insert' => 'collection/lib/manage.setInfo',
         'update' => 'collection/lib/manage.setInfo',
         'update_status' => 'collection/lib/manage.setInfo',
+        'update_top' => 'collection/lib/manage.setTop',
     ),
 
     # 数据结构
@@ -460,7 +461,7 @@ $config = array
             'edit'      => true,
         ),
 
-        
+        /*
         'hr4'       => array
         (
             'name'      => '首页按钮配置',
@@ -507,6 +508,7 @@ $config = array
             'match'     => 'option',
             //'update'    => 'color',
         ),
+        */
 
         'hr5'       => array
         (
@@ -807,9 +809,8 @@ $config = array
             ),
             'type' => 'all',
             'order' => array('reorder' => 'desc', 'pdate' => 'desc', 'id' => 'desc'),
-            //'page' => array(10, 'list'),
-            'limit' => '0,10',
-            'col' => $col,
+            'page' => array(10, 'list'),
+            'col' => 'id,name,`desc`,pic_cover',
         ),
 
         'getNew' => array

+ 15 - 0
app/collection/lib/Manage.php

@@ -324,6 +324,21 @@ class Manage
         }
     }
 
+    public function setTop($id, $name, $param)
+    {
+        $top = Dever::param('top', $param);
+        if ($top) {
+
+            $info = Dever::db('collection/info')->one($id);
+            if ($info['cate_id']) {
+                $cate = Dever::db('collection/info')->one(array('cate_id' => $info['cate_id'], 'top' => 1));
+                if ($cate) {
+                    Dever::db('collection/cate')->update(array('where_id' => $info['cate_id'], 'top' => 1));
+                }
+            }
+        }
+    }
+
     # 获取预览
     public function preview_api()
     {

+ 22 - 26
app/collection/src/Api.php

@@ -100,39 +100,35 @@ class Api extends Core
     # 我的合集列表
     public function getList()
     {
+        # 类型 1是全部,2是我的
+        $type = Dever::input('type', 1);
         # 获取推荐合集
-        /*
-        $data['hot'] = array();
-        $hot = Dever::db('collection/info')->getHot();
-        if ($hot) {
-            foreach ($hot as $k => $v) {
-                $data['hot'][] = $this->getOne($v['id']);
+        $data['info'] = $data['cate'] = array();
+        if ($type == 1) {
+            $data['cate'] = Dever::db('collection/cate')->getData(array('top' => 1));
+            if ($data['cate']) {
+                $data['info'] = Dever::db('collection/info')->getHot(array('cate_id' => $data['cate'][0]['id']));
             }
-        }
-        */
-
-        # 获取我拥有的合集
-        $data['info'] = $data['cate'] = $data['focus'] = array();
-        if ($this->uid > 0) {
-            $collection = Dever::load('user/lib/collection')->getList($this->uid);
-            if ($collection) {
-                $cate = array();
-                foreach ($collection as $k => $v) {
-                    $info = $this->getOne($v['info_id']);
-                    $data['info'][$info['cate_id']][] = $info;
-                    $cate[$info['cate_id']] = $info['cate_id'];
+        } else {
+            # 获取我拥有的合集
+            if ($this->uid > 0) {
+                $cate = Dever::load('user/lib/collection')->getCateList($this->uid);
+                print_r($cate);die;
+                if ($cate) {
+                    $cate = array_keys($cate);
+                    $data['cate'] = Dever::db('collection/cate')->getData(array('ids' => $cate));
+                    if ($data['cate']) {
+                        $data['info'] = Dever::load('user/lib/collection')->getList($this->uid, $data['cate'][0]['id']);
+                    }
                 }
 
-                $cate = implode(',', $cate);
-                $data['cate'] = Dever::db('collection/cate')->getData(array('ids' => $cate));
+                # 焦点图
+                //$data['focus'] = Dever::load('push/lib/data')->get('focus', '阅览焦点图', 5);
             }
-
-            # 焦点图
-            $data['focus'] = Dever::load('push/lib/data')->get('focus', '阅览焦点图', 5);
         }
-
         # 获取分享信息
         $data['share'] = $this->getConfigShare();
+        print_r($data);die;
 
         return $data;
     }
@@ -350,7 +346,7 @@ class Api extends Core
         $data['times_id'] = $this->times;
 
         if ($data['info']['buy'] == 2) {
-            Dever::load('user/lib/collection')->upAct($this->uid, $this->id, 1, $this->share_uid);
+            Dever::load('user/lib/collection')->upAct($this->uid, $this->id, $data['info']['cate_id'], 1, $this->share_uid);
         }
 
         # 获取按钮样式

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

@@ -59,6 +59,16 @@ return array
             'list'      => '{source_uid} > 0 ? Dever::load("passport/user-one#username", {source_uid}) : "无"',
         ),
 
+        'cate_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '合集分类',
+            'default'   => '',
+            'desc'      => '合集分类',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+        ),
+
         'info_id'      => array
         (
             'type'      => 'int-11',
@@ -125,14 +135,41 @@ return array
             (
                 'uid' => 'yes',
                 'info_id' => 'yes',
+                'cate_id' => 'yes',
                 'state' => 1,
             ),
+            # 联表
+            'join' => array
+            (
+                array
+                (
+                    'table' => 'collection/info',
+                    'type' => 'left join',
+                    'on' => array('info_id','id'),
+                    'col' => 't_2.id,t_2.name,t_2.desc,t_2.pic_cover',
+                ),
+            ),
             'type' => 'all',
-            'order' => array('id' => 'desc'),
+            'order' => array('t_2.reorder' => 'desc', 't_2.pdate' => 'desc', 't_2.id' => 'desc'),
             'page' => array(10, 'list'),
             'col' => 'info_id,num',
         ),
 
+        'getCateAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'cate_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'group' => 'cate_id',
+            'col' => 'info_id,cate_id,num|cate_id',
+        ),
+
         'num' => array
         (
             # 匹配的正则或函数 选填项

+ 17 - 4
app/user/lib/Collection.php

@@ -7,7 +7,7 @@ use Dever;
 class Collection
 {
     # 保存信息 收费
-    public function up($ticket_id, $uid, $source_uid, $info_id, $num = 1)
+    public function up($ticket_id, $uid, $source_uid, $info_id, $cate_id, $num = 1)
     {
         $ticket = Dever::db('user/ticket')->one($ticket_id);
         if (!$ticket) {
@@ -15,7 +15,7 @@ class Collection
         }
         if ($ticket['num'] > 0 && $ticket['num'] >= $num) {
 
-            $state = $this->upAct($uid, $info_id, $num, $source_uid, $ticket_id);
+            $state = $this->upAct($uid, $info_id, $cate_id, $num, $source_uid, $ticket_id);
             if ($state) {
                 Dever::score($uid, 'use_ticket', '使用门票', false, false, false, 'collection', $info_id);
                 
@@ -34,7 +34,7 @@ class Collection
     }
 
     # 保存信息 免费
-    public function upAct($uid, $info_id, $num = 1, $source_uid = false, $ticket_id = false)
+    public function upAct($uid, $info_id, $cate_id, $num = 1, $source_uid = false, $ticket_id = false)
     {
         $where['uid'] = $uid;
         $where['info_id'] = $info_id;
@@ -50,6 +50,7 @@ class Collection
             if ($ticket_id) {
                 $where['ticket_id'] = $ticket_id;
             }
+            $where['cate_id'] = $cate_id;
             return Dever::db('user/collection')->insert($where);
         }
 
@@ -67,14 +68,26 @@ class Collection
     }
 
     # 获取用户拥有的合集
-    public function getList($uid)
+    public function getList($uid, $cate_id = false)
     {
         $where['uid'] = $uid;
+        if ($cate_id) {
+            $where['cate_id'] = $cate_id;
+        }
         $info = Dever::db('user/collection')->getAll($where);
 
         return $info;
     }
 
+    # 获取用户拥有的合集分类
+    public function getCateList($uid)
+    {
+        $where['uid'] = $uid;
+        $info = Dever::db('user/collection')->getCateAll($where);
+
+        return $info;
+    }
+
     # 获取某个合集的拥有数量
     public function getNum($info_id)
     {

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

@@ -194,7 +194,7 @@ class Ticket
 
                 if ($ticket_id) {
                     # 更新拥有合集数量
-                    Dever::load('user/lib/collection')->up($ticket_id, $order['uid'], $order['uid'], $order['info_id'], 1);
+                    Dever::load('user/lib/collection')->up($ticket_id, $order['uid'], $order['uid'], $order['info_id'], $order['cate_id'], 1);
                     # 加入门票榜单
                     Dever::load('collection/lib/ranking')->up($order['uid'], $order['info_id'], 1, $order['buy_num']);
                 }