dever 6 years ago
parent
commit
b8e00a4fdd
4 changed files with 176 additions and 24 deletions
  1. 137 0
      live/database/active.php
  2. 25 16
      live/database/stream.php
  3. 7 4
      live/lib/Manage.php
  4. 7 4
      main/src/Live.php

+ 137 - 0
live/database/active.php

@@ -0,0 +1,137 @@
+<?php
+$live = function()
+{
+    $array = array();
+    $info = Dever::db('live/info')->state();
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+$type = Dever::config('base', 'live')->live_type;
+
+$status = Dever::config('base')->status;
+
+return array
+(
+    # 表名
+    'name' => 'active',
+    # 显示给用户看的名称
+    'lang' => '直播活动',
+    'order' => 20,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'        => true,
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '活动名称',
+            'default'   => '',
+            'desc'      => '活动名称',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'live_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属直播云',
+            'default'   => '1',
+            'desc'      => '所属直播云',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $live,
+            'search'    => 'select',
+            'list'      => true,
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '上线状态',
+            'default'   => '2',
+            'desc'      => '上线状态',
+            'match'     => 'is_numeric',
+            //'update'  => 'select',
+            'option'    => $status,
+            'search'    => 'select',
+            'list'      => true,
+            'edit'      => true,
+        ),
+
+        'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'search'	=> 'order',
+			'list'		=> true,
+			'order'		=> 'desc',
+			'edit'		=> true,
+		),
+
+        '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
+    (
+        //'excel'   => true,
+        //'delete' => false,
+        //'edit' => false,
+        //'insert' => false,
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'status' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'col' => 'id,name,live_id',
+        ),
+    )
+
+);

+ 25 - 16
live/database/stream.php

@@ -11,6 +11,17 @@ $live = function()
     return $array;
 };
 
+$active = function()
+{
+    $array = array();
+    $info = Dever::db('live/active')->state();
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
 $status = array
 (
     1 => '未开始',
@@ -18,8 +29,6 @@ $status = array
     3 => '已结束',
 );
 
-$yes = Dever::config('base')->status;
-
 $disabled = array
 (
     1 => '启动',
@@ -68,6 +77,19 @@ return array
             //'list'      => true,
         ),
 
+        'active_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属活动',
+            'default'   => '1',
+            'desc'      => '所属活动',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $active,
+            'search'    => 'select',
+            'list'      => true,
+        ),
+
         'name'      => array
         (
             'type'      => 'varchar-300',
@@ -199,20 +221,6 @@ return array
             'edit'      => true,
         ),
 
-        'online'        => array
-        (
-            'type'      => 'int-11',
-            'name'      => '上线状态',
-            'default'   => '2',
-            'desc'      => '上线状态',
-            'match'     => 'is_numeric',
-            //'update'  => 'select',
-            'option'    => $yes,
-            'search'    => 'select',
-            'list'      => true,
-            'edit'      => true,
-        ),
-
         'state'     => array
         (
             'type'      => 'tinyint-1',
@@ -259,6 +267,7 @@ return array
                 'status' => 'yes',
                 'online' => 'yes',
                 'key' => 'yes',
+                'state' => 1,
             ),
             'type' => 'all',
             'order' => array('id' => 'desc'),

+ 7 - 4
live/lib/Manage.php

@@ -9,12 +9,13 @@ class Manage
 	public function getStream_api()
     {
         $handle = new Handle();
-    	$info = Dever::db('live/info')->state();
+    	$info = Dever::db('live/active')->state();
         foreach ($info as $k => $v) {
-            $data = $handle->method($v)->gets();
+            $live = Dever::db('live/info')->one($v['live_id']);
+            $data = $handle->method($live)->gets();
             if (isset($data['keys']) && $data['keys']) {
                 foreach ($data['keys'] as $k1 => $v1) {
-                    $this->insertStream($v1);
+                    $this->insertStream($v1, $live['id'], $v['id']);
                 }
             }
         }
@@ -22,13 +23,15 @@ class Manage
         return 'yes';
     }
 
-    private function insertStream($name)
+    private function insertStream($name, $live_id, $active_id)
     {
         $data['key'] = $name;
         $info = Dever::db('live/stream')->one($data);
 
         if (!$info) {
             $data['name'] = $name;
+            $data['active_id'] = $active_id;
+            $data['live_id'] = $live_id;
             $id = Dever::db('live/stream')->insert($data);
         } else {
             $id = $info['id'];

+ 7 - 4
main/src/Live.php

@@ -13,13 +13,16 @@ class Live
         if ($signature != md5('signature_dever_2018_jm')) {
             Dever::alert('signature error');
         }
-        $key = Dever::input('key');
-        $data = Dever::db('live/stream')->getAll(array('online' => 2));
+
+        $data = Dever::db('live/active')->getAll(array('status' => 2));
 
         if ($data) {
-            return array('live' => $data);
+            foreach ($data as $k => $v) {
+                $data[$k]['stream'] = Dever::db('live/stream')->getAll();
+            }
+            return array('active' => $data);
         } else {
-            return array('live' => (object) array());
+            return array('active' => (object) array());
         }
     }
 }