<?php
Doo::loadClass('shareact');
Doo::loadClass('contractact');
Doo::loadClass('actmeasure');
Doo::loadClass('project');
Doo::loadClass('numofperact');
Doo::loadClass('sign');

/**
 * MainController
 * Feel free to delete the methods and replace them with your own code.
 *
 * @author darkredz
 */
class ShareController extends DooController
{
    private $data, $sign, $__shareact, $__contractact, $__actMeasure, $__pro, $__numofperact, $statusArray = array('uncheck' => '<span class = "colGray">未上报</span>', 'checking' => '<span class = "colOrange">审核中</span>', 'checked' => '<span class = "colGreen">已完成</span>', 'checkno' => '<span class = "colRed">不通过</span>');

//    public function beforeRun($resource, $action) {
//        if ($this->auth->getUid()) {
//            $uGroups = $this->profile->getProWithUid($this->auth->getUid());
//            $falg = Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
//            if (!$falg)
//                return Doo::acl()->defaultFailedRoute;
//        }else {
//            return Doo::acl()->defaultFailedRoute;
//        }
//    }

    public function __construct()
    {
        $this->__shareact = new Shareact();
        $this->__contractact = new Contractact();
        $this->__actMeasure = new actMeasure();
        $this->__pro = new Project();
        $this->__numofperact = new NumofperAct();
        $this->sign = new signn();
        $this->data['rootUrl'] = Doo::conf()->APP_URL;
//        $this->data['user'] = $this->profile->getProWithUid($this->auth->getUid());
    }

    public function error()
    {

        $this->render('w-share-erro', $this->data, TRUE);
    }

    public function project()
    {
        $shareRowArray = $this->__shareact->getOne($this->params['hashcode']);
        if (!isset($shareRowArray['ids']) || !isset($shareRowArray['idtype']) || $shareRowArray['idtype'] != 1) {
            return Doo::conf()->APP_URL . 'share/error';
        }
        $this->data['hashcode'] = $this->params['hashcode'];
        if ($shareRowArray['ids'] > 0) {
            $proArray = $this->__pro->getRowByPid($shareRowArray['ids']);
        }
        // 总价
        if ($shareRowArray['ids']) {
            $this->data['pros']['numMeasure'] = $this->__actMeasure->getMearsureCount($shareRowArray['ids']);
            $this->data['pros']['contracttotal'] = $this->__actMeasure->getTotalWithPid($shareRowArray['ids']);
            $this->data['pros']['changTotal'] = $this->__numofperact->getChangTotal($shareRowArray['ids']);
            $this->data['pros']['currdone'] = $this->__numofperact->getCurrDoneNow($shareRowArray['ids']);
            if ($this->data['pros']['contracttotal']) {
                $this->data['pros']['pcurrdone'] = round(($this->data['pros']['currdone'] / $this->data['pros']['contracttotal']) * 100) . '%';
            } else {
                $this->data['pros']['pcurrdone'] = '0%';
            }
            $this->data['pros']['bcontracttotal'] = number_format($this->data['pros']['contracttotal'], 2, '.', ',');
            $this->data['pros']['bchangTotal'] = number_format($this->data['pros']['changTotal'], 2, '.', ',');

        } else {
            $this->data['pros'] = [];
        }
        // 标段计量分布
        $conArray = $this->__contractact->getRowByPid($shareRowArray['ids']);
        $this->data['projectDate'] = '';
        $this->data['conArray'][] = array();
        $this->data['pid'] = $shareRowArray['ids'];
        $this->data['conArray'] = $conArray;
        $contracttotal = 0;
        $totalstid = 0;
        $monthArray = [];
        $allmonth = [];
        $allmonth1 = [];
        foreach ($this->data['conArray'] as $k => $v) {
            $this->data['conArray'][$k]['pstopnow'] = $this->data['conArray'][$k]['pscurrdone'] = 0;
            $retval = $this->__actMeasure->getAllbyStidSum($v['stid']);
            $contracttotal += $retval[0]['contracttotal'];
            $totalstid += $this->__actMeasure->getTotal($v['stid'])['total'];
            $total = $this->__actMeasure->getTotal($v['stid'])['total'];
            if ($total) {
                $this->data['conArray'][$k]['total'] = round($total, 2);
            } else {
                $this->data['conArray'][$k]['total'] = 0;
            }
            $sntotal = $this->__numofperact->getCountTotalSTID2($v['stid'])['totalplus'];
            if ($sntotal) {
                $this->data['conArray'][$k]['stopnow'] = round($sntotal, 2);
            } else {
                $this->data['conArray'][$k]['stopnow'] = 0;
            }
            $this->data['conArray'][$k]['currdone'] = $this->__numofperact->getCurrDoneSt($v['stid'])['currdone'];
            if ($this->data['conArray'][$k]['total'] > 0) {
                $this->data['conArray'][$k]['pstopnow'] = round(($this->data['conArray'][$k]['stopnow'] / $this->data['conArray'][$k]['total']) * 100);
                $this->data['conArray'][$k]['pscurrdone'] = round(($this->data['conArray'][$k]['currdone'] / $this->data['conArray'][$k]['total']) * 100);
            }
            // 分组出年月 每个月份的独立相加
            $month = $this->__numofperact->getCurrTotalStMonthNoCheckno($v['stid']);
            foreach ($month as $key => $value) {
                $allmonth[] = $value;
                if (!in_array($value['month'], $monthArray))
                    $monthArray[] = $value['month'];
            }

            // 分组出年月 每个月份的独立相加
            $month1 = $this->__numofperact->getCurrDoneStMonthNoCheckno($v['stid']);
            foreach ($month1 as $key => $value) {
                $allmonth1[] = $value;
            }
        }

        // 中文表述年月
        $total = $total1 = array();
        $startyear = $cnymArray = array();
        foreach ($monthArray as $kk => $vv) {
//            foreach ($allmonth as $keyk => $valuev) {
//                if ($valuev['month'] == $vv)
//                    $total[$kk] += $valuev['currtotal'];
//            }
//            foreach ($allmonth1 as $k1 => $v1) {
//                if ($v1['month'] == $vv)
//                    $total1[$kk] += $v1['currdone'];
//            }
//            $ymarray = split('-', $vv);
            $ymarray = explode('-', $vv);
            if (!in_array($ymarray[0], $startyear))
                $startyear[] = $ymarray[0];
//            $cnym = '\'' . $ymarray[1] . '月' . '\'';
//            if ($kk == 0)
//                $cnym = '\'' . $ymarray[0] . '年' . $ymarray[1] . '月' . '\'';
//            $cnymArray[] = $cnym;
        }
        $thismonth = 0;
        foreach($startyear as $sk => $sv){
            for($i = 1; $i <= 12; $i++){
                $j = $i < 10 ? '0'.$i : $i;
                $month = $sv.'-'.$j;
                $thismonth1 = 0;
                foreach ($allmonth1 as $k1 => $v1) {
                    if ($v1['month'] == $month)
                        $thismonth1 += $v1['currdone'];
                }
                $total1[] = $thismonth1 != 0 ? $thismonth1 : 0;
                foreach ($allmonth as $keyk => $valuev) {
                    if ($valuev['month'] == $month)
                        $thismonth += $valuev['currtotal'];
                }
                $total[] = ($thismonth != 0 && $thismonth1 != 0) ? $thismonth : 0;
                $cnymArray[] = $i == 1 ? '\'' .$sv.'年'.$i.'月'. '\'' : '\'' .$i.'月'. '\'';
            }
        }
        foreach ($total as $value2) {
            $total3[] = round(($value2 / $totalstid) * 100);
        }
        foreach ($total1 as $value11) {
            $total4[] = round(($value11 / $totalstid) * 100);
        }

        $this->data['projectDate'] = implode(',', $cnymArray);
        $this->data['t1'] = implode(',', $total3);
        $this->data['t2'] = implode(',', $total4);
        // 标段计量进度
        // 项目按月进度
        // 标段列表
        $contractArray = $this->__contractact->getRowByPid($shareRowArray['ids']); // 获取合同段
        $htmlstr = NULL;
        foreach ($contractArray as $k => $v) {// 获取所有合同段
            $retval = $this->__actMeasure->getAllbyStid($v['stid']); // 获取标段
            $bdhtmlstr = NULL;
            $bdhtmlstr = '<thead>
				    <tr><th class="taC taCble header"  width="225">标段名</th><th class="taC" width="140">计量期数</th><th width="115" class="taC">总价</th><th class="taC" width="">截止上期完成/本期完成/未完成</th></tr></thead>
				<tbody>';
            $biaoduantotalmoney = 0;
            $currTotal = 0;
            $progress = $otherprogress = '0%';
            $currTotal = $this->__numofperact->getCountTotalSTID2($v['stid']);
            foreach ($retval as $key => $value) {
                $displayPercentSnTotalProgress = '0%';
                $displayPercentCurrTotalProgress = '0%';
                $displayPercentLessTotalProgress = '0%';
                $snTotalProgress = $currTotalProgress = $lessTotalProgress = '0%';
                $nTotalProgress = $ncurrTotalProgress = $nlessTotalProgress = number_format(0, 2, '.', ',');
                $numCount = $this->__numofperact->getCountTotalnum2($value['pmid']); // 获取标段已有期数
                if (isset($numCount['numpname'])) {
                    $lastStatusArray = $this->__numofperact->getMaxStatusTimes($value['pmid'], $numCount['numpname']);
                } else {
                    $lastStatusArray['currstatus'] = 'uncheck';
                    $numCount['numpname'] = 0;
                }
                $totalplus = $this->__numofperact->getCountTotalplus($value['pmid']);
                $snTotal = $this->__numofperact->getStopNowTotal($value['pmid']); //根据标段ID获取最新一期（包括不通过）
                $currcomTotal = $this->__numofperact->getCurrdoneNew($value['pmid']); //截止目前
                $numStatusArray = $this->__numofperact->getLastStatus2($shareRowArray['ids'], $value['pmid']);
                if ($numCount > 0) {
                    $nTotalProgress = number_format($snTotal['sntotal'], 2, '.', ',');
                    $ncurrTotalProgress = number_format($currcomTotal['currtotal'], 2, '.', ',');
                    $nlessTotalProgress = number_format($value['contracttotal'] - $snTotal['sntotal'] - $currcomTotal['currtotal'], 2, '.', ',');
                    if (isset($value['contracttotal']) && ($value['contracttotal'] > 0)) {
                        $snTotalProgress = round(($snTotal['sntotal'] / $value['contracttotal']) * 100);
                        $currTotalProgress = round(($currcomTotal['currtotal'] / $value['contracttotal']) * 100);
//			$lessTotalProgress = round((($value['contracttotal'] - ($currcomTotal['currtotal'] + $snTotal['sntotal'])) / $value['contracttotal']) * 100);
                        $lessTotalProgress = 100 - $snTotalProgress - $currTotalProgress;
                        $displayPercentSnTotalProgress = $snTotalProgress . '%';
                        $displayPercentCurrTotalProgress = $currTotalProgress . '%';
                        $displayPercentLessTotalProgress = $lessTotalProgress . '%';
                    }
                }
                $biaoduantotalmoney += $value['contracttotal'];
                $totalmoney = number_format($value['contracttotal'], 2, '.', ',');
                if (isset($numStatusArray['currstatus'])) {
                    $statusStr = $this->statusArray[$lastStatusArray['currstatus']];
                } else {
                    $statusStr = '';
                }
                $bdhtmlstr .= '
				<tr>
					<td><a href="/share/project/tender/' . $value['pmid'] . '/' . $this->params['hashcode'] . '">' . $value['pmname'] . '</a></td>
					<td class="">共 ' . $numCount['numpname'] . ' 期（本期 ' . $statusStr . '）</td>
					<td class="taR">￥' . $totalmoney . '</td>
					<td>
					    <div class="progress">
						<div class="progress-bar progress-bar-success" style="width: ' . $displayPercentSnTotalProgress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="截止上期完成：￥' . $nTotalProgress . '">' . $displayPercentSnTotalProgress . '</div>
						<div class="progress-bar" style="width:' . $displayPercentCurrTotalProgress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="本期完成：￥' . $ncurrTotalProgress . '">' . $displayPercentCurrTotalProgress . '</div>
						<div class="progress-bar progress-bar-gary" style="width:' . $displayPercentLessTotalProgress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成：￥' . $nlessTotalProgress . '">' . $displayPercentLessTotalProgress . '</div>
					    </div>
					</td>
				    </tr>';
            }
            $nprogress = $notherprogress = NULL;
//	    $currTotal = $this->numofperact->getCurrdoneSTID($v['stid']);
            if ($biaoduantotalmoney > 0) {
                $nprogress = number_format($currTotal['totalplus'], 2, '.', ',');
                $notherprogress = number_format($biaoduantotalmoney - $currTotal['totalplus'], 2, '.', ',');
                $progress = round(($currTotal['totalplus'] / $biaoduantotalmoney) * 100) . '%'; // 累计完成计量 所有标段合计
                $otherprogress = round((($biaoduantotalmoney - $currTotal['totalplus']) / $biaoduantotalmoney) * 100) . '%';
                $biaoduantotalmoney = number_format($biaoduantotalmoney, 2, '.', ',');
            }
            $htmlstr .= '<div class="project">
			<div class="proSection">
			    <table class="table">
				<thead>
				    <tr>
					<td width="150"><span aria-hidden="true" data-icon="u"></span> ' . $v['stname'] . '<a id="idt_' . $v['stid'] . '" href="#secoption" data-toggle="modal" title="编辑/查看KEY" stid="' . $v['stid'] . '" proname="' . $v['stname'] . '" key="' . $v['stkey'] . '"><span data-icon="S" aria-hidden="true" class="closePanel" data-placement="bottom" data-toggle="tooltip" data-original-title="查看KEY" style="font-size:18px"></span></a></td>
					<td width="90">总价：</td><td width="165">￥<b style="font-size:16px">' . $biaoduantotalmoney . '</b></td>
					<td width="60">完成进度：</td><td><div class="progress">
						<div class="progress-bar progress-bar-success" style="width:' . $progress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="累计完成：￥' . $nprogress . '">' . $progress . '</div>
						<div class="progress-bar progress-bar-danger" style="width:' . $otherprogress . ';" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成：￥' . $notherprogress . '">' . $otherprogress . '</div>
					    </div></td>
				    </tr>
				</thead>
			    </table>
			    <table class="table table-striped table-hover tablelist">
				' . $bdhtmlstr . '
				</tbody>
			    </table>
			</div>
		    </div>';
        }
        $this->data['htmlstr'] = $htmlstr;
        $this->data['pname'] = $proArray['pname'];
        $this->render('w-share-project', $this->data);
    }

    public function proTender()
    {
        $shareRowArray = $this->__shareact->getOne($this->params['hashcode']);
        if (!isset($shareRowArray['ids']) || !isset($shareRowArray['idtype']) || $shareRowArray['idtype'] != 1) {
            return Doo::conf()->APP_URL . 'share/error';
        }
        // 判断有效性
        // 判断hashcode有效性
        // 判断标段ID是否属于当前分享父类ID

// 总价
        $mArray = $this->__actMeasure->getRowByPmid($this->params['tenderid']);
        if(empty($mArray)){
            return Doo::conf()->APP_URL . 'share/error';
        }
        $proArray = $mArray;

        //来源url
        $this->data['comefromurl'] = Doo::conf()->APP_URL.'share/project/'.$this->params['hashcode'];

        $this->data['pmname'] = $mArray['pmname'];
        if ($proArray['pid']) {
            $this->data['pros']['numMeasure'] = $this->__actMeasure->getMearsureCount($proArray['pid']);
            $this->data['pros']['contracttotal'] = $this->__actMeasure->getTotalWithPid($proArray['pid']);
            $this->data['pros']['changTotal'] = $this->__numofperact->getChangTotal($proArray['pid']);
            $this->data['pros']['currdone'] = $this->__numofperact->getCurrDoneNow($proArray['pid']);
            if ($this->data['pros']['contracttotal']) {
                $this->data['pros']['pcurrdone'] = round(($this->data['pros']['currdone'] / $this->data['pros']['contracttotal']) * 100) . '%';
            } else {
                $this->data['pros']['pcurrdone'] = '0%';
            }
            $this->data['pros']['bcontracttotal'] = number_format($this->data['pros']['contracttotal'], 2, '.', ',');
            $this->data['pros']['bchangTotal'] = number_format($this->data['pros']['changTotal'], 2, '.', ',');

        } else {
            $this->data['pros'] = [];
        }
// 图表
        $this->data['MeasureArray'] = $this->__numofperact->getGroupByLastOne($this->params['tenderid']);
        $this->data['totalnum'] = count($this->data['MeasureArray']);
        $measureArray = $this->__actMeasure->getRowByPmid($this->params['tenderid']);
        foreach ($this->data['MeasureArray'] as $key => $value) {
            $lastStatusArray = $this->__numofperact->getMaxStatusTimes($value['pmid'], $value['numpname']);
            $this->data['status'] = $this->statusArray[$lastStatusArray['currstatus']];
            if ($measureArray['contracttotal'] > $value['currdone'] && $value['currdone'] > 0) {
                $this->data['MeasureArray'][$key]['lessTotal'] = round(($value['currdone'] / $measureArray['contracttotal']) * 100);
            } else {
                $this->data['MeasureArray'][$key]['lessTotal'] = 0;
            }
        }

        $this->render('w-share-project-section-detail', $this->data, TRUE);
    }

    public function section()
    {
        $shareRowArray = $this->__shareact->getOne($this->params['hashcode']);
        if (!isset($shareRowArray['ids']) || !isset($shareRowArray['idtype']) || $shareRowArray['idtype'] != 2) {
            return Doo::conf()->APP_URL . 'share/error';
        }
        $this->data['hashcode'] = $this->params['hashcode'];

        $conArray = $this->__contractact->getRowByStid($shareRowArray['ids']);
        if(empty($conArray)){
            return Doo::conf()->APP_URL . 'share/error';
        }
        $this->data['secname'] = $conArray['stname'];
        $biaoduantotalmoney = 0;
        $retval = $this->__actMeasure->getAllbyStid($shareRowArray['ids']); // 获取标段
        $totalretval = $this->__actMeasure->getTotal($shareRowArray['ids']); //获取标段总价格
        $currTotal = $this->__numofperact->getCountTotalSTID2($shareRowArray['ids']);
        $this->data['stidArray'] = $retval;
        $totalstid = $totalretval['total'];
        $contracttotal = 0;
        $monthArray = [];
        foreach ($this->data['stidArray'] as $k => $v) {
            //获取标段类型总价
            $biaoduantotalmoney += $v['contracttotal'];

            // 分组出年月 每个月份的独立相加
            $month = $this->__numofperact->getCurrTotalPmMonth($v['pmid']);
            foreach ($month as $key => $value) {
                $allmonth[] = $value;
                if (!in_array($value['month'], $monthArray))
                    $monthArray[] = $value['month'];
            }

            // 分组出年月 每个月份的独立相加
            $month1 = $this->__numofperact->getCurrDonePmMonth($v['pmid']);
            foreach ($month1 as $key => $value) {
                $allmonth1[] = $value;
            }

            $displayPercentSnTotalProgress = '0%';
            $displayPercentCurrTotalProgress = '0%';
            $displayPercentLessTotalProgress = '0%';
            $snTotalProgress = $currTotalProgress = $lessTotalProgress = '0%';
            $nTotalProgress = $ncurrTotalProgress = $nlessTotalProgress = number_format(0, 2, '.', ',');
            $numCount = $this->__numofperact->getCountTotalnum2($v['pmid']); // 获取标段已有期数
            if (isset($numCount['numpname'])) {
                $lastStatusArray = $this->__numofperact->getMaxStatusTimes($v['pmid'], $numCount['numpname']);
            } else {
                $lastStatusArray['currstatus'] = 'uncheck';
                $numCount['numpname'] = 0;
            }
            $this->data['stidArray'][$k]['qi'] = $numCount['numpname'];
            $numStatusArray = $this->__numofperact->getLastStatus2($v['pid'], $v['pmid']);
            if (isset($numStatusArray['currstatus'])) {
                $statusStr = $this->statusArray[$lastStatusArray['currstatus']];
            } else {
                $statusStr = '';
            }
            $this->data['stidArray'][$k]['statusStr'] = $statusStr;
            $this->data['stidArray'][$k]['totalmoney'] = number_format($v['contracttotal'], 2, '.', ',');
            $totalplus = $this->__numofperact->getCountTotalplus($v['pmid']);
            $snTotal = $this->__numofperact->getStopNowTotal($v['pmid']); //根据标段ID获取最新一期（包括不通过）
            $currcomTotal = $this->__numofperact->getCurrdoneNew($v['pmid']); //截止目前
            $numStatusArray = $this->__numofperact->getLastStatus2($v['pid'], $v['pmid']);
            if ($numCount > 0) {
                $this->data['stidArray'][$k]['nTotalProgress'] = number_format($snTotal['sntotal'], 2, '.', ',');
                $this->data['stidArray'][$k]['ncurrTotalProgress'] = number_format($currcomTotal['currtotal'], 2, '.', ',');
                $this->data['stidArray'][$k]['nlessTotalProgress'] = number_format($v['contracttotal'] - $snTotal['sntotal'] - $currcomTotal['currtotal'], 2, '.', ',');
                if (isset($v['contracttotal']) && ($v['contracttotal'] > 0)) {
                    $snTotalProgress = round(($snTotal['sntotal'] / $v['contracttotal']) * 100);
                    $currTotalProgress = round(($currcomTotal['currtotal'] / $v['contracttotal']) * 100);
//			$lessTotalProgress = round((($value['contracttotal'] - ($currcomTotal['currtotal'] + $snTotal['sntotal'])) / $value['contracttotal']) * 100);
                    $lessTotalProgress = 100 - $snTotalProgress - $currTotalProgress;
                    $this->data['stidArray'][$k]['displayPercentSnTotalProgress'] = $snTotalProgress . '%';
                    $this->data['stidArray'][$k]['displayPercentCurrTotalProgress'] = $currTotalProgress . '%';
                    $this->data['stidArray'][$k]['displayPercentLessTotalProgress'] = $lessTotalProgress . '%';
                }
            }
        }

        if ($biaoduantotalmoney > 0) {
            $this->data['st']['nprogress'] = number_format($currTotal['totalplus'], 2, '.', ',');
            $this->data['st']['notherprogress'] = number_format($biaoduantotalmoney - $currTotal['totalplus'], 2, '.', ',');
            $this->data['st']['progress'] = round(($currTotal['totalplus'] / $biaoduantotalmoney) * 100) . '%'; // 累计完成计量 所有标段合计
            $this->data['st']['otherprogress'] = round((($biaoduantotalmoney - $currTotal['totalplus']) / $biaoduantotalmoney) * 100) . '%';
            $this->data['st']['bcontracttotal'] = number_format($biaoduantotalmoney, 2, '.', ',');
        }


        // 中文表述年月
        $total = $total1 = array();
        foreach ($monthArray as $kk => $vv) {
            foreach ($allmonth as $keyk => $valuev) {
                if ($valuev['month'] == $vv)
                    $total[$kk] += $valuev['currtotal'];
            }
            foreach ($allmonth1 as $k1 => $v1) {
                if ($v1['month'] == $vv)
                    $total1[$kk] += $v1['currdone'];
            }
            $ymarray = explode('-', $vv);
            $cnym = '\'' . $ymarray[1] . '月' . '\'';
            if ($kk == 0)
                $cnym = '\'' . $ymarray[0] . '年' . $ymarray[1] . '月' . '\'';
            $cnymArray[] = $cnym;
        }
        foreach ($total as $value2) {
            $total3[] = round(($value2 / $totalstid) * 100);
        }
        foreach ($total1 as $value11) {
            $total4[] = round(($value11 / $totalstid) * 100);
        }
        $this->data['projectDate'] = implode(',', $cnymArray);
        $this->data['t1'] = implode(',', $total3);
        $this->data['t2'] = implode(',', $total4);

        $this->render('w-share-project-section', $this->data);
    }

    public function secTender()
    {
        $shareRowArray = $this->__shareact->getOne($this->params['hashcode']);
        if (!isset($shareRowArray['ids']) || !isset($shareRowArray['idtype']) || $shareRowArray['idtype'] != 2) {
            return Doo::conf()->APP_URL . 'share/error';
        }
        // 判断hashcode有效性
// 总价
        $mArray = $this->__actMeasure->getRowByPmid($this->params['tenderid']);
        if(empty($mArray)){
            return Doo::conf()->APP_URL . 'share/error';
        }
        $proArray = $mArray;

        //来源url
        $this->data['comefromurl'] = Doo::conf()->APP_URL.'share/section/'.$this->params['hashcode'];

        $this->data['pmname'] = $mArray['pmname'];
        if ($proArray['pid']) {
            $this->data['pros']['numMeasure'] = $this->__actMeasure->getMearsureCount($proArray['pid']);
            $this->data['pros']['contracttotal'] = $this->__actMeasure->getTotalWithPid($proArray['pid']);
            $this->data['pros']['changTotal'] = $this->__numofperact->getChangTotal($proArray['pid']);
            $this->data['pros']['currdone'] = $this->__numofperact->getCurrDoneNow($proArray['pid']);
            if ($this->data['pros']['contracttotal']) {
                $this->data['pros']['pcurrdone'] = round(($this->data['pros']['currdone'] / $this->data['pros']['contracttotal']) * 100) . '%';
            } else {
                $this->data['pros']['pcurrdone'] = '0%';
            }
            $this->data['pros']['bcontracttotal'] = number_format($this->data['pros']['contracttotal'], 2, '.', ',');
            $this->data['pros']['bchangTotal'] = number_format($this->data['pros']['changTotal'], 2, '.', ',');

        } else {
            $this->data['pros'] = [];
        }
// 图表
        $this->data['MeasureArray'] = $this->__numofperact->getGroupByLastOne($this->params['tenderid']);
        $this->data['totalnum'] = count($this->data['MeasureArray']);
        $measureArray = $this->__actMeasure->getRowByPmid($this->params['tenderid']);
        foreach ($this->data['MeasureArray'] as $key => $value) {
            $lastStatusArray = $this->__numofperact->getMaxStatusTimes($value['pmid'], $value['numpname']);
            $this->data['status'] = $this->statusArray[$lastStatusArray['currstatus']];
            if ($measureArray['contracttotal'] > $value['currdone'] && $value['currdone'] > 0) {
                $this->data['MeasureArray'][$key]['lessTotal'] = round(($value['currdone'] / $measureArray['contracttotal']) * 100);
            } else {
                $this->data['MeasureArray'][$key]['lessTotal'] = 0;
            }
        }

        $this->render('w-share-project-section-detail', $this->data, TRUE);
    }

    public function tender()
    {
        $shareRowArray = $this->__shareact->getOne($this->params['hashcode']);
        if (!isset($shareRowArray['ids']) || !isset($shareRowArray['idtype']) || $shareRowArray['idtype'] != 3) {
            return Doo::conf()->APP_URL . 'share/error';
        }
        $this->data['hashcode'] = $this->params['hashcode'];
// 总价
        if ($shareRowArray['ids'] > 0) {
            $mArray = $this->__actMeasure->getRowByPmid($shareRowArray['ids']);
            if(empty($mArray)){
                return Doo::conf()->APP_URL . 'share/error';
            }
            $proArray = $mArray;
        }
        //来源url
        $this->data['comefromurl'] = Doo::conf()->APP_URL.'share/tender/'.$this->params['hashcode'];

        $this->data['pmname'] = $mArray['pmname'];
        if ($proArray['pid']) {
            $this->data['pros']['numMeasure'] = $this->__actMeasure->getMearsureCount($proArray['pid']);
            $this->data['pros']['contracttotal'] = $this->__actMeasure->getTotalWithPid($proArray['pid']);
            $this->data['pros']['changTotal'] = $this->__numofperact->getChangTotal($proArray['pid']);
            $this->data['pros']['currdone'] = $this->__numofperact->getCurrDoneNow($proArray['pid']);
            if ($this->data['pros']['contracttotal']) {
                $this->data['pros']['pcurrdone'] = round(($this->data['pros']['currdone'] / $this->data['pros']['contracttotal']) * 100) . '%';
            } else {
                $this->data['pros']['pcurrdone'] = '0%';
            }
            $this->data['pros']['bcontracttotal'] = number_format($this->data['pros']['contracttotal'], 2, '.', ',');
            $this->data['pros']['bchangTotal'] = number_format($this->data['pros']['changTotal'], 2, '.', ',');

        } else {
            $this->data['pros'] = [];
        }
// 图表
        $this->data['MeasureArray'] = $this->__numofperact->getGroupByLastOne($shareRowArray['ids']);
        $this->data['totalnum'] = count($this->data['MeasureArray']);
        $measureArray = $this->__actMeasure->getRowByPmid($shareRowArray['ids']);
        foreach ($this->data['MeasureArray'] as $key => $value) {
            $lastStatusArray = $this->__numofperact->getMaxStatusTimes($value['pmid'], $value['numpname']);
            $this->data['status'] = $this->statusArray[$lastStatusArray['currstatus']];
            if ($measureArray['contracttotal'] > $value['currdone'] && $value['currdone'] > 0) {
                $this->data['MeasureArray'][$key]['lessTotal'] = round(($value['currdone'] / $measureArray['contracttotal']) * 100);
            } else {
                $this->data['MeasureArray'][$key]['lessTotal'] = 0;
            }
        }

        $this->render('w-share-project-section-detail', $this->data, true);
    }

    public function getShare()
    {
        $page = null;
        $fildArray = null;
        $proArray = $this->__shareact->getHashCode($_POST['pid'],1);
        if(!empty($proArray)){
            $proname = $this->__pro->getRowByPid($_POST['pid']);
            $page = 1;
            $fildArray[] = array('id' => $proArray['ids'], 'name' => $proname['pname'], 'ischeckd' => '1', 'hashcode' => $proArray['hashcode']);
        }else{
            $fildArray = null;
            $tmpArray = $this->__contractact->getRowByPid($_POST['pid']);
            foreach ($tmpArray as $key => $value) {
                $secArray = $this->__shareact->getSectionCount($value['stid']);
                if (!empty($secArray)) {
                    $page = 2;
                    $fildArray[] = array('id' => $value['stid'], 'name' => $value['stname'], 'ischeckd' => '1', 'hashcode' => $secArray['hashcode']);
                } else {
                    $fildArray[] = array('id' => $value['stid'], 'name' => $value['stname'], 'ischeckd' => '0', 'hashcode' => $secArray['hashcode']);
                }
            }
            if($page != 2 && $page != 1){
                $fildArray = null;
                $tmp = $this->__actMeasure->getRowsByPid($_POST['pid']);
                foreach ($tmp as $key => $value) {
                    $tenArray = $this->__shareact->getHashCode($value['pmid'],3);
                    if(!empty($tenArray)){
                        $page = 3;
                        $fildArray[] = array('id' => $value['pmid'], 'name' => $value['pmname'],'ischeckd' => '1', 'hashcode' => $tenArray['hashcode']);
                    }else{
                        $fildArray[] = array('id' => $value['pmid'], 'name' => $value['pmname'],'ischeckd' => '0', 'hashcode' => $tenArray['hashcode']);
                    }
                }
            }
        }
        if($page == null){
            $page = null;
            $fildArray = null;
        }
        die(json_encode(array('page' => $page, 'filearray' => $fildArray)));
    }

    public function setShare()
    {
        if($_POST['check'] == "true"){
            if ($this->__shareact->getCount($_POST['id'], $_POST['type']) > 0) {
                $returnVal = $this->__shareact->updateHashcode($_POST['id'], $_POST['type']);
            } else {
                $returnVal = $this->__shareact->insertHashcode($_POST['id'], $_POST['type']);
            }
        }else{
            $returnVal = $this->__shareact->deleteHashcode($_POST['id'], $_POST['type']);
            $returnVal['hashcode'] = '';
        }

        die(json_encode(array('sharecode' => $returnVal['hashcode'])));

//        if (isset($_POST['stid'])) {
//            if ($this->__shareact->getCount($_POST['stid'], 2) > 0) {
//                $returnVal = $this->__shareact->updateHashcode($_POST['stid'], 2);
//            } else {
//                $returnVal = $this->__shareact->insertHashcode($_POST['stid'], 2);
//            }
//            die(json_encode(array('sharecode' => $returnVal['hashcode'])));
//        }
//        if(isset($_POST['pmid'])) {
//            if ($this->__shareact->getCount($_POST['pmid'], 3) > 0) {
//                $returnVal = $this->__shareact->updateHashcode($_POST['pmid'], 3);
//            } else {
//                $returnVal = $this->__shareact->insertHashcode($_POST['pmid'], 3);
//            }
//            die(json_encode(array('sharecode' => $returnVal['hashcode'])));
//        }

    }

    public function ajaxGetProject()
    {
        $proArray = $this->__shareact->getHashCode($_POST['pid'],1);
        $proname = $this->__pro->getRowByPid($_POST['pid']);
        if(!empty($proArray)){
            $fildArray[] = array('id' => $proArray['ids'], 'name' => $proname['pname'], 'ischeckd' => '1', 'hashcode' => $proArray['hashcode']);
        }else{
            $fildArray[] = array('id' => $_POST['pid'], 'name' => $proname['pname'], 'ischeckd' => '0', 'hashcode' => $proArray['hashcode']);
        }
        die(json_encode($fildArray));
    }

    public function ajaxGetSection()
    {
        $fildArray = null;
        $tmpArray = $this->__contractact->getRowByPid($_POST['pid']);
        foreach ($tmpArray as $key => $value) {
            $secArray = $this->__shareact->getSectionCount($value['stid']);
            if (!empty($secArray)) {
                $fildArray[] = array('id' => $value['stid'], 'name' => $value['stname'], 'ischeckd' => '1', 'hashcode' => $secArray['hashcode']);
            } else {
                $fildArray[] = array('id' => $value['stid'], 'name' => $value['stname'], 'ischeckd' => '0', 'hashcode' => $secArray['hashcode']);
            }
        }
        die(json_encode($fildArray));
    }

    public function ajaxGetTender()
    {
        $fildArray = array();
        $tmp = $this->__actMeasure->getRowsByPid($_POST['pid']);
        foreach ($tmp as $key => $value) {
            $tenArray = $this->__shareact->getHashCode($value['pmid'],3);
            if(!empty($tenArray)){
                $fildArray[] = array('id' => $value['pmid'], 'name' => $value['pmname'],'ischeckd' => '1', 'hashcode' => $tenArray['hashcode']);
            }else{
                $fildArray[] = array('id' => $value['pmid'], 'name' => $value['pmname'],'ischeckd' => '0', 'hashcode' => $tenArray['hashcode']);
            }
        }
        die(json_encode($fildArray));
    }

    public function signShare()
    {
        if(isset($_GET['sid']) && is_numeric($_GET['sid'])){
            $signmsg = $this->sign->getOneSignbysid($_GET['sid']);
            if(!empty($signmsg) && $signmsg['ishare'] == 1){
                //获取报表图片
                $maxwidth = 794; //默认图片最大宽度   a4
//                $maxheight = 1123; //默认图片最大高度  a4
                //获取报表图片
                $signattlist = $this->sign->getSignAttList($_GET['sid']);
                if(!empty($signattlist)){
                    foreach($signattlist as $sak => $sav){
                        $signattlist[$sak]['auditatt'] = $this->sign->getSignAuditAttList($sav['said']);
                        if($sak == 0){
                            $imgmsg = getimagesize(Doo::conf()->APP_URL.$sav['filepath']);
                            $maxwidth = $imgmsg[0];
//                            $maxheight = $imgmsg[1];
//                            break;
                        }
                    }
                }
                $this->data['maxwidth'] = $maxwidth;
                $this->data['attlist'] = $signattlist;
                $this->render('sign-share', $this->data, TRUE);
            }
            exit('没有权限查看该报表');
        }
        exit('不存在该报表');
    }

}

?>