From 3c44d5d20044e1fa466281889af74b05aa638b81 Mon Sep 17 00:00:00 2001 From: yulingwei <2436953959@qq.com> Date: Fri, 14 Feb 2020 11:38:38 +0800 Subject: [PATCH] upt --- Application/Admin/Common/extend.php | 23 ++ .../Controller/PromoteController.class.php | 1 + .../Controller/SettlementController.class.php | 246 ++++++++++++++++++ .../Controller/StatementController.class.php | 3 +- Data/update.sql | 5 + 5 files changed, 276 insertions(+), 2 deletions(-) create mode 100644 Application/Admin/Controller/SettlementController.class.php diff --git a/Application/Admin/Common/extend.php b/Application/Admin/Common/extend.php index 8ebfc1ae6..921d46eda 100644 --- a/Application/Admin/Common/extend.php +++ b/Application/Admin/Common/extend.php @@ -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; +} + ?> diff --git a/Application/Admin/Controller/PromoteController.class.php b/Application/Admin/Controller/PromoteController.class.php index 6aada89f3..69aa30e1c 100644 --- a/Application/Admin/Controller/PromoteController.class.php +++ b/Application/Admin/Controller/PromoteController.class.php @@ -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']} ") diff --git a/Application/Admin/Controller/SettlementController.class.php b/Application/Admin/Controller/SettlementController.class.php new file mode 100644 index 000000000..da284fbff --- /dev/null +++ b/Application/Admin/Controller/SettlementController.class.php @@ -0,0 +1,246 @@ +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) + { + + } +} \ No newline at end of file diff --git a/Application/Admin/Controller/StatementController.class.php b/Application/Admin/Controller/StatementController.class.php index d4a5a1f95..eb43138ce 100644 --- a/Application/Admin/Controller/StatementController.class.php +++ b/Application/Admin/Controller/StatementController.class.php @@ -303,7 +303,6 @@ class StatementController extends ThinkController }else{ $this->ajaxReturn(array("error"=>"database error","code"=>2000)); } - - } + } diff --git a/Data/update.sql b/Data/update.sql index 36e91ea72..1db536576 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -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-自动审核'; \ No newline at end of file