rabin 4 years ago
parent
commit
b6aebc963d

+ 163 - 0
app/source/database/info.php

@@ -0,0 +1,163 @@
+<?php
+
+$link = function()
+{
+	$array = array
+	(
+		-1 => array('id' => -1, 'name' => '通用'),
+	);
+	$info = Dever::db('source/link')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+$cate = function()
+{
+	$array = array();
+	$info = Dever::db('journal/cate')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+$type = array
+(
+	//1 => '购买小刊',
+	2 => '购买小刊兑换码',
+	3 => '购买VIP会员',
+);
+
+return array
+(
+	# 表名
+	'name' => 'info',
+	# 显示给用户看的名称
+	'lang' => '渠道管理',
+	'order' => 10,
+	'end' => array
+	(
+		'insert' => 'source/lib/manage.updateCode',
+		'update' => 'source/lib/manage.updateCode',
+	),
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '名称',
+			'default' 	=> '',
+			'desc' 		=> '请输入名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'cate_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '小刊分类',
+			'default' 	=> '1',
+			'desc' 		=> '小刊分类',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $cate,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '类型',
+			'default' 	=> '1',
+			'desc' 		=> '类型',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $type,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'link_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '推广链接',
+			'default' 	=> '-1',
+			'desc' 		=> '推广链接',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $link,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'code'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '渠道链接',
+			'default' 	=> '',
+			'desc' 		=> '渠道链接',
+			'match' 	=> 'option',
+			//'update'	=> 'textarea',
+			//'list'		=> 'Dever::load("source/lib/manage.show", "{id}")',
+			'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,
+		),
+	),
+
+	# 默认值
+	'default' => array
+	(
+		'col' => 'name,link_id,state,cdate',
+		'value' => array
+		(
+			'"官方",-1,1,' . time(),
+		),
+	),
+
+	'manage' => array
+	(
+		//'delete' => false,
+		//'edit' => false,
+		# 列表
+		'list_buttons' => array
+		(
+			//'list' => array('渠道统计', '"stat&search_option_info_id={id}&oper_parent=info"'),
+		),
+	),
+);

+ 96 - 0
app/source/database/link.php

@@ -0,0 +1,96 @@
+<?php
+
+$type = array
+(
+	1 => 'H5',
+	//2 => '小程序',
+);
+
+return array
+(
+	# 表名
+	'name' => 'link',
+	# 显示给用户看的名称
+	'lang' => '推广链接管理',
+	'order' => 1,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-80',
+			'name' 		=> '名称',
+			'default' 	=> '',
+			'desc' 		=> '请输入名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '类型',
+			'default' 	=> '1',
+			'desc' 		=> '类型',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $type,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'link'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '链接或路径-填写完整的h5链接或者小程序路径',
+			'default' 	=> '',
+			'desc' 		=> '链接或路径',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'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,
+		),
+	),
+
+	'manage' => array
+	(
+		//'delete' => false,
+		//'edit' => false,
+		# 列表
+		'list_button' => array
+		(
+			//'list' => array('渠道列表', '"info&search_option_link_id={id}&oper_parent=link"'),
+		),
+	),
+);

+ 134 - 0
app/source/database/user.php

@@ -0,0 +1,134 @@
+<?php
+
+$source = function()
+{
+	$array = array();
+	$info = Dever::db('source/info')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+return array
+(
+	# 表名
+	'name' => 'user',
+	# 显示给用户看的名称
+	'lang' => '渠道用户',
+	'order' => 10,
+	'menu'	=> false,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'vid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '第三方ID',
+			'default' 	=> '',
+			'desc' 		=> '第三方id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户ID',
+			'default' 	=> '',
+			'desc' 		=> '用户id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'source_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '渠道',
+			'default' 	=> '',
+			'desc' 		=> '渠道',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'option'	=> $source,
+			'search'	=> 'select',
+			'list'		=> true,
+		),
+
+		'account_type'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '账户类型',
+			'default' 	=> '',
+			'desc' 		=> 'account_type',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'account_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '账户ID',
+			'default' 	=> '',
+			'desc' 		=> 'account_id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'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,
+		),
+	),
+
+	'manage' => array
+	(
+		'delete' => false,
+		'edit' => false,
+		//'insert' => false,
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getTotal' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'source_id' => 'yes',
+				'start' => array('yes-cdate', '>='),
+				'end' => array('yes-cdate', '<='),
+				'state' => 1,
+			),
+			'type' => 'count',
+		),
+	),
+);

+ 8 - 0
app/source/index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'source');
+define('DEVER_APP_LANG', '渠道来源');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 10);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-credit-card layui-icon-cellphone');
+include(DEVER_APP_PATH . '../boot.php');

+ 95 - 0
app/source/lib/Core.php

@@ -0,0 +1,95 @@
+<?php
+
+namespace Source\Lib;
+
+use Dever;
+
+class Core
+{
+    private $key = 'source';
+
+    /**
+     * 记录用户信息
+     *
+     * @return mixed
+     */
+    public function saveUser($vid, $uid, $source_id, $account_type, $account_id)
+    {
+    	$data['vid'] = $vid;
+    	$data['uid'] = $uid;
+    	$data['source_id'] = $source_id;
+    	$data['account_type'] = $account_type;
+    	$data['account_id'] = $account_id;
+
+    	$info = Dever::db('source/user')->one($data);
+
+    	if (!$info) {
+    		Dever::db('source/user')->insert($data);
+    	}
+
+        return true;
+    }
+
+    /**
+     * 日志记录
+     *
+     * @return mixed
+     */
+    public function save($uid, $type, $source_id, $log = array())
+    {
+        return;
+    	$log += Dever::input();
+        $url = Dever::url();
+
+        $log['uid'] = $uid;
+        $log['source_id'] = $source_id;
+        $log['url'] = $url;
+        $log['ip'] = Dever::ip();
+
+        Dever::log($log, $this->key . '/' . $source_id . '/' . $type);
+
+        return true;
+    }
+
+    public function get($day, $type, $source_id, $start = 0, $end = 0)
+    {
+        $log = Dever::getLog($day, $this->key . '/' . $source_id . '/' . $type);
+        $source = array();
+        $source['pv'] = 0;
+    	$source['uv'] = 0;
+    	$source['user_num'] = 0;
+    	$source['user_yes_num'] = 0;
+        if ($log) {
+        	$result = array();
+        	$pv = $uv = 0;
+        	$user = array();
+        	foreach ($log as $k => $v) {
+        		if ($v) {
+        			$temp = explode('dever&', $v);
+        			$info = explode(' ', $temp[0]);
+        			$result[$k]['time'] = $info[0];
+        			$result[$k]['project'] = $info[1];
+        			$result[$k]['app'] = $info[2];
+        			parse_str($temp[1], $result[$k]['param']);
+        			$pv++;
+        			if (isset($result[$k]['param']['uid']) && $result[$k]['param']['uid'] > 0) {
+        				$user[$result[$k]['param']['uid']] = 1;
+        			} else {
+        				$user[$result[$k]['param']['ip']] = 1;
+        			}
+        		}
+        	}
+        	$source['pv'] = $pv;
+        	$source['uv'] = count($user);
+
+        	if ($start && $end) {
+        		$where['source_id'] = $source_id;
+	        	$where['start'] = $start;
+	        	$where['end'] = $end;
+	        	$source['user_num'] = Dever::db('source/user')->getTotal($where);
+	        	$source['user_yes_num'] = $source['user_num'];
+        	}
+        }
+        return $source;
+    }
+}

+ 50 - 0
app/source/lib/Manage.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace Source\Lib;
+
+use Dever;
+
+class Manage
+{
+	/**
+	 * 显示信息
+	 *
+	 * @return mixed
+	 */
+	public function show($id)
+	{
+		$info = Dever::db('source/info')->one($id);
+		$link = Dever::db('source/link')->one($id);
+
+		return '';
+	}
+
+	public function updateCode($id, $name, $param)
+	{
+		$cate_id = Dever::param('cate_id', $param);
+		$type = Dever::param('type', $param);
+		$link_id = Dever::param('link_id', $param);
+		$link = Dever::db('source/link')->one($link_id);
+		if (!$link) {
+			$link['link'] = Dever::url('home', 'buy');
+		}
+
+		$send['cate'] = $cate_id;
+    	$send['source'] = $id;
+        $send['type'] = $type;
+        $send['seller'] = 1;
+        $key = 'jmbuybuybuyv1';
+        $param = array();
+        $param['p'] = Dever::encode(Dever::json_encode($send), $key);
+
+    	$param = http_build_query($param);
+    	if (strstr($link['link'], '?')) {
+    		$url = $link['link'] . '&' . $param;
+    	} else {
+    		$url = $link['link'] . '?' . $param;
+    	}
+    	
+
+    	Dever::db('source/info')->update(array('where_id' => $id, 'code' => $url));
+	}
+}