|
@@ -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)
|
|
|
+ {
|
|
|
+
|
|
|
+ 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) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $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
|
|
|
+ (
|
|
|
+
|
|
|
+
|
|
|
+ '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 = 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']);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ Dever::alert('支付失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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']) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $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']) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $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;
|
|
|
}
|
|
|
}
|