dever 6 years ago
parent
commit
bfb95f4884
6 changed files with 193 additions and 2 deletions
  1. 116 0
      act/database/watch.php
  2. 47 0
      act/lib/Watch.php
  3. 2 1
      journal/database/buy_num.php
  4. 22 0
      journal/lib/Manage.php
  5. 1 1
      journal/lib/Pay.php
  6. 5 0
      main/src/View.php

+ 116 - 0
act/database/watch.php

@@ -0,0 +1,116 @@
+<?php
+
+$table = Dever::config('base')->type;
+return array
+(
+    # 表名
+    'name' => 'watch',
+    # 显示给用户看的名称
+    'lang' => '观看人数',
+    # 是否显示在后台菜单
+    'order' => 79,
+    'menu' => false,
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'order'     => 'desc',
+            //'list'        => true,
+        ),
+        
+
+        'uid'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '用户名',
+            'default'   => '0',
+            'desc'      => '请选择用户',
+            'match'     => 'is_numeric',
+            //'update'  => 'select',
+            //'search'  => 'select',
+            'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            'list'      => '{uid} > 0 ? Dever::load("passport/user-one#username", {uid}) : "匿名用户"',
+        ),
+
+        'type'      => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '类别',
+            'default'   => '',
+            'desc'      => '类别',
+            'match'     => 'option',
+            'search'    => 'select',
+            'option'    => $table,
+            'list'      => true,
+        ),
+        
+        'data_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '标题',
+            'default'   => '',
+            'desc'      => '标题',
+            'match'     => 'option',
+            'list'      => 'Dever::load("act/lib/manage.load", "{type}", {data_id})',
+        ),
+        
+        '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
+    (
+        'insert' => false,
+        'edit' => false,
+        'delete' => false,
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'uid' => 'yes',
+                'data_id' => 'yes',
+                'type' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'page' => array(15, 'list'),
+            'col' => 'uid,type,data_id,cdate',
+        ),
+    )
+);

+ 47 - 0
act/lib/Watch.php

@@ -0,0 +1,47 @@
+<?php
+
+namespace Act\Lib;
+
+use Dever;
+
+class Watch
+{
+    # 获取当前小刊的观看数
+    public function get(id, $type = 4)
+    {
+        $where['type'] = $type;
+        $where['data_id'] = $id;
+        $where['state'] = 1;
+        $info = Dever::db('act/watch')->total($where);
+
+        return $info;
+    }
+
+    # 观看
+    public function submit($uid, $id, $type = 3)
+    {
+        $where['uid'] = $uid;
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $info = Dever::db('act/watch')->one($where);
+        if (!$info) {
+            Dever::db('act/watch')->insert($where);
+        }
+
+        if ($type == 3) {
+            # 更新观看数
+            $where = array();
+            $where['data_id'] = $id;
+            $where['type'] = $type;
+            $where['state'] = 1;
+            $total = Dever::db('act/watch')->total($where);
+            $table = Dever::config('base')->type_table[$type];
+            Dever::db($table)->update(array('where_id' => $id, 'num_user' => $total));
+
+            Dever::score($uid, 'submit_watch', '观看直播');
+        }
+        
+
+        return true;
+    }
+}

+ 2 - 1
journal/database/buy_num.php

@@ -62,7 +62,7 @@ return array
             'match'     => 'option',
             'update'    => 'text',
             'search'    => 'fulltext',
-            'list'      => true,
+            'list'      => 'Dever::load("journal/lib/manage.getName", {id})',
         ),
 
         'price'     => array
@@ -73,6 +73,7 @@ return array
             'desc'      => '购买时的标价',
             'match'     => 'option',
             'update'    => 'text',
+            'list'      => 'Dever::load("journal/lib/manage.getPrice", {id})',
         ),
 
         'cash'      => array

+ 22 - 0
journal/lib/Manage.php

@@ -265,4 +265,26 @@ class Manage
             Dever::db('journal/content')->update($update);
         }
     }
+
+    public function getName($id)
+    {
+        $info = Dever::db('journal/buy_num')->one($id);
+        if ($info && $info['name']) {
+            return $info['name'];
+        } else {
+            return '购买' . $info['num'] . '本';
+        }
+    }
+
+    public function getPrice($id)
+    {
+        $info = Dever::db('journal/buy_num')->one($id);
+
+        $journal = Dever::db('journal/info')->one($info['info_id']);
+        if ($info && $info['price']) {
+            return $info['price'];
+        } else {
+            return $info['num'] * $journal['cash'] . '元';
+        }
+    }
 }

+ 1 - 1
journal/lib/Pay.php

@@ -31,7 +31,7 @@ class Pay
                 Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 2));
 
                 # 订阅
-                Dever::load('act/lib/subscribe')->submit($uid, $product_id, 1);
+                Dever::load('act/lib/subscribe')->submit($uid, $order['product_id'], 1);
 
                 $score = false;
                 $num = false;

+ 5 - 0
main/src/View.php

@@ -98,6 +98,11 @@ class View extends Core
             } else {
                 $this->data['user_act']['note'] = 2;
             }
+
+            if (isset($this->data['info']['statue']) && $this->data['info']['statue'] == 2) {
+                # 直播中
+                Dever::load('act/lib/watch')->submit($this->data['uid'], $id, $type);
+            }
         }