master
yulingwei 5 years ago
parent 0983ea1027
commit 3c44d5d200

@ -2080,4 +2080,27 @@ function getGameCpRadio($game_id,$amount,$type) {
}
function getPromoteGameRatio($promoteID = 0, $relationGameId = 0, $amount=0, $timeStart=0, $timeEnd=0, $isDefault = false)
{
$map = " promote_id = {$promoteID} and relation_game_id = {$relationGameId} and status = 1 and begin_time <= {$timeStart} ";
if ($timeEnd) {
$map .= " and (end_time = 0 or end_time >= {$timeEnd}) ";
}
$result = M('promote_game_ratio_log', 'tab_')->where($map)->order('id desc')->find();
if (!$result) return 0;
$ratios = array_reverse(json_decode($result['turnover_ratio'], true));
if (!$ratios) return 0;
if ($isDefault) {
return $result['ratio'] ?: 0;
}
$ratio = $result['ratio'];
foreach ($ratios as $item) {
if (($item['instanceof'] == 1 && $amount >= $item['turnover']) || ($item['instanceof'] == 2 && $amount > $item['turnover'])) {
$ratio = $item['ratio'];
break;
}
}
return $ratio;
}
?>

@ -1362,6 +1362,7 @@ class PromoteController extends ThinkController
'company_belong' => $promote_belong['company_belong'],
'company_relation' => $promote_belong['company_relation'],
'can_view_recharge' => $promote_belong['can_view_recharge'],
'account_type' => $promote_belong['company_type']
];
$res = M("promote", "tab_")
->where("chain like '%/{$promote_belong['promote_id']}/%' or id={$promote_belong['promote_id']} ")

@ -0,0 +1,246 @@
<?php
namespace Admin\Controller;
/**
* 结算单
* @author ylw
*/
class SettlementController extends ThinkController
{
// 汇总结算单列表
public function getSettlementSheetList()
{
}
// 生成结算单 月结算补点 周结不算
public function generateSettlementSheet($settlement_type = 0, $settlement_time_type = 0, $time_start=0, $time_end = 0)
{
if (IS_GET) {
$msg = '';
if (empty($settlement_type)) {
$msg = '请选择汇总结算单类型';
}
if (empty($settlement_time_type)) {
$msg = '请选择结算方式';
}
if (empty($time_start) || empty($time_end)) {
$msg = '请选择正确的时间区间';
}
// 判断结算时间是否冲突
// 生成结算单数据
if (!$msg) {
if ($settlement_type == 1) {
if ($settlement_time_type == 1) {
$map = " and p.settlement_type = 1";
} else {
$map = '';
}
$result = M('spend', 'tab_')->query("
SELECT
sum(s.pay_amount) as amount, g.relation_game_id, g.relation_game_name, p.partner, p.id as p_id, p.channel_rate, p.invoice_rate, g.id as game_id
FROM
tab_spend as s
INNER JOIN tab_game g on s.game_id = g.id
INNER JOIN tab_partner p on p.id = g.partner_id {$map}
where s.pay_status = 1 and s.pay_time BETWEEN {$time_start} and {$time_end}
GROUP BY relation_game_id, p.id
ORDER BY p_id asc");
$list = [];
foreach ($result as $key => $item) {
if (!isset($list[$item['p_id']])) {
// 奖罚金额
$reward = M('reward_record', 'tab_')
->field('sum(money) as money, reward_type')
->where("company_type = 1 and company_id = {$item['p_id']} and reward_time between {$time_start} and {$time_end}")
->group('reward_type')
->select();
if (!empty($reward)) {
$reward = array_column($reward, 'money', 'reward_type');
}
$list[$item['p_id']] = [
'company_id'=>$item['p_id'],
'company_name'=>$item['partner'],
'bonuses'=>isset($reward[1]) ? $reward[1] : 0,
'fine'=>isset($reward[2]) ? $reward[2] : 0 ,
'channel_rate' => $item['channel_rate'], // 渠道费
'invoice_rate' => $item['invoice_rate'], // 税费
];
}
$data = [];
// 获取分成比例
if ($settlement_time_type == 1) {
$data['game_ratio'] = getGameCpRadio($item['game_id'], $item['amount'], false);
} else {
$data['game_ratio'] = getGameCpRadio($item['game_id'], $item['amount'], true);
}
$data['relation_game_id'] = $item['relation_game_id'];
$data['relation_game_name'] = $item['relation_game_name'];
$data['amount'] = $item['amount'];
$data['self_game_ratio'] = 100 - $data['game_ratio'];
$data['parter_settlement'] = $item['amount'] * $data['game_ratio']/100 - ($item['amount']*$item['channel_rate'] ) + $list[$item['p_id']]['bonuses'] - $list[$item['p_id']]['fine'];
$list[$item['p_id']]['channel'][] = $data;
}
echo json_encode($list);exit;
} else if (\in_array($settlement_type, [2, 3])) {
$map = "p.account_type = 1 and p.`level` = 1 and p.company_belong " . ($settlement_type == 2 ? " = 0 " : " in (1, 2) ") ;
if ($settlement_time_type == 1) {
$map .= " and p.settlement_type = {$settlement_time_type} ";
}
$result = M()->query("
SELECT
p.id, p.account, pc.company_name, pc.id as p_id, pc.fax_ratio, pc.settlement_contact
FROM
tab_promote p
INNER JOIN tab_promote_company pc on p.company_id = pc.id
where {$map}
order by pc.id asc
");
$list = [];
foreach ($result as $key => $item) {
$res = M()->query("
select
g.relation_game_name, g.relation_game_id, sum(s.pay_amount) as amount
from
tab_spend s
inner join tab_promote p on p.chain like '/{$item['id']}/%' and s.promote_id = p.id
inner join tab_game g on s.game_id = g.id
where s.pay_status = 1 and s.pay_time BETWEEN {$time_start} and {$time_end}
group by g.relation_game_id
");
if (!isset($list[$item['p_id']])) {
// 奖罚金额
$reward = M('reward_record', 'tab_')
->field('sum(money) as money, reward_type')
->where("company_type = 2 and company_id = {$item['p_id']} and reward_time between {$time_start} and {$time_end}")
->group('reward_type')
->select();
if (!empty($reward)) {
$reward = array_column($reward, 'money', 'reward_type');
}
$list[$item['p_id']] = [
'company_id'=>$item['p_id'],
'company_name'=>$item['company_name'],
'fax_ratio' => $item['fax_ratio'],
'bonuses'=>isset($reward[1]) ? $reward[1] : 0,
'fine'=>isset($reward[2]) ? $reward[2] : 0 ,
'settlement_contact' => $item['settlement_contact'],
'create_time' => time()
];
}
if ($res) {
foreach ($res as $k => $val) {
$gameRatio = getPromoteGameRatio($item['id'], $val['relation_game_id'], $val['amount'], $time_start, $time_end, true);
if ($settlement_time_type == 2) {
$gameRatioMax = getPromoteGameRatio($item['id'], $val['relation_game_id'], $val['amount'], $time_start, $time_end, false);
} else {
$gameRatioMax = $gameRatio;
}
$price = $val['amount']*$gameRatioMax/100 - $val['amount']*$item['fax_ratio']/100;
$list[$item['p_id']]['channels'][] = [
'promote_id' => $item['id'],
'account'=>$item['account'],
'relation_game_name'=>$val['relation_game_name'],
'relation_game_id'=>$val['relation_game_id'],
'game_ratio'=>$gameRatio,
'game_ratio_max'=>$gameRatioMax-$gameRatio,
'price'=> $val['amount']*$gameRatioMax/100 - $val['amount']*$item['fax_ratio']/100,
'amount' => $val['amount']
];
}
}
}
echo json_encode($list);exit;
} else if ($settlement_type == 4) {
$map = "p.account_type = 2 and p.`level` = 1 " ;
if ($settlement_time_type == 1) {
$map .= " and p.settlement_type = {$settlement_time_type} ";
}
$result = M()->query("
SELECT
p.id, p.account, pc.company_name, pc.id as p_id, company_relation, p.admin_id, pc.bank_card, pc.bank_cardname, pc.bank_name, pc.bank_address
FROM
tab_promote p
INNER JOIN tab_promote_company pc on p.company_id = pc.id
where {$map}
order by pc.id asc
");
$list = [];
foreach ($result as $key => $item) {
$res = M()->query("
select
g.relation_game_name, g.relation_game_id, sum(s.pay_amount) as amount
from
tab_spend s
inner join tab_promote p on p.chain like '/{$item['id']}/%' and s.promote_id = p.id
inner join tab_game g on s.game_id = g.id
where s.pay_status = 1 and s.pay_time BETWEEN {$time_start} and {$time_end}
group by g.relation_game_id
");
if (!isset($list[$item['p_id']])) {
// 奖罚金额
$reward = M('reward_record', 'tab_')
->field('sum(money) as money, reward_type')
->where("company_type = 2 and company_id = {$item['p_id']} and reward_time between {$time_start} and {$time_end}")
->group('reward_type')
->select();
if (!empty($reward)) {
$reward = array_column($reward, 'money', 'reward_type');
}
$list[$item['p_id']] = [
'company_id'=>$item['p_id'],
'company_name'=>$item['company_name'],
'bonuses'=>isset($reward[1]) ? $reward[1] : 0,
'fine'=>isset($reward[2]) ? $reward[2] : 0 ,
'settlement_contact' => $item['settlement_contact'],
'bank_card' => $item['bank_card'],
'bank_address' => $item['bank_address'],
'create_time' => time()
];
}
if ($res) {
foreach ($res as $k => $val) {
$gameRatio = getPromoteGameRatio($item['id'], $val['relation_game_id'], $val['amount'], $time_start, $time_end, true);
if ($settlement_time_type == 2) {
$gameRatioMax = getPromoteGameRatio($item['id'], $val['relation_game_id'], $val['amount'], $time_start, $time_end, false);
} else {
$gameRatioMax = $gameRatio;
}
$price = $val['amount']*$gameRatioMax/100;
$list[$item['p_id']]['channels'][] = [
'promote_id' => $item['id'],
'account'=>$item['account'],
'relation_game_name'=>$val['relation_game_name'],
'relation_game_id'=>$val['relation_game_id'],
'game_ratio'=>$gameRatio,
'game_ratio_max'=>$gameRatioMax-$gameRatio,
'price'=> $val['amount']*$gameRatioMax/100,
'amount' => $val['amount'],
'type_name' => '个人',
'company_relation_name' => $item['company_relation'] == 0 ? "自主开发及维护" : ($item['company_relation'] == 1 ? "只维护" : "无"),
'admin_name' => get_admin_nickname($item['admin_id']) ?: '无'
];
}
}
}
echo json_encode($list);exit;
} else {
}
}
} else {
// 判断结算时间是否冲突
}
}
public function settlementSheetDetail($id=0)
{
}
}

@ -303,7 +303,6 @@ class StatementController extends ThinkController
}else{
$this->ajaxReturn(array("error"=>"database error","code"=>2000));
}
}
}

@ -1154,6 +1154,11 @@ MODIFY COLUMN `company_belong` tinyint(1) UNSIGNED NOT NULL DEFAULT 3 COMMENT '
MODIFY COLUMN `company_relation` tinyint(1) UNSIGNED NOT NULL DEFAULT 2 COMMENT '工会关系0-自主开发及维护1-只维护 2 无' AFTER `company_belong`;
ADD COLUMN `company_type` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '工会类型 1公司 2个人' AFTER `can_view_recharge`;
-- 2020-02-10 yulingwei 推广工会管理 新增属性类型
ALTER TABLE `tab_promote`
MODIFY COLUMN `company_belong` tinyint(1) NOT NULL DEFAULT 0 COMMENT '工会归属0-内团1-外团 2-分发联盟 3 无' AFTER `company_id`,
MODIFY COLUMN `company_relation` tinyint(1) NOT NULL DEFAULT 0 COMMENT '工会关系0-自主开发及维护1-只维护 2 无' AFTER `company_belong`;
-- 2020-02-10 cxj 推广提现--新增审核模式
ALTER TABLE `tab_withdraw`
ADD COLUMN `review_type` tinyint(3) NOT NULL DEFAULT 1 COMMENT '审核模式1-人工审核 2-自动审核';
Loading…
Cancel
Save