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.

113 lines
4.1 KiB
PHP

<?php
namespace Admin\Controller;
//use Think\Controller;
/**
* 上下游结算单
* @author cz
*/
class SubUserStatementController extends ThinkController
{
public $DBModel;
public function _initialize()
{
$this->DBModel = M("UserStatement","sub_",SUBSITE_DB);//指定子库
parent::_initialize();
}
public function lists() {
$params = I('get.');
$page = $params['p'] ? intval($params['p']) : 1;
$row = $params['row'] ? intval($params['row']) : 10;
//权限分配
$map = [
"_string"=>"1=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"] = "(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})";
} 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})";
}
$data = $this->DBModel->where($map)->page($page,$row)->field("statement_info",true)->order("statement_begin_time 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["valid"] = "{$v['statement_begin_time']}-{$v['statement_end_time']}";
}
$count = $this->DBModel->where($map)->count();
$params['p'] = $page;
$params['row'] = $row;
$page = set_pagination($count, $row, $params);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('data',$data);
$this->display();
}
public function updateStatement()
{
if(!isset($_REQUEST['id'])){
$this->error('参数错误');
}
$id = $_REQUEST['id'];
$temp = $this->DBModel->where(['id'=>$id])->getField('statement_end_time');
$temp = date('Y-m-d',$temp-0+1);
$params = "php ".SUBSITE_INDEX." SubCompanyStatementSet/setFreeDateCount/begin/{$temp}/end/{$temp}/company/pu";
$r = D("CmdTasks")->addTask("SubCompanyStatementSet",$params,true);
if($r){
$this->DBModel->where(['id'=>$id])->delete();
$this->ajaxReturn(["status"=>1,"info"=>"旧数据已删除且重算登记成功,请稍后刷新页面查看最新数据"]);
}else{
$this->ajaxReturn(["status"=>0,"info"=>"重算登记错误"]);
}
}
public function viewStatement()
{
$is_export= false;
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
$is_export = true;
}
if(!isset($_REQUEST['id'])){
$this->error('参数错误');
}
$id = $_REQUEST['id'];
$data = $this->DBModel->where(['id'=>$id])->getField("statement_info");
$data = json_decode($data,true);
$line = 2;
foreach ($data as $k => &$v) {
$v['row'] = count($v['statement_info']);
if ($is_export) {
foreach ($v['statement_info'] as $key => &$val) {
$val['sum_money'] = "=ROUND(F{$line}*G{$line},2)";
$line++;
}
}
}
if ($is_export) {
$title = $data[0]['statement_info'][0]['statement_begin_time']."-".$data[0]['statement_info'][0]['statement_end_time']."个人汇总单";
$this->assign("title",$title);
}
$this->assign("data",$data);
$this->assign("is_export",$is_export);
$this->display("viewPuPool");
}
}