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.

368 lines
13 KiB
PHP

<?php
namespace Admin\Controller;
/**
* 线下打款
* @author cz
*/
class CompanyStatementOfflineController extends ThinkController
{
public $CompanyType = [
"1"=>"下游公司",
"2"=>"下游个人",
"3"=>"上游公司"
];
public $IsPayment = [
"1"=>"",
"2"=>""
];
public $PayStatus=[
"-1"=>"打款失败",
"0"=>"未打款",
"1"=>"打款成功"
];
public function lists() {
$params = I('get.');
$page = $params['p'] ? intval($params['p']) : 1;
$row = $params['row'] ? intval($params['row']) : 10;
//权限分配
if(!IS_ROOT){
$this->OpAuthList= getModuleControllerAuth();
}
$this->assign('menubtn',$this->menuAuth());
$map = [
"c.verify_status"=>2,
"p.verify_status"=>["GT",1]
];
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
$time_start = strtotime($_REQUEST['time_start']);
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(c.statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (c.statement_end_time BETWEEN {$time_start} AND {$time_end}) OR (c.statement_begin_time <= {$time_end} AND c.statement_end_time >= {$time_end})";
} elseif (isset($_REQUEST['time_start'])) {
$time_start = strtotime($_REQUEST['time_start']);
$map["_string"] = "(c.statement_begin_time >= {$time_start} ) OR (c.statement_end_time >= {$time_start})";
} elseif (isset($_REQUEST['time_end'])) {
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(c.statement_begin_time <= {$time_end} ) OR (c.statement_end_time <= {$time_end})";
}
//其他
if(isset($_REQUEST['company_type'])){
$map['c.company_type'] = $_REQUEST['company_type'];
}
if(isset($_REQUEST['company_name'])){
$map['c.company_name'] =["LIKE","%{$_REQUEST['company_name']}%"];
}
if(isset($_REQUEST['statement_pool_num'])){
$map['p.statement_num'] =["LIKE","%{$_REQUEST['statement_pool_num']}%"];
}
//条件end
$data = SM("company_statement_info","tab_")
->alias("c")
->field("c.*,p.statement_num,p.verify_status")
->where($map)
->join("tab_company_statement_pool as p ON c.pool_id = p.id")
->page($page,$row)
->order("id desc")
->select();
foreach($data as $k => &$v) {
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
$v['company_type_str'] = $this->CompanyType[$v['company_type']];
$v["valid"] = "{$v['statement_begin_time']}-{$v['statement_end_time']}";
$v["pay_status_str"] = $this->PayStatus[$v["pay_status"]];
$v["pay_info"] = json_decode($v['pay_info'], true);
if(isset($v['pay_info']['payment_user'])){
$v["payment"]= "{$v['pay_status_str']}({$v['pay_info']['payment_user']})<br>{$v['pay_info']['payment_time']}";
}else{
$v["payment"] = $v["pay_status_str"];
}
if ($v['pay_check'] == 0) {
$v['pay_check_str'] = "---";
} else {
$member = M("ucenter_member")
->field("username")
->where(['id'=>$v['pay_check_member_id']])
->find();
$v['pay_check_str'] = $member['username'].(($v['pay_check'] == 1)?'已确认':'未确认')."<br>".date('Y-m-d H:i:s', $v['pay_check_time']);;
// $v['pay_check_str'] = "已确认";
}
$v['oplist'] = $this->OpAuth($v);
}
$count = SM("company_statement_info","tab_")->alias("c")->field("count(c.id) count,sum(c.statement_money) statement_money")->join("tab_company_statement_pool as p ON c.pool_id = p.id")->where($map)->find();
// dd($count);
$params['p'] = $page;
$params['row'] = $row;
$page = set_pagination($count['count'], $row, $params);
if ($page) {
$this->assign('_page', $page);
}
// dd($data);
$this->assign('data',$data);
$this->assign('count',$count);
$this->assign('CompanyType',$this->CompanyType);
$this->display();
}
//打款设置
public function setPayment(){
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$CompanyInfo = M("company_statement_info","tab_")
->alias('i')
->field("i.id,i.pool_id,i.company_name,i.company_info,i.statement_money,i.remark,i.pay_status,i.verify_status,p.statement_num,i.statement_money")
->join("tab_company_statement_pool p ON p.id = i.pool_id")
->where("i.id in({$id})")
->select();
$all_money = 0;
foreach($CompanyInfo as $k=>&$v){
if($v['verify_status'] == 2){
$v['is_payment'] = 2;
}else{
$v['is_payment'] = 1;
}
$v['company_info'] = json_decode($v['company_info'],true);
$v['company_info']['ali_user'] ?? '';
$v['company_info']['ali_account'] ?? '';
$all_money += $v['statement_money'];
}
$this->assign('all_money',$all_money);
$this->assign("CompanyInfo",$CompanyInfo);
$this->assign("id",$id);
$this->display();
}
//修改打款设置
public function editPayment(){
// dump($_SESSION);die();
if(!isset($_REQUEST['info'])) $this->error("参数错误");
$info = $_REQUEST['info'];
// dump($info);die();
$CompanyInfo = M("company_statement_info","tab_");
//循环保存
foreach($info as $k=>$v){
$ydata = $CompanyInfo->where("id= '{$k}'")->find();
$company_info = json_decode($ydata['company_info'],true);
if($ydata['verify_status'] == 2){
$company_info['payee_name'] = $v['payee_name'];
$company_info['bank_account'] = $v['bank_account'];
$company_info['opening_bank'] = $v['opening_bank'];
}else{
$company_info['ali_user'] = $v['ali_user'];
$company_info['ali_account'] = $v['ali_account'];
}
$savedata = [
"company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE),
"remark"=>$v['remark'],
"pay_check"=>1,
"pay_check_member_id"=> $_SESSION['onethink_admin']['user_auth']['uid'],
"id"=>$k,
"pay_check_time"=>time()
];
$CompanyInfo->save($savedata);
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"打款信息编辑成功"
));
}
public function returnSetPayment() {
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$ids = explode(',',$ids);
$CompanyInfo = M("company_statement_info","tab_");
$CompanyInfo
->where(['id'=>['in',$ids]])
->save([
'pay_check'=>0,
'pay_check_member_id'=>0,
'pay_check_time'=>0
]);
$this->ajaxReturn(array(
'status' => 1,
"info"=>"打款信息编辑成功"
));
}
public function doPayment()
{
if(!isset($_REQUEST['ids']) || !isset($_REQUEST['payment_time'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$payment_time = $_REQUEST['payment_time'];
//获取所有的母单id
$companyStatementInfo = SM("company_statement_info","tab_");
$statementPool = $companyStatementInfo->where("id in ($ids) and pay_status <> 1")->field("pool_id,count(id) count")->group("pool_id")->select();
$yPoolInfo = [];
foreach ($statementPool as $k => $v) {
$yPoolInfo[$v['pool_id']] = $v['count'];
}
unset($statementPool);
//获取母单未支付完成订单
$poolIds = implode(",",array_keys($yPoolInfo));
$poolInfo = $companyStatementInfo->where("pool_id in ($poolIds) and pay_status <> 1")->field("pool_id,count(id) count")->group("pool_id")->select();
//修改info
$saveData = [
"pay_type"=>3,
"pay_status"=>1,
"pay_info"=>json_encode(["payment_user"=>$_SESSION['onethink_admin']['user_auth']["username"],"payment_time"=>$payment_time])
];
$ires = $companyStatementInfo->where("id in ($ids)")->save($saveData);
//全部就打款成功,否则打款中
$companyStatementPool = SM("company_statement_pool","tab_");
foreach ($poolInfo as $k => $v) {
if($v['count'] == $yPoolInfo[$v['pool_id']]){
//打款成功
$this->setOneVerifyStatus(4,"payment",$v['pool_id']);
}else{
//打款中
$this->setOneVerifyStatus(3,"payment",$v['pool_id']);
}
}
$this->ajaxReturn(array(
'status' =>1,
"info"=>"打款确认成功"
));
}
public function viewStatement()
{
if(!isset($_REQUEST['id'])){
$this->error('参数错误');
}
$id = $_REQUEST['id'];
$is_export= false;
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
$is_export = true;
}
//获取基本信息
$dbres = SM("company_statement_info","tab_")->where("id='{$id}'")->select();
$title = $dbres[0]['company_name'];
$this->assign("title",$title);
if($dbres[0]['company_type'] == 3){
//上游
A("CompanyStatementPool")->viewCpPool($dbres,$is_export);
}elseif($dbres[0]['company_type'] == 1){
//下游公司
A("CompanyStatementPool")->viewPcPool($dbres,$is_export);
}else{
A("CompanyStatementPool")->viewPuPool($dbres,$is_export,["withdraw_type"=>3]);
}
}
public function export(){
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = SM("company_statement_info","tab_")->where("id in ({$ids})")->select();
$is_export= false;
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
$is_export = true;
}
if($dbres[0]['company_type'] == 3){
//上游
$this->assign("title","上游公司线下打款");
A("CompanyStatementPool")->viewCpPool($dbres,$is_export);
}elseif($dbres[0]['company_type'] == 1){
//下游公司
$this->assign("title","下游公司线下打款");
A("CompanyStatementPool")->viewPcPool($dbres,$is_export);
}else{
$this->assign("title","下游个人线下打款");
A("CompanyStatementPool")->viewPuPool($dbres,$is_export,["withdraw_type"=>3]);
}
}
protected function setOneVerifyStatus($change_status,$op_pre,$id)
{
$dbres = SM("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_admin']['user_auth']["username"];
$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;
SM("company_statement_pool","tab_")->save($dbres);
}
public function OpAuth($info)
{
$id = $info['id'];
$type = $info['company_type'];
//原始列表
$opBtn = [
"viewStatement"=>"<a class='confirm viewStatement' data-id='{$id}' data-companytype='{$type}'>查看</a>",
];
//操作对应菜单
$optist = ["viewStatement"];
$resarr = [];
foreach ($optist as $k => $v) {
if(IS_ROOT){
$resarr[] = $opBtn[$v];
}else{
if(in_array($v,$this->OpAuthList)){
$resarr[] = $opBtn[$v];
}
}
}
return $resarr;
}
public function menuAuth()
{
$mentBtn = [
"setPayment"=>"<a class='butn' id='setPayment'>打款信息确认</a>",
"returnSetPayment"=>"<a class='butn' id='returnSetPayment'>打款信息确认撤回</a>",
"doPayment"=>"<a class='butn' id='doPayment'>打款确认</a>",
"export"=>"<a class='butn' id='export'>批量导出</a>",
];
$resarr = [];
foreach ($mentBtn as $k => $v) {
if(IS_ROOT){
$resarr[] = $v;
}else{
if(in_array($k,$this->OpAuthList)){
$resarr[] = $v;
}
}
}
return $resarr;
}
}