@ -214,15 +214,15 @@ class FinanceController extends ThinkController
//获取数据
$from = "
(
SELECT root_id,root_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE root_id = '{$root_id}' and count_date='{$month}' group by root_id
SELECT parent_id,parent_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE root_id = '{$root_id}' and count_date='{$month}' group by parent_id
UNION
SELECT promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE parent_id = '{$root_id}' and count_date='{$month}' group by promote_id
@ -49,6 +52,8 @@ class SpendCountSetController extends \Think\Controller
$this->getBingData();
$this->getInsideData();
$this->setRoot();
//执行用户表统计
$this->setUserCount();
$this->model->commit();
}
@ -56,7 +61,9 @@ class SpendCountSetController extends \Think\Controller
die("success");
}
//流水聚合接口
/**
* 每个月的统计接口
*/
public function setSpendCount()
{
//判断是否已经聚合
@ -71,6 +78,9 @@ class SpendCountSetController extends \Think\Controller
$this->getBingData();
$this->getInsideData();
$this->setRoot();
//执行用户表统计
$this->setUserCount();
$this->model->commit();
die("success");
}
@ -286,4 +296,126 @@ class SpendCountSetController extends \Think\Controller
}
}
}
/**
* 获取角色聚合
*/
public function setUserCount()
{
//获取会长信息
$this->getRootUser();
$this->getParentUser();
$this->getPromoteUser();
}
/** --------以下为辅助函数--------- **/
//获取会长信息
public function getRootUser()
{
//获取所有数据
$month = $this->date;
$from = "
(
SELECT root_id,root_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE root_id > 0 and count_date='{$month}' group by root_id
UNION
SELECT promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE parent_id = 0 and count_date='{$month}' group by promote_id
UNION
SELECT parent_id,parent_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE parent_id > 0 and root_id = 0 and count_date='{$month}' group by parent_id
SELECT parent_id,parent_name,root_id,root_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE root_id > 0 and count_date='{$month}' group by parent_id
UNION
SELECT promote_id,promote_account,parent_id,parent_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE parent_id >0 and root_id = 0 and count_date='{$month}' group by promote_id
SELECT promote_id,promote_account,parent_id,parent_name,root_id,root_name,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,inside_cash_count FROM tab_spend_count WHERE parent_id > 0 and root_id > 0 and count_date='{$month}' group by promote_id
)
";
$subQueryAll = M()->table($from." a")
->field('*')
// ->limit(1)
->group("a.promote_id")
->having("cash_count > 0 or balance_coin_count > 0 or inside_cash_count > 0")