财务比对5

master
chenzhi 5 years ago
parent 202f9a45d1
commit c4eb963cfe

@ -5,9 +5,12 @@ class FinanceCompareController extends ThinkController
public $zfb = [1];//官方支付宝渠道id
public $wx = [2,3];//微信渠道id
public $ybzf = [17];//易宝渠道id
public $erro_size = 2000;//错误阈值,到达就不执行
public $page_size = 10;//每次执行比较的数量
public function add()
{
$this->assign("page_size",$this->page_size);
$this->display();
# code...
}
@ -40,9 +43,9 @@ class FinanceCompareController extends ThinkController
foreach($data as $k=>$v){
$pay_where = substr($v[$keys[0]], 0, 2);
$tmp = [
"pt_pay_amount"=>$v[$keys[1]],
"pt_pay_amount"=>0,
"diff_money"=>$v[$keys[1]],
"sj_pay_amount"=>0,
"sj_pay_amount"=>$v[$keys[1]],
"type"=>3,
"pay_order_number"=>$v[$keys[0]],
"compare_id"=>$compare_id,
@ -50,10 +53,13 @@ class FinanceCompareController extends ThinkController
"is_read"=>0
];
if($pay_where == 'SP'){
$tmp['order_type']=1;
$sp[$v[$keys[0]]] = $tmp;
}elseif($pay_where == 'PF'){
$tmp['order_type']=2;
$pf[$v[$keys[0]]] = $tmp;
}else{
$tmp['order_type']=0;
$er[$v[$keys[0]]] = $tmp;
}
}
@ -65,43 +71,183 @@ class FinanceCompareController extends ThinkController
if($sres){
$this->setDiffData($sres,$sp);
}
$saveres = $this->saveCheckData($sp);
if($saveres == false){
$this->ajaxReturn(array("error"=>"添加失败","code"=>40001));
}
}
//判断平台币流水
if(count($pf) > 0){
$keys = implode(",",array_keys($pf));
$where = ["pay_order_number"=>["in",$keys]];
$sres = M("Deposit","tab_")->field("pay_order_number,pay_amount,pay_status,pay_way")->where($where)->select();
if($sres){
$this->setDiffData($sres,$pf);
}
$saveres = $this->saveCheckData($pf);
if($saveres == false){
$this->ajaxReturn(array("error"=>"添加失败","code"=>40002));
}
}
//不存在订单添加
if(count($er) > 0){
$saveerrores = $this->saveCheckData($er);
if($saveerrores == false){
$this->ajaxReturn(array("error"=>"添加失败","code"=>40003));
}
}
dd($sres);
$this->ajaxReturn(array("success"=>"ok","code"=>0,"data"=>[]));
}
/**
* 验证平台游戏流水
*/
public function checkSpendData()
{
$checkdata = I('POST.');
if ($checkdata['pay_way'] == 1) {
$check_arr = $this->zfb;
}elseif($checkdata['pay_way'] == 2){
$check_arr = $this->wx;
}elseif($checkdata['pay_way'] == 3){
$check_arr = $this->ybzf;
}
$check_arr = implode(",",$check_arr);
//组件sql
$fmap = [
"compare_id"=>$checkdata['compare_id'],
"order_type"=>1
];
$fcisql = M("finance_compare_info","tab_")->field("pay_order_number")->where($fmap)->select(false);
$map = [
"pay_order_number"=>["not in",$fcisql],
"pay_time" => ['between', [strtotime($checkdata['begin_time']), strtotime($checkdata['end_time']) + 86399]],
"pay_status"=>1,
"pay_way"=>["in",$check_arr]
];
$res = M("Spend","tab_")->field("pay_order_number,pay_amount,pay_status,pay_way")->where($map)->limit($this->erro_size)->select();
if(count($res) >= $this->erro_size){
$this->ajaxReturn(array("error"=>"数据差别相差大于{$this->erro_size}条,没有比较的意义,请确认表格的渠道和时间是否正确","code"=>40004));
}
$saveres = true;
if(count($res) > 0){
$add = [];
foreach($res as $k=>$v){
$tmp = [
"pt_pay_amount"=>$v["pay_amount"],
"diff_money"=>$v["pay_amount"],
"sj_pay_amount"=>0,
"type"=>2,
"pay_order_number"=>$v["pay_order_number"],
"compare_id"=>$checkdata['compare_id'],
"pay_way"=>$checkdata['pay_way'],
"order_type"=>1,
"is_read"=>0
];
$add[] = $tmp;
}
unset($res);
$saveres = M("finance_compare_info","tab_")->addAll($add);
}
if($saveres){
$this->ajaxReturn(array("success"=>"ok","code"=>0,"data"=>[]));
}else{
$this->ajaxReturn(array("error"=>"比对数据添加失败","code"=>40005));
}
}
/**
* 验证平台币流水
*/
public function checkDepositData()
{
$checkdata = I('POST.');
if ($checkdata['pay_way'] == 1) {
$check_arr = $this->zfb;
}elseif($checkdata['pay_way'] == 2){
$check_arr = $this->wx;
}elseif($checkdata['pay_way'] == 3){
$check_arr = $this->ybzf;
}
$check_arr = implode(",",$check_arr);
//组件sql
$fmap = [
"compare_id"=>$checkdata['compare_id'],
"order_type"=>2
];
$fcisql = M("finance_compare_info","tab_")->field("pay_order_number")->where($fmap)->select(false);
$map = [
"pay_order_number"=>["not in",$fcisql],
"create_time" => ['between', [strtotime($checkdata['begin_time']), strtotime($checkdata['end_time']) + 86399]],
"pay_status"=>1,
"pay_way"=>["in",$check_arr]
];
$res = M("Deposit","tab_")->field("pay_order_number,pay_amount,pay_status,pay_way")->where($map)->select();
if(count($res) > 10000){
$this->ajaxReturn(array("error"=>"数据差别相差大于10000条没有比较的意义请确认表格的渠道和时间是否正确","code"=>40004));
}
protected function setDiffData($dbres,$ydata)
$saveres = true;
if(count($res) > 0){
$add = [];
foreach($res as $k=>$v){
$tmp = [
"pt_pay_amount"=>$v["pay_amount"],
"diff_money"=>$v["pay_amount"],
"sj_pay_amount"=>0,
"type"=>2,
"pay_order_number"=>$v["pay_order_number"],
"compare_id"=>$checkdata['compare_id'],
"pay_way"=>$checkdata['pay_way'],
"order_type"=>2,
"is_read"=>0
];
$add[] = $tmp;
}
unset($res);
$saveres = M("finance_compare_info","tab_")->addAll($add);
}
if($saveres){
$this->ajaxReturn(array("success"=>"ok","code"=>0,"data"=>[]));
}else{
$this->ajaxReturn(array("error"=>"比对数据添加失败","code"=>40005));
}
}
//比较数据库与原数据
protected function setDiffData($dbres,&$ydata)
{
//type 1:金额不符 2商家数据缺失 3:平台数据缺失 4:状态不符5:渠道不符
foreach ($dbres as $k => $v) {
if(array_key_exists($v['pay_order_number'],$ydata)){
//存在
$flag = true;
$ydata[$v['pay_order_number']]['sj_pay_amount'] = $v['pay_amount'];
$ydata[$v['pay_order_number']]['pt_pay_amount'] = $v['pay_amount'];
$ydata[$v['pay_order_number']]['diff_money'] = abs($ydata[$v['pay_order_number']]['pt_pay_amount']-$v['pay_amount']);
if($ydata[$v['pay_order_number']]['sj_pay_amount'] != $v['pay_amount']){//金额不符
$ydata[$v['pay_order_number']]['type'] = 1;
$flag = false;
continue;
}
if($v['pay_status'] != 1){//状态不符合
$ydata[$v['pay_order_number']]['type'] = 4;
$ydata[$v['pay_order_number']]['diff_money'] = $v['pay_amount'];
$flag = false;
continue;
}
//判断渠道
$way = $ydata[$v['pay_order_number']]['pay_way'];
if ($way == 1) {
$checkarr = $this->$zfb;
$checkarr = $this->zfb;
}elseif($way == 2){
$checkarr = $this->$wx;
$checkarr = $this->wx;
}elseif($way == 3){
$checkarr = $this->$ybzf;
$checkarr = $this->ybzf;
}
if(!in_array($way,$checkarr)){//渠道不符
$ydata[$v['pay_order_number']]['type'] = 5;
$flag = false;
}
if($ydata[$v['pay_order_number']]['pt_pay_amount'] != $v['pay_amount']){//金额不符
$ydata[$v['pay_order_number']]['type'] = 1;
$flag = false;
}
if($v['pay_status'] != 1){//状态不符合
$ydata[$v['pay_order_number']]['type'] = 4;
$ydata[$v['pay_order_number']]['diff_money'] = $v['pay_amount'];
$flag = false;
continue;
}
if($flag){
@ -109,6 +255,16 @@ class FinanceCompareController extends ThinkController
}
}
}
dd($ydata);
}
//添加详情
protected function saveCheckData(&$data){
$arr = [];
foreach ($data as $k => $v) {
$arr[] = $v;
}
unset($data);
$res = M("finance_compare_info","tab_")->addAll($arr);
unset($arr);
return $res;
}
}

@ -125,7 +125,7 @@
callback(data.data);
}else{
MSG.hidemsg();
layer.msg(data.error);
layer.alert(data.error);
return false;
}
@ -153,13 +153,39 @@
checkarr:sendDefaultData.filedata.splice(0,check_size)
}
COMPARE.publiucAjax("{:U('compareData')}",senddata,function(data){
var checkok = page*check_size > sendDefaultData.filedata_count ? sendDefaultData.filedata_count : page*check_size;
MSG.showmsg("比较数据 ["+checkok+"/"+sendDefaultData.filedata_count+"] ......");
page++;
COMPARE.loopCheck(page,callback)
});
},
//生成游戏订单平台缺失订单
checkSpendData:function(callback){
var senddata = {
compare_id:sendDefaultData.compare_id,
pay_way:sendDefaultData.pay_way,
begin_time:sendDefaultData.begin_time,
end_time:sendDefaultData.end_time,
}
COMPARE.publiucAjax("{:U('checkSpendData')}",senddata,function(data){
MSG.showmsg("生成平台 游戏流水比对订单......");
console.log(data)
callback();
});
},
//生成游戏订单平台缺失订单
checkDepositData:function(callback){
var senddata = {
compare_id:sendDefaultData.compare_id,
pay_way:sendDefaultData.pay_way,
begin_time:sendDefaultData.begin_time,
end_time:sendDefaultData.end_time,
}
COMPARE.publiucAjax("{:U('checkDepositData')}",senddata,function(data){
MSG.showmsg("生成平台 平台币比对订单......");
console.log(data)
callback();
});
}
}
@ -167,7 +193,7 @@
<script type="text/javascript">
var isfile = false;
var rABS = false; //是否将文件读取为二进制字符串
var check_size = 10;//每次验证的数量
var check_size = "{$page_size}";//每次验证的数量
var sendDefaultData = {
"keys": [],
@ -175,7 +201,9 @@
"compare_id": 0,
"check_page":0,
"filedata":[],
"pay_way":-1
"pay_way":-1,
"begin_time":0,
"end_time":0
}
$(function () {
@ -219,6 +247,8 @@
//获取需要循环的次数
sendDefaultData.check_page = Math.ceil(sendDefaultData.filedata_count/check_size);
sendDefaultData.pay_way = paychannel;
sendDefaultData.begin_time = start;
sendDefaultData.end_time = end;
//创建面单
var senddata = {
begin_time:start,
@ -228,9 +258,13 @@
}
COMPARE.creatCompare(senddata,function(){
COMPARE.loopCheck(1,function(){
COMPARE.checkSpendData(function(){
COMPARE.checkDepositData(function(){
})
})
})
})
})
})

@ -1555,6 +1555,7 @@ CREATE TABLE `tab_finance_compare_info` (
`sj_pay_amount` decimal(10,2) unsigned NOT NULL DEFAULT '0' COMMENT '商家金额',
`diff_money` decimal(10,2) unsigned NOT NULL DEFAULT '0' COMMENT '异常金额',
`type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '0:正常;1:金额不符;2:商家数据缺失;3:平台数据缺失;4:状态不符;5:渠道不符',
`order_type` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '1:游戏流水;2:平台币订单;0未知',
`compare_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '父表id',
`is_read` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '是否已处理',
PRIMARY KEY (`id`),
@ -1562,6 +1563,7 @@ CREATE TABLE `tab_finance_compare_info` (
KEY `pay_order_number` (`pay_order_number`) USING BTREE,
KEY `compare_id` (`compare_id`) USING BTREE,
KEY `compare_type` (`compare_id`,`type`) USING BTREE,
KEY `compare_order_type` (`compare_id`,`order_type`,`pay_order_number`) USING BTREE,
KEY `pay_way` (`pay_way`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='财务导入对账详情表';

Loading…
Cancel
Save