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.

342 lines
12 KiB
PHTML

<?php
namespace Home\Controller;
use OT\DataDictionary;
use Admin\Model\ApplyModel;
use Think\Model;
use Base\Facade\Request;
use Base\Service\ApplyService;
use Base\Service\PromoteService;
/**
* 前台首页控制器
* 主要获取首页聚合数据
*/
class WithdrawController extends BaseController
{
public function index($p=0)
{
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
$id = get_pid();
$safePwd = M('promote','tab_')->where(['id'=>$id])->field('second_pwd')->find();
if(empty($safePwd['second_pwd'])) {
$this->display('Public/setSafePwd');
exit;
}
$map = [];
$map["promote.id"] = get_pid();
$map['tab_company_statement_info.company_type'] = ['in',"1,2"];
if ($_REQUEST['pay_status'] || $_REQUEST['pay_status'] == '0') {
$map['pay_status'] = $_REQUEST['pay_status'];
}
if(!empty($_REQUEST['start'])&&empty($_REQUEST['end'])){
$map['statement_begin_time'] = array('GT',strtotime($_REQUEST['start']));
unset($_REQUEST['start']);
}
if(empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){
$map['statement_end_time'] = array('LT',strtotime($_REQUEST['end'])+24*60*60-1);
unset($_REQUEST['end']);
}
if(!empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){
$map['statement_begin_time'] = array('GT',strtotime($_REQUEST['start']));
$map['statement_end_time'] = array('LT',strtotime($_REQUEST['end'])+24*60*60-1);
unset($_REQUEST['start']);unset($_REQUEST['end']);
}
$promote_data = M("promote","tab_")->where(['id'=>get_pid()])->find();
$this->assign("promote_data",$promote_data);
$data = M("company_statement_info","tab_")
->field("tab_company_statement_info.*")
->join("left join tab_promote_company company on tab_company_statement_info.company_id=company.id")
->join("left join tab_promote promote on company.id=promote.company_id")
->page($page,$row)
->where($map)
->select();
foreach ($data as $key => $value) {
$data[$key]['time'] = date("Y-m-d H:i:s",$value["statement_begin_time"])."-".date("Y-m-d H:i:s",$value["statement_end_time"]);
}
$parameter =I('get.');
$parameter['p']=I('get.p',1);
$parameter['row']=I('get.row');
$count = M("company_statement_info","tab_")
->field("tab_company_statement_info.*")
->join("left join tab_promote_company company on tab_company_statement_info.company_id=company.id")
->join("left join tab_promote promote on company.id=promote.company_id")
->where($map)
->count();
$page = set_pagination($count,$row,$parameter);
if($page) {$this->assign('_page', $page);}
$this->assign("data",$data);
$this->display();
}
//执行打款
public function doPayment()
{
$id = get_pid();
$safePwd = M('promote','tab_')->where(['id'=>$id])->field('second_pwd')->find();
if(empty($safePwd['second_pwd'])) {
$this->display('Public/setSafePwd');
exit;
}
$id = $_REQUEST['id'];
$remark = $_REQUEST['remark'];
Vendor("Alipay2020/Fund");
$fund = new \Fund();
//
$dbres = M("company_statement_info","tab_")->where("id='{$id}'")->find();
// $this->ajaxReturn(["msg"=>"打款成功","data"=>$dbres,"status"=>1]);die();
$company_info = json_decode($dbres['company_info'],true);
4 years ago
if($dbres['pay_status'] != 1 && $dbres['verify_status'] == 1){
//执行打款
$title = "测试-".$dbres['company_name']."结算";
$amount = $dbres['statement_money'];
4 years ago
//TODO:线上要关闭这个
$amount = 0.1;//测试金额为0
$payres = $fund->transfer($company_info['ali_account'],$company_info['ali_user'],$dbres['statement_num'],$amount, $title);
$resultCode = $payres->code;
$savedata = ["id"=>$dbres['id']];
if(!empty($resultCode)&&$resultCode == 10000){
$savedata["pay_status"]=1;
} else {
$savedata["pay_status"]=-1;
}
$payres = json_decode( json_encode($payres),true);
$payres["remark"] = $remark;
$savedata["pay_info"] = json_encode($payres,JSON_UNESCAPED_UNICODE);
$savedata["pay_type"]=1;
$savedata["pay_time"]=time();
} else {
$this->poolCount($dbres['pool_id']);
$this->ajaxReturn(["msg"=>"已经打款过","data"=>$dbres,"status"=>0]);
}
$this->poolCount($dbres['pool_id']);
M("company_statement_info","tab_")->save($savedata);
if ($savedata["pay_status"] == -1) {
$this->ajaxReturn(["msg"=>"提现失败","data"=>$dbres,"status"=>0]);
}
$this->ajaxReturn(["msg"=>"提现成功","data"=>$dbres,"status"=>1]);
}
/**
* 执行最后聚合表统计
* 整合数据,全部成功则支付成功,否则为支付中
*/
public function poolCount($poolid){
$f = M("company_statement_info","tab_")->where("pool_id = {$poolid} AND pay_status <> 1")->find();
if(empty($f)){
//全部完成
$this->setOneVerifyStatus(4,"payment",$poolid);
}else{
//打款中
$this->setOneVerifyStatus(3,"payment",$poolid);
}
}
protected function setOneVerifyStatus($change_status,$op_pre,$id)
{
$dbres = M("company_statement_pool","tab_")->field("id,verify_status,verify_log")->where("id = {$id}")->find();
$dbres['verify_log'] = json_decode($dbres['verify_log'],true);
$dbres['verify_log'][$op_pre.'_user']=$_SESSION['onethink_home']['promote_auth']['account'];
$dbres['verify_log'][$op_pre.'_time']=date("Y-m-d H:i:s");
$dbres['verify_log'] = json_encode($dbres['verify_log']);
$dbres['verify_status']=$change_status;
M("company_statement_pool","tab_")->save($dbres);
}
public function withdrawDetail() {
$id = get_pid();
$safePwd = M('promote','tab_')->where(['id'=>$id])->field('second_pwd')->find();
if(empty($safePwd['second_pwd'])) {
$this->display('Public/setSafePwd');
exit;
}
$id = $_REQUEST["id"];
$dbres = M("company_statement_info","tab_")
->field("*,tab_company_statement_info.id")
->join("left join tab_promote_company company on tab_company_statement_info.company_id=company.id")
->where("tab_company_statement_info.id='{$id}'")->find();
// dump($dbres);die();
$relation = M("company_relation","tab_")->where("second_company_id={$dbres['company_id']}")->find();
if (!$relation) {
$this->error("乙方关联信息不存在!");
}
if ($relation['invoice_type']==1) {
$relation['invoice_type'] = "专票";
} else if ($relation['invoice_type'] == 2) {
$relation['invoice_type'] = "普票";
} else {
$relation['invoice_type'] = "无";
}
$first_companmInfo = M("company_info","tab_")->where("id={$relation['first_company_id']}")->find();
if (!$first_companmInfo) {
$this->error("甲方公司信息不存在!");
}
$this->assign("relation",$relation);
$this->assign("first_company_info",$first_companmInfo);
$company_info = json_decode($dbres['company_info'],true);
$statemnt_info = json_decode($dbres['statement_info'],true);
$dbres['pay_time'] = date("Y-m-d H:i:s",$dbres['pay_time']);
$dbres['statement_begin_time'] = date("Y-m-d",$dbres['statement_begin_time']);
$dbres['statement_end_time'] = date("Y-m-d",$dbres['statement_end_time']);
$dbres['hletter_amount'] = convertAmountToCn($dbres['statement_money']);
// dump($company_info);
// dump($statemnt_info);die();
$rowspan = count($statemnt_info);
$this->assign("data",$dbres);
$this->assign("rowspan",$rowspan);
$this->assign("company_info",$company_info);
$this->assign("statemnt_info",$statemnt_info);
$this->display("withdrawdetail");
}
public function withdrawOrderDetail($p=0) {
$id = get_pid();
$safePwd = M('promote','tab_')->where(['id'=>$id])->field('second_pwd')->find();
if(empty($safePwd['second_pwd'])) {
$this->display('Public/setSafePwd');
exit;
}
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据
$row=10;
if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}
$start = $_REQUEST['start'];
$end = $_REQUEST['end'];
$game_map['relation_game_id'] = $_REQUEST['relation_game_id'];
$game_id = M("game","tab_")->field("id")->where($game_map)->select();
$promote_data = [];
$promote_id = M("promote","tab_")->field("id")->where(['company_id'=>$_REQUEST['company_id']])->select();
foreach ($promote_id as $key => $value) {
$promote_data[] = $value['id'];
$data = M("promote","tab_")->field("id")->where(['chain'=>['like',"/{$value['id']}/"]])->select();
foreach ($data as $k => $v) {
$promote_data[] = $v['id'];
}
}
if ($promote_data) {
$map['promote_id'] = ['in',$promote_data];
}
$game_id = array_column($game_id,'id');
$map['pay_time'] = ['between',[strtotime($start),strtotime($end)+86399]];
$map['pay_status'] = 1;
$map['game_id'] = ['in',$game_id];
if ($_REQUEST['team_leader_id']) {
$promote_id = M("promote","tab_")->field("id")->where("id = {$_REQUEST['team_leader_id']} or chain like '%/{$_REQUEST['team_leader_id']}/%'")->select();
$map['promote_id'] = ['in',array_column($promote_id,'id')];
}
if(!empty($_REQUEST['start'])&&empty($_REQUEST['end'])){
$map['pay_time'] = array('GT',strtotime($_REQUEST['start']));
unset($_REQUEST['start']);
}
if(empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){
$map['pay_time'] = array('LT',strtotime($_REQUEST['end'])+24*60*60-1);
unset($_REQUEST['end']);
}
if(!empty($_REQUEST['start'])&&!empty($_REQUEST['end'])){
$map['pay_time'] = array('between',[strtotime($_REQUEST['start']),strtotime($_REQUEST['end'])+24*60*60-1]);
unset($_REQUEST['start']);unset($_REQUEST['end']);
}
if($_REQUEST['pay_order_number']) {
$map['pay_order_number'] = ['like',"%{$_REQUEST['pay_order_number']}%"];
}
if (!$game_id) {
$this->error("游戏不存在");
}
$data = M("spend","tab_")
->where($map)
->page($page,$row)
->select();
// var_dump($data);die();
foreach ($data as $key => $value) {
$data[$key]['pay_time'] = date("Y-m-d H:i:s",$data[$key]['pay_time']);
if ($value['promote_account'] == "官方渠道") {
$data[$key]['promote_account'] = "江息网络";
}
}
$parameter =I('get.');
$parameter['p']=I('get.p',1);
$parameter['row']=I('get.row');
$count = M("spend","tab_")
->where($map)
->count();
$page = set_pagination($count,$row,$parameter);
if($page) {$this->assign('_page', $page);}
$this->assign('data',$data);
$this->display("withdraworderdetail");
}
}