dever пре 4 година
родитељ
комит
4bd907b7f2

+ 20 - 4
app/collection/database/ranking.php

@@ -11,7 +11,7 @@ $type = array
 $periods = array
 (
     //1 => '天',
-    //2 => '周',
+    2 => '周',
     3 => '月',
     4 => '年',
 );
@@ -29,6 +29,7 @@ return array
     # 显示给用户看的名称
     'lang' => '榜单设置',
     'menu' => false,
+    'check' => 'info_id,type',
     'ends' => array
     (
         'insert' => 'collection/lib/manage.setRankingCache',
@@ -90,7 +91,7 @@ return array
         (
             'type'      => 'int-11',
             'name'      => '榜单类型',
-            'default'   => '3',
+            'default'   => '1',
             'desc'      => '榜单类型',
             'match'     => 'is_numeric',
             'update'    => 'radio',
@@ -200,8 +201,8 @@ return array
         # 列表
         'list_button' => array
         (
-            'list1' => array('榜单期数', '"ranking_periods&search_option_info_id={info_id}&search_option_ranking_id={id}&top_table=ranking_data&oper_table=ranking"'),
-            'list' => array('榜单数据', '"ranking_data&search_option_info_id={info_id}&search_option_ranking_id={id}&top_table=ranking_data&oper_table=ranking"'),
+            'list1' => array('榜单期数', '"ranking_periods&search_option_info_id={info_id}&search_option_ranking_id={id}&top_table=ranking_data&oper_table=ranking&top_table=info"'),
+            'list' => array('榜单数据', '"ranking_data&search_option_info_id={info_id}&search_option_ranking_id={id}&top_table=ranking_data&oper_table=ranking&top_table=info"'),
         ),
     ),
 
@@ -213,6 +214,7 @@ return array
             'option' => array
             (
                 'info_id' => 'yes',
+                'type' => 'yes',
                 'state' => 1,
                 'status' => 1,
             ),
@@ -220,5 +222,19 @@ return array
             'order' => array('reorder' => 'desc', 'id' => 'desc'),
             'col' => '*',
         ),
+
+        'getOne' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'info_id' => 'yes',
+                'type' => 'yes',
+                'state' => 1,
+                'status' => 1,
+            ),
+            'type' => 'one',
+            'col' => '*',
+        ),
     ),
 );

+ 1 - 11
app/collection/database/ranking_data.php

@@ -102,17 +102,6 @@ return array
             'list'      => '"{num}"',
         ),
 
-        'day'     => array
-        (
-            'type'      => 'int-11',
-            'name'      => '日期',
-            'default'   => '',
-            'desc'      => '日期',
-            'match'     => 'is_numeric',
-            'update'    => 'day',
-            'list'      => true,
-        ),
-
         'state'     => array
         (
             'type'      => 'tinyint-1',
@@ -148,6 +137,7 @@ return array
             # 匹配的正则或函数 选填项
             'option' => array
             (
+                'uid' => 'yes',
                 'info_id' => 'yes',
                 'ranking_id' => 'yes',
                 'periods_id' => 'yes',

+ 31 - 9
app/collection/database/ranking_periods.php

@@ -1,5 +1,9 @@
 <?php
-
+$status = array
+(
+    1 => '开启',
+    2 => '关闭',
+);
 return array
 (
     # 表名
@@ -69,23 +73,24 @@ return array
             'list'      => true,
         ),
 
-        'users'     => array
+        'status'     => array
         (
             'type'      => 'int-11',
-            'name'      => '参与人数',
-            'default'   => '0',
-            'desc'      => '参与人数',
+            'name'      => '本期状态-手动设置状态,也可以设置下方的时间来自动控制',
+            'default'   => '1',
+            'desc'      => '本期状态',
             'match'     => 'is_numeric',
-            'update'    => 'text',
-            'order'		=> 'desc',
+            'update'    => 'radio',
+            'option'    => $status,
             'list'      => true,
+            'edit'      => true,
         ),
 
         'start'       => array
         (
             'type'      => 'int-11',
             'default'   => '',
-            'name'      => '本期开始时间',
+            'name'      => '本期开始时间-可以为空,则按照总榜设置的榜单周期自动开始',
             'match'     => 'option',
             'desc'      => '本期开始时间',
             'update'    => 'date',
@@ -97,7 +102,7 @@ return array
         (
             'type'      => 'int-11',
             'default'   => '',
-            'name'      => '本期结束时间',
+            'name'      => '本期结束时间-可以为空,则按照总榜设置的榜单周期自动结束',
             'match'     => 'option',
             'desc'      => '本期结束时间',
             'update'    => 'date',
@@ -142,6 +147,7 @@ return array
             (
                 'info_id' => 'yes',
                 'ranking_id' => 'yes',
+                'status' => 1,
                 'state' => 1,
             ),
             'type' => 'all',
@@ -149,5 +155,21 @@ return array
             'limit' => '0,20',
             'col' => '*',
         ),
+
+        # 获取当前最新的期数
+        'getNew' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'info_id' => 'yes',
+                'ranking_id' => 'yes',
+                'status' => 1,
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'order' => array('periods' => 'desc', 'cdate' => 'desc'),
+            'col' => '*',
+        ),
     ),
 );

+ 3 - 3
app/collection/lib/Core.php

@@ -58,15 +58,15 @@ class Core
         return $this->info;
     }
 
-    # 检查是否购买
-    protected function checkBuy()
+    # 检查是否可以查看
+    protected function checkView()
     {
         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']);
+            $this->info['buy_data'] = Dever::load('user/lib/collection')->check($this->uid, $this->info['id']);
             return $this->info['buy_data'] ? true : false;
         } else {
             # 免费

+ 116 - 0
app/collection/lib/Ranking.php

@@ -0,0 +1,116 @@
+<?php
+
+namespace Collection\Lib;
+
+use Dever;
+
+class Ranking
+{
+
+	# 获取最新的总榜
+    public function getInfo($info_id, $type = 1)
+    {
+    	$where['info_id'] = $info_id;
+    	$where['type'] = $type;
+        $info = Dever::db('collection/ranking')->getOne($where);
+
+        return $info;
+    }
+
+    # 获取最新的一期
+    public function getPeriodsNew($info_id, $type = 1)
+    {
+        $info = $this->getInfo($info_id, $type);
+        if ($info) {
+        	$where['info_id'] = $info_id;
+	    	$where['ranking_id'] = $info['id'];
+	        $info = Dever::db('collection/ranking_periods')->getNew($where);
+
+	        return $info;
+        }
+        return false;
+    }
+
+    # 获取当前期的数据
+    public function getData($periods_id)
+    {
+    	$where['periods_id'] = $periods_id;
+        $data = Dever::db('collection/ranking_data')->getAll($where);
+
+        return $data;
+    }
+
+    # 加入门票榜单
+    public function up($uid, $info_id, $type = 1, $num = 1)
+    {
+        $periods = $this->getPeriodsNew($info_id, $type);
+        if ($periods) {
+        	$update['uid'] = $uid;
+        	$update['periods_id'] = $periods['id'];
+        	$data = Dever::db('collection/ranking_data')->one($update);
+        	$update['info_id'] = $info_id;
+        	$update['ranking_id'] = $periods['ranking_id'];
+        	if ($data) {
+        		$update['where_id'] = $data['id'];
+        		$update['num'] = $data['num'] + $num;
+        		Dever::db('collection/ranking_data')->update($update);
+        	} else {
+        		$update['num'] = $num;
+        		Dever::db('collection/ranking_data')->insert($update);
+        	}
+        }
+    }
+
+    # 加入到cron里 检测所有榜单是否有新的期数,如果没有,自动添加新的一期
+    public function cron_api()
+    {
+    	$ranking = Dever::db('collection/ranking')->getAll();
+
+    	if ($ranking) {
+    		$cur = time();
+    		foreach ($ranking as $k => $v) {
+	    		$where['ranking_id'] = $v['id'];
+	        	$info = Dever::db('collection/ranking_periods')->getNew($where);
+	        	if (!$info) {
+	        		# 如果没有,就建立新的期数
+	        		$this->createPeriods(1, $cur, $v);
+	        	} else {
+	        		# 如果有,检查结束时间到没到期,如果到了,就把这一期置为已结束,重新建立新的期数
+	        		if ($cur > $info['end']) {
+	        			Dever::db('collection/ranking_periods')->update(array('where_id' => $info['id'], 'status' => 2));
+	        			$this->createPeriods($info['periods'] + 1, $cur, $v);
+	        		}
+	        	}
+    		}
+    	}
+    }
+
+    private function createPeriods($periods, $cur, $info)
+    {
+    	# 查看总榜的结束时间是否结束
+    	if ($info['end'] && $cur > $info['end']) {
+    		Dever::db('collection/ranking')->update(array('where_id' => $info['id'], 'status' => 2));
+    		return;
+    	}
+
+    	$data['info_id'] = $info['info_id'];
+    	$data['ranking_id'] = $info['id'];
+    	$data['name'] = '第' . $periods . '期';
+    	$data['periods'] = $periods;
+    	$data['users'] = 0;
+    	$data['status'] = 1;
+    	$data['start'] = $cur;
+    	if ($info['periods'] == 2) {
+    		# 周
+    		$time = 3600*24*7;
+    	} elseif ($info['periods'] == 3) {
+    		# 月
+    		$time = 3600*24*30;
+    	} elseif ($info['periods'] == 4) {
+    		# 年
+    		$time = 3600*24*365;
+    	}
+    	$data['end'] = $data['start'] + $time;
+    	Dever::db('collection/ranking_periods')->insert($data);
+    }
+}

+ 2 - 6
app/collection/src/Api.php

@@ -175,11 +175,7 @@ class Api extends Core
         }
         $data['info']['pic_bg'] = explode(',', $data['info']['pic_bg']);
 
-        $data['is_buy'] = $this->checkBuy();
-        $data['buy_data'] = array();
-        if ($data['is_buy']) {
-            $data['buy_data'] = $this->info['buy_data'];
-        }
+        $data['is_buy'] = $this->checkView();
         
         # 获取按钮样式
         $data['button'] = $this->button($data['info']);
@@ -205,7 +201,7 @@ class Api extends Core
         # 获取按钮样式
         $data['info']['button'] = $this->button($data['info']);
         # 是否可以看
-        $data['show'] = $this->checkBuy();
+        $data['show'] = $this->checkView();
 
         # 获取每个模块
         $data['items'] = Dever::load('collection/lib/content')->getList($this->id, $this->page_id);

+ 0 - 2
app/content/database/video_comment.php

@@ -132,8 +132,6 @@ return array
             'place'     => '150',
             'upload'    => 'yun',
             'large'     => true,
-            //不覆盖原文件,生成新文件
-            'cover'     => 2,   
         ),
 
         'video_info'        => array

+ 23 - 15
app/user/database/collection.php

@@ -41,42 +41,50 @@ return array
             'list'      => '{uid} > 0 ? Dever::load("passport/user-one#username", {uid}) : "匿名用户"',
         ),
 
-        'info_id'      => array
+        'source_uid'       => array
         (
             'type'      => 'int-11',
-            'name'      => '合集',
-            'default'   => '',
-            'desc'      => '合集',
+            'name'      => '来源',
+            'default'   => '0',
+            'desc'      => '请选择用户',
             'match'     => 'is_numeric',
             'update'    => 'text',
+            //'search'  => 'select',
+            'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            'list'      => '{source_uid} > 0 ? Dever::load("passport/user-one#username", {source_uid}) : "无"',
         ),
 
-        'num'      => array
+        'info_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => '拥有数量',
-            'default'   => '0',
-            'desc'      => '拥有数量',
+            'name'      => '合集',
+            'default'   => '',
+            'desc'      => '合集',
             'match'     => 'is_numeric',
             'update'    => 'text',
         ),
 
-        'share_num'      => array
+        'ticket_id'      => array
         (
             'type'      => 'int-11',
-            'name'      => '分享数量',
-            'default'   => '0',
-            'desc'      => '分享数量',
+            'name'      => '门票id',
+            'default'   => '',
+            'desc'      => '门票id',
             'match'     => 'is_numeric',
             'update'    => 'text',
         ),
 
-        'use_num'      => array
+        'num'      => array
         (
             'type'      => 'int-11',
-            'name'      => '使用数量',
+            'name'      => '数量',
             'default'   => '0',
-            'desc'      => '使用数量',
+            'desc'      => '数量',
             'match'     => 'is_numeric',
             'update'    => 'text',
         ),

+ 132 - 0
app/user/database/ticket.php

@@ -0,0 +1,132 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'ticket',
+    # 显示给用户看的名称
+    'lang' => '用户持有合集门票记录',
+    'menu' => false,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'update'    => 'hidden',
+            //'list'        => true,
+        ),
+
+        'uid'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '用户名',
+            'default'   => '0',
+            'desc'      => '请选择用户',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            //'search'  => 'select',
+            'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            'list'      => '{uid} > 0 ? Dever::load("passport/user-one#username", {uid}) : "匿名用户"',
+        ),
+
+        'info_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '合集',
+            'default'   => '',
+            'desc'      => '合集',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+        ),
+
+        'total'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '总数量',
+            'default'   => '0',
+            'desc'      => '总数量',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+        ),
+
+        'num'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '当前拥有数量',
+            'default'   => '0',
+            'desc'      => '当前拥有数量',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '操作时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            //'insert'    => true,
+            'search'    => 'date',
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        
+    ),
+
+    'request' => array
+    (
+        # 更新数量
+        'add' => array
+        (
+            'type' => 'update',
+            'where' => array
+            (
+                'id' => 'yes',
+            ),
+            'set' => array
+            (
+                'num' => array('yes', '+='),
+                'total' => array('yes', '+='),
+            ),
+        ),
+
+        # 减少数量
+        'des' => array
+        (
+            'type' => 'update',
+            'where' => array
+            (
+                'id' => 'yes',
+            ),
+            'set' => array
+            (
+                'num' => array('yes', '-='),
+            ),
+        ),
+    ),
+);

+ 1 - 1
app/user/index.php

@@ -1,7 +1,7 @@
 <?php
 
 define('DEVER_APP_NAME', 'user');
-define('DEVER_APP_LANG', '合集用户行为');
+define('DEVER_APP_LANG', '用户行为');
 define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
 define('DEVER_MANAGE_ORDER', 199);
 define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-theme');

+ 20 - 12
app/user/lib/Collection.php

@@ -7,24 +7,32 @@ use Dever;
 class Collection
 {
     # 保存信息
-    public function up($uid, $info_id, $num = 1)
+    public function up($ticket_id, $uid, $source_uid, $info_id, $num = 1)
     {
-        $where['uid'] = $uid;
-        $where['info_id'] = $info_id;
-        $info = Dever::db('user/collection')->one($where);
-        if (!$info) {
-            $where['num'] = $num;
-            Dever::db('user/collection')->insert($where);
+        $ticket = Dever::db('user/ticket')->one($ticket_id);
+        if (!$ticket) {
+            return false;
+        }
+        if ($ticket['num'] > 0 && $ticket['num'] >= $num) {
+            $where['uid'] = $uid;
+            $where['info_id'] = $info_id;
+            $where['ticket_id'] = $ticket_id;
+            $info = Dever::db('user/collection')->one($where);
+            if (!$info) {
+                $where['num'] = $num;
+                $where['source_uid'] = $source_uid;
+                Dever::db('user/collection')->insert($where);
+                Dever::db('user/ticket')->des(array('where_id' => $ticket_id, 'num' => $num));
+            }
+            return true;
         } else {
-            $update['where_id'] = $info['id'];
-            $update['num'] = $info['num'] + $num;
-            Dever::db('user/collection')->update($update);
+            return false;
         }
-        return true;
+        
     }
 
     # 获取信息
-    public function one($uid, $info_id)
+    public function check($uid, $info_id)
     {
         $where['uid'] = $uid;
         $where['info_id'] = $info_id;

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

@@ -6,10 +6,33 @@ use Dever;
 
 class Ticket
 {
+    # 保存信息
+    public function up($uid, $info_id, $num = 1)
+    {
+        $where['uid'] = $uid;
+        $where['info_id'] = $info_id;
+        $info = Dever::db('user/ticket')->one($where);
+        if (!$info) {
+            $where['num'] = $num;
+            $where['total'] = $num;
+            return Dever::db('user/ticket')->insert($where);
+        } else {
+            $update['where_id'] = $info['id'];
+            $update['num'] = $num;
+            $update['total'] = $num;
+            Dever::db('user/ticket')->add($update);
+            return $info['id'];
+        }
+    }
+
     # 验证是否购买
     public function check($uid, $info_id)
     {
-        
+        $where['uid'] = $uid;
+        $where['info_id'] = $info_id;
+        $info = Dever::db('user/ticket')->one($where);
+
+        return $info;
     }
 
     # 发起支付
@@ -109,8 +132,16 @@ class Ticket
         if ($order && $order['status'] == 1) {
             if ($status == 2) {
 
-                # 更新购买数量
-                Dever::load('user/lib/collection')->up($order['uid'], $order['info_id'], $order['buy_num']);
+                # 更新持有门票数量
+                $ticket_id = $this->up($order['uid'], $order['info_id'], $order['buy_num']);
+
+                if ($ticket_id) {
+                    # 更新拥有合集数量
+                    Dever::load('user/lib/collection')->up($ticket_id, $order['uid'], $order['uid'], $order['info_id'], 1);
+                    # 加入门票榜单
+                    Dever::load('collection/lib/ranking')->up($order['uid'], $order['info_id'], 1, $order['buy_num']);
+                }
+
                 # 增加积分
                 if ($order['parent_uid'] > 0) {
                     $uid = $order['parent_uid'] . '_' . $order['uid'];