新增cp公司优化奖罚自动获取

master
chenzhi 5 years ago
parent 2e4f1edb5a
commit 58eb6a0e12

@ -18,8 +18,14 @@ class StatementController extends ThinkController
$first_party_info = json_decode($dbres['first_party_info'],true);
$second_party_info = json_decode($dbres['second_party_info'],true);
$statement_info = json_decode($dbres['statement_info'],true);
$fine = array_pop($statement_info);
if($dbres['company_name'] == $first_party_info['partner']){
$first_partner_type=0;
}else{
$first_partner_type=1;
}
// $fine = array_pop($statement_info);
$senddata = array(
"first_partner_type"=>$first_partner_type,
"first_part_company"=>$first_party_info['partner'],
"second_part_company"=>$second_party_info['partner'],
"statement_type"=>$_REQUEST['pay_type'] == 0 ? 1 :0,
@ -27,13 +33,13 @@ class StatementController extends ThinkController
"second_party_info"=>$second_party_info,
"statement_info"=>$statement_info,
"statement_count"=>array("sum_money"=>$dbres['statement_money'],"pay_amount"=>$dbres['pay_amount']),
"fine"=>$fine['sum_money'],
"fine"=>0,
"statement_begin_time"=>date("Y-m-d",$dbres['statement_begin_time']),
"statement_end_time"=>date("Y-m-d",$dbres['statement_end_time'])
);
$this->assign("data",$senddata);
if($_REQUEST['pay_type'] == 0){
$this->assign("company",$dbres['company_name']);
$this->assign("company",$second_party_info['partner']);
}else{
$this->assign("company",$first_party_info['partner']);
}
@ -56,15 +62,20 @@ class StatementController extends ThinkController
$this->ajaxReturn(array("error"=>"database error","code"=>2000));
}
}
public function getCompanyList()
{
$data = array();
$data['ptCompany']= M("CompanyInfo","tab_")->field('id,partner')->select();
$data['cpCompany']= getPartner();
$this->ajaxReturn(array("success"=>$data,"code"=>2000));
}
//获取推广公司基础信息
public function getCpCompanyInfo()
{
$CompanyId = $_REQUEST['company_id'];
if($CompanyId == 0){
$mycompany = M("tool","tab_")->field("config")->where("name='company_info'")->find();
$info = json_decode($mycompany['config'],true);
$info['id'] = 0;
unset($info['status']);
$company_type = $_REQUEST['company_type'];
if($company_type == 'pt'){
$info = M("CompanyInfo","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank")->where("id = '{$CompanyId}'")->find();
}else{
$info = M("partner","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank")->where("id = '{$CompanyId}'")->find();
}
@ -81,7 +92,8 @@ class StatementController extends ThinkController
$map["pay_status"] = 1;
$CompanyId = $_REQUEST['company_id']; //对账公司id
$statement_type = $_REQUEST['statement_type'];
$statement_type = $_REQUEST['statement_type'];//付款方
$first_partner_type = $_REQUEST['first_partner_type'];//甲方类型0cp,1pt
$is_month = false;//是否是月结判断,非月结无需梯度计算
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
@ -164,8 +176,14 @@ class StatementController extends ThinkController
// $redio = $ratiores[0]['ratio'];
// }
$redio = getGameCpRadio($v['game_id'],$v['pay_amount'],$is_month);//获取分成比例
$v['second_ratio'] = $redio;
$v['first_ratio'] = (100-$redio);
if($first_partner_type==0){
//甲方cp
$v['first_ratio'] = round($redio,2);
$v['second_ratio'] = round((100-$redio),2);
}else{
$v['second_ratio'] = round($redio,2);
$v['first_ratio'] = round((100-$redio),2);
}
if($statement_type == 0){
$v['sum_money'] = round($v['pay_amount']*$v['first_ratio']/100,2);
}else{
@ -180,6 +198,41 @@ class StatementController extends ThinkController
$v['statement_end_time']=$_REQUEST['time_end'];
$v['statement_type']=0;
}
//获取奖罚
$rrmap = array(
"reward_time" => ['between', [strtotime($_REQUEST['time_start']), strtotime($_REQUEST['time_end']) + 86399]],
);
$rfres = M("RewardRecord","tab_")
->field("
IFNULL(SUM(CASE WHEN reward_type = 1 THEN money ELSE 0 END),0) as reward_count,
IFNULL(SUM(CASE WHEN reward_type = 2 THEN money ELSE 0 END),0) as fine_count
")
->where($rrmap)->find();
if($rfres['reward_count'] > 0){
$list[] = array(
"statement_begin_time"=>$_REQUEST['time_start'],
"statement_end_time"=>$_REQUEST['time_end'],
'statement_type'=>2,
"game_name"=>"奖励",
'pay_amount'=>$rfres['reward_count'],
'sum_money'=>$rfres['reward_count'],
);
$countarr['pay_amount'] +=$rfres['reward_count'];
$countarr['sum_money']+=$rfres['reward_count'];
}
if($rfres['fine_count'] > 0){
$list[] = array(
"statement_begin_time"=>$_REQUEST['time_start'],
"statement_end_time"=>$_REQUEST['time_end'],
'statement_type'=>1,
"game_name"=>"罚款",
'pay_amount'=>$rfres['fine_count'],
'sum_money'=>$rfres['fine_count'],
);
$countarr['pay_amount'] -= $rfres['fine_count'];
$countarr['sum_money'] -= $rfres['fine_count'];
}
$countarr['pay_amount'] = round($countarr['pay_amount'],2);
$countarr['sum_money'] = round($countarr['sum_money'],2);
@ -188,19 +241,26 @@ class StatementController extends ThinkController
}
//添加数据
public function doAddCpStatement($id = 0){
$first_partner_type = $_REQUEST['first_partner_type'];
if($first_partner_type == 0){
//甲方cp
$company = $_REQUEST['first_party_info'];
}else{
$company =$_REQUEST['second_party_info'];
}
$second_party_info = $_REQUEST['second_party_info'];
$statement_info = $_REQUEST['statement_info'];
$statement_info[] = array(
"sum_money"=>$_REQUEST['fine'],
"type_name"=>"罚款",
"statement_type"=>1
);
// $statement_info[] = array(
// "sum_money"=>$_REQUEST['fine'],
// "type_name"=>"罚款",
// "statement_type"=>1
// );
//拼凑数据
$adddata = array(
"statement_type"=>0,
"company_id"=>$second_party_info['id'],
"company_name"=>$second_party_info['partner'],
"link_phone"=>$second_party_info['link_phone'],
"company_id"=>$company['id'],
"company_name"=>$company['partner'],
"link_phone"=>$company['link_phone'],
"statement_begin_time"=>strtotime($_REQUEST['statement_begin_time']),
"statement_end_time"=>strtotime($_REQUEST['statement_end_time']),
'create_time'=>time(),

@ -89,16 +89,24 @@
<div class="tab-content tabcon1711" id="firstPartBaseInfo">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="l">公司类型:</td>
<td class="r">
<div class="input-list input-list-game search_label_rehab">
<select id="first_partner_type" name="first_partner_type" class="select_gallery">
<option value="">请选择甲方公司类型</option>
<option value="0">CP上游公司</option>
<option value="1">平台归属公司</option>
</select>
</div>
</td>
</tr>
<tr>
<td class="l">甲方:</td>
<td class="r">
<div class="input-list input-list-game search_label_rehab">
<select id="first_partner_id" name="partner_id" class="select_gallery">
<option value="">请选择合作公司</option>
<option value="0" selected>海南万盟天下科技有限公司</option>
<volist name=":getPartner()" id="vo">
<option partner-id="{$vo.id}" value="{$vo.id}" <if condition="$vo.id eq $_GET['partner_id']">selected=selected</if>>{$vo.partner}</option>
</volist>
</select>
</div>
</td>
@ -107,25 +115,25 @@
<tr>
<td class="l">联系人:</td>
<td class="r">
<input type="text" class="txt" name="link_man" value="" placeholder="请输入联系人">
<input type="text" class="txt" name="link_man" value="" disabled="disabled" placeholder="请先选择甲方公司">
</td>
</tr>
<tr>
<td class="l">联系电话:</td>
<td class="r">
<input type="text" class="txt" name="link_phone" value="" placeholder="请输入联系电话">
<input type="text" class="txt" name="link_phone" value="" disabled="disabled" placeholder="请先选择甲方公司">
</td>
</tr>
<tr>
<td class="l">邮寄地址:</td>
<td class="r">
<input type="text" class="txt" name="address" value="" placeholder="请输入地址">
<input type="text" class="txt" name="address" value="" disabled="disabled" placeholder="请先选择甲方公司">
</td>
</tr>
<tr>
<td class="l">公司税号:</td>
<td class="r">
<input type="text" class="txt" name="company_tax_no" value="" placeholder="请输入公司税号">
<input type="text" class="txt" name="company_tax_no" disabled="disabled" value="" placeholder="请先选择甲方公司">
</td>
</tr>
</tbody>
@ -135,16 +143,16 @@
<div class="tab-content tabcon1711" id="secondPartBaseInfo">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="l"></td>
<td class="r"></td>
</tr>
<tr>
<td class="l">乙方:</td>
<td class="r">
<div class="input-list input-list-game search_label_rehab">
<select id="second_partner_id" name="partner_id" class="select_gallery">
<option value="">请选择合作公司</option>
<option value="0">海南万盟天下科技有限公司</option>
<volist name=":getPartner()" id="vo">
<option partner-id="{$vo.id}" value="{$vo.id}" <if condition="$vo.id eq $_GET['partner_id']">selected=selected</if>>{$vo.partner}</option>
</volist>
</select>
</div>
</td>
@ -381,26 +389,34 @@
<script type="text/html" id="statementTpl">
{@each list as it,index}
<tr>
<td>${it.statement_begin_time}-${it.statement_end_time}</td>
<td>${it.statement_begin_time}~${it.statement_end_time}</td>
<td>${it.game_name}</td>
<td>${it.pay_amount}元</td>
<td><input type="text" class="txt statementchange" name="first_ratio" data-index ="${index}" data-change="statement_info[${index}]['first_ratio']" value="${it.first_ratio}" style="width: 30px;">%</td>
<td><input type="text" class="txt statementchange" name="second_ratio" data-index ="${index}" data-change="statement_info[${index}]['second_ratio']" value="${it.second_ratio}" style="width: 30px;">%</td>
<td><input type="text" class="txt statementchange" name="promote_ratio" data-index ="${index}" data-change="statement_info[${index}]['promote_ratio']" value="${it.promote_ratio}" style="width: 30px;">%</td>
<td><input type="text" class="txt statementchange" name="fax_ratio" data-index ="${index}" data-change="statement_info[${index}]['fax_ratio']" value="${it.fax_ratio}" style="width: 30px;">%</td>
<td>${it.sum_money}元</td>
{@if it.statement_type==1}
<td>-${it.pay_amount}元</td>
{@else}
<td>${it.pay_amount}元</td>
{@/if}
{@if it.statement_type==0}
<td><input type="text" class="txt statementchange" name="first_ratio" data-index ="${index}" data-change="statement_info[${index}]['first_ratio']" value="${it.first_ratio}" style="width: 40px;">%</td>
<td><input type="text" class="txt statementchange" name="second_ratio" data-index ="${index}" data-change="statement_info[${index}]['second_ratio']" value="${it.second_ratio}" style="width: 40px;">%</td>
<td><input type="text" class="txt statementchange" name="promote_ratio" data-index ="${index}" data-change="statement_info[${index}]['promote_ratio']" value="${it.promote_ratio}" style="width: 40px;">%</td>
<td><input type="text" class="txt statementchange" name="fax_ratio" data-index ="${index}" data-change="statement_info[${index}]['fax_ratio']" value="${it.fax_ratio}" style="width: 40px;">%</td>
{@else}
<td></td>
<td></td>
<td></td>
<td></td>
{@/if}
{@if it.statement_type==1}
<td>-${it.sum_money}元</td>
{@else}
<td>${it.sum_money}元</td>
{@/if}
</tr>
{@/each}
<tr>
<td></td>
<td>罚款</td>
<td><input type="text" class="txt statementchange" name="fine" data-change="fine" value="${fine}" style="width: 50px;"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>${fine}元</td>
</tr>
<tr>
<td>合计</td>
<td></td>
@ -438,7 +454,7 @@
})
EVENT.changeCompany();
EVENT.createStatement();
$("#first_partner_id").change();//默认甲方只能是我们公司
// $("#first_partner_id").change();//默认甲方只能是我们公司
});
//基础类
@ -512,6 +528,7 @@
}
//数据类
var DATAOBJ = {
first_partner_type:false,
first_part_company:false,
second_part_company:false,
@ -527,13 +544,51 @@
//事件类
var EVENT = {
changeCompany(){
$("#first_partner_type").on("change",function(){
var type = $(this).find("option:selected").val();
if(type == ''){
type=false;
}
DATAOBJ.first_partner_type = type;
//获取cp和内部公司
var url = "{:U('getCompanyList')}";
PUBLIC.postData(url,{},function(data){
var ptCompany = data.success.ptCompany;
var cpCompany = data.success.cpCompany;
var ptstr = '<option value="">请选择平台归属公司</option>';
for (var i in ptCompany) {
ptstr += "<option value='" + ptCompany[i].id + "'>" + ptCompany[i].partner + "</option>"
}
var cpstr = '<option value="">请选择合作公司</option>';
for (var i in cpCompany) {
cpstr += "<option value='" + cpCompany[i].id + "'>" + cpCompany[i].partner + "</option>"
}
//
if(type == 0){
$("#first_partner_id").html(cpstr);
$("#second_partner_id").html(ptstr);
}else{
$("#first_partner_id").html(ptstr);
$("#second_partner_id").html(cpstr);
}
$("#first_partner_id").select2();
$("#second_partner_id").select2();
})
})
$("#first_partner_id").on("change",function(){
//获取数据
var comid = $(this).find("option:selected").val();
//获取基础数据
var url = "{:U('getCpCompanyInfo')}";
PUBLIC.postData(url,{company_id:comid},function(data){
console.log(data);
var company_type;
if(DATAOBJ.first_partner_type == 0){
//CP上游公司
company_type = "cp";
}else{
company_type = "pt";
}
PUBLIC.postData(url,{company_id:comid,company_type:company_type},function(data){
DATAOBJ.first_part_company = data.success.partner;
DATAOBJ.first_party_info = data.success;
data.success.type = "first_party_info";
@ -545,7 +600,14 @@
var comid = $(this).find("option:selected").val();
//获取基础数据
var url = "{:U('getCpCompanyInfo')}";
PUBLIC.postData(url,{company_id:comid},function(data){
var company_type;
if(DATAOBJ.first_partner_type == 0){
//CP上游公司
company_type = "pt";
}else{
company_type = "cp";
}
PUBLIC.postData(url,{company_id:comid,company_type:company_type},function(data){
DATAOBJ.second_part_company = data.success.partner;
DATAOBJ.second_party_info = data.success;
data.success.type = "second_party_info";
@ -565,15 +627,24 @@
layer.msg('开始时间必须小于等于结束时间');
return false;
}
var company_id;
if(DATAOBJ.first_partner_type == 0){
//CP上游公司
company_id = $("#first_partner_id").find("option:selected").val();
}else{
company_type = $("#second_partner_id").find("option:selected").val();
}
//发起查询
var selectData = {
"time_start":time_start,
"time_end":time_end,
"statement_type":DATAOBJ.statement_type,
"company_id": $("#second_partner_id").find("option:selected").val()
"first_partner_type":DATAOBJ.first_partner_type,
"company_id": company_id
}
var url = "{:U('getSpendStatement')}";
PUBLIC.postData(url,selectData,function(data){
console.log(data);
if(data.code > 0){
layer.alert(data.error);
return false;

@ -106,7 +106,7 @@
<td class="r">
<div class="input-list input-list-game search_label_rehab">
<select id="first_partner_id" name="partner_id" class="select_gallery">
<option value="0" selected>海南万盟天下科技有限公司</option>
<option value="{$data['first_party_info']['id']}" selected>{$data['first_part_company']}</option>
</select>
</div>
</td>
@ -148,7 +148,7 @@
<td class="r">
<div class="input-list input-list-game search_label_rehab">
<select id="second_partner_id" name="partner_id" class="select_gallery">
<option value="{$company_id}" selected>{$company_name}</option>
<option value="{$data['second_party_info']['id']}" selected>{$data['second_part_company']}</option>
</select>
</div>
</td>
@ -381,29 +381,37 @@
</table>
</div>
</script>
<script type="text/html" id="statementTpl">
<script type="text/html" id="statementTpl">
{@each list as it,index}
<tr>
<td>${it.statement_begin_time}-${it.statement_end_time}</td>
<td>${it.statement_begin_time}~${it.statement_end_time}</td>
<td>${it.game_name}</td>
<td>${it.pay_amount}元</td>
<td><input type="text" class="txt statementchange" name="first_ratio" data-index ="${index}" data-change="statement_info[${index}]['first_ratio']" value="${it.first_ratio}" style="width: 30px;">%</td>
<td><input type="text" class="txt statementchange" name="second_ratio" data-index ="${index}" data-change="statement_info[${index}]['second_ratio']" value="${it.second_ratio}" style="width: 30px;">%</td>
<td><input type="text" class="txt statementchange" name="promote_ratio" data-index ="${index}" data-change="statement_info[${index}]['promote_ratio']" value="${it.promote_ratio}" style="width: 30px;">%</td>
<td><input type="text" class="txt statementchange" name="fax_ratio" data-index ="${index}" data-change="statement_info[${index}]['fax_ratio']" value="${it.fax_ratio}" style="width: 30px;">%</td>
<td>${it.sum_money}元</td>
{@if it.statement_type==1}
<td>-${it.pay_amount}元</td>
{@else}
<td>${it.pay_amount}元</td>
{@/if}
{@if it.statement_type==0}
<td><input type="text" class="txt statementchange" name="first_ratio" data-index ="${index}" data-change="statement_info[${index}]['first_ratio']" value="${it.first_ratio}" style="width: 40px;">%</td>
<td><input type="text" class="txt statementchange" name="second_ratio" data-index ="${index}" data-change="statement_info[${index}]['second_ratio']" value="${it.second_ratio}" style="width: 40px;">%</td>
<td><input type="text" class="txt statementchange" name="promote_ratio" data-index ="${index}" data-change="statement_info[${index}]['promote_ratio']" value="${it.promote_ratio}" style="width: 40px;">%</td>
<td><input type="text" class="txt statementchange" name="fax_ratio" data-index ="${index}" data-change="statement_info[${index}]['fax_ratio']" value="${it.fax_ratio}" style="width: 40px;">%</td>
{@else}
<td></td>
<td></td>
<td></td>
<td></td>
{@/if}
{@if it.statement_type==1}
<td>-${it.sum_money}元</td>
{@else}
<td>${it.sum_money}元</td>
{@/if}
</tr>
{@/each}
<tr>
<td></td>
<td>罚款</td>
<td><input type="text" class="txt statementchange" name="fine" data-change="fine" value="${fine}" style="width: 50px;"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>${fine}元</td>
</tr>
<tr>
<td>合计</td>
<td></td>

Loading…
Cancel
Save