|
@@ -0,0 +1,527 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Main\Src;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+use Main\Lib\Core;
|
|
|
+
|
|
|
+class Journal_v1 extends Core
|
|
|
+{
|
|
|
+ public function getCate()
|
|
|
+ {
|
|
|
+ $id = Dever::input('system', 1);
|
|
|
+
|
|
|
+ $cate = array();
|
|
|
+ if ($id > 0) {
|
|
|
+ $cate = Dever::db('journal/cate')->one($id);
|
|
|
+ $this->data['cate'] = $cate;
|
|
|
+ }
|
|
|
+
|
|
|
+ $cateList = Dever::db('journal/cate')->getAll();
|
|
|
+ $this->data['cateList'] = $cateList;
|
|
|
+
|
|
|
+ return $cate;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function getList()
|
|
|
+ {
|
|
|
+ $data = array();
|
|
|
+
|
|
|
+ if ($data) {
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ $cate = $this->getCate();
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+ $day = (7 * 86400);
|
|
|
+
|
|
|
+
|
|
|
+ $where = array();
|
|
|
+ if (isset($cate['id'])) {
|
|
|
+ $where['cate_id'] = $cate['id'];
|
|
|
+ }
|
|
|
+ if ($this->app) {
|
|
|
+ $where['cate_id_1'] = 1;
|
|
|
+ $where['time'] = $time - $day;
|
|
|
+
|
|
|
+
|
|
|
+ $this->data['push'] = Dever::db('journal/info')->getNew($where);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (isset($cate['journal_id'])) {
|
|
|
+ $this->data['push'] = Dever::db('journal/info')->getOne($cate['journal_id']);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $this->data['push'] = Dever::db('journal/info')->getNew();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $this->data['push'] = $this->ding($this->data['push']);
|
|
|
+
|
|
|
+
|
|
|
+ $data = Dever::db('journal/info')->getAllByPage($where);
|
|
|
+
|
|
|
+ if ($data) {
|
|
|
+ foreach ($data as $k => $v) {
|
|
|
+ $data[$k] = $this->info($v);
|
|
|
+ }
|
|
|
+ $this->data['journal'] = $data;
|
|
|
+ } else {
|
|
|
+ $this->data['journal'] = array();
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function ding($data)
|
|
|
+ {
|
|
|
+ $data = Dever::load('journal/api')->ding($data);
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private function info($data, $subscribe = true)
|
|
|
+ {
|
|
|
+ if ($data['pdate'] > 0) {
|
|
|
+ $data['pdate_time'] = date('Y-m-d H:i:s', $data['pdate']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $data['ytype'] = 1;
|
|
|
+ if (isset($data['ydate']) && $data['ydate'] > 0) {
|
|
|
+ if ($data['ydate'] <= time()) {
|
|
|
+
|
|
|
+ $data['ytype'] = 2;
|
|
|
+ }
|
|
|
+ $data['ydate_time'] = date('Y-m-d H:i:s', $data['ydate']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $this->ding($data);
|
|
|
+
|
|
|
+ if ($data['pic_view_bg']) {
|
|
|
+ $data['pic_view_bg'] = explode(',', $data['pic_view_bg']);
|
|
|
+ } else {
|
|
|
+ $data['pic_view_bg'] = array();
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['buy'] = intval($data['buy']);
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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('id' => $info['id']));
|
|
|
+ $this->data['info']['active'] = 2;
|
|
|
+ if ($active && $active['status'] == 1) {
|
|
|
+ $this->data['info']['active'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+ if ($active && $time >= $active['start'] && $time < $active['end']) {
|
|
|
+ $this->data['info']['active'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->data['info']['active'] == 1) {
|
|
|
+ $this->setButton('share', 1);
|
|
|
+ } else {
|
|
|
+ $this->setButton('share', -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($info['buy'] == 2) {
|
|
|
+
|
|
|
+ $this->setButton('read', 1);
|
|
|
+ $this->setButton('buy', -1);
|
|
|
+ $this->setButton('share', -1);
|
|
|
+ } elseif ($subscribe == 1) {
|
|
|
+ $this->data['info']['subscribe'] = 1;
|
|
|
+
|
|
|
+ $this->setButton('read', 1);
|
|
|
+ $this->setButton('buy', 1);
|
|
|
+
|
|
|
+ if (checkVersion()->journal_buy == 2) {
|
|
|
+ $this->setButton('share', -1);
|
|
|
+ }
|
|
|
+ } elseif ($info['buy'] == 1 || $info['buy'] == 3) {
|
|
|
+ if ($info['ytype'] == 2) {
|
|
|
+
|
|
|
+ $this->setButton('read', 3);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $this->setButton('read', 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->setButton('buy', 1);
|
|
|
+
|
|
|
+ if (checkVersion()->journal_buy == 2) {
|
|
|
+ $this->setButton('buy', -1);
|
|
|
+ $this->setButton('share', -1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($this->app) {
|
|
|
+
|
|
|
+ if (isset($this->data['info']['share_content'])) {
|
|
|
+ $source = Dever::db('source/info')->one(1);
|
|
|
+ $this->data['info']['share_link'] = $source['code'];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $this->data['info']['vip_state'] = 1;
|
|
|
+ $version_code = Dever::input('version_code');
|
|
|
+ if ($version_code) {
|
|
|
+ $source_type = Dever::input('source_type');
|
|
|
+ $version_where['source_type'] = $source_type;
|
|
|
+ $version_where['name'] = $version_code;
|
|
|
+ $version = Dever::db('main/version')->getOne($version_where);
|
|
|
+ if ($version && $version['vip'] > 0) {
|
|
|
+ $this->data['info']['vip_state'] = $version['vip'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $this->data['info']['vip'] = 2;
|
|
|
+ $vip = Dever::load('vip/lib/member')->get($uid, $info['cate_id']);
|
|
|
+ if ($vip > 0) {
|
|
|
+ $this->data['info']['subscribe'] = 1;
|
|
|
+ $this->data['info']['vip'] = 1;
|
|
|
+ $this->setButton('read', 1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $user = Dever::db('passport/user')->one($uid);
|
|
|
+ if ($user && $user['mobile']) {
|
|
|
+ $mobileWhere['mobile'] = $user['mobile'];
|
|
|
+ $mobileWhere['product_id'] = $info['id'];
|
|
|
+ $mobile = Dever::db('journal/mobile')->one($mobileWhere);
|
|
|
+ if ($mobile) {
|
|
|
+ $this->data['info']['subscribe'] = 1;
|
|
|
+ $this->setButton('read', 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ $applet_type = Dever::input('applet_type');
|
|
|
+ if ($applet_type == 2 && isset($this->data['config']['ios_pay']) && $this->data['config']['ios_pay'] == 1 && $info['buy'] == 1) {
|
|
|
+
|
|
|
+ if ($subscribe == 1) {
|
|
|
+ $this->data['info']['subscribe'] = 1;
|
|
|
+ $this->setButton('read', 1);
|
|
|
+ } else {
|
|
|
+ $this->setButton('read', 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->setButton('buy', -1);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function setButton($key = false, $status = false, $name = false)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!$this->data['button']) {
|
|
|
+ $this->data['button'] = array
|
|
|
+ (
|
|
|
+
|
|
|
+ 'read' => array('status' => -1, 'name' => '阅读'),
|
|
|
+
|
|
|
+ 'buy' => array('status' => -1, 'name' => '订阅'),
|
|
|
+
|
|
|
+ 'share' => array('status' => 1, 'name' => '排行榜'),
|
|
|
+ );
|
|
|
+
|
|
|
+ if ($key == -1) {
|
|
|
+ unset($this->data['button']['buy']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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('id' => $id));
|
|
|
+
|
|
|
+ $this->data['buy_desc'] = '';
|
|
|
+ if ($buy) {
|
|
|
+ $this->data['buy_desc'] = $buy['buy_content'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->data['buy_applet_notice'] = '在此购买单本可直接阅读电子刊,购买多本,直接累计积分,不会生成兑换码。';
|
|
|
+ if ($buy && isset($buy['buy_applet_notice']) && $buy['buy_applet_notice']) {
|
|
|
+ $this->data['buy_applet_notice'] = $buy['buy_applet_notice'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->data['info']['buy'] == 2) {
|
|
|
+ $this->data['buy_list'] = array();
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->data['buy_list'] = Dever::db('journal/buy_num')->getAll(array('info_id' => $id));
|
|
|
+
|
|
|
+ if ($this->data['info']['cash'] <= 0) {
|
|
|
+ $this->data['info']['cash'] = 100000;
|
|
|
+ }
|
|
|
+ if ($this->data['buy_list']) {
|
|
|
+ foreach ($this->data['buy_list'] as $k => $v) {
|
|
|
+ if (!$v['name']) {
|
|
|
+ $this->data['buy_list'][$k]['name'] = '购买' . $v['num'] . '本';
|
|
|
+ }
|
|
|
+
|
|
|
+ $price = $v['num'] * $this->data['info']['cash'];
|
|
|
+ if (!$v['price']) {
|
|
|
+ $this->data['buy_list'][$k]['price'] = $price;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->data['buy_list'][$k]['cash'] = $price;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function top()
|
|
|
+ {
|
|
|
+ $id = $this->check();
|
|
|
+
|
|
|
+ $this->data['top'] = Dever::load('act/lib/num')->getList($id);
|
|
|
+
|
|
|
+
|
|
|
+ $this->data['active'] = Dever::db('journal/active')->one(array('id' => $id));
|
|
|
+
|
|
|
+
|
|
|
+ if (!$this->data['active']) {
|
|
|
+ $this->data['active'] = (object) array();
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+ if ($this->data['active'] && $time >= $this->data['active']['start'] && $time < $this->data['active']['end']) {
|
|
|
+ $this->data['active']['status'] = 1;
|
|
|
+ } else {
|
|
|
+ $this->data['active']['status'] = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($time < $this->data['active']['start']) {
|
|
|
+ $this->data['active']['status'] = 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public function read()
|
|
|
+ {
|
|
|
+ if (!$this->data['uid']) {
|
|
|
+ Dever::alert('错误的用户信息');
|
|
|
+ }
|
|
|
+
|
|
|
+ $id = $this->check();
|
|
|
+ $this->data['info'] = $this->info($this->data['info'], false);
|
|
|
+
|
|
|
+
|
|
|
+ $subscribe = 2;
|
|
|
+
|
|
|
+ if ($subscribe == 2) {
|
|
|
+
|
|
|
+ if ($this->app) {
|
|
|
+
|
|
|
+ $vip = Dever::load('vip/lib/member')->get($this->data['uid'], $this->data['info']['cate_id']);
|
|
|
+
|
|
|
+ if ($vip <= 0) {
|
|
|
+
|
|
|
+ $user = Dever::db('passport/user')->one($this->data['uid']);
|
|
|
+ if ($user && $user['mobile']) {
|
|
|
+ $mobileWhere['mobile'] = $user['mobile'];
|
|
|
+ $mobileWhere['product_id'] = $id;
|
|
|
+ $mobile = Dever::db('journal/mobile')->one($mobileWhere);
|
|
|
+ if ($mobile) {
|
|
|
+ $vip = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($vip > 0) {
|
|
|
+ $subscribe = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($subscribe == 2) {
|
|
|
+ $subscribe = Dever::load('act/lib/subscribe')->get($id, $this->data['uid'], 4);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->data['info']['buy'] == 1 && $subscribe == 2) {
|
|
|
+ Dever::alert('未订阅');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $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'] = array();
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public 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['type'] == 7 || $info['type'] == 8) && $info['text']) {
|
|
|
+ $info['text'] = Dever::array_decode($info['text']);
|
|
|
+ if ($info['text']) {
|
|
|
+ foreach ($info['text'] as $k => $v) {
|
|
|
+ if (isset($info['text'][$k]['bgcolor_type']) && $info['text'][$k]['bgcolor_type'] == array(2)) {
|
|
|
+ $info['text'][$k]['bgcolor'] = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ unset($info['text']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($info['type'] == 10 && $info['palaces']) {
|
|
|
+ $info['palaces'] = Dever::array_decode($info['palaces']);
|
|
|
+ } else {
|
|
|
+ unset($info['palaces']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($info['type'] == 21 && $info['talk']) {
|
|
|
+ $info['talk'] = Dever::array_decode($info['talk']);
|
|
|
+ foreach ($info['talk'] as $k => $v) {
|
|
|
+ $info['talk'][$k]['talk_type'] = implode(',', $v['talk_type']);
|
|
|
+ $info['talk'][$k]['talk_location'] = implode(',', $v['talk_location']);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ unset($info['talk']);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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'], $this->data['uid']);
|
|
|
+ } elseif ($info['type'] == 4 || $info['type'] == 5) {
|
|
|
+ $info['video'] = convert($info['video'], 'mp4', 'journal/content', $info['id'], 'video');
|
|
|
+ $info = Dever::load('video/lib/vod')->avinfo($info, 'video', 'journal/content');
|
|
|
+ if ($info['type'] == 5) {
|
|
|
+ $info['name'] = $name;
|
|
|
+ }
|
|
|
+ } elseif ($info['type'] == 6) {
|
|
|
+ $info['name'] = $name;
|
|
|
+
|
|
|
+
|
|
|
+ } 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 ($this->data['uid'] > 0) {
|
|
|
+ $info['info']['note'] = Dever::load('act/lib/note')->get($this->data['uid'], $info['info']['id'], 3);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ $info['info']['note'] = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($info['info']['author_id']) && $info['info']['author_id']) {
|
|
|
+ $info['info']['author'] = Dever::db('content/author')->one($info['info']['author_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($info['pic']) && $info['pic']) {
|
|
|
+ $info['pic'] = str_replace('http://', 'https://', $info['pic']);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function check()
|
|
|
+ {
|
|
|
+ $id = Dever::input('id');
|
|
|
+ if (!$id) {
|
|
|
+ Dever::alert('小刊已下架');
|
|
|
+ }
|
|
|
+
|
|
|
+ $status = false;
|
|
|
+ if (strstr($id, 'preview_')) {
|
|
|
+ $id = str_replace('preview_', '', $id);
|
|
|
+ $status = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ $where['id'] = $id;
|
|
|
+ $this->data['info'] = Dever::db('journal/info')->one($where);
|
|
|
+
|
|
|
+ if (!$this->data['info']) {
|
|
|
+ Dever::alert('小刊已下架');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($status) {
|
|
|
+ $this->data['info']['status'] = '2';
|
|
|
+ }
|
|
|
+
|
|
|
+ return $id;
|
|
|
+ }
|
|
|
+}
|