dever 6 years ago
parent
commit
bf2f9b417f

+ 17 - 1
act/lib/Subscribe.php

@@ -6,8 +6,24 @@ use Dever;
 
 class Subscribe
 {
+    # 获取小刊是否被人订阅
+    public function get($id, $uid, $type = 4)
+    {
+        $where['uid'] = $uid;
+        $where['type'] = $type;
+        $where['data_id'] = $id;
+        $where['state'] = 1;
+        $data = Dever::db('act/subscribe')->one($where);
+
+        if ($data) {
+            return 1;
+        } else {
+            return 2;
+        }
+    }
+    
     # 获取小刊订阅列表
-    public function get($id, $type = 4)
+    public function getList($id, $type = 4)
     {
         $where['type'] = $type;
         $where['data_id'] = $id;

+ 8 - 2
content/database/article.php

@@ -378,6 +378,12 @@ return array
 			'desc' 		=> '请输入内容',
 			'match' 	=> 'is_string',
 			'update'	=> 'editor',
+			'key'		=> '1',
+			//'media'		=> '5',//下面的音视频已经做到了
+			//直接上传到云端
+			//'upload'	=> 'qiniu',
+			//上传大数据
+			//'large' 	=> true,
 			//自定义编辑器右侧按钮
 			'editor'	=> array
 			(
@@ -395,8 +401,8 @@ return array
 					),
 					array
 					(
-						'name' => '音频',
-						'key' => 2,
+						'name' => '音频',
+						'key' => 5,
 						'type' => 'media',
 					),
 					array

+ 7 - 0
content/lib/Article.php

@@ -17,6 +17,13 @@ class Article
             Dever::alert('错误的文章信息');
         }
     
+        $data = $this->getContent($data);
+
+        return $data;
+    }
+
+    public function getContent($data)
+    {
         //embed
         $data['content_array'] = array();
 

+ 172 - 3
doc/apidoc.php

@@ -33,7 +33,7 @@
  * @apiDescription 类型设置说明
  *
  * @apiParam {String} source_type 请在header中定义,ios:ios | android:android | 移动h5:h5  | 小程序:applet | 公众号:service | pc网站:pc
- * @apiParam {Number} type 图文:1 | 视频:2 | 直播:3 | 小刊:4 | 音频:5 | 链接:10 | 评论: 11
+ * @apiParam {Number} type 图文:1 | 视频:2 | 直播:3 | 小刊:4 | 音频:5 | 链接:10 | 评论: 11
  * @apiParam {Number} push_ 所有带push_开头的返回参数,返回字典都是一样的,参考获取首页数据中的push_focus
  */
 
@@ -404,7 +404,7 @@
  * @apiSuccess {String}   info.share_content 分享内容
  * @apiSuccess {String}   info.function 开启的功能,这是一个字符串,用逗号隔开的,1代表显示浏览量,2代表显示评论,3代表显示喜欢,如值为1,2,则显示浏览量、评论,不显示喜欢
  * @apiSuccess {String}   info.content 内容
- * @apiSuccess {String}   info.content_array 数组内容,请使用该字段循环,type为类型,请参考类型设置说明,content为内容,type为1时为图文内容,type为2时content为视频详情的字段,type为3时content为直播详情的字段,type为5时content为音频地址
+ * @apiSuccess {String}   info.content_array 数组内容,请使用该字段循环,type为类型,请参考类型设置说明,content为内容,type为1时为图文内容,type为2时content为视频详情的字段,type为3时content为直播详情的字段,type为5时content为音频或者视频地址
  *
  * @apiSuccess {Object[]} comment 评论列表
  * @apiSuccess {String}   comment.id 
@@ -624,7 +624,7 @@
  * @apiSuccess {String}   journal.subname 期号
  * @apiSuccess {String}   journal.pic_cover 列表封面图片 暂时无效
  * @apiSuccess {String}   journal.pic_view_cover 小刊封面图片 封面图都用这个
- * @apiSuccess {String}   journal.pic_view_bg 全屏背景图-进入小刊阅读页之前的全屏背景图,可以多张切换,多个用逗号隔开,请用逗号截取成数组
+ * @apiSuccess {String}   journal.pic_view_bg 全屏背景图,多张图片,这是一个数组
  * @apiSuccess {String}   journal.pdate 时间
  * @apiSuccess {String}   journal.num_ding 订阅数
  * @apiSuccess {String}   journal.num_view 浏览量
@@ -646,7 +646,176 @@
   * @apiSuccess {Number} push_jingxuan_more 是否显示更多按钮1显示2不显示
  */
 
+/**
+ * @api {get} wonderful/main/?l=journal.read 小刊阅读页
+ * @apiVersion 1.0.0
+ * @apiName journal.read
+ * @apiGroup Journal
+ *
+ * @apiDescription 小刊阅读页
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {Number} id 小刊id
+ *
+ * @apiSuccess {Object[]} content 内容数据列表,每页显示10条,请在翻到第7或者第8条时,请求第2
+ * @apiSuccess {String}   content.id 内容id
+ * @apiSuccess {String}   content.type 内容类型1全屏图、2长图、3图文内容、11关联图文、12关联视频、13关联直播
+ * @apiSuccess {String}   content.pic 全屏图或者长图,type=1,2时有效
+ * @apiSuccess {String}   content.is_button 全屏图上的保存按钮,1显示2不显示,type=1时有效
+ * @apiSuccess {String}   content.button_name 全屏图上的保存按钮的文字,type=1时有效
+ * @apiSuccess {String}   content.button_color 全屏图上的保存按钮的文字颜色,type=1时有效
+ * @apiSuccess {Object[]}   content.text 全屏图上的九个文字位置,type=1时有效
+ * @apiSuccess {String}   content.text.text 文字位置,1上左2上中3上右4中左5正中6中右7下左8下中9下右
+ * @apiSuccess {String}   content.text.name 文字内容 换行用\n隔开
+ * @apiSuccess {String}   content.text.color 文字颜色
+ * @apiSuccess {String}   content.text.bgcolor 文字背景颜色
+ * @apiSuccess {String}   content.text.size 文字像素大小
+ * @apiSuccess {Object[]}   content.info type=3,11,12,13时有效,当等于11,12,13时,分别对应图文详情、视频详情、直播详情里的字段,等于3时,请查看以下字段
+ * @apiSuccess {String}   content.info.name 标题
+ * @apiSuccess {String}   content.info.focus 焦点图
+ * @apiSuccess {String}   content.info.content 内容
+ * @apiSuccess {String}   content.info.content_array 数组内容
+ * @apiSuccess {Object[]}   content.info.author 作者
+ */
+
+/**
+ * @api {get} wonderful/main/?l=journal.view 小刊详情页
+ * @apiVersion 1.0.0
+ * @apiName journal.view
+ * @apiGroup Journal
+ *
+ * @apiDescription 小刊详情页
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {Number} id 小刊id
+ *
+ * @apiSuccess {Object[]} info 小刊详情
+ * @apiSuccess {String}   info.id 小刊id
+ * @apiSuccess {String}   info.name 名称
+ * @apiSuccess {String}   journal.subname 期号
+ * @apiSuccess {String}   info.pic_cover 列表封面图片 暂时无效
+ * @apiSuccess {String}   info.pic_view_cover 小刊封面图片 封面图都用这个
+ * @apiSuccess {String}   info.pic_view_bg 全屏背景图,多张图片,这是一个数组
+ * @apiSuccess {String}   info.pdate 时间
+ * @apiSuccess {String}   info.num_ding 订阅数
+ * @apiSuccess {String}   info.num_view 浏览量
+ * @apiSuccess {String}   info.num_comment 评论量
+ * @apiSuccess {String}   info.buy 小刊是否收费 1收费 2不收费
+ * @apiSuccess {String}   info.subscribe 是否订阅,1为已订阅2为未订阅
+ * @apiSuccess {String}   info.active 是否有活动,1为有2为没有,有则显示分享邀请按钮
+
+ * @apiSuccess {Object[]}   button 按钮判断 如果不需要这个,可以不用
+ * @apiSuccess {Object[]}   button.read 第一个按钮 一般为购买按钮
+ * @apiSuccess {String}   button.read.status 状态 -1不显示 1为进入阅读 2为购买
+ * @apiSuccess {String}   button.read.name 按钮上的名字
+ * @apiSuccess {Object[]}   button.code 第二个按钮 一般为兑换码按钮
+ * @apiSuccess {String}   button.code.status 状态 -1不显示 1为兑换码兑换 2为购买(再次购买)
+ * @apiSuccess {String}   button.code.name 按钮上的名字
+ * @apiSuccess {Object[]}   button.share 第三个按钮 一般为分享邀请按钮
+ * @apiSuccess {String}   button.share.status 状态 -1不显示 1为免费阅读赢取大礼包
+ * @apiSuccess {String}   button.share.name 按钮上的名字
+ */
+
+/**
+ * @api {get} wonderful/main/?l=journal.active 小刊活动页
+ * @apiVersion 1.0.0
+ * @apiName journal.active
+ * @apiGroup Journal
+ *
+ * @apiDescription 小刊活动页
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {Number} id 小刊id
+ *
+ * @apiSuccess {Object[]} info 小刊详情
+ * @apiSuccess {String}   info.id 小刊id
+ * @apiSuccess {String}   info.name 名称
+ *
+ * @apiSuccess {Object[]}   active 活动说明表
+ * @apiSuccess {String}   active.name 名称
+ * @apiSuccess {String}   active.desc 描述
+ * @apiSuccess {String}   active.buy_title 购买标题
+ * @apiSuccess {String}   active.buy_desc 购买描述
+ * @apiSuccess {String}   active.invite_title 邀请好友标题
+ * @apiSuccess {String}   active.invite_desc 邀请好友描述 换行用\n隔开
+ * @apiSuccess {String}   active.content 活动说明,富文本
+ */
+
+/**
+ * @api {get} wonderful/main/?l=journal.buy 小刊购买页
+ * @apiVersion 1.0.0
+ * @apiName journal.buy
+ * @apiGroup Journal
+ *
+ * @apiDescription 小刊购买页
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {Number} id 小刊id
+ *
+ * @apiSuccess {Object[]} info 小刊详情
+ * @apiSuccess {String}   info.id 小刊id
+ * @apiSuccess {String}   info.name 名称
+ *
+ * @apiSuccess {String} buy_desc 购买说明
+ * @apiSuccess {Object[]}   buy_list 购买列表
+ * @apiSuccess {String}   buy_list.id 购买id 支付时使用
+ * @apiSuccess {String}   buy_list.name 名称
+ * @apiSuccess {String}   buy_list.price 标价
+ * @apiSuccess {String}   buy_list.cash 实际支付价格
+ */
+
+/**
+ * @api {get} wonderful/main/?l=journal.buy_action 发起微信支付
+ * @apiVersion 1.0.0
+ * @apiName journal.buy_action
+ * @apiGroup Journal
+ *
+ * @apiDescription 发起微信支付
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {String} journal_id 小刊id
+ * @apiParam {String} buy_id 购买本数id
+ * @apiParam {String} source_signature 分享人的signature,scene参数中的source_signature
+*
+ * @apiSuccess {Object[]} pay 微信支付返回的数据
+ * @apiSuccess {String}   pay.time 服务器时间戳
+ * @apiSuccess {String}   pay.nonce_str 随机字符串
+ * @apiSuccess {String}   pay.prepay_id 统一下单接口返回的 prepay_id 参数值,通过'prepay_id=' + prepay_id 拼装成package
+ * @apiSuccess {String}   pay.sign_type 签名算法
+ * @apiSuccess {String}   pay.sign 签名
+ */
 
+/**
+ * @api {get} wonderful/main/?l=journal.code 提交兑换码
+ * @apiVersion 1.0.0
+ * @apiName journal.code
+ * @apiGroup Journal
+
+ * @apiDescription 提交兑换码
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {String} journal_id 小刊id
+ * @apiParam {String} code 兑换码
+ * @apiParam {String} source_signature 分享人的signature,scene参数中的source_signature
+ *
+ * @apiSuccess {String}   order_id 兑换成功则返回订单id
+ */
+
+/**
+ * @api {get} wonderful/main/?l=journal.checkCode 验证兑换码是否有效
+ * @apiVersion 1.0.0
+ * @apiName journal.checkCode
+ * @apiGroup Journal
+ *
+ * @apiDescription 验证兑换码是否有效
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {String} code 兑换码
+
+ * @apiSuccess {Object[]} product 小刊信息
+ * @apiSuccess {String}   product.id 小刊id
+ * @apiSuccess {String}   product.name 小刊名称
+ */
 
 /**
  * @api {get} wonderful/main/?l=user.my 获取用户信息

+ 9 - 1
live/config/base.php

@@ -8,6 +8,14 @@ $config['base'] = array
 	),
 
 	# 对应的视频表,必须有stream_id、sdate、edate、url_m3u8、url_mp4五个字段
-	'video' => 'video/live',
+	'video' => array
+	(
+		'table' => 'video/live',
+		'stream_id' => 'stream_id',
+		'sdate' => 'sdate',
+		'edate' => 'edate',
+		'url_m3u8' => 'url_m3u8',
+		'url_mp4' => 'url_mp4',
+	)
 );
 return $config;

+ 5 - 5
live/lib/Cron.php

@@ -33,18 +33,18 @@ class Cron
     # 定时获取 所有的直播视频的回放地址
     public function getUrl()
     {
-        $table = Dever::config('base', 'live')->video;
-        $data = Dever::db($table)->state();
+        $video = Dever::config('base', 'live')->video;
+        $data = Dever::db($video['table'])->state();
 
         if ($data) {
             $time = time();
             foreach ($data as $k => $v) {
-                if ($v['stream_id'] > 0 && !$v['url_m3u8'] && $v['sdate'] > 0 && $v['edate'] > 0 && $time >= $v['edate']) {
-                    $info = Dever::db('live/stream')->one($v['stream_id']);
+                if ($v[$video['stream_id']] > 0 && !$v[$video['url_m3u8']] && $v[$video['sdate']] > 0 && $v[$video['edate']] > 0 && $time >= $v[$video['edate']]) {
+                    $info = Dever::db('live/stream')->one($v[$video['stream_id']]);
                     $config = Dever::db('live/info')->one($info['live_id']);
                     $handle = new Handle();
                     $method = $handle->method($config);
-                    $handle->createUrlOne($v, $table, $method, $config, $info);
+                    $handle->createUrlOne($v, $video['table'], $method, $config, $info);
                 }
             }
         }

+ 19 - 14
live/lib/Handle.php

@@ -50,7 +50,7 @@ class Handle
     }
 
     # 建立ios直播日志
-    public function saveIosLog($id, $log_id = false, $table = false)
+    public function saveIosLog($id, $log_id = false, $video = false)
     {
         $info = Dever::db('live/stream')->one($id);
 
@@ -83,8 +83,8 @@ class Handle
             Dever::db('live/stream_ios_log')->update($data);
             $id = $log_id;
 
-            if ($table) {
-                $this->createUrl($table, $method, $config, $info);
+            if ($video) {
+                $this->createUrl($video, $method, $config, $info);
             }
         }
         
@@ -92,36 +92,41 @@ class Handle
     }
 
     # 生成回放地址
-    public function createUrl($table, $method, $config, $info)
+    public function createUrl($video, $method, $config, $info)
     {
-        $data = Dever::db($table)->state(array('stream_id' => $info['id']));
+        $where[$video['stream_id']] = $info['id'];
+        $data = Dever::db($video['table'])->state($where);
         if ($data) {
             foreach ($data as $k => $v) {
-                $this->createUrlOne($v, $table, $method, $config, $info);
+                $this->createUrlOne($v, $video, $method, $config, $info);
             }
         }
     }
 
-    public function createUrlOne($data, $table, $method, $config, $info)
+    public function createUrlOne($data, $video, $method, $config, $info)
     {
-        if (!$data['url_m3u8'] && $data['sdate'] > 0 && $data['edate'] > 0) {
+        if (!$data[$video['url_m3u8']] && $data[$video['sdate']] > 0 && $data[$video['edate']] > 0) {
 
-            $data['sdate'] = intval($data['sdate']);
-            $data['edate'] = intval($data['edate']);
+            $data[$video['sdate']] = intval($data[$video['sdate']]);
+            $data[$video['edate']] = intval($data[$video['edate']]);
 
             try {
-                $url_m3u8 = $config['host'] . $method->save($info['key'],$data['sdate'], $data['edate']);
-                $url_mp4 = $config['host'] . $method->save($info['key'], $data['sdate'], $data['edate'], 'mp4');
+                $url_m3u8 = $config['host'] . $method->save($info['key'],$data[$video['sdate']], $data[$video['edate']]);
+                $url_mp4 = $config['host'] . $method->save($info['key'], $data[$video['sdate']], $data[$video['edate']], 'mp4');
             } catch (\Exception $e) {
                 $url_m3u8 = $url_mp4 = '';
             }
 
             if (!$url_m3u8) {
-                return;
+                return false;
             }
 
-            Dever::db($table)->update(array('where_id' => $data['id'], 'url_m3u8' => $url_m3u8, 'url_mp4' => $url_mp4));
+            Dever::db($video['table'])->update(array('where_id' => $data['id'], $data[$video['url_m3u8']] => $url_m3u8, $data[$video['url_mp4']] => $url_mp4));
+
+            return array('id' => $data['id'], 'm3u8' => $url_m3u8, 'mp4' => $url_mp4);
         }
+
+        return false;
     }
 
     # 开始直播

+ 2 - 2
live/src/Api.php

@@ -90,8 +90,8 @@ class Api
         	Dever::alert('错误的id');
         }
         $handle = new Handle();
-        $table = Dever::config('base', 'live')->video;
-        $handle->saveIosLog($id, $log_id, $table);
+        $video = Dever::config('base', 'live')->video;
+        $handle->saveIosLog($id, $log_id, $video);
 
         # 获取这个流对应的直播信息
         

+ 31 - 0
main/lib/Core.php

@@ -16,6 +16,9 @@ class Core
         } else {
             $this->data['uid'] = Dever::load('passport/applet')->check(false);
         }
+        if ($this->data['uid'] < 0) {
+            $this->data['uid'] = 0;
+        }
         //$this->data['uid'] = 1;
 
         # 获取基本配置
@@ -90,6 +93,34 @@ class Core
         return $info;
     }
 
+    protected function getSourceUid($error = true)
+    {
+        $source_signature = Dever::input('source_signature');
+
+        if (!$source_signature) {
+            if (!$error) {
+                return false;
+            }
+            Dever::alert('错误的来源uid');
+        }
+        $user = Dever::loginResult($source_signature, false);
+        if (!isset($user['uid'])) {
+            if (!$error) {
+                return false;
+            }
+            //Dever::alert('错误的来源uid');
+        }
+
+        //$source_uid = $user['uid'];
+        $source_uid = 1;
+
+        if ($this->data['uid'] == $source_uid) {
+            return false;
+        }
+
+        return $source_uid;
+    }
+
     protected function log()
     {
         $input = Dever::json_encode(Dever::input());

+ 443 - 6
main/src/Journal.php

@@ -29,17 +29,25 @@ class Journal extends Core
     }
 
     # 获取详细信息
-    private function info($data)
+    private function info($data, $subscribe = true)
     {
         if ($data['pdate'] > 0) {
             $data['pdate_time'] = date('Y-m-d H:i:s', $data['pdate']);
         }
 
+        if ($data['pic_view_bg']) {
+            $data['pic_view_bg'] = explode(',', $data['pic_view_bg']);
+        }
+
+        $data['buy'] = intval($data['buy']);
+
         # 获取订阅列表
-        $data['subscribe'] = Dever::load('act/lib/subscribe')->get($data['id'], 4);
+        if ($subscribe) {
+            $data['subscribe'] = Dever::load('act/lib/subscribe')->getList($data['id'], 4);
 
-        if (!$data['subscribe']) {
-            $data['subscribe'] = (object) array();
+            if (!$data['subscribe']) {
+                $data['subscribe'] = (object) array();
+            }
         }
 
         return $data;
@@ -77,15 +85,444 @@ class Journal extends Core
     # 小刊查看详情
     public function view()
     {
-        # 三个按钮的判断
+        $id = $this->check();
+        $this->data['info'] = $this->info($this->data['info'], false);
+        $this->button($this->data['info']);
+
+        return $this->data;
+    }
+
+    # 按钮设置
+    private function button($info)
+    {
+        $this->data['button'] = array();
+        $this->setButton();
+
+        $uid = $this->data['uid'];
+
+        # 查看是否订阅
+        $subscribe = Dever::load('act/lib/subscribe')->get($info['id'], $uid, 4);
+        $this->data['info']['subscribe'] = 2;
+
+        # 查看是否有活动
+        $active = Dever::db('journal/active')->one(array('info_id' => $info['id']));
+        $this->data['info']['active'] = 2;
+        if ($active && $active['status'] == 1) {
+            $this->data['info']['active'] = 1;
+        }
+
+        if ($this->data['info']['active'] == 1) {
+            $this->setButton('share', 1);
+        } else {
+            $this->setButton('share', -1);
+        }
+
+        if ($subscribe == 1) {
+            $this->data['info']['subscribe'] = 1;
+            # 已订阅
+            $this->setButton('read', 1, '开始阅读');
+            $this->setButton('code', 2, '再次购买');
+        } elseif ($info['buy'] == 1) {
+            # 需要购买
+            $this->setButton('read', 2, '购买阅读');
+            $this->setButton('code', 1, '兑换码阅读');
+        } elseif ($info['buy'] == 2) {
+            # 免费的
+            $this->setButton('read', 1, '开始阅读');
+            $this->setButton('code', -1);
+            $this->setButton('share', -1);
+        }
+    }
+
+    private function setButton($key = false, $status = false, $name = false)
+    {
+        # 按钮状态,-1为不显示
+        if (!$this->data['button']) {
+            $this->data['button'] = array
+            (
+                # 第一个按钮
+                'read' => array('status' => -1, 'name' => '购买阅读'),
+                # 第二个按钮
+                'code' => array('status' => -1, 'name' => '兑换码阅读'),
+                # 第三个按钮
+                'share' => array('status' => 1, 'name' => '免费阅读赢取大礼包'),
+            );
+        }
+
+        if ($key && isset($this->data['button'][$key])) {
+            if ($status) {
+                $this->data['button'][$key]['status'] = $status;
+            }
+            if ($name) {
+                $this->data['button'][$key]['name'] = $name;
+            }
+        }
+    }
+
+    # 购买阅读页
+    public function buy()
+    {
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+        $id = $this->check();
+
+        # 获取购买说明
+        $buy = Dever::db('journal/buy')->one(array('info_id' => $id));
+
+        $this->data['buy_desc'] = '';
+        if ($buy) {
+            $this->data['buy_desc'] = $buy['buy_content'];
+        }
+
+        # 获取购买列表
+        $this->data['buy_list'] = Dever::db('journal/buy_num')->getAll(array('info_id' => $id));
+
+        return $this->data;
+    }
+
+    # 小刊邀请活动页
+    public function active()
+    {
+        $id = $this->check();
+
+        # 获取购买说明
+        $buy = Dever::db('journal/buy')->one(array('info_id' => $id));
+
+        # 获取活动说明
+        $this->data['active'] = Dever::db('journal/active')->one(array('info_id' => $id));
+
+        $this->data['active']['buy_title'] = '';
+        $this->data['active']['buy_desc'] = '';
+        if ($buy) {
+            $this->data['active']['buy_title'] = $buy['buy_title'];
+            $this->data['active']['buy_desc'] = $buy['buy_desc'];
+        }
+
+        # 获取我邀请的好友
+
+
+        return $this->data;
+    }
+
+    # 积分排行榜
+    public function score()
+    {
+
+    }
+
+    # 邀请好友排行榜
+    public function invite()
+    {
 
-        
     }
 
 
     # 小刊阅读页
     public function read()
     {
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+        # 验证是否可以阅读
+        $id = $this->check();
+
+        $subscribe = Dever::load('act/lib/subscribe')->get($id, $this->data['uid'], 4);
+
+        if ($this->data['info']['buy'] == 1 && $subscribe == 2) {
+            //Dever::alert('未订阅');
+        }
+
+        # 获取最新10条内容
+        $where = array();
+        $where['info_id'] = $id;
+        $data = Dever::db('journal/content')->getAll($where);
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $data[$k] = $this->readContent($v);
+            }
+            $this->data['content'] = $data;
+        } else {
+            $this->data['content'] = (object) array();
+        }
+
+        return $this->data;
+    }
+
+    private function readContent($info)
+    {
+        $name = $info['name'];
+        $focus = $info['focus'];
+        $author_id = $info['author_id'];
+        $content = $info['content'];
+        unset($info['name']);
+        unset($info['focus']);
+        unset($info['author_id']);
+        unset($info['content']);
+
+        if ($info['type'] == 1 && $info['text']) {
+            $info['text'] = Dever::array_decode($info['text']);
+        } else {
+            unset($info['text']);
+        }
+
+        if ($info['type'] == 3) {
+            $info['info'] = array();
+            $info['info']['name'] = $name;
+            $info['info']['focus'] = $focus;
+            $info['info']['author_id'] = $author_id;
+            $info['info']['content'] = $content;
+            $info['info'] = Dever::load('content/lib/article')->getContent($info['info']);
+        } elseif ($info['type'] == 11) {
+            $info['info'] = Dever::load('content/lib/article')->get($info['article_id']);
+        } elseif ($info['type'] == 12) {
+            $info['info'] = Dever::load('video/lib/vod')->get($info['vod_id']);
+        } elseif ($info['type'] == 13) {
+            $info['info'] = Dever::load('video/lib/live')->get($info['live_id']);
+        }
+
+        if (isset($info['info']['author_id']) && $info['info']['author_id']) {
+            $info['info']['author'] = Dever::db('content/author')->one($info['info']['author_id']);
+        }
+
+        return $info;
+    }
+
+    private function check()
+    {
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::alert('小刊已下架');
+        }
+
+        $where['id'] = $id;
+        $this->data['info'] = Dever::db('journal/info')->one($where);
+
+        if (!$this->data['info']) {
+            Dever::alert('小刊已下架');
+        }
+
+        return $id;
+    }
+
+
+    # 海报
+    public function poster() 
+    {
+        $id = Dever::input('product_id');
+        $template = Dever::input('template', 'share');
+        $path = Dever::input('path', 'template/home/index');
+        $info = Dever::db('product/info')->one($id);
+        $scene = $this->data['uid'] . ',' . $id;
+
+        $send['project'] = Dever::input('project', 1);
+        $send['send'] = $scene;
+        $send['width'] = 152;
+        $send['path'] = $path;
+        $logo = Dever::load('wechat_applet/code.get', $send);
+
+        $model = array
+        (
+            //'pic' => Dever::local($info['pic']),
+            //'name' => $info['name'],
+            'logo' => Dever::local(str_replace('https', 'http', $logo)),
+        );
+        $template = $info['share'];
+        $img = Dever::load('poster/api')->get($scene, $template, $model);
+        return $img;
+    }
+
+    # 购买
+    public function buy_action()
+    {
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+        $source_uid = $this->getSourceUid(false);
+        $buy_id = Dever::input('buy_id');
+        $journal_id = Dever::input('journal_id');
+
+        if (!$buy_id) {
+            Dever::alert('请传入正确的支付ID');
+        }
+        if (!$journal_id) {
+            Dever::alert('请传入正确的小刊ID');
+        }
+
+        $info = Dever::db('journal/info')->one($journal_id);
+        $buy = Dever::db('journal/buy_num')->one($buy_id);
+
+        if (!$buy || !$info) {
+            Dever::alert('请传入正确的小刊ID');
+        }
+
+        $user = Dever::db('passport/user')->one($this->data['uid']);
+        $wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid']));
+
+        $order_id = $this->createOrder('JP');
+        $order_data['order_id'] = $order_id;
+        $order_data['product_id'] = $journal_id;
+        $order_data['buy_id'] = $buy_id;
+        $order_data['uid'] = $this->data['uid'];
+        if ($source_uid > 0) {
+            $order_data['source_uid'] = $source_uid;
+        }
+        
+        $order_data['type'] = 1;
+        $order_data['status'] = 1;
+        $order_data['name'] = $info['name'] . '-' . $buy['name'];
+        $order_data['num'] = Dever::input('num', 1);
+        $order_data['cash'] = $buy['cash'] * $order_data['num'];
+
+        $id = Dever::db('product/order')->insert($order_data);
+
+        if (!$id) {
+            Dever::alert('支付失败');
+        }
+
+        //$param参数
+        $param = array
+        (
+            'account_id' => 1,
+            'uid' => $this->data['uid'],
+            'username' => $user['username'],
+            'name' => $order_data['name'],
+            'cash' => $order_data['cash'],
+            'cash' => '0.01',
+            'openid' => $wechat['openid'],
+            'product_id' => $journal_id . '-' . $buy_id,
+            'order_id' => $order_id,
+        );
+
+        $this->data['pay'] = Dever::load('pay/api')->applet($param);
+
+        if (isset($this->data['pay']['prepay_id'])) {
+            Dever::setInput('form_id', $this->data['pay']['prepay_id']);
+            //$this->writeFormId();
+        } else {
+            Dever::alert('支付失败');
+        }
+
+        return $this->data;
+    }
+
+    # 根据code检索是否存在
+    public function checkCode()
+    {
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+        $code = Dever::input('code');
+
+        if ($code) {
+
+            $info = Dever::db('code/info')->one(array('code' => $code));
+
+            if (!$info) {
+                Dever::alert('兑换码不存在');
+            }
+
+            if ($info['type'] == 3) {
+                Dever::alert('兑换码已被使用');
+            }
+
+            if ($info['type'] == 2 && $this->data['uid'] != $info['uid']) {
+                //Dever::alert('兑换码已被领取');
+            }
+
+            $order = Dever::db('journal/order')->one(array('code' => $code));
+
+            if ($order) {
+                Dever::alert('兑换码已被使用');
+            }
+
+            if ($info['product_id']) {
+                $product = Dever::db('journal/info')->one($info['product_id']);
+                $this->data['product'] = $product;
+
+                return $this->data;
+            }
+
+        } else {
+            Dever::alert('请输入正确的兑换码');
+        }
+
+        return true;
+    }
+
+    # 兑换
+    public function code()
+    {
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+        $journal_id = Dever::input('journal_id', false, '> 0', '请传入正确的小刊id');
+
+        $code = Dever::input('code');
+
+        $source_uid = $this->getSourceUid(false);
+
+        if ($code) {
+
+            $product = Dever::db('journal/info')->one($journal_id);
+
+            $info = Dever::db('code/info')->one(array('product_id' => $journal_id, 'code' => $code));
+
+            if (!$info) {
+                Dever::alert('兑换码不存在');
+            }
+
+            if ($info['type'] == 3) {
+                Dever::alert('兑换码已被使用');
+            }
+
+            if ($info['type'] == 2 && $this->data['uid'] != $info['uid']) {
+                //Dever::alert('兑换码已被领取');
+            }
+
+            $order = Dever::db('journal/order')->one(array('product_id' => $journal_id, 'code' => $code, 'uid' => $this->data['uid']));
+
+            if ($order) {
+                Dever::alert('您已经使用过该兑换码');
+            }
+
+            Dever::db('code/info')->update(array('where_id' => $info['id'], 'type' => 3, 'uid' => $this->data['uid'], 'ldate' => time()));
+
+            $order_id = $this->createOrder('JC');
+
+            $order_data['order_id'] = $order_id;
+            $order_data['product_id'] = $journal_id;
+            $order_data['uid'] = $this->data['uid'];
+            $order_data['code'] = $code;
+            if ($source_uid > 0) {
+                $order_data['source_uid'] = $source_uid;
+            }
+            
+            $order_data['type'] = 2;
+            $order_data['status'] = 2;
+            $order_data['name'] = $product['name'];
+
+            $id = Dever::db('journal/order')->insert($order_data);
+
+            # 订阅
+
+        } else {
+            Dever::alert('请输入正确的兑换码');
+        }
+
+        return array('order_id' => $order_id);
+    }
+
+    private function createOrder($prefix = 'JC')
+    {
+        $order = Dever::order($prefix);
+
+        $info = Dever::db('journal/order')->one(array('order_id' => $order));
+
+        if ($info) {
+            return $this->createOrder();
+        }
 
+        return $order;
     }
 }

+ 1 - 12
main/src/User.php

@@ -115,18 +115,7 @@ class User extends Core
     # 回流
     public function submit_share_reflux()
     {
-        $source_signature = Dever::input('source_signature');
-
-        if (!$source_signature) {
-            Dever::alert('错误的来源uid');
-        }
-        $user = Dever::loginResult($source_signature, false);
-        if (!isset($user['uid'])) {
-            //Dever::alert('错误的来源uid');
-        }
-
-        $source_uid = $user['uid'];
-        $source_uid = 1;
+        $source_uid = $this->getSourceUid();
 
         $id = Dever::input('id');
         if (!$id) {