公会分成管理--更新

master
chenxiaojun 5 years ago
commit 6e05546db6

@ -295,11 +295,14 @@ class AjaxController extends ThinkController{
$data['game_ratio'] = $handleStatementData;
$data['company_name'] = $second_party_info['partner'];
$data['mobile_phone'] = $second_party_info['link_phone'];
$data['bank_card'] = $second_party_info['bank_account'];
$data['account_openin'] = $second_party_info['opening_bank'];
$data['settlement_type'] = $second_party_info['settlement_type'];
$data['address'] = $second_party_info['address'];
$data['real_name'] = $second_party_info['link_man'];
$data['bank_account_name'] = $second_party_info['bank_account_name'];
$data['settlement_type_value'] = $getStatementData['settlement_type'];
$data['settlement_type_value'] = $getStatementData['settlement_type'];
$data['invoice_item'] = $second_party_info['invoice_item'];
$data['invoice_type'] = $second_party_info['invoice_type'];

@ -326,7 +326,7 @@ class PromoteGameRatioController extends ThinkController
$this->assign('lastRatio', $lastRatio);
}
$this->assign('gameList', getAllGameList());
$this->assign('gameList', getAllGameList(true));
$this->assign('promoteList', getPromoteByLevel(1));
$this->meta_title = $metaTitle;
$this->display();

@ -1470,14 +1470,17 @@ class QueryController extends ThinkController
}
if ($_REQUEST['device']) {
$map['game_name'] = ['like','%'.$_REQUEST['device'].'%'];
}
// $map['tab_spend.sdk_version'] = $_REQUEST['device'];
$spendMap['tab_spend.sdk_version'] = $_REQUEST['device'];
}
$spendMap['tab_spend.pay_status'] = 1;
//获取spend表中的数据同时根据会长id进行group分类
$data = M('Spend','tab_')
->field("FROM_UNIXTIME(pay_time,'%Y-%m') as my_time,sum(pay_amount) as pay_amount,game_id,game_name,SUBSTRING_INDEX(`game_name`,\"(\",1) as game_names,promote_id,promote_account,company_relation,company_belong,CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(`chain`,\"/\",2),\"/\",-1)='' THEN promote_id ELSE SUBSTRING_INDEX(SUBSTRING_INDEX(`chain`,\"/\",2),\"/\",-1) END as root_id ")
->field("FROM_UNIXTIME(pay_time,'%Y-%m') as my_time,sum(pay_amount) as pay_amount,game_id,tab_spend.game_name,SUBSTRING_INDEX(tab_spend.`game_name`,\"(\",1) as game_names,promote_id,promote_account,company_relation,company_belong,CASE WHEN SUBSTRING_INDEX(SUBSTRING_INDEX(`chain`,\"/\",2),\"/\",-1)='' THEN promote_id ELSE SUBSTRING_INDEX(SUBSTRING_INDEX(`chain`,\"/\",2),\"/\",-1) END as root_id,tab_game.ratio ")
->join("left join tab_promote on promote_id = tab_promote.id")
->where(['pay_status'=>1])
->join("left join tab_game on tab_game.id=tab_spend.game_id")
->where($spendMap)
->group("my_time,game_names,root_id")
->order("my_time Desc")
->select(false);
@ -1493,7 +1496,7 @@ class QueryController extends ThinkController
//关联表获取会长账号名
$data = M()->table('('.$data.') as a')
->field("my_time,pay_amount,a.game_id,game_name,game_names,a.promote_id,a.promote_account,a.company_relation,a.company_belong,CASE WHEN root_id is null THEN 0 ELSE root_id END as root_id,CASE WHEN account is null THEN '官方渠道' ELSE account END as account,tab_ratio.ratio as ratio,turnover_ratio")
->field("my_time,pay_amount,a.game_id,game_name,game_names,a.promote_id,a.promote_account,a.company_relation,a.company_belong,CASE WHEN root_id is null THEN 0 ELSE root_id END as root_id,CASE WHEN account is null THEN '官方渠道' ELSE account END as account,tab_ratio.ratio as ratio,turnover_ratio,a.ratio as game_ratio")
->join("left join tab_promote on root_id = tab_promote.id")
->join("left join tab_promote_game_ratio as tab_ratio on tab_ratio.game_id = a.game_id and tab_ratio.promote_id=root_id")
// ->join("left join tab_cp_game_ratio as game_ratio on game_ratio.game_id = a.game_id")
@ -1520,10 +1523,9 @@ class QueryController extends ThinkController
if ($value['ratio']) {
$data[$key]['downstream'] = $value['pay_amount'] * ($value['ratio']*0.01);
} else {
$data[$key]['downstream'] = $value['pay_amount'] * 0;
$data[$key]['downstream'] = $value['pay_amount'] * ($value['game_ratio']*0.01);
}
$value['turnover_ratio'] = json_decode($value['turnover_ratio'],true);
// dd($value);

@ -268,37 +268,42 @@ class WithdrawModel extends Model{
$balance = 0;
$notInGameIds = [-1];
foreach ($promoteGameRatios as $promoteGameRatio) {
$spendWhere['game_id'] = $promoteGameRatio['game_id'];
if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) {
$notInGameIds[] = $promoteGameRatio['game_id'];
$ratio = $promoteGameRatio['ratio'];
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendWhere)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
$gameIds = D('game')->where(array('relation_game_id' => $promoteGameRatio['game_id']))->getField('id', true);
if (!empty($gameIds)) {
foreach ($gameIds as $gameId) {
$spendWhere['game_id'] = $gameId;
$notInGameIds[] = $gameId;
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendWhere)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
$thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance")
->where($spendWhere)
->find()['balance'];
$thisBalance = $thisBalance ?? 0;
$balance = bcadd($balance, $thisBalance, 2);
$gameRatios[$gameId] = [];
$gameRatios[$gameId][] = [
'selle_ratio' => $ratio,
'default_ratio' => $promoteGameRatio['ratio'],
'sum_amount' => $sumAmount,
'begin_time' => $beginTime,
'end_time' => $endTime,
];
}
}
$thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance")
->where($spendWhere)
->find()['balance'];
$thisBalance = $thisBalance ?? 0;
$balance = bcadd($balance, $thisBalance, 2);
$gameRatios[$promoteGameRatio['game_id']] = [];
$gameRatios[$promoteGameRatio['game_id']][] = [
'selle_ratio' => $ratio,
'default_ratio' => $promoteGameRatio['ratio'],
'sum_amount' => $sumAmount,
'begin_time' => $beginTime,
'end_time' => $endTime,
];
}
}
@ -391,33 +396,38 @@ class WithdrawModel extends Model{
$gameRatios = [];
foreach ($promoteGameRatios as $promoteGameRatio) {
if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) {
$spendMap['game_id'] = $promoteGameRatio['game_id'];
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendMap)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
$ratio = 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
$gameIds = D('game')->where(array('relation_game_id' => $promoteGameRatio['game_id']))->getField('id', true);
if (!empty($gameIds)) {
foreach ($gameIds as $gameId) {
$spendMap['game_id'] = $gameId;
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendMap)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
$ratio = 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
if ($ratio > 0) {
$ratio = bcsub($ratio, $promoteGameRatio['ratio'], 2);
$thisBalance = bcdiv(bcmul($sumAmount, $ratio, 2), 100, 2);
$balance = bcadd($balance, $thisBalance, 2);
$gameRatios[$promoteGameRatio['game_id']][] = [
'selle_ratio' => $ratio,
'default_ratio' => $promoteGameRatio['ratio'],
'sum_amount' => $sumAmount,
'begin_time' => date('Y-m-d', $settlementBeginTime),
'end_time' => date('Y-m-d', $settlementEndTime),
];
if ($ratio > 0) {
$ratio = bcsub($ratio, $promoteGameRatio['ratio'], 2);
$thisBalance = bcdiv(bcmul($sumAmount, $ratio, 2), 100, 2);
$balance = bcadd($balance, $thisBalance, 2);
$gameRatios[$gameId][] = [
'selle_ratio' => $ratio,
'default_ratio' => $promoteGameRatio['ratio'],
'sum_amount' => $sumAmount,
'begin_time' => date('Y-m-d', $settlementBeginTime),
'end_time' => date('Y-m-d', $settlementEndTime),
];
}
}
}
}
}
@ -477,25 +487,30 @@ class WithdrawModel extends Model{
$balance = 0;
foreach ($promoteGameRatios as $promoteGameRatio) {
if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) {
$spendMap['game_id'] = $promoteGameRatio['game_id'];
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendMap)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
$ratio = 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
$gameIds = D('game')->where(array('relation_game_id' => $promoteGameRatio['game_id']))->getField('id', true);
if (!empty($gameIds)) {
foreach ($gameIds as $gameId) {
$spendMap['game_id'] = $gameId;
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendMap)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
$ratio = 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
if ($ratio > 0) {
$ratio = bcsub($ratio, $promoteGameRatio['ratio'], 2);
$thisBalance = bcdiv(bcmul($sumAmount, $ratio, 2), 100, 2);
$balance = bcadd($balance, $thisBalance, 2);
if ($ratio > 0) {
$ratio = bcsub($ratio, $promoteGameRatio['ratio'], 2);
$thisBalance = bcdiv(bcmul($sumAmount, $ratio, 2), 100, 2);
$balance = bcadd($balance, $thisBalance, 2);
}
}
}
}
}
@ -532,28 +547,33 @@ class WithdrawModel extends Model{
$balance = 0;
$notInGameIds = [-1];
foreach ($promoteGameRatios as $promoteGameRatio) {
$spendWhere['game_id'] = $promoteGameRatio['game_id'];
if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) {
$notInGameIds[] = $promoteGameRatio['game_id'];
$ratio = $promoteGameRatio['ratio'];
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendWhere)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
$gameIds = D('game')->where(array('relation_game_id' => $promoteGameRatio['game_id']))->getField('id', true);
if (!empty($gameIds)) {
foreach ($gameIds as $gameId) {
$spendWhere['game_id'] = $gameId;
$notInGameIds[] = $gameId;
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendWhere)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
$thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance")
->where($spendWhere)
->find()['balance'];
$thisBalance = $thisBalance ?? 0;
$balance = bcadd($balance, $thisBalance, 2);
}
}
$thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance")
->where($spendWhere)
->find()['balance'];
$thisBalance = $thisBalance ?? 0;
$balance = bcadd($balance, $thisBalance, 2);
}
}

@ -105,11 +105,11 @@
<option value="">游戏名称</option>
<empty name="record">
<volist name="gameList" id="vo">
<option value="{$vo.id}">{$vo.game_name}</option>
<option value="{$vo.id}">{$vo.relation_game_name}</option>
</volist>
<else/>
<volist name="gameList" id="vo">
<option value="{$vo.id}" <if condition="$vo['id'] eq $record['game_id']">selected</if> >{$vo.game_name}</option>
<option value="{$vo.id}" <if condition="$vo['id'] eq $record['game_id']">selected</if> >{$vo.relation_game_name}</option>
</volist>
</empty>
</select>

@ -111,8 +111,8 @@
<div class="input-list input-list-game search_label_rehab">
<select name="device" class="select_gallery">
<option value="">设备类型</option>
<option value="安卓版">安卓</option>
<option value="苹果版">IOS</option>
<option value="1">安卓</option>
<option value="2">IOS</option>
</select>
</div>
<input type="hidden" name="" value="" class="sortBy">

@ -211,6 +211,7 @@
//搜索功能
$("#ext_field").change(function(){
key = 0;
var ext_field = $("#ext_field").val();
console.log(ext_field);
$("tbody").empty();
@ -259,7 +260,7 @@
console.log(data)
for (var i in data){
if (data[i].company_id) {
add += "<option company_id='" + data[i].company_id + "' value='" + data[i].company_id + "' " + ('selected') + ">" + data[i].company_name + "</option>"
add += "<option company_id='" + data[i].company_id + "' value='" + data[i].company_name + "' " + ('selected') + ">" + data[i].company_name + "</option>"
}
}
$("#company_name").empty();
@ -334,6 +335,7 @@
//搜索功能
$("#company_name").change(function(){
key = 0;
var ext_field = $("#company_name option:selected").attr('company_id');
console.log(ext_field);
$("tbody").empty();

@ -52,7 +52,7 @@
</div>
<div class="input-list input-list-promote search_label_rehab" style="width: 50%">
银行账号:
<input type="text" readonly id="bank_card" name="bank_card" class="" value="" placeholder="银行账号" style="width: 50%"/>
<input type="text" id="bank_card" name="bank_card" class="" value="" placeholder="银行账号" style="width: 50%"/>
</div>
<div class="input-list input-list-promote search_label_rehab" style="width: 50%">
@ -204,7 +204,7 @@
success:function(data){
console.log($("#company_name option:selected").attr('company-type'))
$("#company_name").val(data.data.company_name);
$("#company_name").append("<option value='"+data.data.company_name+"' selected='selected'>"+data.data.company_name+"</option>");
$("#settlement_type").text(data.data.settlement_type);
$("#bank_card").val(data.data.bank_card);
$("#account_openin").val(data.data.account_openin);

@ -139,7 +139,7 @@
</td>
</tr>
</volist>
<tr><td>合计</td><td colspan="10">公司对账金额合计:{$sum[0]}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cp对账金额合计{$sum[1]}</td></tr>
<tr><td>合计</td><td colspan="10">公司对账金额合计:{$sum[1]}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cp对账金额合计{$sum[0]}</td></tr>
</notemtpy>
</tbody>
</table>

@ -1106,6 +1106,10 @@ function getGameSelleRatioByPromote($promoteId = null, $gameId = null)
$promoteId = intval($promoteId);
$gameId = intval($gameId);
$promote = M('promote', 'tab_')->find($promoteId);
$gameId = M('game', 'tab_')->where(array('id' => $gameId))->getField('relation_game_id');
if (empty($gameId)) {
return false;
}
if (empty($promote)) {
return false;

@ -1098,3 +1098,11 @@ CREATE TABLE `sys_document_pop_rules` (
`operater_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '操作者ID',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
-- 2020-01-14
-- cxj
ALTER TABLE `tab_promote_game_ratio`
MODIFY COLUMN `turnover_ratio` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '流水分成比例' AFTER `last_ratio_status`,
MODIFY COLUMN `last_turnover_ratio` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '' COMMENT '上次流水分成比例';
UPDATE tab_spend SET selle_ratio = 0.00 where selle_ratio is null
Loading…
Cancel
Save