|
@@ -0,0 +1,825 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Main\Src;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+use Main\Lib\Core;
|
|
|
+
|
|
|
+class Journal extends Core
|
|
|
+{
|
|
|
+ private function getCate()
|
|
|
+ {
|
|
|
+ $id = Dever::input('system', 1);
|
|
|
+
|
|
|
+ $cate = array();
|
|
|
+ if ($id > 0) {
|
|
|
+ $cate = Dever::db('journal/cate')->one($id);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$cate) {
|
|
|
+ Dever::alert('分类错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->data['cate'] = $cate;
|
|
|
+
|
|
|
+ return $cate;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function home()
|
|
|
+ {
|
|
|
+
|
|
|
+ $this->jingxuan(-1, 5);
|
|
|
+
|
|
|
+ $cate = $this->getCate();
|
|
|
+
|
|
|
+
|
|
|
+ $where = array();
|
|
|
+ $where['cate_id'] = $cate['id'];
|
|
|
+ if (checkVersion()->journal_buy == 2) {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ $data = Dever::db('journal/info')->getAll($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 getList()
|
|
|
+ {
|
|
|
+ $cate = $this->getCate();
|
|
|
+
|
|
|
+ $this->data['push'] = Dever::db('journal/info')->getOne($cate['journal_id']);
|
|
|
+
|
|
|
+
|
|
|
+ $where = array();
|
|
|
+ $where['cate_id'] = $cate['id'];
|
|
|
+ $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 getMyList()
|
|
|
+ {
|
|
|
+ if (!$this->data['uid']) {
|
|
|
+ Dever::alert('错误的用户信息');
|
|
|
+ }
|
|
|
+
|
|
|
+ $cate = $this->getCate();
|
|
|
+
|
|
|
+ $this->data['push'] = Dever::db('journal/info')->getOne($cate['journal_id']);
|
|
|
+
|
|
|
+
|
|
|
+ $this->data['user'] = Dever::load('passport/api')->info($this->data['uid']);
|
|
|
+
|
|
|
+
|
|
|
+ $where = array();
|
|
|
+ $where['type'] = 4;
|
|
|
+ $where['source'] = '1,2,3,4';
|
|
|
+ $where['cate_id'] = $cate['id'];
|
|
|
+ $data = Dever::db('act/subscribe')->getMyAll($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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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']);
|
|
|
+ } else {
|
|
|
+ $data['pic_view_bg'] = array();
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['buy'] = intval($data['buy']);
|
|
|
+
|
|
|
+
|
|
|
+ if ($subscribe) {
|
|
|
+ $data['subscribe'] = Dever::load('act/lib/subscribe')->getList($data['id'], 4);
|
|
|
+
|
|
|
+ if (!$data['subscribe']) {
|
|
|
+ $data['subscribe'] = array();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function jingxuan($page = true, $num = 4)
|
|
|
+ {
|
|
|
+ if (!$page) {
|
|
|
+ $page = true;
|
|
|
+ }
|
|
|
+ if ($page === -1) {
|
|
|
+ $page = false;
|
|
|
+ }
|
|
|
+ if (!$num) {
|
|
|
+ $num = 4;
|
|
|
+ }
|
|
|
+ $this->data['push_jingxuan'] = Dever::load('push/lib/data')->get('jingxuan', '小刊精选推荐', 4, $page, $num);
|
|
|
+
|
|
|
+ $count = count($this->data['push_jingxuan']);
|
|
|
+
|
|
|
+
|
|
|
+ if ($num == 5) {
|
|
|
+ if ($count < 4 || !$this->data['push_jingxuan']) {
|
|
|
+ $this->data['push_jingxuan'] = array();
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->data['push_jingxuan_more'] = 2;
|
|
|
+
|
|
|
+ if ($count > 4 && isset($this->data['push_jingxuan'][4])) {
|
|
|
+ unset($this->data['push_jingxuan'][4]);
|
|
|
+ $this->data['push_jingxuan_more'] = 1;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $page = Dever::pageInfo();
|
|
|
+ if ($page['status'] != 1) {
|
|
|
+ Dever::$global['page']['current']['next_page'] = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function view()
|
|
|
+ {
|
|
|
+ $id = $this->check();
|
|
|
+ $this->data['info'] = $this->info($this->data['info'], false);
|
|
|
+ $this->button($this->data['info']);
|
|
|
+
|
|
|
+ if ($this->data['uid'] > 0) {
|
|
|
+ Dever::score($this->data['uid'], 'view_journal', '浏览小刊首页');
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($this->data['info']['share_content'])) {
|
|
|
+ $source = Dever::db('source/info')->one(1);
|
|
|
+ $this->data['info']['share_link'] = $source['code'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $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('code', -1);
|
|
|
+ $this->setButton('share', -1);
|
|
|
+ } elseif ($subscribe == 1) {
|
|
|
+ $this->data['info']['subscribe'] = 1;
|
|
|
+
|
|
|
+ $this->setButton('read', 1, '开始阅读');
|
|
|
+ $this->setButton('code', 2, '再次购买');
|
|
|
+
|
|
|
+ if (checkVersion()->journal_buy == 2) {
|
|
|
+ $this->setButton('code', 1, '兑换码阅读');
|
|
|
+ $this->setButton('share', -1);
|
|
|
+ }
|
|
|
+ } elseif ($info['buy'] == 1 || $info['buy'] == 3) {
|
|
|
+
|
|
|
+ $this->setButton('read', 2, '购买阅读');
|
|
|
+ $this->setButton('code', 1, '兑换码阅读');
|
|
|
+
|
|
|
+ if (checkVersion()->journal_buy == 2) {
|
|
|
+ $this->setButton('read', -1);
|
|
|
+ $this->setButton('share', -1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $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', -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->setButton('code', 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('id' => $id));
|
|
|
+
|
|
|
+ $this->data['buy_desc'] = '';
|
|
|
+ if ($buy) {
|
|
|
+ $this->data['buy_desc'] = $buy['buy_content'];
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 active()
|
|
|
+ {
|
|
|
+ $id = $this->check();
|
|
|
+
|
|
|
+
|
|
|
+ $buy = Dever::db('journal/buy')->one(array('id' => $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;
|
|
|
+ }
|
|
|
+
|
|
|
+ $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'];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if ($this->data['uid']) {
|
|
|
+ $this->data['invite'] = Dever::load('act/lib/invite')->getList($this->data['uid'], $id);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $this->data['buy'] = 1;
|
|
|
+ if (checkVersion()->journal_buy == 2) {
|
|
|
+ $this->data['buy'] = 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function score()
|
|
|
+ {
|
|
|
+ $id = $this->check();
|
|
|
+
|
|
|
+ $this->data['score'] = Dever::load('act/lib/score')->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 invite()
|
|
|
+ {
|
|
|
+ if (!$this->data['uid']) {
|
|
|
+ Dever::alert('错误的用户信息');
|
|
|
+ }
|
|
|
+
|
|
|
+ $id = $this->check();
|
|
|
+
|
|
|
+ $this->data['invite'] = Dever::load('act/lib/invite')->getList($this->data['uid'], $id);
|
|
|
+
|
|
|
+ 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 = Dever::load('act/lib/subscribe')->get($id, $this->data['uid'], 4);
|
|
|
+
|
|
|
+ if ($this->data['info']['buy'] == 1 && $subscribe == 2) {
|
|
|
+ Dever::alert('未订阅');
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->data['info']['buy'] == 2) {
|
|
|
+ Dever::load('act/lib/subscribe')->submit($this->data['uid'], $id, 4);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->data['uid'] > 0) {
|
|
|
+ Dever::score($this->data['uid'], 'read_journal', '阅读小刊');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $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();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Dever::db('journal/info')->addView($id);
|
|
|
+
|
|
|
+ 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['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'] == 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');
|
|
|
+ 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('小刊已下架');
|
|
|
+ }
|
|
|
+
|
|
|
+ $where['id'] = $id;
|
|
|
+ $this->data['info'] = Dever::db('journal/info')->one($where);
|
|
|
+
|
|
|
+ if (!$this->data['info']) {
|
|
|
+ Dever::alert('小刊已下架');
|
|
|
+ }
|
|
|
+
|
|
|
+ return $id;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ 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');
|
|
|
+ $cate = $this->getCate();
|
|
|
+
|
|
|
+ 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');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$buy['name']) {
|
|
|
+ $buy['name'] = '购买' . $buy['num'] . '本';
|
|
|
+ }
|
|
|
+
|
|
|
+ $user = Dever::db('passport/user')->one($this->data['uid']);
|
|
|
+ $wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid'], 'type' => 1, 'system_id' => $this->data['system']));
|
|
|
+
|
|
|
+ $source_type = Dever::input('source_type');
|
|
|
+
|
|
|
+ if ($source_type == 'ios') {
|
|
|
+ $method = 'apple';
|
|
|
+ $order_data['system'] = 3;
|
|
|
+ $account_id = 3;
|
|
|
+
|
|
|
+ $receipt = Dever::input('receipt');
|
|
|
+ if (!$receipt) {
|
|
|
+ Dever::alert('苹果内购支付失败,没有receipt参数');
|
|
|
+ }
|
|
|
+ } elseif ($source_type == 'android') {
|
|
|
+ $method = 'app';
|
|
|
+ $order_data['system'] = 4;
|
|
|
+ $account_id = 3;
|
|
|
+ } else {
|
|
|
+ $method = 'applet';
|
|
|
+ $order_data['system'] = 1;
|
|
|
+ $account_id = 1;
|
|
|
+
|
|
|
+ if ($cate && $cate['id'] == 2) {
|
|
|
+ $account_id = 4;
|
|
|
+ } elseif ($cate && $cate['id'] == 2) {
|
|
|
+ $account_id = 5;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $order_id = $this->createOrder('JP');
|
|
|
+ $order_data['cate_id'] = $cate['id'];
|
|
|
+ $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'] = $buy['num'];
|
|
|
+ if (isset($buy['price']) && $buy['price'] && $buy['price'] > 0) {
|
|
|
+ $order_data['cash'] = $buy['price'];
|
|
|
+ } else {
|
|
|
+ $order_data['cash'] = $info['cash'] * $order_data['num'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $source = Dever::input('source');
|
|
|
+ if ($source) {
|
|
|
+ $order_data['source'] = $source;
|
|
|
+ }
|
|
|
+ $seller = Dever::input('seller');
|
|
|
+ if ($seller) {
|
|
|
+ $order_data['seller_id'] = $seller;
|
|
|
+ }
|
|
|
+
|
|
|
+ $id = Dever::db('journal/order')->insert($order_data);
|
|
|
+
|
|
|
+ if (!$id) {
|
|
|
+ Dever::alert('支付失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $param = array
|
|
|
+ (
|
|
|
+ 'account_id' => $account_id,
|
|
|
+ 'project_id' => 1,
|
|
|
+ 'uid' => $this->data['uid'],
|
|
|
+ 'username' => $user['username'],
|
|
|
+ 'name' => $order_data['name'],
|
|
|
+ 'cash' => $order_data['cash'],
|
|
|
+
|
|
|
+ 'openid' => $wechat['openid'],
|
|
|
+ 'product_id' => $journal_id . '-' . $buy_id,
|
|
|
+ 'order_id' => $order_id,
|
|
|
+ );
|
|
|
+
|
|
|
+ if ($method == 'apple') {
|
|
|
+ $param['other'] = $receipt;
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->data['pay'] = Dever::load('pay/api.' . $method, $param);
|
|
|
+
|
|
|
+ if ($order_data['system'] == 1) {
|
|
|
+ if (isset($this->data['pay']['prepay_id'])) {
|
|
|
+ Dever::load('act/lib/form')->submit($this->data['uid'], $this->data['pay']['prepay_id'], 2, $this->data['system']);
|
|
|
+ } else {
|
|
|
+ Dever::alert('支付失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->data;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function checkCode()
|
|
|
+ {
|
|
|
+ if (!$this->data['uid']) {
|
|
|
+ Dever::alert('错误的用户信息');
|
|
|
+ }
|
|
|
+ $code = trim(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) {
|
|
|
+
|
|
|
+ $code = trim($code);
|
|
|
+
|
|
|
+ $code = str_replace("\n", '', $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, 'type' => 2, '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);
|
|
|
+
|
|
|
+
|
|
|
+ Dever::load('act/lib/subscribe')->submit($this->data['uid'], $journal_id, 2);
|
|
|
+
|
|
|
+ $score = false;
|
|
|
+ $num = false;
|
|
|
+ if (isset($info['product_num']) && $info['product_num'] > 0) {
|
|
|
+ if ($product && $product['dh_score'] > 0) {
|
|
|
+ $score = $info['product_num'] * $product['dh_score'];
|
|
|
+ } elseif ($product) {
|
|
|
+ $num = $info['product_num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Dever::score($this->data['uid'], 'dh_journal', '兑换小刊', 'act/lib/score.submit?method=code&type=4&id=' . $journal_id, $score, $num);
|
|
|
+
|
|
|
+ } 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($prefix);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $order;
|
|
|
+ }
|
|
|
+}
|