diff --git a/Application/Admin/Controller/StatementWarningController.class.php b/Application/Admin/Controller/StatementWarningController.class.php new file mode 100644 index 000000000..776141fd6 --- /dev/null +++ b/Application/Admin/Controller/StatementWarningController.class.php @@ -0,0 +1,282 @@ +'业务收入', + 2=>'业务成本', + 3=>'毛利', + 4=>'营业利润' + ]; + //创建 + public function _initialize(){ + //初始化 + $this->statementWarningModel=M("statement_warning","tab_"); + $this->statementWarningInfoModel=M("statement_warning_info","tab_"); + $this->statementWarningKey=A("StatementWarningSet")->getStatementWarningKey(); + parent::_initialize(); + } + public function lists() + { + if(!array_key_exists("year",$_REQUEST)){ + $this->redirect(ACTION_NAME, array('year' => date('Y',time()))); + } + $year = $_REQUEST['year']; + $yearData = $this->statementWarningModel->where("count_year = '{$year}'")->select(); + $yearData = $this->setWaringDataShow( $this->setWaringDataCount( $this->resetWaringData($yearData) ) ); + + $isCan = D("CmdTasks")->isCanAddTask("StatementWarningSet"); + + $this->assign("is_can",$isCan); + $this->assign("data",$yearData); + $this->getLastUpdate(); + $this->getYearList(); + $this->display(); + } + + private function getLastUpdate() + { + $lastUpdate = $this->statementWarningModel->where([ + 'count_year'=>$_REQUEST['year'], + "name"=>'wm_platm', + "type"=>1 + ])->field("MAX(count_month),create_time")->find(); + if($lastUpdate){ + $lastUpdate = date('Y-m-d H:i:s',$lastUpdate['create_time']); + }else{ + $lastUpdate = '未更新'; + } + $this->assign('last_update', $lastUpdate); + } + + private function resetWaringData($data) + { + $sendData = []; + foreach ($this->statementWarningType as $key => $va) { + $sendData[$key] = [ + 'name'=>$va, + 'list'=>[], + 'count'=>[0,0,0,0,0,0,0,0,0,0,0,0,0] + ]; + if($key == 3){ + $sendData[$key]['list']['margin_ratio'] = [0,0,0,0,0,0,0,0,0,0,0,0,0]; + } + if($key == 4){ + $sendData[$key]['list']['profit_ratio'] = [0,0,0,0,0,0,0,0,0,0,0,0,0]; + } + } + foreach ($data as $k => $v) { + $name = $v['name']; + $typelist = &$sendData[$v['type']]['list']; + if( !isset($typelist[$name]) ){ + $typelist[$name] = [0,0,0,0,0,0,0,0,0,0,0,0,0]; + } + $typelist[$name][$v['count_month']-1] = $v['money']; + } + return $sendData; + } + private function setWaringDataCount($data) + { + //业务成本/收入 + for ($type=1; $type < 3; $type++) { + foreach ($data[$type]['list'] as $k => &$item) { + $item[12] = array_sum($item); + for ($i=0; $i < 13; $i++) { + $data[$type]['count'][$i] += $item[$i]; + } + } + } + //毛利 + $data[3]['list']['费用'][12] = array_sum($data[3]['list']['费用']); + $data[3]['list']['其他收入'][12] = array_sum($data[3]['list']['其他收入']); + for ($i=0; $i < 13; $i++) { + $data[3]['count'][$i] = $data[1]['count'][$i]-$data[2]['count'][$i]; + $data[4]['count'][$i] = ($data[3]['count'][$i]-$data[3]['list']['费用'][$i]+$data[3]['list']['其他收入'][$i]); + + if($data[1]['count'][$i] != 0){ + $data[3]['list']['margin_ratio'][$i] = round( $data[3]['count'][$i]/$data[1]['count'][$i],4); + $data[4]['list']['profit_ratio'][$i] = round($data[4]['count'][$i]/$data[1]['count'][$i],4); + } + } + return $data; + } + private function setWaringDataShow($data) + { + foreach ($data as $type => $item) { + for ($i=0; $i < 13; $i++) { + $data[$type]['count'][$i] = round($data[$type]['count'][$i]/10000,2); + } + foreach ($item['list'] as $name => $value) { + for ($i=0; $i < 13; $i++) { + if( in_array($name,['margin_ratio','profit_ratio']) ){ + $value[$i] = ( ($value[$i]*100)."%"); + }else{ + $value[$i] = round($value[$i]/10000,2); + } + } + unset($data[$type]['list'][$name]); + if(isset($this->statementWarningKey[$name])){ + $data[$type]['list'][$name]['name'] = $this->statementWarningKey[$name]; + $data[$type]['list'][$name]['list'] = $value; + $data[$type]['list'][$name]['is_edit'] = 0; + }else{ + $data[$type]['list'][$name]['name'] = $name; + $data[$type]['list'][$name]['list'] = $value; + $data[$type]['list'][$name]['is_edit'] = 1; + } + } + } + return $data; + } + //获取历史年份 + private function getYearList() + { + $star = 2021; + $end = date("Y",time()); + $list = []; + for ($i=$star; $i <= $end; $i++) { + $temp = array( + "value"=>$i, + "name"=>"{$i}年" + ); + $list[] = $temp ; + } + $this->assign('YearList', $list); + } + public function edit() + { + $act = $_REQUEST['act']; + $isEdit = 1; + if($act == 'add'){ + $isEdit = 0; + $this->assign('is_edit', 0); + }else{ + $this->assign('is_edit', 1); + } + $this->getYearList(); + if(IS_POST) { + $parm = I('post.'); + if(count($parm['value']) < 12){ + $this->ajaxReturn(["msg"=>"不想添加的月份请设置值为0,不能为空","code"=>0]); + } + if($parm['is_edit'] == 0){ + $this->doAdd($parm); + }else{ + $this->doEdit($parm); + } + $this->ajaxReturn(["msg"=>"添加成功","code"=>1,"url"=>U("lists")]); + }else{ + if($isEdit == 1){ + $this->resetWarningData(); + $this->assign('title', '编辑预警类目'); + }else{ + $this->assign('title', '新增预警类目'); + } + $this->display(); + } + } + private function doAdd($p) + { + $adddata = []; + $baseArray = [ + 'count_year'=>$p['year'], + 'type'=>$p['type'], + 'name'=>trim($p['name']), + 'create_time'=>time() + ]; + + for ($i=0; $i < 12; $i++) { + if($p['value'][$i] != 0){ + $countMoth = ($i-0+1); + if(strlen($countMoth) < 2) $countMoth="0".$countMoth; + $baseArray['count_month'] = $countMoth; + $baseArray['money'] = $p['value'][$i]*10000; + $adddata[] = $baseArray; + } + } + if(empty($adddata)){ + $this->ajaxReturn(["msg"=>"添加失败,值不能全为0","code"=>0]); + } + $res = $this->statementWarningModel->addAll($adddata); + if(!$res){ + $this->ajaxReturn(["msg"=>"添加失败","code"=>0]); + } + } + private function resetWarningData() + { + $where = [ + 'name'=>$_REQUEST['name'], + 'count_year'=>$_REQUEST['count_year'] + ]; + $data = $this->statementWarningModel->where($where)->select(); + + $sendData = [ + 'count_year'=>$data[0]['count_year'], + 'type'=>$data[0]['type'], + 'name'=>$data[0]['name'], + 'value'=>[0,0,0,0,0,0,0,0,0,0,0,0], + 'ids'=>[0,0,0,0,0,0,0,0,0,0,0,0] + ]; + + foreach ($data as $key => $value) { + $sendData['value'][$value['count_month']-1] = $value['money']/10000; + $sendData['ids'][$value['count_month']-1] = $value['id']; + } + $this->assign('data', $sendData); + } + private function doEdit($p) + { + $adddata = []; + $baseArray = [ + 'count_year'=>$p['year'], + 'type'=>$p['type'], + 'name'=>trim($p['name']), + 'create_time'=>time() + ]; + + for ($i=0; $i < 12; $i++) { + $id = $p['ids'][$i]; + $money = $p['value'][$i]; + if($id > 0){ + $save['id'] = $id; + $save['money'] = $p['value'][$i]*10000; + $save['name'] = trim($p['name']); + $this->statementWarningModel->save($save); + continue; + } + if($money != 0){ + $countMoth = ($i-0+1); + if(strlen($countMoth) < 2) $countMoth="0".$countMoth; + $baseArray['count_month'] = $countMoth; + $baseArray['money'] = $p['value'][$i]*10000; + $adddata[] = $baseArray; + } + } + if(!empty($adddata)){ + $this->statementWarningModel->addAll($adddata); + } + } + + public function updateStatement() + { + if(!isset($_REQUEST['time'])) $this->error("参数错误"); + + $time = $_REQUEST['time']; + $params = "php ".SUBSITE_INDEX." StatementWarningSet/setFreeMonth/count_date/{$time}"; + $r = D("CmdTasks")->addTask("StatementWarningSet",$params); + if($r){ + $this->ajaxReturn(["success"=>"ok"]); + }else{ + $this->ajaxReturn(["error"=>"error"]); + } + } + +} diff --git a/Application/Admin/Controller/StatementWarningSetController.class.php b/Application/Admin/Controller/StatementWarningSetController.class.php index d23670e4a..404b79bbf 100644 --- a/Application/Admin/Controller/StatementWarningSetController.class.php +++ b/Application/Admin/Controller/StatementWarningSetController.class.php @@ -26,7 +26,9 @@ class StatementWarningSetController extends Controller { 'wm_platm'=>'万盟平台', 'up_statement'=>'上游', 'pc_statement'=>'下游内团', - 'pu_statement'=>'下游外团' + 'pu_statement'=>'下游外团', + 'margin_ratio'=>'毛利率', + 'profit_ratio'=>'利润率' ]; private $statementWarningModel; @@ -81,6 +83,7 @@ class StatementWarningSetController extends Controller { D("CmdTasks")->addScheduleTask("StatementWarningSet",$params,$time); } $this->setStatementWarning(); + $this->setDefaultStatementWarning(); } /** * 更新某月毛利数据 @@ -89,6 +92,7 @@ class StatementWarningSetController extends Controller { { $this->configInit($count_date); $this->setStatementWarning(); + $this->setDefaultStatementWarning(); } /** @@ -199,6 +203,30 @@ class StatementWarningSetController extends Controller { $this->statementWarningModel->add($saveData); } } + /** + * 添加默认信息 + */ + private function setDefaultStatementWarning() + { + $Where = [ + "count_month"=>$this->month, + "count_year"=>$this->year, + "name"=>'费用', + "type"=>3 + ]; + $hasDb = $this->statementWarningModel->where($Where)->find(); + $saveData = array_merge(['money'=>700000,'create_time'=>time()],$Where); + if(!$hasDb){ + $this->statementWarningModel->add($saveData); + } + + $Where['name'] = '其他收入'; + $hasDb = $this->statementWarningModel->where($Where)->find(); + $saveData = array_merge(['money'=>26000,'create_time'=>time()],$Where); + if(!$hasDb){ + $this->statementWarningModel->add($saveData); + } + } /** * 获取上游的结算金额 */ @@ -407,7 +435,7 @@ class StatementWarningSetController extends Controller { $statementAmount = 0; foreach ($company as $key => $value) { $statementMoney = array_key_exists('statement_money',$value) ? ($value['statement_money']-0) : 0; - $statementAmount += $statementMoney; + $company[$key]['is_wm'] = $this->getCompanyIsWm($key,$companyBelong); $company[$key]['company_belong'] = $companyBelong; $company[$key]['count_month'] = $this->month; @@ -420,6 +448,7 @@ class StatementWarningSetController extends Controller { $company[$key]['wm_amount'] = 0; $company[$key]['other_amount'] = $statementMoney; } + $statementAmount += $company[$key]['wm_amount']; $id = $this->statementWarningInfoModel->where([ 'count_year'=>$this->year, 'count_month'=>$this->month, diff --git a/Application/Admin/View/StatementWarning/edit.html b/Application/Admin/View/StatementWarning/edit.html new file mode 100644 index 000000000..e18a5ae2b --- /dev/null +++ b/Application/Admin/View/StatementWarning/edit.html @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + {$title} + 说明:单位(万元) + + + + + + + + + + + + + + + + + + + + + + *年度: + + + disabled > + + selected + >{$vo.name} + + + + + + + *类型: + + + disabled > + selected >业务收入 + selected >业务成本 + + + + + + + *类型名称: + + + disabled> + + + + + + + + {$i-0+1}月份: + + + + + + + + + + + {$i-0+1}月份: + + + + + + + + + + + + + + + + + + + 保存 + + + 返回 + + + + + + + + + + + if(C('COLOR_STYLE')=='blue_color') echo ''; + + + + + + + diff --git a/Application/Admin/View/StatementWarning/lists.html b/Application/Admin/View/StatementWarning/lists.html new file mode 100644 index 000000000..a6d0cc76a --- /dev/null +++ b/Application/Admin/View/StatementWarning/lists.html @@ -0,0 +1,296 @@ + + + + + + + + + + + + + 财务汇总统计 + + + + + + + + 搜索: + + + + + selected + >{$vo.name} + + + + + + 搜索 + + + + + + + + 月份重算 + + 新增类目 + + + + + + + + 结算时间:{$last_update} + + + 单位:万元 + + + + + + 项目1月2月3月4月5月6月7月8月9月10月11月12月年度合计操作 + + + + + + {$item.name} + + {$item['count'][$i]} + + + + + + {$vo['name']} + + {$vo['list'][$i]} + + + + 编辑 + + 删除 + + + + + + + + + + + + + + + + + + + + if(C('COLOR_STYLE')=='blue_color') echo ' + '; + + + + + + + + \ No newline at end of file
说明:单位(万元)