dever 6 years ago
parent
commit
b5a7dee17f

+ 121 - 0
act/database/journal_num.php

@@ -0,0 +1,121 @@
+<?php
+
+$table = Dever::config('base')->type;
+
+return array
+(
+	# 表名
+	'name' => 'journal_num',
+	# 显示给用户看的名称
+	'lang' => '本数排行榜',
+	# 是否显示在后台菜单
+	'order' => 1,
+	'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+		
+
+		'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户名',
+			'default' 	=> '0',
+			'desc' 		=> '请选择用户',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'search'	=> 'select',
+			'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+			'list'		=> '{uid} > 0 ? Dever::load("passport/user-one#username", {uid}) : "匿名用户"',
+		),
+		
+		'journal_id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '标题',
+			'default' 	=> '',
+			'desc' 		=> '标题',
+			'update'	=> 'text',
+			'match' 	=> 'option',
+		),
+
+		'num' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '购买本数',
+			'default' 	=> '',
+			'desc' 		=> '购买本数',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'order'		=> 'desc',
+			'list'		=> 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
+	(
+		'insert' => false,
+		'edit' => false,
+		'delete' => false,
+		'button' => array
+		(
+			'导出排行榜' => array('location', 'act/lib/num.out?id=' . Dever::input('search_option_data_id')),
+		),
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'uid' => 'yes',
+				'data_id' => 'yes',
+				'type' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('num' => 'desc','id' => 'desc'),
+			'page' => array(50, 'list'),
+			'col' => '*',
+		),
+	)
+);

+ 541 - 0
act/database/order.php

@@ -0,0 +1,541 @@
+<?php
+
+$type = array
+(
+    1 => '购买小刊',
+    2 => '兑换小刊',
+    3 => '购买兑换码',
+    4 => '使用通用兑换码',
+);
+
+# 系统
+$system = array
+(
+    1 => '小程序',
+    2 => 'H5',
+    3 => 'ios',
+    4 => '安卓',
+);
+
+# 渠道
+$source = function()
+{
+    return Dever::db('source/info')->state();
+};
+
+$status = array
+(
+    1 => '待支付',
+    2 => '已支付',
+    3 => '支付失败',
+    //4 => '申请退款',
+    5 => '已退款',
+);
+
+$product = function()
+{
+    return Dever::db('journal/info')->state();
+};
+
+$buy = function()
+{
+    return Dever::db('journal/buy_num')->state();
+};
+# 获取小刊分类权限
+$auth = Dever::tops();
+$cate = function() use ($auth)
+{
+    $array = array();
+    if ($auth) {
+        $info = Dever::db('journal/cate')->getIds(array('ids' => $auth));
+    } else {
+        $info = Dever::db('journal/cate')->state();
+    }
+    if($info)
+    {
+        $array += $info;
+    }
+    return $array;
+};
+
+$seller = function()
+{
+    return Dever::db('code/seller')->state();
+};
+
+return array
+(
+    # 表名
+    'name' => 'order',
+    # 显示给用户看的名称
+    'lang' => '订单管理',
+    'order' => 1,
+
+    'end' => array
+    (
+        'update' => 'journal/lib/pay.order',
+    ),
+
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'      => true,
+        ),
+
+        'order_id'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '订单id',
+            'default'   => '',
+            'desc'      => '付款订单id',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'        => true,
+            //'list'        => '"{order_id}" ? "{order_id}" : "{code}"',
+        ), 
+
+        'cate_journal'     => array
+        (
+            'name'      => '小刊',
+            'default'   => '',
+            'desc'      => '小刊',
+            'search'    => 'linkage',
+            'search_col' => 'cate_id,product_id',
+            'option'    => Dever::url('lib/manage.search_cate_journal', 'journal'),
+        ),
+
+        'cate_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '小刊分类',
+            'default'   => '1',
+            'desc'      => '小刊分类',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $cate,
+            //'search'    => 'select',
+            'list'      => true,
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-80',
+            'name'      => '订单名称',
+            'default'   => '',
+            'desc'      => '订单名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list_name' => '订单信息',
+            'list'      => 'Dever::load("journal/lib/manage.showOrderUser", "{id}")',
+        ),
+
+        'uid'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '用户名',
+            'default'   => '',
+            'desc'      => '用户id',
+            'match'     => 'is_numeric',
+            'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            'update'    => 'text',
+        ),
+
+        'source_uid'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '邀请人',
+            'default'   => '',
+            'desc'      => '邀请人',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+        ),
+
+        'note'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '是否发送状态提醒-1未发送,2已发送',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+
+        'product_id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '小刊',
+            'default'   => '',
+            'desc'      => '小刊',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $product,
+            //'search'    => 'select',
+            //'list'        => true,
+        ),
+
+        'buy_id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '购买本数',
+            'default'   => '',
+            'desc'      => '购买本数',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $buy,
+            //'search'    => 'select',
+            //'list'        => true,
+        ),
+
+        'buy_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '购买本数',
+            'default'   => '',
+            'desc'      => '购买本数',
+            'match'     => 'is_numeric',
+            //'search'    => 'select',
+            //'list'        => true,
+        ),
+
+        'type'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '支付方式',
+            'default'   => '1',
+            'desc'      => '支付方式',
+            'match'     => 'is_numeric',
+            'option'    => $type,
+            'search'    => 'select',
+            'update'    => 'radio',
+            //'list'        => true,
+            'control'   => 'type',
+        ),
+
+        'system'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '系统',
+            'default'   => '1',
+            'desc'      => '系统',
+            'match'     => 'is_numeric',
+            'option'    => $system,
+            'search'    => 'select',
+            'update'    => 'radio',
+            'list'        => true,
+        ),
+
+        'source'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '渠道来源',
+            'default'   => '1',
+            'desc'      => '支付方式',
+            'match'     => 'is_numeric',
+            'option'    => $source,
+            'search'    => 'select',
+            'update'    => 'radio',
+            'list'        => true,
+        ),
+
+        'seller_id'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '销售商',
+            'default'   => '1',
+            'desc'      => '销售商',
+            'match'     => 'is_numeric',
+            'update'    => 'select',
+            'option'    => $seller,
+            'search'    => 'select',
+            //'list'      => true,
+        ),
+
+        'notice'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '模板消息提醒次数',
+            'default'   => '0',
+            'desc'      => '模板消息提醒次数',
+            'match'     => 'is_numeric',
+        ),
+
+        'cash'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '支付金额',
+            'default'   => '',
+            'desc'      => '支付金额',
+            'match'     => 'option',
+            'update'    => 'text',
+            //'list'        => true,
+            'show'      => 'type=1',
+        ),
+
+        'code'      => array
+        (
+            'type'      => 'varchar-50',
+            'name'      => '使用的兑换码',
+            'default'   => '',
+            'desc'      => '使用的兑换码',
+            'match'     => 'option',
+            'update'    => 'text',
+            //'list'        => true,
+            'show'      => 'type=2',
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '订单状态',
+            'default'   => '1',
+            'desc'      => '请选择订单状态',
+            'match'     => 'is_numeric',
+            'option'    => $status,
+            'search'    => 'select',
+            'update'    => 'radio',
+            'list'      => 'Dever::load("journal/lib/manage.showOrderStatus", "{id}")',
+            'control'   => 'status',
+        ),
+
+        'tk_pic'     => array
+        (
+            'type'      => 'varchar-150',
+            'name'      => '退款截图',
+            'default'   => '',
+            'desc'      => '退款截图',
+            'match'     => 'is_string',
+            'update'    => 'image',
+            'key'       => 1
+        ),
+
+        'tk_time'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '退款时间',
+            'default'   => '',
+            'desc'      => '退款时间',
+            'match'     => 'option',
+            //'list'        => true,
+            //'update'    => 'date',
+            'callback'  => 'maketime',
+            'show'      => 'status=5',
+        ),
+
+        'tk_admin'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '退款审核人',
+            'default'   => '1',
+            'desc'      => '退款审核人',
+            'match'     => 'option',
+            //'list'        => true,
+            'show'      => 'status=5',
+        ),
+
+        'tk_desc'       => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '退款备注',
+            'default'   => '',
+            'desc'      => '退款备注',
+            'match'     => 'option',
+            'update'    => 'textarea',
+            //'show'        => 'status=5',
+        ),
+
+        '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})',
+            //'list'      => 'Dever::load("service/lib/manage.showOrderTime", "{id}")',
+        ),
+
+        'info'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '备注',
+            'default'   => '',
+            'desc'      => '备注',
+            'match'     => 'option',
+            'update'    => 'textarea',
+            //'show'        => 'status=5'
+            //'list'      => '"{info}" ? "{info}" : "双击添加备注"',
+            //'edit'      => true,
+        ),
+
+        'mobile'        => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '手机号',
+            'default'   => '',
+            'desc'      => '手机号',
+            'match'     => 'option',
+            //'show'        => 'status=5'
+            'search'    => array
+            (
+                'api' => 'passport/user-all',//接口地址,最好是获取多条数据的地址
+                'col' => 'mobile',//要查询的字段
+                'result' => 'id',//返回的字段
+                'search' => 'uid',//本表的字段,默认为当前的字段
+            ),
+        ),
+    ),
+
+    'top' => Dever::config('base')->top,
+
+    # 增加这个,为了给当前的list增加一个option
+    'top_option' => array
+    (
+        'value' => $auth,
+        'col' => 'cate_id',
+    ),
+
+    'manage' => array
+    (
+        'delete' => false,
+        'edit' => false,
+        'insert' => false,
+
+        'button' => array
+        (
+            //'导出订单' => array('location', 'journal/lib/manage.out'),
+        ),
+
+        'list_button' => array(
+            'edit' => array('退款', 'status,tk_time,tk_pic,tk_desc,tk_admin', '{status} == 2 && ({type} == 1 || {type} == 3)'),
+            //'delete' => array('删除', '', '{status} == 1'),
+        ),
+    ),
+
+    'request' => array
+    (
+        'getAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'type' => 'yes',
+                'create_uid' => 'yes',
+                'status' => array('1', '!='),
+                'uid' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('cdate' => 'desc'),
+            'page' => array(10, 'list'),
+            'col' => '*',
+        ),
+
+        'getYes' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'product_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('cdate' => 'desc'),
+            'col' => '*',
+        ),
+
+        # 获取提交订单超过12个小时
+        'getDataByTime' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'cdate' => array('yes', '>='),
+                'notice' => 'yes',
+                'note' => 'yes',
+                'type' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('cdate' => 'desc'),
+            'col' => '*',
+        ),
+
+        # 获取没有兑换码的订单
+        'getUnCode' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'code' => array('yes', '='),
+                'status' => 'yes',
+                'type' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'limit' => '0,100',
+            'col' => '*',
+        ),
+
+        # 获取1,2
+        'getBuy' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'status' => 'yes',
+                'type' => array('yes', 'in'),
+                'product_id' => 'yes',
+                'order_id' => 'yes',
+                'uid' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'col' => '*',
+        ),
+
+        'getMyAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'type' => 'yes',
+                'uid' => 'yes',
+                'status' => 'yes',
+                'cate_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'page' => array(10, 'list'),
+            'col' => 'order_id,name,buy_num,cdate',
+        ),
+    ),
+);

+ 116 - 0
act/lib/Num.php

@@ -0,0 +1,116 @@
+<?php
+
+namespace Act\Lib;
+
+use Dever;
+
+class Num
+{
+    # 获取我在这个小刊中的本数
+    public function get($id, $uid)
+    {
+        $where['uid'] = $uid;
+        $where['journal_id'] = $id;
+        $where['state'] = 1;
+        $data = Dever::db('act/journal_num')->one($where);
+
+        if ($data) {
+            return $data['num'];
+        } else {
+            return 0;
+        }
+    }
+    
+    # 获取小刊的积分排行
+    public function getList($id, $uid = false)
+    {
+        $where['type'] = $type;
+        $where['journal_id'] = $id;
+        if ($uid > 0) {
+            $where['uid'] = $uid;
+        }
+        $data = Dever::db('act/journal_num')->getAll($where);
+
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $user = Dever::load('passport/api')->info($v['uid']);
+                $data[$k]['username'] = $user['username'];
+                $data[$k]['avatar'] = $user['avatar'];
+                $data[$k]['mobile'] = $user['mobile'];
+            }
+        }
+        return $data;
+    }
+
+    public function submit($id, $uid = false, $num = false)
+    {
+        $where['uid'] = $uid;
+        $where['journal_id'] = $id;
+        $db = Dever::db($table);
+        $info = $db->one($where);
+        if (!$info) {
+            $where['num'] = $num;
+            $db->insert($where);
+        } else {
+            $where['where_id'] = $info['id'];
+            $where['num'] = $info['num'] + $num;
+            $db->update($where);
+        }
+
+        return true;
+    }
+
+    # 矫正数据用的,放到计划任务中
+    public function cron()
+    {
+        
+
+        return true;
+    }
+
+    /**
+     * 导出成excel
+     *
+     * @return mixed
+     */
+    public function out_api()
+    {
+        $id = Dever::input('id');
+        $journal = Dever::db('journal/info')->one($id);
+
+        if (!$journal) {
+            return;
+        }
+
+        $score = $this->getList($id);
+        $header = $data = array();
+        $name = $journal['name'];
+        if ($score) {
+            $i = 0;
+            foreach ($score as $k => $v) {
+                $data[$i] = array
+                (
+                    $i+1,
+                    $v['username'],
+                    $v['mobile'],
+                    $v['num'],
+                );
+                $i++;
+            }
+        }
+
+        $header = array
+        (
+            '排序', '用户名', '手机号', '本数'
+        );
+
+        $file = $name . '_排行榜';
+        if (Dever::input('test')) {
+            print_r($header);
+            print_r($data);die;
+        }
+        
+        Dever::excelExport($data, $header, $file, $sheet = 0, $sheetName = $name);
+        return;
+    }
+}

+ 179 - 0
act/lib/Pay.php

@@ -0,0 +1,179 @@
+<?php
+#新版本的异步支付
+namespace Journal\Lib;
+
+use Dever;
+
+class Pay
+{
+    private $key = 'jmss_2018';
+
+    # 退款操作
+    public function order($id, $name, $data)
+    {
+        $status = Dever::param('status', $data);
+
+        if ($status == 5 && $id > 0) {
+            $send = array();
+            $info = Dever::db('act/order')->one($id);
+            $send['pay_project_id'] = 1;
+            $send['pay_uid'] = $info['uid'];
+            $send['pay_order_id'] = $info['order_id'];
+            $send['pay_tk_pic'] = Dever::param('tk_pic', $data);
+            $send['pay_tk_time'] = Dever::param('tk_time', $data);
+            $send['pay_tk_desc'] = Dever::param('tk_desc', $data);
+            $send['pay_status'] = $status;
+            $send['dever_token'] = $this->key;
+
+            # 减少积分
+
+            Dever::load('pay/lib/set.updateStatus', $send);
+        }
+    }
+
+	/**
+	 * 支付成功后,调取的接口 这里的安全以后再升级吧,升级成和pay/lib/set.updateStatus一样的
+	 *
+	 * @return mixed
+	 */
+	public function act_api($param = array())
+	{
+        $send = Dever::preInput('pay_');
+        $key = md5($this->key);
+        ksort($send);
+        $send['signature'] = md5($key . '&' . http_build_query($send));
+        $signature = Dever::input('signature');
+        if ($send['signature'] == $signature) {
+            $product_id = $send['pay_product_id'];
+            $uid = $send['pay_uid'];
+            $cash = $send['pay_cash'];
+            $order_id = $send['pay_order_id'];
+            $status = $send['pay_status'];
+            $msg = $send['pay_msg'];
+
+            $order = Dever::db('act/order')->one(array('order_id' => $order_id, 'uid' => $uid));
+
+            if ($send['pay_status'] == 2 && $order) {
+                
+                $update = array();
+                $update['where_id'] = $order['id'];
+                $update['status'] = 2;
+                if ($order['type'] == 3 && !$order['code']) {
+                    $code = Dever::load('code/lib/core')->createCodeByOrder($order, -1);
+                    if ($code) {
+                        $update['code'] = $code;
+                    }
+                }
+
+                Dever::db('act/order')->update($update);
+
+                if ($order['type'] != 1) {
+                    return;
+                }
+
+                # 订阅
+                Dever::load('act/lib/subscribe')->submit($uid, $order['product_id'], 1);
+
+                $score = false;
+                $num = false;
+                $journal = Dever::load('act/order')->getJournal($order['product_id']);
+                if ($order['buy_id'] > 0) {
+                    $buy = Dever::load('act/order')->getBuy($order['buy_id']);
+                    if ($buy && $buy['score'] > 0) {
+                    	$score = $buy['num'] * $buy['score'];
+                    } else {
+                    	if ($order['type'] == 1) {
+	                    	# 直接购买
+	                    	$col = 'score';
+	                    } elseif ($order['type'] == 3) {
+	                    	$col = 'dh_score';
+	                    }
+
+	                    if ($journal && $buy && $journal[$col] > 0) {
+	                        $score = $buy['num'] * $journal[$col];
+	                    } elseif ($journal && $buy) {
+	                        $num = $buy['num'];
+	                    }
+                    }
+
+                    if ($buy && $buy['num']) {
+                    	# 增加本数
+                    	Dever::load('act/lib/num')->submit($order['product_id'], $uid, $buy['num']);
+                    }
+                }
+                # 积分
+                Dever::score($uid, 'buy_journal', '购买小刊', '', $score, $num);
+
+                # 发消息
+                $journal['id'] = $order['product_id'];
+                $journal['name'] = $order['name'];
+                if (strstr('-', $journal['name'])) {
+                	$name = explode('-', $journal['name']);
+                	$journal['name'] = $name[0];
+                }
+                
+                //$journal = Dever::db('journal/info')->one($order['product_id']);
+
+                if (Dever::project('message')) {
+                    Dever::load('message/lib/data')->push(-1, $uid, '购买提醒', '购买成功,您获得了 '.$journal['name'].' 的阅读资格!', 11, $order['cate_id'], 1, Dever::load('act/lib/note')->push(4, $journal['id'], $journal['name']));
+                }
+
+                $user = Dever::db('passport/user')->one($uid);
+
+                # 发短信
+                if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms') && $order['cate_id'] == 1) {
+                    $send = array();
+                    $send['name'] = $journal['name'];
+                    Dever::load('sms/api.send', 'buy_journal', $user['mobile'], $send);
+                }
+
+                # 发模板消息
+                $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid, 'type' => 1, 'system_id' => $order['cate_id']));
+                if ($wechat && Dever::project('wechat_applet')) {
+                    $send['key'] = 'buy_journal';
+                    $send['project_id'] = $order['cate_id'];
+                    $send['touser'] = $wechat['openid'];
+                    $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
+                    $send['data'] = array
+                    (
+                        'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
+                        'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
+                    );
+                    $send['data'] = json_encode($send['data']);
+                    $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
+
+                    if ($send['form_id']) {
+                        Dever::load('wechat_applet/msg.send', $send);
+                    }
+                }
+
+            } else {
+                Dever::db('act/order')->update(array('where_id' => $order['id'], 'status' => 3));
+            }
+        }
+	}
+
+    public function send_api()
+    {
+        $uid = Dever::input('uid', 8);
+        # 发模板消息
+        $wechat = Dever::db('passport/wechat')->one(array('uid' => $uid));
+        if ($wechat && Dever::project('wechat_applet')) {
+            $send['key'] = 'buy_journal';
+            $send['project_id'] = 2;
+            $send['touser'] = $wechat['openid'];
+            $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($uid) . ',' . '4,' . $order['product_id'];
+            $send['data'] = array
+            (
+                'keyword1' => array('value' => date('Y年m月d日 H:i', $order['cdate'])),
+                'keyword2' => array('value' => '购买成功,您获得了 '.$journal['name'].' 的阅读资格!'),
+            );
+            $send['data'] = json_encode($send['data']);
+            $send['form_id'] = Dever::load('act/lib/form')->get($uid, 2, $order['cate_id']);
+
+            if ($send['form_id']) {
+                Dever::load('wechat_applet/msg.send', $send);
+            }
+        }
+    }
+}

+ 296 - 0
act/src/Order.php

@@ -0,0 +1,296 @@
+<?php
+# 电子刊购买接口,本接口下所有接口都无需缓存 做好配置:act/order
+namespace Act\Src;
+
+use Dever;
+use Main\Lib\Core;
+
+class Order extends Core
+{
+	# 获取电子刊信息,走缓存,先不走接口
+	public function getJournal($journal_id = false)
+	{
+        $journal_id = Dever::input('journal_id', $journal_id, '> 0', '请传入正确的小刊ID');
+
+        $key = 'journal_info_' . $journal_id;
+
+        $journal = Dever::cache($key);
+
+        if (!$journal) {
+        	$journal = Dever::db('journal/info')->one($journal_id);
+	        if (!$journal) {
+	            Dever::alert('请传入正确的小刊ID');
+	        }
+
+	        Dever::cache($key, $journal);
+        }
+        return $journal;
+	}
+
+	# 获取购买的信息,走缓存,先不走接口
+	public function getBuy($buy_id = false)
+	{
+        $buy_id = Dever::input('buy_id', $buy_id, '> 0', '请传入正确的支付ID');
+
+        $key = 'journal_buy_' . $buy_id;
+
+        $buy = Dever::cache($key);
+
+        if (!$buy) {
+	        $buy = Dever::db('journal/buy_num')->one($buy_id);
+
+	        if (!$buy) {
+	            Dever::alert('请传入正确的小刊ID');
+	        }
+
+	        if (!$buy['name']) {
+	            $buy['name'] = '购买' . $buy['num'] . '本';
+	        }
+
+	        Dever::cache($key, $buy);
+        }
+        return $buy;
+	}
+
+	# 根据分类获取我已订阅的小刊列表,我的订单列表,此处要修改为我的订单列表 getMyAll待增加
+    public function getMyList()
+    {
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+
+        $cate = Dever::input('system', 1);
+
+        if (!$cate) {
+            Dever::alert('错误的信息');
+        }
+
+        # 我的订单列表
+        $where = array();
+        $where['uid'] = $this->data['uid'];
+        $where['cate_id'] = $cate;
+        $where['status'] = 2;
+
+        $this->data['order'] = Dever::db('act/order')->getMyAll($where);
+
+        if ($this->data['order']) {
+            foreach ($this->data['order'] as $k => $v) {
+                $this->data['order'][$k]['cdate'] = date('Y年m月d日 H:i:s', $v['cdate']);
+            }
+        }
+
+        return $this->data;
+    }
+
+    # 根据订单id获取我的兑换码列表
+    public function getMyCodeList()
+    {
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+
+        $order_id = Dever::input('order_id');
+
+        if (!$order_id) {
+            Dever::alert('错误的信息');
+        }
+
+        # 我的订单列表
+        $where = array();
+        $where['create_uid'] = $this->data['uid'];
+        $where['order_id'] = $order_id;
+
+        $this->data['code'] = Dever::db('code/info')->getMyAll($where);
+
+        return $this->data;
+    }
+
+    # 购买 改成直接购买兑换码
+    public function pay()
+    {
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+
+        $journal = $this->getJournal();
+        $buy = $this->getBuy();
+
+        $user = Dever::db('passport/user')->one($this->data['uid']);
+        $wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid'], 'type' => 1, 'system_id' => $journal['cate_id']));
+
+        $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;
+            # 根据cate_id走不同的支付id,暂时不需要
+            if ($journal['cate_id'] == 2) {
+                $account_id = 4;
+            } elseif ($journal['cate_id'] == 3) {
+                $account_id = 5;
+            }
+            //$account_id = $cate['pay_id'];
+        }
+
+        $order_id = $this->createOrder('JP');
+        $order_data['cate_id'] = $journal['cate_id'];
+        $order_data['order_id'] = $order_id;
+        $order_data['product_id'] = $journal['id'];
+        $order_data['buy_id'] = $journal['id'];
+        $order_data['uid'] = $this->data['uid']; 
+        $order_data['type'] = 3;
+        $order_data['status'] = 1;
+
+        $order_data['name'] = $journal['name'] . '-' . $buy['name'];
+        $order_data['buy_num'] = $buy['num'];
+
+        if (isset($buy['price']) && $buy['price'] && $buy['price'] > 0) {
+            $order_data['cash'] = $buy['price'];
+        } else {
+            $order_data['cash'] = $journal['cash'] * $order_data['num'];
+        }
+
+        $source = Dever::input('source');
+        $system = Dever::input('system', 1);
+        if (!$source) {
+            $source = $system;
+        }
+        if ($source) {
+            $order_data['source'] = $source;
+        }
+        $seller = Dever::input('seller');
+        if ($seller) {
+            $order_data['seller_id'] = $seller;
+        }
+
+        $id = Dever::db('act/order')->insert($order_data);
+
+        if (!$id) {
+            Dever::alert('支付失败');
+        }
+
+        //$param参数
+        $param = array
+        (
+            'account_id' => $account_id,
+            'project_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,
+        );
+
+        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, $journal['cate']['id']);
+            } else {
+                Dever::alert('支付失败');
+            }
+        }
+
+        return $this->data;
+    }
+
+    # 开始兑换
+    public function code()
+    {
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+
+        $code = Dever::input('code');
+
+        if ($code) {
+            $code = trim($code);
+            $code = str_replace("\n", '', $code);
+
+            $journal_id = Dever::input('journal_id', $journal_id, '> 0', '请传入正确的小刊ID');
+
+            $info = Dever::db('code/info')->one(array('code' => $code));
+
+            if (!$info) {
+                Dever::alert('兑换码不存在');
+            }
+
+            if ($info['type'] == 3) {
+                Dever::alert('兑换码已被使用');
+            }
+
+            if ($info['state'] != 1) {
+                Dever::alert('兑换码已作废');
+            }
+
+            if ($info['type'] == 4) {
+                Dever::alert('兑换码已作废');
+            }
+
+            if ($info['type'] == 2 && $this->data['uid'] != $info['uid']) {
+                //Dever::alert('兑换码已被领取');
+            }
+
+            if ($info['product_id'] > 0 && $info['product_id'] != $journal_id) {
+                Dever::alert('请正确使用小刊兑换码');
+            }
+
+            if (isset($info['order_id']) && $info['order_id'] > 0) {
+                $order_info = Dever::db('act/order')->one(array('order_id' => $info['order_id']));
+                if (!$order_info) {
+                    Dever::alert('您要使用的兑换码还未支付');
+                }
+
+                if ($order_info && $order_info['status'] != 2) {
+                    Dever::alert('您要使用的兑换码还未支付');
+                }
+            }
+
+            Dever::db('code/info')->update(array('where_id' => $info['id'], 'type' => 3, 'uid' => $this->data['uid'], 'ldate' => time()));
+
+            # 订阅
+            Dever::load('act/lib/subscribe')->submit($this->data['uid'], $journal_id, 2);
+
+        } else {
+            Dever::alert('请输入正确的兑换码');
+        }
+
+        return 'ok';
+    }
+
+    private function createOrder($prefix = 'JC')
+    {
+        $order = Dever::order($prefix);
+
+        //$order = Dever::rand(2, 2) . Dever::rand(6, 0);
+
+        $info = Dever::db('journal/order')->one(array('order_id' => $order));
+
+        if ($info) {
+            return $this->createOrder($prefix);
+        }
+
+        return $order;
+    }
+}

+ 27 - 3
code/database/info.php

@@ -39,14 +39,23 @@ $cate = function() use ($auth)
     return $array;
 };
 
+$name = 'info';
+$create = true;
+$product_id = Dever::input('set_product_id');
+if ($product_id && $product_id > 0) {
+	$name .= '_' . $product_id;
+	$create = false;
+}
+
 return array
 (
 	# 表名
-	'name' => 'info',
+	'name' => $name,
 	# 显示给用户看的名称
 	'lang' => '兑换码列表',
 	'menu' => 'journal',
 	'order' => 1,
+	'create' => $create,
 	# 数据结构
 	'struct' => array
 	(
@@ -288,11 +297,26 @@ return array
                 'state' => 1,
             ),
             'type' => 'all',
-            'order' => array('cdate' => 'desc'),
+            'order' => array('id' => 'desc'),
             'page' => array(30, 'list'),
             'col' => '*',
         ),
 
+        'getMyAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'order_id' => 'yes',
+                'create_uid' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'page' => array(10, 'list'),
+            'col' => 'code,type',
+        ),
+
         'getData' => array
         (
             # 匹配的正则或函数 选填项
@@ -303,7 +327,7 @@ return array
                 'state' => 1,
             ),
             'type' => 'all',
-            'order' => array('type' => 'desc', 'cdate' => 'desc'),
+            'order' => array('type' => 'desc', 'id' => 'desc'),
             'col' => '*',
         ),
     )

+ 11 - 15
code/lib/Core.php

@@ -6,15 +6,16 @@ use Dever;
 
 class Core
 {
-	public function createCodeByOrder($order)
+	public function createCodeByOrder($order, $num = 0)
 	{
 		$code = '';
         if ($order['type'] == 3 && !$order['code']) {
+        	Dever::setInput('set_product_id', $order['product_id']);
             # 购买兑换码
             $product_num = 1;
             $code_num = 1;
             if ($order['buy_id'] > 0) {
-                $buy = Dever::db('journal/buy_num')->one($order['buy_id']);
+                $buy = Dever::load('act/order')->getBuy($order['buy_id']);
                 $product_num = $buy['num'];
                 $code_num = $buy['code'];
             }
@@ -33,33 +34,28 @@ class Core
 
             if ($code_num > 1) {
                 $product_num = intval($product_num/$code_num);
-                for ($i = 0; $i < $code_num; $i++) {
-                    $code = $this->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $order['uid'], $order['order_id']);
+
+                if ($num < 0) {
+                	$code = $this->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $order['uid'], $order['order_id'], 0, 3, 1);
                 }
+                $this->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $order['uid'], $order['order_id'], 0, 1, $code_num + $num);
             } else {
-                $code = $this->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $order['uid'], $order['order_id']);
+                $code = $this->createCode($order['cate_id'] . ',' . $order['product_id'], $order['cate_id'], $order['product_id'], $order['seller_id'], $product_num, $order['uid'], $order['order_id'], 0, 3);
             }
         }
 
         return $code;
 	}
 
-	public function createCode($product, $cate_id, $product_id, $seller_id, $product_num = 0, $create_uid = -1, $order_id = false, $score = 0)
+	public function createCode($product, $cate_id, $product_id, $seller_id, $product_num = 0, $create_uid = -1, $order_id = false, $score = 0, $type = 1, $num = 1)
 	{
-		$code = Dever::rand(8, 0);
-		$data['code'] = $code;
-		$total = Dever::db('code/info')->total($data);
-		if ($total > 0) {
-			return $this->createCode($product, $cate_id, $product_id, $seller_id, $product_num, $create_uid, $order_id, $score);
-		}
-		
 		//$data['product'] = $product;
 		$data['cate_id'] = $cate_id;
 		$data['product_id'] = $product_id;
 		$data['seller_id'] = $seller_id;
 		$data['product_num'] = $product_num;
 		
-		$data['type'] = 1;
+		$data['type'] = $type;
 		if ($order_id) {
 			$data['order_id'] = $order_id;
 		}
@@ -67,7 +63,7 @@ class Core
 			$data['create_uid'] = $create_uid;
 		}
 		$data['score'] = $score;
-		Dever::db('code/info')->insert($data);
+		$code = Dever::db('code/info')->insert($data, $num);
 		return $code;
 	}
 }

+ 28 - 1
config/env/localhost/default.php

@@ -49,6 +49,32 @@ $config['database'] = array
     )
 );
 
+$dc['mysql_user'] = array
+(
+    'host' => array
+    (
+        'read' => 'web-mysql:3306',
+        'update' => 'web-mysql:3306',
+    ),
+    'database' => 'wonderful',
+    'username' => 'root',
+    'password' => '123456',
+);
+
+
+# 设置哪些项目需要切换到弹性数据库
+if (isset($dc['mysql_user'])) {
+    $dc['mysql_user']['charset'] = 'utf8';
+    $dc['mysql_user']['database'] = 'wonderful_v1';
+    $dc['mysql_user']['type'] = 'pdo';
+    $config['database']['code'] = $dc['mysql_user'];
+    $config['database']['act'] = $dc['mysql_user'];
+    $config['database']['passport'] = $dc['mysql_user'];
+    $config['database']['pay'] = $dc['mysql_user'];
+    $config['database']['score'] = $dc['mysql_user'];
+    $config['database']['score'] = $dc['mysql_user'];
+}
+
 # 缓存配置
 $config['cache'] = array
 (
@@ -65,7 +91,7 @@ $config['cache'] = array
     # 启用路由缓存
     'route' => 0,
 
-    # 缓存精细控制,可以根据缓存的key(mysql为表名、service为小写类名,规则是模糊匹配),来控制每一条缓存
+    # 缓存精细控制,根据uri来控制,0则无需缓存
     'routeKey' => array
     (
         'journal.buy_action' => 0,
@@ -78,6 +104,7 @@ $config['cache'] = array
         'service_my_code' => 0,
         'service_buy.pay' => 0,
         'vip_' => 0,
+        'order.' => 0,
     ),
 
     # 哪些路由中的参数不参与生成缓存的key

+ 309 - 0
doc/apidoc_v1.php

@@ -0,0 +1,309 @@
+<?php 
+/**
+ * @api {get} wonderful/passport/?l=applet.login 用户登录
+ * @apiVersion 2.0.0
+ * @apiName applet.login
+ * @apiGroup AppletPassport
+ *
+ * @apiDescription 用户登录
+ *
+ * @apiParam {String} code 微信登录返回的code
+ * @apiParam {String} nickname 用户昵称
+ * @apiParam {String} avatarurl 用户头像
+ * @apiParam {String} gender 性别
+ * @apiParam {String} city 城市
+ * @apiParam {String} province 省份
+ * @apiParam {String} country 县区
+ * @apiParam {String} iv 微信的加密参数
+ * @apiParam {String} encryptedData 微信的加密参数
+ *
+ * @apiSuccess {Number}   vid  微信id,请保存在本地
+ * @apiSuccess {Number}   uid  用户id,请保存在本地
+ * @apiSuccess {String}   signature 用于登录后的uid验证,每次都要传入,请登录后将这个值保存在本地
+ */
+
+/**
+ * @api {get} wonderful/main/?l=journal_v1.getList 小刊列表
+ * @apiVersion 2.0.0
+ * @apiName journal.getList
+ * @apiGroup Journal
+ *
+ * @apiDescription 小刊列表,按照分类读取
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {String} system 分类id,默认为1,传入-1就是获取全部
+ *
+ * @apiSuccess {Object[]} journal 小刊数据列表
+ * @apiSuccess {String}   journal.id 小刊id
+ * @apiSuccess {String}   journal.name 名称
+ * @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_gd 小刊推广图
+ * @apiSuccess {String}   journal.pdate 时间
+ * @apiSuccess {String}   journal.num_ding 订阅数
+ * @apiSuccess {String}   journal.buy 小刊是否收费 1收费 2免费 3会员
+ * @apiSuccess {String}   journal.bgmusic 小刊背景音乐
+ *
+ * @apiSuccess {Object[]} push 主推小刊
+ * @apiSuccess {String}   push.id 小刊id
+ * @apiSuccess {String}   push.name 名称
+ * @apiSuccess {String}   push.num_ding 订阅数
+
+ * @apiSuccess {Object[]} cate 当前分类
+ * @apiSuccess {String}   cate.id 分类id
+ * @apiSuccess {String}   cate.name 名称
+
+ * @apiSuccess {Object[]} cateList 分类列表
+ * @apiSuccess {String}   cateList.id 分类id
+ * @apiSuccess {String}   cateList.name 名称
+ */
+
+/**
+ * @api {get} wonderful/act/?l=order.getMyList 我的订单列表
+ * @apiVersion 2.0.0
+ * @apiName order.getMyList
+ * @apiGroup UserAction
+ *
+ * @apiDescription 我的订单列表
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {String} system 分类id
+ *
+ * @apiSuccess {Object[]} order 订单信息
+ * @apiSuccess {String}   order.name 名称
+ * @apiSuccess {String}   order.order_id 订单id
+ * @apiSuccess {String}   order.buy_num 购买本数
+ * @apiSuccess {String}   order.cdate 购买时间
+ */
+
+/**
+ * @api {get} wonderful/act/?l=order.getMyCodeList 我的兑换码列表
+ * @apiVersion 2.0.0
+ * @apiName order.getMyCodeList
+ * @apiGroup UserAction
+ *
+ * @apiDescription 我的兑换码列表
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {String} order_id 订单id
+ *
+ * @apiSuccess {Object[]} code 兑换码列表
+ * @apiSuccess {String}   code.code 兑换码
+ * @apiSuccess {String}   code.type 类型 1为未使用 3为已使用 4为已作废
+ */
+
+/**
+ * @api {get} wonderful/main/?l=journal_v1.read 小刊阅读页
+ * @apiVersion 2.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关联直播、4全屏视频、5留言视频、6留言音频|||新增:7长屏图、8横屏图、9无边框图片、10四宫格图片、21对话模板
+ * @apiSuccess {String}   content.name 标题。type=5,6时有效
+ * @apiSuccess {String}   content.cover 音频或者视频的封面图,type=4,5,6时有效
+ * @apiSuccess {String}   content.video 视频地址。type=4,5时有效
+ * @apiSuccess {String}   content.music 音频地址。type=6时有效
+ * @apiSuccess {String}   content.pic 全屏图或者长图,type=1,2,7,8,9时有效
+ * @apiSuccess {String}   content.pic_info 全屏图或者长图的图片信息,type=1,2,7,8,9时有效,值如1024_768_548.12_35,请用_分隔成数组使用,1024为宽度,768为高度,548.12为图片大小,35为图片id
+ * @apiSuccess {String}   content.is_button 全屏图上的保存按钮,1显示2不显示,type=1时有效
+ * @apiSuccess {String}   content.button_name 全屏图上的保存按钮的文字,type=1时有效
+ * @apiSuccess {String}   content.button_color 全屏图上的保存按钮的文字颜色,type=1时有效
+ * @apiSuccess {String}   content.note 是否预约提醒1为已预约,2为未预约
+ * @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.bgcolor_type 是否设置文字背景颜色,1设置,2不设置,不设置则文字背景颜色为透明。
+ * @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 作者
+
+ * @apiSuccess {Object[]}   content.palaces 四宫格图片的四个图片,type=10时有效
+ * @apiSuccess {String}   content.palaces.palaces 图片位置,1上左2上右3下左4下右
+ * @apiSuccess {String}   content.palaces.pic 图片
+
+ * @apiSuccess {String}   content.talk_pic 对话模板的置顶图片,为空则不显示,type=21时有效
+ * @apiSuccess {Object[]}   content.talk 对话模板里的对话内容,type=21时有效
+ * @apiSuccess {String}   content.talk.talk_location 对话位置,12
+ * @apiSuccess {String}   content.talk.talk_type 对话类型,1文字,2图片,3音频
+ * @apiSuccess {String}   content.talk.avatar 头像
+ * @apiSuccess {String}   content.talk.text 文字
+ * @apiSuccess {String}   content.talk.pic 图片
+ * @apiSuccess {String}   content.talk.audio 音频
+ */
+
+/**
+ * @api {get} wonderful/main/?l=journal_v1.view 小刊详情页
+ * @apiVersion 2.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.pic_gd 小刊推广图
+ * @apiSuccess {String}   info.pdate 时间
+ * @apiSuccess {String}   info.ydate 预售时间
+ * @apiSuccess {String}   info.ytype 预售状态,1为可以阅读2显示预售弹窗,如果用button就不用判断该字段了
+ * @apiSuccess {String}   info.num_ding 订阅数
+ * @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为兑换 3为预售
+ * @apiSuccess {String}   button.read.name 按钮上的名字
+ * @apiSuccess {Object[]}   button.buy 第二个按钮 购买按钮
+ * @apiSuccess {String}   button.code.status 状态 -1不显示 1为购买
+ * @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_v1.active 小刊活动页
+ * @apiVersion 2.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.status 活动状态 1活动进行中 2活动已结束
+ * @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 活动说明,富文本
+
+  * @apiSuccess {Object[]}   invite 我的邀请
+ * @apiSuccess {String}   invite.uid 用户id
+ * @apiSuccess {String}   invite.username 用户名
+ * @apiSuccess {String}   invite.avatar 头像
+
+ * @apiSuccess {String}   buy 是否显示购买按钮,1显示,2不显示
+ */
+
+/**
+ * @api {get} wonderful/main/?l=journal_v1.buy 小刊购买页
+ * @apiVersion 2.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/act/?l=order.pay 发起支付
+ * @apiVersion 2.0.0
+ * @apiName order.pay
+ * @apiGroup UserAction
+ *
+ * @apiDescription 发起支付:请注意,如果是苹果支付,请在发起苹果支付之后,将苹果返回的验证数据,传入该接口
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {String} journal_id 小刊id
+ * @apiParam {String} buy_id 购买本数id
+ * @apiParam {String} receipt 当header中的source_type为ios时,请传入该参数,参数的值为苹果支付后返回的参数,即可发起支付验证。
+*
+ * @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 签名
+ * @apiSuccess {String}   pay.yes 苹果支付时显示改参数,1为支付成功2为支付失败
+ */
+
+/**
+ * @api {get} wonderful/act/?l=order.code 兑换码兑换
+ * @apiVersion 2.0.0
+ * @apiName order.code
+ * @apiGroup UserAction
+
+ * @apiDescription 兑换码兑换
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {String} journal_id 小刊id
+ * @apiParam {String} code 兑换码
+ *
+ * @apiSuccess {String}   ok 兑换成功
+ */
+
+/**
+ * @api {get} wonderful/main/?l=journal_v1.top 小刊本数排行榜
+ * @apiVersion 2.0.0
+ * @apiName journal.top
+ * @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[]}   top 本数排行
+ * @apiSuccess {String}   top.uid 用户id
+ * @apiSuccess {String}   top.num 本数
+ * @apiSuccess {String}   top.username 用户名
+ * @apiSuccess {String}   top.avatar 头像
+  *
+ * @apiSuccess {Object[]}   active 活动说明表
+ * @apiSuccess {String}   active.name 名称
+ * @apiSuccess {String}   active.status 活动状态 1活动进行中 2活动已结束
+ * @apiSuccess {String}   active.desc 描述
+ * @apiSuccess {String}   active.invite_title 邀请好友标题
+ * @apiSuccess {String}   active.invite_desc 邀请好友描述 换行用\n隔开
+ * @apiSuccess {String}   active.content 活动说明,富文本
+ */

BIN
doc/mobile.xlsx


+ 1 - 1
journal/database/cate.php

@@ -25,7 +25,7 @@ $type = array
     21 => '对话模板',
 
     # 关联类型 > 10
-    11 => '关联图文',
+    //11 => '关联图文',
     12 => '关联视频',
     13 => '关联直播',
 );

+ 14 - 0
journal/database/info.php

@@ -339,6 +339,20 @@ $config = array
 			'auth'		=> '"{pdate}" > 0',
 		),
 
+		'ydate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '预售时间',
+			'match' 	=> 'option',
+			'default'	=> '',
+			'desc' 		=> '',
+			'update'	=> 'date',
+			'callback'	=> 'maketime',
+			'insert'	=> true,
+			//'list'		=> 'date("Y-m-d H:i:s", {pdate})',
+			'auth'		=> '"{ydate}" > 0',
+		),
+
 		'share'		=> array
 		(
 			'type' 		=> 'text-255',

+ 4 - 0
journal/lib/Pay.php

@@ -7,6 +7,8 @@ class Pay
 {
     private $key = 'jmss_2018';
 
+    
+    /*
     public function go_api()
     {
         $where['code'] = 'null';
@@ -49,7 +51,9 @@ class Pay
         $data['status'] = 1;
         $this->order(1, 'test', $data);
     }
+    */
 
+    # 退款操作
     public function order($id, $name, $data)
     {
         $status = Dever::param('status', $data);

+ 7 - 1
main/lib/Core.php

@@ -22,7 +22,13 @@ class Core
         //$this->data['uid'] = 1;
 
         # 获取基本配置
-        $this->data['config'] = Dever::db('main/config')->one();
+        $key = 'config';
+        $this->data['config'] = Dever::cache($key);
+        if (!$this->data['config']) {
+            $this->data['config'] = Dever::db('main/config')->one();
+            Dever::cache($key, $this->data['config']);
+        }
+        
         $this->data['system'] = Dever::input('system', 1);
 
         $this->source_type = Dever::input('source_type');

+ 527 - 0
main/src/Journal_v1.php

@@ -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);
+            }
+        }
+
+        # 仅app有效
+        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 {
+        	# 小程序下的判断,ios里关闭支付
+	        $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);
+	            //$this->setButton('share', -1);
+	        }
+        }
+    }
+
+    private function setButton($key = false, $status = false, $name = false)
+    {
+        # 按钮状态,-1为不显示
+        if (!$this->data['button']) {
+            $this->data['button'] = array
+            (
+                # 第一个按钮 1为阅读、2为兑换、3为预售
+                '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);
+
+        # 默认不能看 为1则可以直接看了,为2则不能看,要验证权限,为了高效并发,暂时去掉验证
+        $subscribe = 2;
+
+        if ($subscribe == 2) {
+        	# APP专用
+	        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('未订阅');
+	        }
+        }
+
+        # 获取最新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'] = 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;
+            //音频先不转码
+            //$info['music'] = convert($info['music'], 'mp3', 'journal/content', $info['id'], 'music');
+        } 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;
+    }
+}

+ 20 - 0
score/database/action_log.php

@@ -18,6 +18,13 @@ $score_type = array
 	3 => '达到积分上限',
 );
 
+$cron_type = array
+(
+	1 => '未开始',
+	2 => '进行中',
+	3 => '已完成',
+);
+
 return array
 (
 	# 表名
@@ -83,6 +90,19 @@ return array
 			'list'		=> true,
 		),
 
+		'cron_type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '是否增加积分',
+			'default' 	=> '1',
+			'desc' 		=> '是否增加积分',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $score_type,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
 		'score'		=> array
 		(
 			'type' 		=> 'varchar-30',

+ 11 - 0
score/database/user_log.php

@@ -94,6 +94,17 @@ return array
 			'list'		=> true,
 		),
 
+		'action_log_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所属行为日志',
+			'default' 	=> '1',
+			'desc' 		=> '所属行为日志',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
 		'status'        => array
         (
             'type'      => 'tinyint-1',

+ 10 - 6
score/lib/Core.php

@@ -31,9 +31,10 @@ class Core
 			if ($num > 0) {
 				$insert['num'] = $num;
 			}
+			$insert['cron_type'] = 1;
 			$log_id = Dever::db('score/action_log')->insert($insert);
 
-			Dever::daemon('lib/core.oper?log_id='.$log_id, 'score');
+			//Dever::daemon('lib/core.oper?log_id='.$log_id, 'score');
 			//Dever::load('score/lib/core.oper?log_id='.$log_id);
 		}
 	}
@@ -70,6 +71,7 @@ class Core
 			$info['num'] = $info['num'] * $log['num'];
 		}
 		if ($info['num'] == 0) {
+			Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'cron_type' => 3));
 			return;
 		}
 
@@ -88,11 +90,11 @@ class Core
 		if ($info['upper'] == 2 && $info['upper_limit'] >= 1) {
 			$upper = $this->upper($uid, $info, $log);
 			if (!$upper) {
-				Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'score_type' => 3, 'score' => '0'));
+				Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'score_type' => 3, 'cron_type' => 3, 'score' => '0'));
 				return;
 			}
 		}
-		Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'score_type' => 2, 'score' => $num));
+		Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'score_type' => 2, 'cron_type' => 3, 'score' => $num));
 
 		$update = array();
 		$update['where_id'] = $user['id'];
@@ -100,6 +102,7 @@ class Core
 
 		$insert['uid'] = $uid;
 		$insert['config_id'] = $info['config_id'];
+		$insert['action_log_id'] = $log['id'];
 		$insert['action_id'] = $info['action_id'];
 		$insert['status'] = 1;
 		$insert['num'] = $num;
@@ -161,7 +164,8 @@ class Core
 
 	private function operAction($log)
 	{
-		if ($log && $log['score_type'] == 1) {
+		if ($log && $log['cron_type'] == 1) {
+			Dever::db('score/action_log')->update(array('where_id' => $log['id'], 'cron_type' => 2));
 			$where = array();
 			$where['state'] = 1;
 			$where['id'] = $log['action_id'];
@@ -180,13 +184,13 @@ class Core
 	}
 
     /**
-	 * 根据积分日志和规则,增加积分,这是一个定时任务,暂时不开启了
+	 * 根据积分日志和规则,增加积分,这是一个定时任务,可以设置每天凌晨启动
 	 *
 	 * @return mixed
 	 */
 	public function cron()
 	{
-		$where['score_type'] = 1;
+		$where['cron_type'] = 1;
 		$log = Dever::db('score/action_log')->all($where);
 		if ($log) {
 			foreach ($log as $k => $v) {