rabin 2 năm trước cách đây
mục cha
commit
2399d009b8

+ 2 - 0
database/config.php

@@ -333,7 +333,9 @@ return array
         'list_button' => array
         (
         	'list' => array('账户列表', '"info&set_config_id={id}&parent=config"'),
+        	'list3' => array('收益列表', '"profit&set_config_id={id}&parent=config"'),
         	'list1' => array('充值卡列表', '"config_card&set_config_id={id}&parent=config"'),
+        	'list2' => array('收益设置', '"config_profit&set_config_id={id}&parent=config"'),
         )
 	),
 

+ 1 - 1
database/config_card.php

@@ -30,7 +30,7 @@ return array
 			'desc' 		=> '账户id',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'hidden',
-			'value'		=> Dever::input('search_option_config_id'),
+			'value'		=> Dever::input('set_config_id'),
 		),
 
         'name'      => array

+ 144 - 0
database/config_profit.php

@@ -0,0 +1,144 @@
+<?php
+$status = array
+(
+	1 => '已结算',
+	2 => '未结算',
+);
+return array
+(
+    # 表名
+    'name' => 'config_profit',
+    # 显示给用户看的名称
+    'lang' => '钱包收益设置',
+    'menu' => false,
+    'check' => 'key',
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'        => true,
+        ),
+
+        'config_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '账户id',
+			'default' 	=> '',
+			'desc' 		=> '账户id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+			'value'		=> Dever::input('set_config_id'),
+		),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-150',
+            'name'      => '收益名称',
+            'default'   => '',
+            'desc'      => '收益名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'list'    	=> true,
+        ),
+
+        'key'		=> array
+		(
+			'type' 		=> 'varchar-50',
+			'name' 		=> '唯一标识',
+			'default' 	=> '',
+			'desc' 		=> '唯一标识',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+        'account/config_profit_rule'=> array
+		(
+			'name' 		=> '收益规则设置-“层级”为0是当前数值入库时的用户,输入1就是入库用户的直推上级,符合“条件”才能拿到收益[如{a}>1 && {a}<=100],根据“公式”可以计算出具体收益[如{a}*0.1]',
+			'default' 	=> '',
+			'desc' 		=> '收益规则设置',
+			'match' 	=> 'option',
+			'sync'		=> array('profit_id' => 'id'),
+			'update'	=> array(1),
+			'update_type' => 2,
+		),
+
+        'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			'search'	=> 'order',
+			'list_name' => '排序',
+			'list'		=> true,
+			'order'		=> 'desc',
+			'edit'		=> 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_name' => '交易时间',
+            'list'        => 'date("Y-m-d H:i", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+    	'desc' => '<blockquote class="layui-elem-quote">条件变量定义:<br />
+    	{a}:当前数值,如订单金额<br />
+    	{b}:用户ID,适合对某一特殊用户做收益操作<br />
+    	{c}:用户角色ID<br />
+    	{d}:为用户角色下的等级数值<br />
+        {e}:为当前层级用户的下一层子用户被分走的收益,如当前订单应分10元,我的下级分走了5元,我应该拿到5元,直接用{a}-{e}即可<br />
+    	后续新增更多,公式里仅支持{a}变量
+    	</blockquote>',
+
+        'link' => 'parent=config.config_profit',
+        //'insert' => false,
+        //'edit' => false,
+
+        # 自定义快捷新增和编辑
+        /*
+        'button' => array
+        (
+            '新增' => array('fast'),
+        ),
+        'list_button' => array
+        (
+            'edit' => array('编辑'),
+        )*/
+    ),
+
+    'request' => array
+    (
+        
+    ),
+);

+ 107 - 0
database/config_profit_rule.php

@@ -0,0 +1,107 @@
+<?php
+return array
+(
+	# 表名
+	'name' => 'config_profit_rule',
+	# 显示给用户看的名称
+	'lang' => '钱包收益规则设置',
+	'menu' => false,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+			'order'		=> 'asc',
+		),
+
+		'profit_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '收益id',
+			'default' 	=> '',
+			'desc' 		=> '收益id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+			'value'		=> Dever::input('search_option_profit_id'),
+		),
+
+		'level'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '层级',
+			'default' 	=> '0',
+			'desc' 		=> '层级',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+		),
+
+		'condition'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '条件',
+            'default'   => '',
+            'desc'      => '条件',
+            'match'     => 'is_string',
+            'update'    => 'text',
+        ),
+
+		'exp'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '公式',
+            'default'   => '',
+            'desc'      => '收益',
+            'match'     => 'is_string',
+            'update'    => 'text',
+        ),
+		
+		'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,
+
+        # 自定义快捷新增和编辑
+        'button' => array
+        (
+            '新增' => array('fast'),
+        ),
+		'list_button' => array
+        (
+        	'edit' => array('编辑'),
+        )
+	),
+
+	'request' => array
+	(
+		
+	)
+);

+ 2 - 14
database/info.php

@@ -1,24 +1,12 @@
 <?php
 $config = function()
 {
-	$array = array();
-	$info = Dever::db('account/config')->state();
-	if($info)
-	{
-		$array += $info;
-	}
-	return $array;
+	return Dever::db('account/config')->state();
 };
 
 $project = function()
 {
-	$array = array();
-	$data = Dever::load('account/config_project-state');
-	if($data)
-	{
-		$array += $data;
-	}
-	return $array;
+	return Dever::load('account/config_project-state');
 };
 
 $user = '用户ID';

+ 157 - 0
database/profit.php

@@ -0,0 +1,157 @@
+<?php
+return array
+(
+    # 表名
+    'name' => 'profit',
+    # 显示给用户看的名称
+    'lang' => '用户收益列表',
+    'order' => 100,
+    'menu' => false,
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            //'list'        => true,
+        ),
+
+        'uid'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '用户名称',
+            'default'   => '0',
+            'desc'      => '用户名称',
+            'match'     => 'is_numeric',
+            'list'      => 'Dever::load("account/lib/project.getUsername", {uid}, {config_id})',
+        ),
+
+        'config_id'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '账户名称',
+            'default'   => '1',
+            'desc'      => '账户名称',
+            'match'     => 'is_numeric',
+            'list'      => 'account/config-one#name',
+            'value'     => Dever::input('set_config_id'),
+        ),
+
+        'project_id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属项目',
+            'default'   => '1',
+            'desc'      => '所属项目',
+            'match'     => 'is_numeric',
+            'list'      => 'account/config_project-one#name',
+        ),
+
+        'config_profit_id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '所属收益',
+            'default'   => '1',
+            'desc'      => '所属收益',
+            'match'     => 'is_numeric',
+            'list'      => 'account/config_profit-one#name',
+        ),
+
+        'cash'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '总金额',
+            'default'   => '0',
+            'desc'      => '总金额',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list_name' => '未结算',
+            'list'      => '{cash}-{y_cash}',
+        ),
+
+        'ycash'        => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '已结算',
+            'default'   => '0',
+            'desc'      => '已结算',
+            'match'     => 'option',
+            '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,
+        ),
+    ),
+
+    # 索引
+    'index' => array
+    (
+        1 => array
+        (
+            'search' => 'uid,config_id,project_id,config_profit_id',
+        ),
+        
+        # 版本号 更改版本号会更新当前表的索引
+        'version' => 1,
+    ),
+
+    'manage' => array
+    (
+        'delete' => false,
+        'edit' => false,
+        'insert' => false,
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        # 更新
+        'incCash' => array
+        (
+            'type' => 'update',
+            'where' => array
+            (
+                'id' => 'yes',
+            ),
+            'set' => array
+            (
+                'cash' => array('yes', '+='),
+            ),
+        ),
+
+        # 更新
+        'incYcash' => array
+        (
+            'type' => 'update',
+            'where' => array
+            (
+                'id' => 'yes',
+            ),
+            'set' => array
+            (
+                'ycash' => array('yes', '+='),
+            ),
+        ),
+    )
+);

+ 212 - 0
database/profit_log.php

@@ -0,0 +1,212 @@
+<?php
+$status = array
+(
+    1 => '未结算',
+    2 => '已结算',
+    3 => '部分结算',
+    4 => '结算失败',
+);
+return array
+(
+    # 表名
+    'name' => 'profit_log',
+    # 显示给用户看的名称
+    'lang' => '用户收益流水',
+    'menu' => false,
+    'status' => $status,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'        => true,
+        ),
+
+        'order_num'      => array
+        (
+            'type'      => 'varchar-100',
+            'name'      => '流水号',
+            'default'   => '',
+            'desc'      => '流水号',
+            'match'     => 'is_string',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-200',
+            'name'      => '标题',
+            'default'   => '',
+            'desc'      => '标题',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'profit_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '收益账户id',
+			'default' 	=> '',
+			'desc' 		=> '收益账户id',
+			'match' 	=> 'is_numeric',
+            'search'    => 'hidden',
+		),
+
+        'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户ID',
+			'default' 	=> '0',
+			'desc' 		=> '用户名称',
+			'match' 	=> 'is_numeric',
+            'search'	=> 'hidden',
+            'list_name'	=> '用户名称',
+			'list'		=> 'Dever::load("account/lib/project.getUsername", {uid}, {config_id})',
+		),
+
+        'source'      => array
+        (
+            'type'      => 'varchar-150',
+            'name'      => '来源表名',
+            'default'   => '',
+            'desc'      => '来源表名',
+            'match'     => 'is_numeric',
+        ),
+
+        'source_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '来源表id',
+            'default'   => '',
+            'desc'      => '来源表id',
+            'match'     => 'is_string',
+            'update'    => 'text',
+        ),
+
+        'cash'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '总金额',
+            'default'   => '0',
+            'desc'      => '总金额',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'ycash'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '已结算金额',
+            'default'   => '0',
+            'desc'      => '已结算金额',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'desc'      => array
+        (
+            'type'      => 'varchar-600',
+            'name'      => '收益说明',
+            'default'   => '',
+            'desc'      => '收益说明',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+        ),
+
+        'status'        => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '状态',
+            'match'     => 'is_numeric',
+            'option'    => $status,
+            'list'      => true,
+        ),
+
+        'fdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '结算时间',
+            'default'   => '',
+            'match'     => 'is_numeric',
+            'desc'      => '',
+        ),
+
+        '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_name' => '交易时间',
+            'list'        => 'time',
+        ),
+    ),
+
+    # 索引
+    'index' => array
+    (
+        1 => array
+        (
+            'search_1' => 'profit_id,source,source_id',
+            'search_2' => 'profit_id,uid',
+        ),
+        
+        # 版本号 更改版本号会更新当前表的索引
+        'version' => 1,
+    ),
+
+    'manage' => array
+    (
+        'insert' => false,
+        'delete' => false,
+        'edit' => false,
+        'excel' => true,
+    ),
+
+    'request' => array
+    (
+        'getData' => array
+        (
+            'type' => 'all',
+            'option' => array
+            (
+                'config_id' => 'yes',
+                'profit_id' => 'yes',
+                'uid' => 'yes',
+                'start' => array('yes-cdate', '>='),
+                'end' => array('yes-cdate', '<='),
+                'state' => 1,
+            ),
+            'page' => array(10, 'list'),
+            'col' => '*',
+        ),
+    ),
+);

+ 1 - 1
lib/Log.php

@@ -79,7 +79,7 @@ class Log
         $info['config_name'] = $config['name'];
         $info['status_name'] = $this->status($info['type_id'], $info['status']);
         $info['type_name'] = Dever::load("account/config_type-one#name", $info['type_id']);
-        $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
+        $info['cdate_string'] = date('Y-m-d H:i', $info['cdate']);
         $info['fee'] = Dever::number($info['ycash'] - $info['cash']);
         return $info;
     }

+ 242 - 0
lib/Profit.php

@@ -0,0 +1,242 @@
+<?php
+namespace Account\Lib;
+use Dever;
+class Profit
+{
+    # 获取详情
+    public function get($uid, $profit_id, $config_id, $project_id)
+    {
+        $data['uid'] = $uid;
+        $data['config_id'] = $config_id;
+        $data['project_id'] = $project_id;
+        $data['config_profit_id'] = $profit_id;
+        $data['clear'] = true;
+        $info = Dever::db('account/profit')->find($data);
+        if (!$info) {
+            $info['id'] = Dever::db('account/profit')->insert($data);
+            if (!$info['id']) {
+                return Dever::alert('账户信息不存在');
+            }
+            $info['cash'] = '0.00';
+            $info['ycash'] = '0.00';
+        }
+        return $info;
+    }
+
+    # 获取日志列表
+    public function getList($uid, $profit_id)
+    {
+        $where['profit_id'] = $profit_id;
+        $where['uid'] = $uid;
+        $data = Dever::db('account/profit_log')->getData($where, function(&$info) {
+            return $this->info($info);
+        });
+
+        return $data;
+    }
+
+    # 获取日志详情
+    public function getInfo($id)
+    {
+        $data = Dever::db('account/profit_log')->find($id);
+        $data = $this->info($data);
+        return $data;
+    }
+
+    # 获取详情
+    private function info($info)
+    {
+        $info['username'] = '无';
+        $profit = Dever::db('account/profit')->find($info['profit_id']);
+        $status = Dever::db('account/profit_log')->config['status'];
+        $config = Dever::db('account/config')->find($profit['config_id']);
+        $project = Dever::db('account/config_project')->find($config['project_id']);
+        $source = Dever::db($project['source'])->find($info['uid']);
+        if ($source) {
+            $info['username'] = $source[$project['source_name']];
+        }
+        $info['config_name'] = $config['name'];
+        $info['status_name'] = Dever::status($status, $info['status']);
+        $info['cdate_string'] = date('Y-m-d H:i', $info['cdate']);
+        if ($info['fdate']) {
+            $info['fdate_string'] = date('Y-m-d H:i', $info['fdate']);
+        }
+        
+        return $info;
+    }
+
+    # 入账
+    public function up_commit($uid, $cash, $profit, $status, $source, $source_id, $name = '', $desc = '')
+    {
+        if ($cash == 0) {
+            return Dever::alert('金额不能为空0');
+        }
+
+        if (!is_array($profit)) {
+            $profit = Dever::db('account/config_profit')->find(array('key' => $profit));
+        }
+        
+        if (!$profit) {
+            return Dever::alert('收益类型不存在');
+        }
+
+        $config = Dever::db('account/config')->find($profit['config_id']);
+        if (!$config) {
+            return Dever::alert('账户信息不存在');
+        }
+
+        $project = Dever::db('account/config_project')->find($config['project_id']);
+        $user = Dever::db($project['source'])->find($uid);
+        if (!$user) {
+            return Dever::alert('账户信息不存在');
+        }
+        $info = $this->get($uid, $profit['id'], $config['id'], $config['project_id']);
+
+        # 开始处理入账
+        $this->handle($profit, $uid, $cash, $info['id'], $project['source'], $source, $source_id, $name, $status, $desc);
+        
+        return true;
+    }
+
+    # 入账
+    private function add($uid, $cash, $profit_id, $status, $source, $source_id, $name = '', $desc = '')
+    {
+        $data['clear'] = true;
+        $data['profit_id'] = $profit_id;
+        $data['source'] = $source;
+        $data['source_id'] = $source_id;
+        
+        $log = Dever::db('account/profit_log')->one($data);
+        $data['uid'] = $uid;
+
+        if ($name) {
+            $data['name'] = $name;
+        }
+        if ($desc) {
+            $data['desc'] = $desc;
+        }
+        $data['status'] = $status;
+        if ($log) {
+            # 结算
+            if ($cash > 0 && $log['cash'] != $cash) {
+                $status = 3;
+                if ($cash > $log['cash']) {
+                    $cash = $log['cash'];
+                }
+            }
+            if ($status == 2) {
+                $data['ycash'] = $cash;
+            } elseif ($status == 3) {
+                $data['ycash'] = $log['ycash'] + $cash;
+            } elseif ($status == 4) {
+                $data['ycash'] = 0;
+            }
+            $data['where_id'] = $log['id'];
+            Dever::db('account/profit_log')->update($data);
+
+            $update['where_id'] = $profit_id;
+            $update['set_ycash'] = $data['ycash'];
+            Dever::db('account/profit')->incYcash($update);
+        } else {
+            # 入账
+            $data['cash'] = $cash;
+            if ($status == 2) {
+                $data['ycash'] = $cash;
+            }
+            $data['order_num'] = $this->createOrderNum();
+            $id = Dever::db('account/profit_log')->insert($data);
+
+            $update['where_id'] = $profit_id;
+            $update['set_cash'] = $data['cash'];
+            Dever::db('account/profit')->incCash($update);
+        }
+    }
+
+    # 生成订单号
+    private function createOrderNum()
+    {
+        $where['order_num'] = Dever::order('S');
+        $state = Dever::db('account/profit_log')->one($where);
+        if (!$state) {
+            return $where['order_num'];
+        } else {
+            return $this->createOrderNum();
+        }
+    }
+
+    # 计算金额
+    private function handle($profit, $uid, $cash, $profit_id, $project_source, $source, $source_id, $name, $status, $desc)
+    {
+        $rule = Dever::db('account/config_profit_rule')->select(array('profit_id' => $profit['id']));
+        if ($rule) {
+            $child = array();
+            foreach ($rule as $k => $v) {
+                $child[$v['level']] = $this->rule($v, $child, $uid, $cash, $profit_id, $project_source, $source, $source_id, $name, $status, $desc);
+            }
+        }
+        return $cash;
+    }
+
+    private function rule($rule, $child, $uid, $cash, $profit_id, $project_source, $source, $source_id, $name, $status, $desc)
+    {
+        if ($rule['level'] > 0) {
+            $parent = Dever::load('invite/api')->getParent($uid, $rule['level']);
+            if ($parent) {
+                $uid = $parent;
+            } else {
+                return false;
+            }
+        }
+
+        $replace = array();
+        $replace['{a}'] = $cash;
+        $replace['{b}'] = $uid;
+        $user = Dever::db($project_source)->find($uid);
+        if (isset($user['role']) && $user['role']) {
+            $temp = explode(',', $user['role']);
+            $replace['{c}'] = $temp[0];
+            if (isset($temp[1]) && $temp[1]) {
+                $level = $temp[1];
+                $level = Dever::db('user/role_level')->find($level);
+                if ($level) {
+                    $replace['{d}'] = $level['level'];
+                }
+            }
+        }
+
+        # 验证条件
+        $condition = $rule['condition'];
+        if ($condition) {
+            $check = $this->run($condition, $replace);
+            if (!$check) {
+                return false;
+            }
+        }
+
+        $level = $rule['level'] - 1;
+        if ($child && isset($child[$level]) && $child[$level]) {
+            $replace['{e}'] = $child[$level];
+        }
+
+        # 计算公式
+        $exp = $rule['exp'];
+        if ($exp) {
+            $cash = $this->run($exp, $replace);
+        }
+        if ($cash > 0) {
+            $this->add($uid, $cash, $profit_id, $status, $source, $source_id, $name, $desc);
+            return $cash;
+        }
+        return false;
+    }
+
+    private function run($string, $replace)
+    {
+        $keys = array_keys($replace);
+        $values = array_values($replace);
+        $string = str_replace($keys, $values, $string);
+        $eval = '$value = ' . $string . ';';
+        eval($eval);
+        return $value;
+    }
+}

+ 57 - 0
src/Profit.php

@@ -0,0 +1,57 @@
+<?php
+namespace Account\Src;
+use Dever;
+use User\Lib\Core;
+class Profit extends Core
+{
+    public function getHome()
+    {
+        $data['account'] = Dever::load('account/lib/info')->getInfo($this->uid);
+        $data['list'] = Dever::db('account/config_profit')->select(array('config_id' => $data['account']['config_id']));
+        $data['total'] = 0;
+        if ($data['list']) {
+        	foreach ($data['list'] as $k => $v) {
+        		$profit = Dever::db('account/profit')->one(array('uid' => $this->uid, 'config_profit_id' => $v['id']));
+        		if ($profit) {
+        			$data['total'] += $profit['cash'];
+        		}
+        	}
+        }
+        $data['total'] = Dever::number($data['total']);
+        return $data;
+    }
+
+    public function getList()
+    {
+    	$id = Dever::input('id');
+    	if (!$id) {
+    		Dever::alert('收益错误');
+    	}
+    	$account = Dever::load('account/lib/info')->getInfo($this->uid);
+        
+        $data['info'] = Dever::load('account/lib/profit')->get($this->uid, $id, $account['config_id'], $account['project_id']);
+        $data['list'] = Dever::load('account/lib/profit')->getList($this->uid, $data['info']['id']);
+        return $data;
+    }
+
+    public function getView()
+    {
+        $id = Dever::input('id');
+        $id = Dever::input('id');
+    	if (!$id) {
+    		Dever::alert('收益错误');
+    	}
+        return Dever::load('account/lib/profit')->getInfo($id);
+    }
+
+    public function test()
+    {
+    	# 插入一个收益记录
+    	//Dever::load('account/lib/profit.up_commit', $this->uid, 100, 'zhitui', 'type', 1, 'xxx订单记录', 1, 'test');
+
+    	# 结算5块钱
+    	Dever::load('account/lib/profit.up_commit', $this->uid, 100, 'zhitui', 'type', 2, 'xxx订单记录', 2, 'test');
+
+    	return 'ok';
+    }
+}