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.

430 lines
15 KiB
PHTML

4 years ago
<?php
namespace Admin\Controller;
/**
* 上下游结算单
* @author cz
*/
class CompanyStatementLackController extends ThinkController
{
public $CompanyType = [
"1"=>"下游公司",
"2"=>"下游个人",
"3"=>"上游公司"
];
public $IsPayment = [
"1"=>"是",
"2"=>"否"
];
public $admininfo;
public $DBModel;
public function _initialize()
{
$this->admininfo = $_SESSION['onethink_admin']['user_auth'];
$this->DBModel = M("CompanyLackStatementInfo","tab_");
parent::_initialize();
}
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 = [
"is_pool"=>0
];
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
$time_start = strtotime($_REQUEST['time_start']);
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
4 years ago
$map["_string"] = "(statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (statement_end_time BETWEEN {$time_start} AND {$time_end}) OR (statement_begin_time <= {$time_end} AND statement_end_time >= {$time_end})";
4 years ago
} elseif (isset($_REQUEST['time_start'])) {
$time_start = strtotime($_REQUEST['time_start']);
$map["_string"] = "(statement_begin_time >= {$time_start} ) OR (statement_end_time >= {$time_start})";
} elseif (isset($_REQUEST['time_end'])) {
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(statement_begin_time <= {$time_end} ) OR (statement_end_time <= {$time_end})";
}
//其他
if(isset($_REQUEST['company_type'])){
$map['company_type'] = $_REQUEST['company_type'];
}
4 years ago
if(isset($_REQUEST['company_name'])){
$map['company_name'] =["LIKE","%{$_REQUEST['company_name']}%"];
4 years ago
}
if(isset($_REQUEST['statement_pool_num'])){
$map['statement_pool_num'] =["LIKE","%{$_REQUEST['statement_pool_num']}%"];
4 years ago
}
if(isset($_REQUEST['is_payment'])){
$map['is_payment'] = $_REQUEST['is_payment'];
}
4 years ago
// $this->checkListOrCountAuthRestMap($map);//导出权限
4 years ago
//条件end
$data = $this->DBModel
->field("*")
->where($map)
->page($page,$row)
4 years ago
->order("id desc")
4 years ago
->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']);
4 years ago
$v['is_payment_str'] = $this->IsPayment[$v['is_payment']];
$v['company_type_str'] = $this->CompanyType[$v['company_type']];
$v["valid"] = "{$v['statement_begin_time']}-{$v['statement_end_time']}";
4 years ago
$v['oplist'] = $this->OpAuth($v);
$v['withdraw_type_str'] = ($v['withdraw_type']==3?"特殊补点":"正常结算");;
4 years ago
}
$count = $this->DBModel->field("count(id) count,sum(statement_money) statement_money")->where($map)->find();
// dd($count);
4 years ago
$params['p'] = $page;
$params['row'] = $row;
$page = set_pagination($count['count'], $row, $params);
4 years ago
if ($page) {
$this->assign('_page', $page);
}
$this->assign('data',$data);
$this->assign('count',$count);
$this->assign('CompanyType',$this->CompanyType);
$this->assign('IsPayment',$this->IsPayment);
$this->display();
}
//查看
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 = $this->DBModel->where("id='{$id}'")->select();
$withdraw_type = -9;
4 years ago
$title = $dbres[0]['company_name'];
$this->assign("title",$title);
4 years ago
if($dbres[0]['company_type'] == 3){
//上游
A("CompanyStatementPool")->viewCpPool($dbres,$is_export);
4 years ago
}elseif($dbres[0]['company_type'] == 1){
4 years ago
//下游公司
A("CompanyStatementPool")->viewPcPool($dbres,$is_export,$withdraw_type);
4 years ago
}else{
4 years ago
A("CompanyStatementPool")->viewPuPool($dbres,$is_export,["withdraw_type"=>3]);
4 years ago
}
}
//汇总
public function pool()
{
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = $this->DBModel->field("*")->where("id in ({$ids})")->select();
$hav_special = 0;
$hav_common = 0;
foreach ($dbres as $key => $value) {
if ($value['withdraw_type'] == 3) {
$hav_special = 1;
} else {
$hav_common = 1;
}
}
if ($hav_special && $hav_common) {
$this->error("特殊补点不能与正常结算一起汇总");
}
4 years ago
//分单
$basedata = [
"pay_amount"=>0,
"statement_money"=>0,
"lack_statement_money"=>0,
"platform_amount"=>0,
"lack_platform_amount"=>0,
"del_lack_ids"=>[],
"info_ids"=>[],
"statement_begin_time"=>0,
"statement_end_time"=>0,
"fine"=>0,
"reward"=>0,
"verify_status"=>0,
"verify_log"=>json_encode(["create_user"=>$this->admininfo["username"],"create_time"=>date("Y.m.d H:i:s")]),
4 years ago
"op_time"=>time(),
"company_list"=>[],
4 years ago
];
$datas = ["ups","up","downs","down","user","users"];
//初始化数据
foreach($datas as $k=>$v){
if($v =="ups"){
$basedata['company_type']=3;
$basedata['is_payment']=1;
}
if($v =="up"){
$basedata['company_type']=3;
$basedata['is_payment']=2;
}
if($v =="downs"){
$basedata['company_type']=1;
$basedata['is_payment']=1;
}
if($v =="down"){
$basedata['company_type']=1;
$basedata['is_payment']=2;
}
if($v =="users"){
$basedata['company_type']=2;
$basedata['is_payment']=1;
}
if($v =="user"){
$basedata['company_type']=2;
$basedata['is_payment']=2;
}
$datas[$v]=$basedata;
unset($datas[$k]);
}
foreach ($dbres as $k=>$v) {
if($v['company_type'] == 3){
//上游
if($v['is_payment'] == 1){
$this->setDf($datas['ups'],$v);
}else{
$this->setDf($datas['up'],$v);
}
}elseif($v['company_type'] == 1){
if($v['is_payment'] == 1){
$this->setDf($datas['downs'],$v);
}else{
$this->setDf($datas['down'],$v);
}
}else{
if($v['is_payment'] == 1){
$this->setDf($datas['users'],$v);
}else{
$this->setDf($datas['user'],$v);
}
}
}
4 years ago
$Pool = M("company_statement_pool","tab_");
$Statemen = M("company_statement","tab_");
4 years ago
foreach ($datas as $k => $v) {
4 years ago
if(count($v['company_list']) <= 0){continue;}
4 years ago
//保存公司信息
$company_list = $v['company_list'];
foreach ($company_list as $ke => $va) {
$this->addStatementInfo($va,$ke,$v,$k);
4 years ago
}
if(empty($v['create_lack_ids']) && empty($v['del_lack_ids']) && empty($v['info_ids'])){ continue;}
$v['statement_num'] = "QZ_".date('Ymd').date('His').sp_random_num(3);
$v['del_lack_ids'] = implode(",",$v['del_lack_ids']) ?? '';
$info = implode(",",$v['info_ids']);
unset($v['info_ids']);
unset($v['company_list']);
$pool_id = $Pool->add($v);
if($pool_id == false){
$this->ajaxReturn(array('status' => 0,"info"=>"汇总失败"));
}
if(!empty($info)){
$save["pool_id"]=$pool_id;
M("company_statement_info","tab_")->where("id in ({$info})")->save($save);
}
if(!empty($v['del_lack_ids'])){
M("company_lack_statement_info","tab_")->where("id in ({$v['del_lack_ids']})")->save(["is_pool"=>1]);
}
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"汇总成功"
));
}
public function export(){
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = $this->DBModel->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","下游个人未汇总");
4 years ago
A("CompanyStatementPool")->viewPuPool($dbres,$is_export,["withdraw_type"=>3]);
}
}
protected function addStatementInfo($va,$ke,&$v,$k){
if($k=="ups" || $k=='downs' || $k =="users"){
$verify_status = 0;
}else{
$verify_status = 2;
}
4 years ago
$StatementInfo = M("company_statement_info","tab_");
if($va['pay_amount'] > 0){
//存成功
$company =[
"pool_id"=>0,
"company_id"=>$ke,
"company_type"=>$v['company_type'],
"company_name"=>$va['company_name'],
"company_info"=>$va['company_info'],
"fine"=>$va['fine'],
"reward"=>$va['reward'],
"statement_money"=>$va['statement_money'],
"pay_amount"=>$va['pay_amount'],
"platform_amount"=>$va['platform_amount'],
"statement_money"=>$va['statement_money'],
"statement_begin_time"=>$v['statement_begin_time'],
"statement_end_time"=>$v['statement_end_time'],
"statement_info"=>json_encode($va['statement_info'],JSON_UNESCAPED_UNICODE),
"statement_num"=>$va['statement_num'],
"verify_status"=>$verify_status,
"withdraw_type"=>$va['withdraw_type']
4 years ago
];
4 years ago
$companyid = $StatementInfo->add($company);
$v['info_ids'][] =$companyid;
$v['statement_money'] +=$va['statement_money'];
$v['pay_amount'] +=$va['pay_amount'];
$v['platform_amount'] +=$va['platform_amount'];
$v['fine'] +=$va['fine'];
$v['reward'] +=$va['reward'];
}
}
//设定组合的子操作
protected function setDf(&$savedata,$v)
{
$savedata['del_lack_ids'][] = $v['id'];
unset($v['id']);
$v['statement_info'] = json_decode( $v['statement_info'],true);
$fine = $v['fine'];
$reward = $v['reward'];
$savedata['withdraw_type'] = $v['withdraw_type'];
4 years ago
if(isset($savedata['company_list'][$v['company_id']])){
//存在游戏合并
$a = &$savedata['company_list'][$v['company_id']];
$a['fine'] += $fine;
$a['reward'] += $reward;
$a['statement_info'] = array_merge($a['statement_info'],$v['statement_info']);
// dump($a['statement_info']);
$a['platform_amount'] += $v['platform_amount'];
$a['pay_amount'] += $v['pay_amount'];
$a['statement_money'] += $v['statement_money'];
}else{
//先分配好订单号,防止重复提交
$tdata = [
"company_info"=>$v['company_info'],
"company_name"=>$v['company_name'],
"platform_amount"=>$v['platform_amount'],
"pay_amount"=>$v['pay_amount'],
"statement_money"=>$v['statement_money'],
"fine"=>$fine,
"reward"=>$reward,
"statement_info"=>$v['statement_info'],
"statement_num"=>"JS_".date('Ymd').date('His').$v['company_id'].sp_random_string(5),
"withdraw_type"=>$v['withdraw_type'],
4 years ago
];
$savedata['company_list'][$v['company_id']] = $tdata;
}
// $savedata['fine'] += $v['fine'];
// $savedata['reward'] += $v['reward'];
// $savedata['pay_amount'] += $v['pay_amount'];
// $savedata['statement_money'] += $v['statement_money'];
// $savedata['platform_amount'] += $v['platform_amount'];
if($savedata['statement_begin_time'] == 0){
$savedata['statement_begin_time'] = $v['statement_begin_time'];
}elseif($v['statement_begin_time'] < $savedata['statement_begin_time']){
$savedata['statement_begin_time'] = $v['statement_begin_time'];
}
if($savedata['statement_end_time'] == 0){
$savedata['statement_end_time'] = $v['statement_end_time'];
}elseif($v['statement_end_time'] > $savedata['statement_end_time']){
$savedata['statement_end_time'] = $v['statement_end_time'];
}
}
//设定并保存数据
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 = [
"pool"=>"<a class='butn' id='pool'>发起汇总</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;
}
}