You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

288 lines
14 KiB
PHP

<?php
namespace Admin\Controller;
use Org\Util\Date;
use Sdk\Controller\AgeController;
use User\Api\MemberApi as MemberApi;
use Org\WeixinSDK\Weixin;
class PayMerchantController extends ThinkController
{
const WAY_ALIPAY = 1;
const WAY_WEIXIN = 2;
const WAY_EXPRESS = 4;
public function index($p = 0) {
// if(!array_key_exists("timestart",$_REQUEST)){
// $this->redirect(ACTION_NAME, array('timestart' => date('Y-m-d',strtotime('-30 day')),"timeend"=>date('Y-m-d')));
// }
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$arraypage = $page;
if (isset($_REQUEST['row'])) {
$row = $_REQUEST['row'];
} else {
$row = 10;
}
$map = [];
if (!empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['payed_time'] = array('between', [strtotime($_REQUEST['timestart']), strtotime($_REQUEST['timeend']) + 86399]);
} elseif (!empty($_REQUEST['timestart']) && empty($_REQUEST['timeend'])) {
$map['payed_time'] = array('between', [strtotime($_REQUEST['timestart']), time()]);
} elseif (empty($_REQUEST['timestart']) && !empty($_REQUEST['timeend'])) {
$map['payed_time'] = array('elt', (strtotime($_REQUEST['timeend']) + 86399));
}
if ($_REQUEST['game_id']) {
$map['game_id'] = $_REQUEST['game_id'];
}
if ($_REQUEST['name']) {
$map['name'] = $_REQUEST['name'];
}
if ($_REQUEST['main_name']) {
$map['main_name'] = $_REQUEST['main_name'];
}
//游戏充值金额
$data = M("spend use index(pay_channel)","tab_")
->field("SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is null THEN pay_amount ELSE 0 END) as cash_amount,
SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is not null THEN pay_amount ELSE 0 END) as test_amount,
0 coin_amount,0 offcial_amount,0 spread_amount,0 supersign_amount,0 test_order_amount,merchant_id,name,channel,identifier,
payed_time,game_id,main_name,merchant_way,merchant.account")
->join("left join tab_test_white_list on tab_spend.user_id=tab_test_white_list.user_id")
->join("left join tab_payment_merchant merchant on merchant.id=tab_spend.merchant_id")
->where(['pay_status'=>1,'tab_spend.pay_way'=>['egt',1],'merchant.status'=>1,'merchant.type'=>1])
->where($map)
->group("merchant_id,merchant_way")
->select(false);
//平台币充值金额计算
$coinData = M('pay_info','tab_')
->join("inner join tab_deposit on tab_pay_info.order_id=tab_deposit.pay_order_number")
->join("left join tab_test_white_list on tab_test_white_list.user_id=tab_pay_info.user_id")
->join("left join tab_payment_merchant merchant on merchant.id=tab_deposit.merchant_id")
->field("0 cash_amount,SUM(CASE WHEN merchant.id is not null and pay_source=2 and tab_test_white_list.user_id is not null THEN pay_amount ELSE 0 END) as test_amount,
SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is null and pay_source=2 THEN pay_amount ELSE 0 END) as coin_amount,
0 offcial_amount,0 spread_amount,0 supersign_amount,0 test_order_amount,merchant_id,name,channel,identifier,payed_time,game_id,main_name,merchant_way,merchant.account")
->where(['pay_status'=>1,'tab_deposit.pay_way'=>['egt',1],'merchant.status'=>1,'merchant.type'=>1])
->where($map)
->group("merchant_id,merchant_way")
->select(false);
// var_dump($coinData);die();
//官网金额
$officalData = M('deposit','tab_')
->join("left join tab_test_white_list on tab_test_white_list.user_id=tab_deposit.user_id")
->join("left join tab_payment_merchant merchant on merchant.id=tab_deposit.merchant_id")
->field("0 cash_amount,SUM(CASE WHEN merchant.id is not null and pay_source=0 and tab_test_white_list.user_id is not null THEN pay_amount ELSE 0 END) as test_amount,
0 as coin_amount,SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is null and pay_source=0 THEN pay_amount ELSE 0 END) as offcial_amount,
0 spread_amount,0 supersign_amount,0 test_order_amount,merchant_id,name,channel,identifier,payed_time,0 as game_id,main_name,merchant_way,merchant.account")
->where(['pay_status'=>1,'tab_deposit.pay_way'=>['egt',1],'merchant.status'=>1,'merchant.type'=>1])
->where($map)
->group("merchant_id,merchant_way")
->select(false);
if ($map['payed_time'])
{
$map['pay_time'] = $map['payed_time'];
unset($map['payed_time']);
}
//推广后台
$spreadData = M("coin_pay_order","tab_")
->field("0 cash_amount,0 test_amount,0 coin_amount,0 offcial_amount,
SUM(CASE WHEN merchant.id is not null THEN pay_amount ELSE 0 END) as spread_amount,0 supersign_amount,
0 test_order_amount,merchant_id,name,channel,identifier,pay_time payed_time,0 game_id,main_name,merchant_way,merchant.account")
->join("left join tab_payment_merchant merchant on merchant.id=tab_coin_pay_order.merchant_id")
->where(['order_status'=>1,'tab_coin_pay_order.pay_way'=>['egt',1],'merchant.status'=>1,'merchant.type'=>1])
->where($map)
->group("merchant_id,merchant_way")
->select(false);
// var_dump($spreadData);die();
//超级签数据
$superSignData = M('game_supersign','tab_')
->field("0 cash_amount,
SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is not null THEN pay_price ELSE 0 END) as test_amount,
0 coin_amount,0 offcial_amount,0 spread_amount,
SUM(CASE WHEN merchant.id is not null and tab_test_white_list.user_id is null THEN pay_price ELSE 0 END) as supersign_amount,
0 test_order_amount,merchant_id,name,channel,identifier,pay_time payed_time,game_id,main_name,merchant_way,merchant.account")
->join("left join tab_payment_merchant merchant on merchant.id=tab_game_supersign.merchant_id")
->join("left join tab_test_white_list on tab_test_white_list.user_id=tab_game_supersign.user_id")
->where(['pay_status'=>1,'tab_game_supersign.pay_way'=>['egt',1],'merchant.status'=>1,'merchant.type'=>1])
->where($map)
->group("merchant_id,merchant_way")
->select(false);
//测试环境内网平台订单
$testOrder = M('test_order', 'tab_')
->where(['tab_test_order.pay_way'=>['egt',1]])
->field('0 cash_amount,0 test_amount,0 coin_amount,0 offcial_amount,0 spread_amount,0 supersign_amount,
SUM(CASE WHEN merchant.id is not null THEN pay_amount ELSE 0 END) as test_order_amount,merchant_id,name,
channel,identifier,pay_time payed_time,game_id,main_name,merchant_way,merchant.account')
->join("left join tab_payment_merchant merchant on merchant.id=tab_test_order.merchant_id")
->where(['merchant.status'=>1,'merchant.type'=>1])
->where($map)
->group("merchant_id,merchant_way")
->select(false);
$sql = "{$data} UNION ALL {$coinData} UNION ALL {$officalData} UNION ALL {$spreadData} UNION ALL {$superSignData} UNION ALL {$testOrder}";
if (!$_REQUEST['export']) {
$data = M()->table("({$sql})a")
->field("sum(cash_amount) cash_amount,sum(test_amount) test_amount,
sum(coin_amount) coin_amount,sum(offcial_amount) offcial_amount,
sum(spread_amount) spread_amount,sum(supersign_amount) supersign_amount,
sum(test_order_amount) test_order_amount,merchant_id,account,merchant_way,main_name,
name,channel,identifier")
->page($p, $row)
->where("name is not null and merchant_way !=0")
// ->where($map)
->group("merchant_id,merchant_way")
->select();
} else {
$data = M()->table("({$sql})a")
->field("sum(cash_amount) cash_amount,sum(test_amount) test_amount,
sum(coin_amount) coin_amount,sum(offcial_amount) offcial_amount,
sum(spread_amount) spread_amount,sum(supersign_amount) supersign_amount,
sum(test_order_amount) test_order_amount,merchant_id,account,merchant_way,main_name,
name,channel,identifier")
->where("name is not null and merchant_way !=0")
->group("merchant_id,merchant_way")
->select();
}
// var_dump($data);die();
$count = M()->table("({$sql})a")
->field("merchant_id")
->page($p, $row)
->where("name is not null and merchant_way !=0")
// ->where($map)
->group("merchant_id,merchant_way")
->count();
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);
}
$sum = M()->table("({$sql})a")
->field("sum(cash_amount) cash_amount,sum(test_amount) test_amount,
sum(coin_amount) coin_amount,sum(offcial_amount) offcial_amount,
sum(spread_amount) spread_amount,sum(supersign_amount) supersign_amount,
sum(test_order_amount) test_order_amount,merchant_id")
->where("name is not null and merchant_way !=0")
// ->where($map)
->find();
$sum['sum'] = $sum['cash_amount']+$sum['test_amount']+$sum['coin_amount']+$sum['offcial_amount']
+$sum['spread_amount']+$sum['supersign_amount']+$sum['test_order_amount'];
$sum_merchant = M()->table("({$sql})a")
->field("sum(cash_amount+test_amount+coin_amount+offcial_amount+spread_amount+supersign_amount+test_order_amount) sum_amount,
merchant_id,name,merchant_way")
->where("name is not null and merchant_way !=0")
// ->where($map)
->group("merchant_id,merchant_way")
->select();
$this->checkListOrCountAuthRestMap($map,[]);
foreach ($data as $key => $value) {
$data[$key]['sum'] = $value['cash_amount']+$value['test_amount']+$value['coin_amount']+
$value['offcial_amount']+$value['spread_amount']+$value['supersign_amount']+$value['test_order_amount'];
$data[$key]['ratio'] = round (($data[$key]['sum']/array_sum(array_column($sum_merchant,'sum_amount')))*100,2);
if ($value['merchant_way'] == self::WAY_ALIPAY) {
$data[$key]['merchant_way'] = "支付宝";
} else if ($value['merchant_way'] == self::WAY_WEIXIN) {
$data[$key]['merchant_way'] = "微信";
} else if ($value['merchant_way'] == self::WAY_EXPRESS) {
$data[$key]['merchant_way'] = "快捷";
} else {
$data[$key]['merchant_way'] = "";
}
}
$sum_radio = [];
foreach ($sum_merchant as $key => $value) {
if ($value['merchant_way'] == self::WAY_ALIPAY) {
$sum_merchant[$key]['merchant_way'] = "支付宝";
$sum_radio[$key]['merchant_way'] = "支付宝";
} else if ($value['merchant_way'] == self::WAY_WEIXIN) {
$sum_merchant[$key]['merchant_way'] = "微信";
$sum_radio[$key]['merchant_way'] = "微信";
} else if ($value['merchant_way'] == self::WAY_EXPRESS) {
$sum_merchant[$key]['merchant_way'] = "快捷";
$sum_radio[$key]['merchant_way'] = "快捷";
} else {
$sum_merchant[$key]['merchant_way'] = "";
$sum_radio[$key]['merchant_way'] = "";
}
$sum_merchant[$key]['sum_amount'] = round($value['sum_amount'],2);
$sum_radio[$key]['name'] = $value['name'];
$sum_radio[$key]['ratio'] = round(($value['sum_amount']/array_sum(array_column($sum_merchant,'sum_amount')))*100,2);
}
if ($_REQUEST['export']) {
$title = ['main_name' => '商户主体',
'name' => '支付商户',
'account' => '商户账号',
'ratio' => '占比(总充值量%)',
'cash_amount' => '游戏现金金额',
'coin_amount' => '平台币直充金额',
'test_amount'=>'测试白名单金额',
'test_order_amount' => '测试环境内外网平台金额',
'supersign_amount' => '超级签',
'offcial_amount' => '官网',
'spread_amount' => '推广后台',
'sum' => '支付渠道内合计'];
$sum['main_name'] = "合计(根据时间检索变化)";
$sum['ratio'] = 100;
$sum_merchant_export['main_name'] = '汇总(根据时间检索变化)';
$sum_radio_export['main_name'] = '收款商户占比';
foreach ($sum_merchant as $key => $value) {
if ($value['merchant_way'] == self::WAY_ALIPAY) {
$merchant_way = "支付宝";
} else if ($value['merchant_way'] == self::WAY_WEIXIN) {
$merchant_way = "微信";
} else if ($value['merchant_way'] == self::WAY_EXPRESS) {
$merchant_way = "快捷";
} else {
$merchant_way = "";
}
$radio = round(($value['sum_amount']/array_sum(array_column($sum_merchant,'sum_amount')))*100,2);
$sum_merchant_export['account'] .= $value['name']."-".$merchant_way.":".$value['sum_amount'];
$sum_radio_export['account'] .= $value['name']."-".$merchant_way.":".$radio."%";
}
$data = array_merge($data,[$sum],[$sum_merchant_export],[$sum_radio_export]);
data2csv($data,'个人总提成列表',$title);
}
// dump($sum_merchant);die();
$this->assign("sum_radio",$sum_radio);
$this->assign("sum_merchant",$sum_merchant);
$this->assign("sum",$sum);
$this->assign("listdata",$data);
$this->display();
}
}