dever 6 years ago
parent
commit
965d8f138d

+ 135 - 0
act/database/invite.php

@@ -0,0 +1,135 @@
+<?php
+
+$table = Dever::config('base')->type;
+
+return array
+(
+	# 表名
+	'name' => 'score',
+	# 显示给用户看的名称
+	'lang' => '积分排行榜',
+	# 是否显示在后台菜单
+	'order' => 1,
+	'menu' => false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'order'		=> 'desc',
+			//'list'		=> true,
+		),
+		
+		'source_uid'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '邀请者',
+            'default'   => '',
+            'desc'      => '邀请者',
+            'match'     => 'option',
+            'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+            'list'      => '{source_uid} > 0 ? Dever::load("passport/user-one#username", {source_uid}) : "匿名用户"',
+        ),
+
+		'type' 		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '订阅类别',
+			'default' 	=> '',
+			'desc' 		=> '订阅类别',
+			'match' 	=> 'option',
+			'update'	=> 'select',
+			//'search'	=> 'select',
+			'option' 	=> $table,
+			//'list'		=> true,
+		),
+		
+		'data_id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '标题',
+			'default' 	=> '',
+			'desc' 		=> '标题',
+			'update'	=> 'text',
+			'match' 	=> 'option',
+			'list'		=> 'Dever::load("act/lib/manage.load", "{type}", {data_id})',
+		),
+
+		'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}) : "匿名用户"',
+		),
+		
+		'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,
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'source_uid' => 'yes',
+				'uid' => 'yes',
+				'data_id' => 'yes',
+				'type' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'page' => array(10, 'list'),
+			'col' => '*',
+		),
+	)
+);

+ 130 - 0
act/database/score.php

@@ -0,0 +1,130 @@
+<?php
+
+$table = Dever::config('base')->type;
+
+return array
+(
+	# 表名
+	'name' => 'score',
+	# 显示给用户看的名称
+	'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}) : "匿名用户"',
+		),
+
+		'type' 		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '订阅类别',
+			'default' 	=> '',
+			'desc' 		=> '订阅类别',
+			'match' 	=> 'option',
+			'update'	=> 'select',
+			//'search'	=> 'select',
+			'option' 	=> $table,
+			//'list'		=> true,
+		),
+		
+		'data_id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '标题',
+			'default' 	=> '',
+			'desc' 		=> '标题',
+			'update'	=> 'text',
+			'match' 	=> 'option',
+			'list'		=> 'Dever::load("act/lib/manage.load", "{type}", {data_id})',
+		),
+
+		'score' 		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'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,
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'data_id' => 'yes',
+				'type' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('score' => 'desc','id' => 'desc'),
+			'page' => array(10, 'list'),
+			'col' => '*',
+		),
+	)
+);

+ 20 - 0
act/database/subscribe.php

@@ -1,6 +1,13 @@
 <?php
 
 $table = Dever::config('base')->type;
+
+$source = array
+(
+	1 => '购买',
+	2 => '兑换码',
+	3 => '邀请活动',
+);
 return array
 (
 	# 表名
@@ -65,6 +72,19 @@ return array
 			'match' 	=> 'option',
 			'list'		=> 'Dever::load("act/lib/manage.load", "{type}", {data_id})',
 		),
+
+		'source' 		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '来源',
+			'default' 	=> '',
+			'desc' 		=> '来源',
+			'match' 	=> 'option',
+			'update'	=> 'select',
+			'search'	=> 'select',
+			'option' 	=> $source,
+			'list'		=> true,
+		),
 		
 		'state'		=> array
 		(

+ 50 - 0
act/lib/Invite.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace Act\Lib;
+
+use Dever;
+
+class Invite
+{
+    # 获取小刊的邀请排行
+    public function getList($uid, $id, $type = 4)
+    {
+    	$where['source_uid'] = $uid;
+        $where['type'] = $type;
+        $where['data_id'] = $id;
+        $data = Dever::db('act/invite')->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'];
+            }
+        }
+        return $data;
+    }
+
+    public function submit($uid, $id, $source = 1, $type = 4)
+    {
+        $where['uid'] = $uid;
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $table = 'act/invite';
+        $info = Dever::db($table)->one($where);
+        if (!$info) {
+            $where['source'] = $source;
+            Dever::db($table)->insert($where);
+        }
+
+        # 更新订阅数
+        $where = array();
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $where['state'] = 1;
+        $total = Dever::db($table)->total($where);
+        $table = Dever::config('base')->type_table[$type];
+        Dever::db($table)->update(array('where_id' => $id, 'num_ding' => $total));
+
+        return true;
+    }
+}

+ 65 - 0
act/lib/Score.php

@@ -0,0 +1,65 @@
+<?php
+
+namespace Act\Lib;
+
+use Dever;
+
+class Score
+{
+    # 获取我在这个小刊中的积分
+    public function get($id, $uid, $type = 4)
+    {
+        $where['uid'] = $uid;
+        $where['type'] = $type;
+        $where['data_id'] = $id;
+        $where['state'] = 1;
+        $data = Dever::db('act/score')->one($where);
+
+        if ($data) {
+            return $data['score'];
+        } else {
+            return 0;
+        }
+    }
+    
+    # 获取小刊的积分排行
+    public function getList($id, $type = 4)
+    {
+        $where['type'] = $type;
+        $where['data_id'] = $id;
+        $data = Dever::db('act/score')->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'];
+            }
+        }
+        return $data;
+    }
+
+    public function submit($uid, $id, $source = 1, $type = 4)
+    {
+        $where['uid'] = $uid;
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $table = 'act/score';
+        $info = Dever::db($table)->one($where);
+        if (!$info) {
+            $where['source'] = $source;
+            Dever::db($table)->insert($where);
+        }
+
+        # 更新订阅数
+        $where = array();
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $where['state'] = 1;
+        $total = Dever::db($table)->total($where);
+        $table = Dever::config('base')->type_table[$type];
+        Dever::db($table)->update(array('where_id' => $id, 'num_ding' => $total));
+
+        return true;
+    }
+}

+ 2 - 1
act/lib/Subscribe.php

@@ -40,7 +40,7 @@ class Subscribe
     }
 
     # 订阅
-    public function submit($uid, $id, $type = 4)
+    public function submit($uid, $id, $source = 1, $type = 4)
     {
         $where['uid'] = $uid;
         $where['data_id'] = $id;
@@ -48,6 +48,7 @@ class Subscribe
         $table = 'act/subscribe';
         $info = Dever::db($table)->one($where);
         if (!$info) {
+            $where['source'] = $source;
             Dever::db($table)->insert($where);
         }
 

+ 1 - 1
config/base.php

@@ -66,7 +66,7 @@ $config['base'] = array
 		# 前面的索引为前端传过来的值
 		2 => 2,
 		1 => 1,
-		0 => 3,
+		3 => 3,
 	),
 	'mobileCode' => array
 	(

+ 11 - 0
doc/apidoc.php

@@ -37,6 +37,17 @@
  * @apiParam {Number} push_ 所有带push_开头的返回参数,返回字典都是一样的,参考获取首页数据中的push_focus
  */
 
+/**
+ * @api {post} upload/upload/?save.start 上传图片接口
+ * @apiVersion 1.0.0
+ * @apiName save.start
+ * @apiGroup Common
+ *
+ * @apiParam {Number} key 值为1,写死即可
+ * @apiParam {String} file 文件流 multipart/form-data形式
+ *
+ * @apiSuccess {String}   url  图片地址
+*/
 
 /**
  * @api {get} wonderful/passport/?l=applet.bind 用户登录

+ 10 - 0
journal/database/buy_num.php

@@ -73,6 +73,16 @@ return array
             'update'    => 'text',
         ),
 
+        'score'         => array
+        (
+            'type'      => 'varchar-80',
+            'name'      => '增加积分数-直接填写购买当前本数设置,用户能获得的积分',
+            'default'   => '',
+            'desc'      => '增加积分数',
+            'match'     => 'is_string',
+            'update'    => 'text',
+        ),
+
         'reorder'       => array
         (
             'type'      => 'int-11',

+ 22 - 15
journal/lib/Pay.php

@@ -10,24 +10,31 @@ class Pay
 	 *
 	 * @return mixed
 	 */
-	public function act($param)
+	public function act_api($param = array())
 	{
-		$product_id = $param['pay_product_id'];
-        $uid = $param['pay_uid'];
-        $cash = $param['pay_cash'];
-        $order_id = $param['pay_order_id'];
-        $status = $param['pay_status'];
-        $msg = $param['pay_msg'];
+        $send = Dever::preInput('pay_');
+        $key = md5('jmss_2018');
+        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('journal/order')->one(array('order_id' => $order_id, 'uid' => $uid));
+            $order = Dever::db('journal/order')->one(array('order_id' => $order_id, 'uid' => $uid));
 
-		if ($status == 2 && $order) {
-            Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 2));
-        } else {
-        	Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 3));
-        }
+            if ($send['pay_status'] == 2 && $order) {
+                Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 2));
 
-        # 订阅
-        Dever::load('act/lib/subscribe')->submit($uid, $product_id);
+                # 订阅
+                Dever::load('act/lib/subscribe')->submit($uid, $product_id, 1);
+            } else {
+                Dever::db('journal/order')->update(array('where_id' => $order['id'], 'status' => 3));
+            }
+        }
 	}
 }

+ 22 - 2
main/src/Journal.php

@@ -208,13 +208,25 @@ class Journal extends Core
     # 积分排行榜
     public function score()
     {
+        $id = $this->check();
+
+        $this->data['score'] = Dever::load('act/lib/score')->getList($id);
 
+        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;
     }
 
 
@@ -359,6 +371,14 @@ class Journal extends Core
         $user = Dever::db('passport/user')->one($this->data['uid']);
         $wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid']));
 
+        $source_type = Dever::input('source_type');
+
+        if ($source_type == 'ios' || $source_type == 'android') {
+            $method = 'app';
+        } elseif ($source_type == 'applet') {
+            $method = 'applet';
+        }
+
         $order_id = $this->createOrder('JP');
         $order_data['order_id'] = $order_id;
         $order_data['product_id'] = $journal_id;
@@ -394,7 +414,7 @@ class Journal extends Core
             'order_id' => $order_id,
         );
 
-        $this->data['pay'] = Dever::load('pay/api')->applet($param);
+        $this->data['pay'] = Dever::load('pay/api.' . $method, $param);
 
         if (isset($this->data['pay']['prepay_id'])) {
             Dever::setInput('form_id', $this->data['pay']['prepay_id']);
@@ -505,7 +525,7 @@ class Journal extends Core
             $id = Dever::db('journal/order')->insert($order_data);
 
             # 订阅
-            Dever::load('act/lib/subscribe')->submit($this->data['uid'], $journal_id);
+            Dever::load('act/lib/subscribe')->submit($this->data['uid'], $journal_id, 2);
 
         } else {
             Dever::alert('请输入正确的兑换码');