$orgId, 'user_id' => $userId, 'apply_id' => $id, 'create_time' => date('Y-m-d H:i:s'), 'status' => 0, 'type' => 0 ]; foreach ($formJson as $k=>$v){ if($v['componentName'] == 'ddjjcontractfield'){ foreach ($v['components'] as $key=>$val){ switch ($val['idx']){ case '0': $company = json_decode($val['values'],true); $data['company_id'] = $company['id']; break; case '1': $program = json_decode($val['values'],true); $data['program_id'] = $program['id']; break; case '2': $data['handle_date'] = $val['values']; break; case '3': $data['title'] = $val['values']; break; case '4': $data['money'] = $val['values']; break; case '5': $data['company2'] = $val['values']; break; case '6': $data['company3'] = $val['values']; break; // case '7': // 经办人 // $data['agent'] = $val['values']; // break; case '8': $data['company3_leader'] = $val['values']; break; case '9': $stamp = json_decode($val['values'],true); $data['sdid'] = $stamp['id']; break; case '10': $data['ispay'] = $val['values'] == '付款'?1:2; break; case '11': // 合同到期日期 $data['end_date'] = $val['values']; break; case '12': // 采购方式 $data['buy_type'] = $val['values']; break; case '13': // 采购方式 $data['tax_sn'] = $val['values']; break; case '14': // 是否为连续签订合同 $data['renew'] = $val['values']&&$val['values'] == '是'?1:0; break; } } break; } } $data['completion'] = $data['total_money'] = $data['money']; $pre = Db::name('company')->where('id',$data['company_id'])->value('sn'); $programSn = Db::name('program')->where('id',$data['program_id'])->value('sn'); $data['contract_sn'] = get_contact_sn($pre).$programSn; $sdinfo = Db::name('stamp_duty')->where('id',$data['sdid'])->find(); // $sd_money = round($data['money'] * $sdinfo['bl'] / 1000,1); // 以前精确到角 $sd_money = round($data['money'] * $sdinfo['bl'] / 1000,2); // 20220907 修改精确到分 if($sd_money < 1 && $sdinfo['type'] == 1){ $sd_money = 1; } if($sd_money < 1 && $sdinfo['type'] == 2){ $sd_money = 0; } $data['sd_money'] = $sd_money; $ret = Db::name('contract')->insert($data); return $ret?true:false; } public function advancedEndContract($id,$orgId,$userId,$formJson){ $data = [ 'update_time' => date('Y-m-d H:i:s'), 'status' => 1 ]; $info = Db::name('contract')->where('apply_id',$id)->find(); $program = Db::name('program')->where('id',$info['program_id'])->find(); // 先获取最大项目编号 $program_sn = Db::name('contract') ->alias('c') ->join('apply a','a.id = c.apply_id') ->where('c.status',1) ->where('c.program_id',$info['program_id']) ->where('a.del',0) ->where('c.type',0) ->order('a.finish_time desc') ->value('program_sn'); if($program_sn){ $sn = intval(substr($program_sn,-4)) + 1; $nsn = $program['sn'].str_pad($sn,4,'0',STR_PAD_LEFT); }else{ $nsn = $program['sn'].'0001'; } $data['program_sn'] = $nsn; $ret2 = $this->createHouseContract($info); if(!$ret2){ return false; } $ret = Db::name('contract')->where('apply_id',$id)->update($data); return $ret?true:false; } public function advancedDisagreeContract($id){ $data = [ 'update_time' => date('Y-m-d H:i:s'), 'status' => 2 ]; $ret = Db::name('contract')->where('apply_id',$id)->update($data); return $ret?true:false; } public function advancedDelContract($id){ $info = Db::name('contract')->where('apply_id',$id)->find(); $data = [ 'update_time' => date('Y-m-d H:i:s'), 'status' => 2 ]; // 检查合同是否又追加合同以及是否付/收过款,这种情况不允许删除 if($info['status'] == 1){ if($info['type'] == 0){ // 合同,检查是否有追加合同 $res = Db::name('contract')->where('type',1)->where('parent_apply_id',$id)->where('status','in',[0,1])->find(); if($res){ $this->error = '已存在追加合同,不能删除'; return false; } } // 检查是否否付/收过款 $res = Db::name('contract_pay')->where('pay_apply_id',$id)->where('status','in',[0,1])->find(); if($res){ if($info['ispay'] == 1){ $this->error = '已存付款记录,不能删除'; return false; }else{ $this->error = '已存收款记录,不能删除'; return false; } } } $ret = Db::name('contract')->where('apply_id',$id)->update($data); if($ret){ // 有房产合同的删除房产合同 Db::name('house_contract')->where('contract_id',$info['id'])->setField('del',1); }else{ $this->error = '操作失败'; } return $ret?true:false; } public function advancedStartAddContract($id,$orgId,$userId,$formJson){ $formJson = json_decode($formJson,true); $data = [ 'org_id' => $orgId, 'user_id' => $userId, 'apply_id' => $id, 'create_time' => date('Y-m-d H:i:s'), 'status' => 0, 'type' => 1 ]; foreach ($formJson as $k=>$v){ if($v['componentName'] == 'ddaddcontractfield'){ foreach ($v['components'] as $key=>$val){ switch ($val['idx']){ // case '0': // $company = json_decode($val['values'],true); // $data['company_id'] = $company['id']; // break; // case '1': // $program = json_decode($val['values'],true); // $data['program_id'] = $program['id']; // break; case '2': $data['handle_date'] = $val['values']; break; case '3': $data['title'] = $val['values']; break; case '4': $data['money'] = $val['values']; break; // case '5': // $data['company2'] = $val['values']; // break; // case '6': // $data['company3'] = $val['values']; // break; // case '7': // $data['agent'] = $val['values']; // break; case '8': $data['company3_leader'] = $val['values']; break; case '9': $stamp = json_decode($val['values'],true); $data['sdid'] = $stamp['id']; break; case '10': $data['parent_apply_id'] = $val['values2'][0]['id']; break; case '11': // 合同到期日期 $data['end_date'] = $val['values']; case '14': // 是否为连续签订合同 $data['renew'] = $val['values']&&$val['values'] == '是'?1:0; break; } } break; } } $pinfo = Db::name('contract') ->where('apply_id',$data['parent_apply_id']) ->where('status',1) ->find(); if(!$pinfo){ return false; } $data['company_id'] = $pinfo['company_id']; $data['program_id'] = $pinfo['program_id']; $data['company2'] = $pinfo['company2']; $data['company3'] = $pinfo['company3']; $data['tax_sn'] = $pinfo['tax_sn']; $data['ispay'] = $pinfo['ispay']; $data['buy_type'] = $pinfo['buy_type']; $pre = Db::name('company')->where('id',$data['company_id'])->value('sn'); // $data['contract_sn'] = get_contact_sn($pre); $sdinfo = Db::name('stamp_duty')->where('id',$data['sdid'])->find(); $sd_money = round($data['money'] * $sdinfo['bl'] / 1000,1); if($sd_money < 1 && $sdinfo['type'] == 1){ $sd_money = 1; } if($sd_money < 1 && $sdinfo['type'] == 2){ $sd_money = 0; } $data['sd_money'] = $sd_money; $ret = Db::name('contract')->insert($data); return $ret?true:false; } public function advancedEndAddContract($id,$orgId,$userId,$formJson){ $data = [ 'update_time' => date('Y-m-d H:i:s'), 'status' => 1 ]; $info = Db::name('contract')->where('apply_id',$id)->find(); $pinfo = Db::name('contract') ->where('apply_id',$info['parent_apply_id']) ->where('status',1) ->find(); $contract_sn = $pinfo['contract_sn']; $count = Db::name('contract') ->where('type',1) ->where('parent_apply_id',$info['parent_apply_id']) ->where('status',1) ->count(); $xh = $count == 0?1:($count+1); $contract_sn = $contract_sn.sprintf('%03s', $xh); $data['contract_sn'] = $contract_sn; $info['contract_sn'] = $contract_sn; // 项目编号 $data['program_sn'] = $pinfo['program_sn'].'补'.str_pad($xh,2,'0',STR_PAD_LEFT); if($info['money'] > 0){ $res = Db::name('contract')->where('id',$pinfo['id'])->update([ 'completion' => round($pinfo['completion'] + $info['money'],2), 'total_money' => round($pinfo['total_money'] + $info['money'],2) ]); if(!$res){ return false; } } $ret2 = $this->createHouseContract($info); if(!$ret2){ return false; } $ret = Db::name('contract')->where('apply_id',$id)->update($data); return $ret?true:false; } public function advancedDisagreeAddContract($id){ $data = [ 'update_time' => date('Y-m-d H:i:s'), 'status' => 2 ]; $ret = Db::name('contract')->where('apply_id',$id)->update($data); return $ret?true:false; } public function advancedDelAddContract($id){ $info = Db::name('contract')->where('apply_id',$id)->find(); $data = [ 'update_time' => date('Y-m-d H:i:s'), 'status' => 2 ]; // 检查合同是否又追加合同以及是否付/收过款,这种情况不允许删除 if($info['status'] == 1){ if($info['type'] == 0){ // 合同,检查是否有追加合同 $res = Db::name('contract')->where('type',1)->where('parent_apply_id',$id)->where('status','in',[0,1])->find(); if($res){ $this->error = '已存在追加合同,不能删除'; return false; } } // 检查是否否付/收过款 $res = Db::name('contract_pay')->where('pay_apply_id',$id)->where('status','in',[0,1])->find(); if($res){ if($info['ispay'] == 1){ $this->error = '已存付款记录,不能删除'; return false; }else{ $this->error = '已存收款记录,不能删除'; return false; } } } $ret = Db::name('contract')->where('apply_id',$id)->update($data); if($ret && $info['status'] == 1){ // 有房产合同的删除房产合同 Db::name('house_contract')->where('contract_id',$info['id'])->setField('del',1); $pinfo = Db::name('contract')->where('apply_id',$info['parent_apply_id'])->where('status',1)->find(); $d = [ 'completion' => round($pinfo['completion'] - $info['total_money'],2), 'total_money' => round($pinfo['total_money'] - $info['total_money'],2) ]; Db::name('contract')->where('id',$pinfo['id'])->update($d); } if(!$ret){ $this->error = '操作失败'; } return $ret?true:false; } private function createHouseContract($info){ // return true; // 暂时隐藏 $depid = Db::name('apply')->where('id',$info['apply_id'])->value('dep_id'); if($depid == 210){ // 投资管理处提交的普通合同,生成租房合同 $hdata = [ 'contract_id' => $info['id'], 'sn' => $info['contract_sn'], 'org_id' => $info['org_id'], 'intro' => $info['title'], 'create_time' => date('Y-m-d H:i:s'), 'amount' => $info['money'], 'sign_date' => $info['handle_date'], 'user_id' => $info['user_id'], ]; $ret2 = Db::name('house_contract')->insert($hdata); if(!$ret2){ return false; } } return true; } public function info($applyId){ $info = Db::name('contract')->where('apply_id',$applyId)->find(); if($info){ $info['company'] = Db::name('company')->where('id',$info['company_id'])->value('title'); $stamp = Db::name('stamp_duty')->where('id',$info['sdid'])->field('id,title,bl,type')->find(); $info['stamp'] = $stamp; $info['agent'] = Db::name('user_info')->where('user_id',$info['user_id'])->value('name'); $info['fh_user_name'] = ''; if($info['fh_user_id'] > 0){ $info['fh_user_name'] = Db::name('user_info')->where('user_id',$info['fh_user_id'])->value('name'); } } return $info; } public function lists($page,$size,$userId,$contractSn,$programSn,$title,$ispay,$programId,$companyId,$startTime,$endTime,$company2){ // 获取用户权限 $applyids1 = Db::name('apply_record') ->alias('ar') ->join('apply a','a.id = ar.apply_id') ->where('ar.user_id',$userId) ->where('a.status',2) ->where('a.del',0) ->where('a.advanced',3) ->where('ar.del',0) ->column('ar.apply_id'); $applyids2 = Db::name('apply') ->where('status',2) ->where('advanced',3) ->where('del',0) ->where('user_id',$userId) ->column('id'); $applyids1 = $applyids1?array_unique($applyids1):[]; $applyids2 = $applyids2?array_unique($applyids2):[]; $applyids = array_unique(array_merge($applyids1,$applyids2)); if(empty($applyids)){ return [ 'total' => 0, 'list' => [] ]; } $map[] = ['apply_id','in',$applyids]; $map[] = ['status','=',1]; $map[] = ['type','=',0]; if($contractSn){ $map[] = ['contract_sn','like','%'.$contractSn.'%']; } if($programSn){ $map[] = ['program_sn','like','%'.$programSn.'%']; } if($title){ $map[] = ['title','like','%'.$title.'%']; } if($company2){ $map[] = ['company2','like','%'.$company2.'%']; } if($ispay > 0){ $map[] = ['ispay','=',$ispay]; } if($programId > 0){ $map[] = ['program_id','=',$programId]; } if($companyId > 0){ $map[] = ['company_id','=',$companyId]; } if($startTime){ $map[] = ['handle_date','>=',$startTime]; } if($endTime){ $map[] = ['handle_date','<=',$endTime]; } $lists = $this ->where($map) ->page($page,$size) ->order('id desc') ->select(); $lists = $lists?$lists->toArray():[]; foreach ($lists as $k=>$v){ $zjmoney = Db::name('contract') ->where('status',1) ->where('type',1) ->where('parent_apply_id',$v['apply_id']) ->sum('money'); // $lists[$k]['totalMoney'] = $v['money'] + $zjmoney; $lists[$k]['zjMoney'] = $zjmoney; $zjpaymoney = Db::name('contract') ->where('status',1) ->where('type',1) ->where('parent_apply_id',$v['apply_id']) ->sum('pay_money'); $lists[$k]['totalPayMoney'] = $v['pay_money'] + $zjpaymoney; $lists[$k]['paybl'] = 0; if($lists[$k]['total_money'] > 0){ $lists[$k]['paybl'] = round($lists[$k]['totalPayMoney'] / $lists[$k]['total_money'],2)*100 . '%'; } $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title'); $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title'); $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title'); $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); $lists[$k]['children'] = $this->appendLists($v['apply_id']); } $total = $this->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists ]; return $data; } // 导出列表 public function exportLists($userId,$contractSn,$programSn,$title,$ispay,$programId,$companyId,$startTime,$endTime,$company2){ // 获取用户权限 $applyids1 = Db::name('apply_record') ->alias('ar') ->join('apply a','a.id = ar.apply_id') ->where('ar.user_id',$userId) ->where('a.status',2) ->where('a.del',0) ->where('a.advanced',3) ->where('ar.del',0) ->column('ar.apply_id'); $applyids2 = Db::name('apply') ->where('status',2) ->where('advanced',3) ->where('del',0) ->where('user_id',$userId) ->column('id'); $applyids1 = $applyids1?array_unique($applyids1):[]; $applyids2 = $applyids2?array_unique($applyids2):[]; $applyids = array_unique(array_merge($applyids1,$applyids2)); if(empty($applyids)){ $map[] = ['apply_id','=',-1]; }else{ $map[] = ['apply_id','in',$applyids]; } $map[] = ['status','=',1]; $map[] = ['type','=',0]; if($contractSn){ $map[] = ['contract_sn','like','%'.$contractSn.'%']; } if($programSn){ $map[] = ['program_sn','like','%'.$programSn.'%']; } if($title){ $map[] = ['title','like','%'.$title.'%']; } if($company2){ $map[] = ['company2','like','%'.$company2.'%']; } if($ispay > 0){ $map[] = ['ispay','=',$ispay]; } if($programId > 0){ $map[] = ['program_id','=',$programId]; } if($companyId > 0){ $map[] = ['company_id','=',$companyId]; } if($startTime){ $map[] = ['handle_date','>=',$startTime]; } if($endTime){ $map[] = ['handle_date','<=',$endTime]; } $lists = $this ->where($map) ->order('id desc') ->select(); $lists = $lists?$lists->toArray():[]; foreach ($lists as $k=>$v){ $zjmoney = Db::name('contract') ->where('status',1) ->where('type',1) ->where('parent_apply_id',$v['apply_id']) ->sum('money'); // $lists[$k]['totalMoney'] = $v['money'] + $zjmoney; $lists[$k]['zjMoney'] = $zjmoney; $zjpaymoney = Db::name('contract') ->where('status',1) ->where('type',1) ->where('parent_apply_id',$v['apply_id']) ->sum('pay_money'); $lists[$k]['totalPayMoney'] = $v['pay_money'] + $zjpaymoney; $lists[$k]['paybl'] = 0; if($lists[$k]['total_money'] > 0){ $lists[$k]['paybl'] = round($lists[$k]['totalPayMoney'] / $lists[$k]['total_money'],2)*100 . '%'; } $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title'); $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title'); $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title'); $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); if($v['sd_status'] == 0){ $lists[$k]['sdStatusText'] = '未上传'; }else{ $lists[$k]['sdStatusText'] = '已上传'; } if($v['ispay'] == 1){ $lists[$k]['ispayText'] = '付款'; }else{ $lists[$k]['ispayText'] = '收款'; } if($v['transferred'] == 0){ $lists[$k]['transferredText'] = '未办结'; }else{ $lists[$k]['transferredText'] = '已办结'; } } $columns = [ ["title" => "合同编号","key" => "contractSn"], ["title" => "项目编号","key" => "programSn"], ["title" => "合同名称","key" => "title"], ["title" => "单位","key" => "company"], ["title" => "项目名称","key" => "program"], ["title" => "对方单位","key" => "company2"], ["title" => "经办单位","key" => "company3"], ["title" => "经办单位负责人","key" => "company3Leader"], ["title" => "经办人","key" => "agent"], ["title" => "印花税目","key" => "sdname"], ["title" => "印花税","key" => "sdMoney"], ["title" => "印花税上税凭证","key" => "sdStatusText"], ["title" => "类型","key" => "ispayText"], ["title" => "合同金额","key" => "money"], ["title" => "合同追加金额","key" => "zjMoney"], ["title" => "总金额","key" => "totalMoney"], ["title" => "已支付/收取款项","key" => "totalPayMoney"], ["title" => "办理日期","key" => "handleDate"], ["title" => "支付比例","key" => "paybl"], ["title" => "办结状态","key" => "transferredText"], ["title" => "合同到期日期","key" => "endDate"], ]; $data = [ 'columns' => $columns, 'list' => $lists ]; return $data; } public function applists($page,$size,$userId){ $map[] = ['status','=',1]; $map[] = ['type','=',0]; $lists = $this ->where($map) ->page($page,$size) ->order('id desc') ->select(); $lists = $lists?$lists->toArray():[]; foreach ($lists as $k=>$v){ $zjpaymoney = Db::name('contract') ->where('status',1) ->where('type',1) ->where('parent_apply_id',$v['apply_id']) ->sum('pay_money'); $lists[$k]['totalPayMoney'] = $v['pay_money'] + $zjpaymoney; if($lists[$k]['total_money'] > 0){ $lists[$k]['paybl'] = round($lists[$k]['totalPayMoney'] / $lists[$k]['total_money'],2)*100 . '%'; }else{ $lists[$k]['paybl'] = '0%'; } $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); } $total = $this->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists ]; return $data; } public function appendLists($applyId){ $map[] = ['status','=',1]; $map[] = ['parent_apply_id','=',$applyId]; $lists = $this ->where($map) ->order('id asc') ->select(); $lists = $lists?$lists->toArray():[]; foreach ($lists as $k=>$v){ $lists[$k]['paybl'] = '0%'; if($v['money'] > 0){ $lists[$k]['paybl'] = round($v['pay_money'] / $v['money'],2)*100 . '%'; } $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title'); $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title'); $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title'); $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); $lists[$k]['zjMoney'] = ''; $lists[$k]['totalPayMoney'] = ''; } return $lists; } // 印花税凭证 public function stamplists($page,$size,$contractSn,$programSn,$title,$status,$startTime,$endTime,$type=0,$companyId,$sbStatus,$print){ if($status >= 0){ $map[] = ['sd_status','=',$status]; } $map[] = ['status','=',1]; // $map[] = ['type','=',0]; if($type == 0){ // 财务 $map[] = ['sd_money','>',0]; } if($companyId > 0){ $map[] = ['company_id','=',$companyId]; } if($startTime){ $map[] = ['handle_date','>=',$startTime]; } if($endTime){ $map[] = ['handle_date','<=',$endTime]; } if($contractSn){ $map[] = ['contract_sn','like','%'.$contractSn.'%']; } if($programSn){ $map[] = ['program_sn','like','%'.$programSn.'%']; } if($title){ $map[] = ['title','like','%'.$title.'%']; } if($sbStatus != ''){ $map[] = ['sb_status','=',$sbStatus]; } if($print != ''){ $map[] = ['print','=',$print]; } $programId = input('programId/d',0); if($programId > 0){ $map[] = ['program_id','=',$programId]; } $lists = $this ->where($map) ->page($page,$size) ->order('sd_status asc,id desc') ->select(); $lists = $lists?$lists->toArray():[]; foreach ($lists as $k=>$v){ $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title'); $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title'); $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title'); $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); $applyuser = Db::name('apply') ->alias('a') ->join('user_info u','u.user_id = a.user_id') ->where('a.id',$v['apply_id']) ->value('u.name'); $lists[$k]['apply_user'] = $applyuser?$applyuser:''; } $total = $this->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists ]; return $data; } // 导出印花税凭证 public function stampListsExport($contractSn,$programSn,$title,$status,$startTime,$endTime,$type=0,$companyId,$sbStatus,$print){ if($status >= 0){ $map[] = ['sd_status','=',$status]; } $map[] = ['status','=',1]; // $map[] = ['type','=',0]; if($type == 0){ // 财务 $map[] = ['sd_money','>',0]; } if($companyId > 0){ $map[] = ['company_id','=',$companyId]; } if($startTime){ $map[] = ['handle_date','>=',$startTime]; } if($endTime){ $map[] = ['handle_date','<=',$endTime]; } if($contractSn){ $map[] = ['contract_sn','like','%'.$contractSn.'%']; } if($programSn){ $map[] = ['program_sn','like','%'.$programSn.'%']; } if($title){ $map[] = ['title','like','%'.$title.'%']; } if($sbStatus != ''){ $map[] = ['sb_status','=',$sbStatus]; } if($print != ''){ $map[] = ['print','=',$print]; } $programId = input('programId/d',0); if($programId > 0){ $map[] = ['program_id','=',$programId]; } $lists = $this ->where($map) ->order('sd_status asc,id desc') ->select(); $lists = $lists?$lists->toArray():[]; foreach ($lists as $k=>$v){ $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title'); $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title'); $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title'); $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); $lists[$k]['type_text'] = $v['type'] == 1?"追加合同":"普通合同"; $lists[$k]['sd_status_text'] = "未上传完税证明"; if($v['sd_status'] == 1){ $lists[$k]['sd_status_text'] = "已上传完税证明"; }else if($v['sd_status'] == 2){ $lists[$k]['sd_status_text'] = "已打回"; } $lists[$k]['sb_status_text'] = $v['sb_status'] == 1?"已申报":"未申报"; $lists[$k]['print_text'] = $v['print'] == 1?"已打印":"未打印"; $applyuser = Db::name('apply') ->alias('a') ->join('user_info u','u.user_id = a.user_id') ->where('a.id',$v['apply_id']) ->value('u.name'); $lists[$k]['apply_user'] = $applyuser?$applyuser:''; } $columns[] = ["title" => "项目编号","key" => "programSn"]; $columns[] = ["title" => "合同发起人","key" => "applyUser"]; $columns[] = ["title" => "合同名称","key" => "title"]; $columns[] = ["title" => "单位","key" => "company"]; $columns[] = ["title" => "项目名称","key" => "program"]; $columns[] = ["title" => "对方单位","key" => "company2"]; $columns[] = ["title" => "类型","key" => "typeText"]; $columns[] = ["title" => "合同金额","key" => "money"]; $columns[] = ["title" => "办理日期","key" => "handleDate"]; $columns[] = ["title" => "报税状态","key" => "sdStatusText"]; $columns[] = ["title" => "打回原因","key" => "sdReason"]; $columns[] = ["title" => "申报状态","key" => "sbStatusText"]; $columns[] = ["title" => "打印状态","key" => "printText"]; $columns[] = ["title" => "合同到期日期","key" => "endDate"]; $data = [ 'columns' => $columns, 'list' => $lists ]; return $data; } // 上传印花税凭证 public function stampupdates($id,$sdFile){ $data = [ 'sd_file' => $sdFile, 'sd_time' => date('Y-m-d H:i:s'), 'sd_status' => 1 ]; if($id <= 0){ HelpHander::error('参数错误'); } if(!$data['sd_file']){ HelpHander::error('未上传印花税上税凭证'); } $info = Db::name('contract')->where('id',$id)->find(); if(!$info || $info['status'] != 1){ HelpHander::error('合同不存在'); } if($info['transferred'] == 1){ HelpHander::error('合同已办结'); } $ret = Db::name('contract')->where('id',$id)->update($data); if(!$ret){ HelpHander::error('操作失败'); } return true; } // 确认印花税 public function stampConfirm($id,$userId){ if($id <= 0){ HelpHander::error('参数错误'); } $info = Db::name('contract')->where('id',$id)->find(); if(!$info || $info['status'] != 1){ HelpHander::error('合同不存在'); } if($info['fh_user_id'] > 0){ HelpHander::error('已确认,无需重复操作'); } $data = [ 'fh_user_id' => $userId, 'fh_time' => date('Y-m-d H:i:s') ]; $ret = Db::name('contract')->where('id',$id)->update($data); if(!$ret){ HelpHander::error('操作失败'); } return true; } // 确认收到合同 public function confirm($id){ if($id <= 0){ HelpHander::error('参数错误'); } $info = Db::name('contract')->where('id',$id)->find(); if(!$info || $info['status'] != 1){ HelpHander::error('合同不存在'); } if($info['transferred'] == 1){ HelpHander::error('合同已办结'); } $ret = Db::name('contract')->where('id',$id)->update([ 'delivery_status' => 1, 'update_time' => date('Y-m-d H:i:s') ]); if(!$ret){ HelpHander::error('操作失败'); } return true; } // 已办结 public function transferred($id){ if($id <= 0){ HelpHander::error('参数错误'); } $info = Db::name('contract')->where('id',$id)->find(); if(!$info || $info['status'] != 1){ HelpHander::error('合同不存在'); } if($info['delivery_status'] == 0){ HelpHander::error('还未收到合同'); } // if($info['sd_money'] > 0 && $info['sd_status'] == 0){ // HelpHander::error('未上传印花税上税凭证'); // } $ret = Db::name('contract')->where('id',$id)->update([ 'transferred' => 1, 'transferred_date' => date('Y-m-d') ]); if(!$ret){ HelpHander::error('操作失败'); } return true; } // 修改印花税 public function modifyStamp($contractId,$sdid,$money,$userId){ $info = Db::name('contract') ->where('id',$contractId) ->where('status',1) ->find(); if(!$info){ HelpHander::error('合同不存在'); } if($info['sdid'] == $sdid && $info['sd_money'] == $money){ HelpHander::error('数据未做任何修改'); } Db::startTrans(); try{ $ret = Db::name('contract')->where('id',$contractId)->update(['sdid' => $sdid,'sd_money'=>$money]); if(!$ret){ \exception('修改失败'); } // 添加修改记录 $data = [ 'contract_id' => $contractId, 'user_id' => $userId, 'sdid' => $sdid, 'sd_money' => $money, 'old_sdid' => $info['sdid'], 'old_sd_money' => $info['sd_money'], 'create_time' => date('Y-m-d H:i:s') ]; $res = Db::name('contract_stamp_log')->insert($data); if(!$res){ \exception('修改失败'); } Db::commit(); }catch (Exception $e){ Db::rollback(); HelpHander::error($e->getMessage()); } return true; } public function modifyStampOld($contractId,$sdid,$money,$userId){ $info = Db::name('contract') ->where('id',$contractId) ->where('status',1) ->find(); if(!$info || $info['sd_status'] == 1){ HelpHander::error('已上传印花税凭证,不能修改'); } if($info['sdid'] == $sdid && $info['sd_money'] == $money){ HelpHander::error('数据未做任何修改'); } Db::startTrans(); try{ $ret = Db::name('contract')->where('id',$contractId)->update(['sd_status' => 0,'sdid' => $sdid,'sd_money'=>$money]); if(!$ret){ \exception('修改失败'); } // 添加修改记录 $data = [ 'contract_id' => $contractId, 'user_id' => $userId, 'sdid' => $sdid, 'sd_money' => $money, 'old_sdid' => $info['sdid'], 'old_sd_money' => $info['sd_money'], 'create_time' => date('Y-m-d H:i:s') ]; $res = Db::name('contract_stamp_log')->insert($data); if(!$res){ \exception('修改失败'); } Db::commit(); }catch (Exception $e){ Db::rollback(); HelpHander::error($e->getMessage()); } return true; } // 印花税修改记录 public function stampLogList($page,$size,$contractId){ $map[] = ['contract_id','=',$contractId]; $lists = Db::name('contract_stamp_log') ->where($map) ->page($page,$size) ->order('id desc') ->select(); $lists = $lists?$lists:[]; foreach ($lists as $k=>$v){ $lists[$k]['user_name'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title'); $lists[$k]['old_sdname'] = Db::name('stamp_duty')->where('id',$v['old_sdid'])->value('title'); } $total = Db::name('contract_stamp_log')->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists ]; return $data; } // 打回 public function backStamp($contractId,$sdReason){ $info = Db::name('contract') ->where('id',$contractId) ->where('status',1) ->find(); if(!$info || $info['sd_status'] != 0){ HelpHander::error('无权限打回'); } $ret = Db::name('contract')->where('id',$contractId)->update(['sd_status'=>2,'sd_reason'=>$sdReason]); if(!$ret){ HelpHander::error('修改失败'); } return true; } /** * 获取数量 * @param $transId * @return float|string */ public function getCountByTransferred($transId){ $map[] = ['status','=',1]; $map[] = ['transferred','=',$transId]; $count = Db::name('contract') ->where($map) ->count(); return $count; } /** * 根据月份获取合同金额 * @param $month * @return mixed */ public function getContractMoneyByMonth($month){ $map[] = ['status','=',1]; $nextmonth = date('Y-m',strtotime(" +1 month",strtotime($month.'-01'))).'-01'; $map[] = ['handle_date','>=',$month.'-01']; $map[] = ['handle_date','<',$nextmonth]; $money = Db::name('contract') ->where($map) ->sum('money'); return $money; } public function appstatis(){ list($start, $end) = Time::month(); $start = date('Y-m-d',$start); $end = date('Y-m-d',$end); $map[] = ['status','=',1]; $map[] = ['handle_date','>=',$start]; $map[] = ['handle_date','<=',$end]; $count1 = Db::name('contract') ->where($map) ->where('type',0) ->count(); $money1 = Db::name('contract') ->where($map) ->where('type',0) ->sum('total_money'); $map2[] = ['status','=',1]; $map2[] = ['transferred','=',1]; $map2[] = ['transferred_date','>=',$start.' 00:00:00']; $map2[] = ['transferred_date','<=',$end.' 23:59:59']; $count2 = Db::name('contract') ->where($map2) ->where('type',0) ->count(); $money2 = Db::name('contract') ->where($map) ->where('type',0) ->sum('total_money'); return [ 'count1' => $count1, 'count2' => $count2, 'money1' => $money1, 'money2' => $money2, 'url' => "https://oa.dr-ipmc.org.cn/mobile/statistics/contractpay" ]; } public function renew(){ $page = input('page/d',1); $size = input('size/d',10); $contractSn = input('contractSn','','trim'); $programSn = input('programSn','','trim'); $title = input('title','','trim'); // $type = input('type/d',-1); $companyId = input('companyId/d',0); $map[] = ['renew','=',1]; $map[] = ['status','=',1]; // if($type >= 0){ // $map[] = ['type','=',$type]; // } if($companyId > 0){ $map[] = ['company_id','=',$companyId]; } $programId = input('programId/d',0); if($programId > 0){ $map[] = ['program_id','=',$programId]; } if($contractSn){ $map[] = ['contract_sn','like','%'.$contractSn.'%']; } if($programSn){ $map[] = ['program_sn','like','%'.$programSn.'%']; } if($title){ $map[] = ['title','like','%'.$title.'%']; } $startTime = input('startTime','','trim'); if($startTime){ $map[] = ['handle_date','>=',$startTime]; } $endTime = input('endTime','','trim'); if($endTime){ $map[] = ['handle_date','<=',$endTime]; } $renew = input('renew/d',-1); if($renew >= 0){ $map[] = ['renew','=',$renew]; } $lists = $this ->where($map) ->page($page,$size) ->order('id desc') ->select(); $lists = $lists?$lists->toArray():[]; foreach ($lists as $k=>$v){ $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title'); $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title'); $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title'); $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); $applyuser = Db::name('apply') ->alias('a') ->join('user_info u','u.user_id = a.user_id') ->where('a.id',$v['apply_id']) ->value('u.name'); $lists[$k]['apply_user'] = $applyuser?$applyuser:''; } $total = $this->where($map)->count(); $data = [ 'total' => $total, 'list' => $lists ]; return $data; } public function renewConfirm($id,$renew,$userId){ $info = Db::name('contract')->where('id',$id)->where('status',1)->find(); if(!$info){ HelpHander::error('合同不存在'); } if($info['renew_confirm'] != 0){ HelpHander::error('该合同已确认'); } $ret = Db::name('contract')->where('id',$id)->update([ 'renew' => $renew, 'renew_confirm' => 1, 'renew_user' => $userId, 'renew_time' => date('Y-m-d H:i:s') ]); if(!$ret){ HelpHander::error('操作失败'); } return true; } public function renewExport(){ $page = input('page/d',1); $size = input('size/d',10); $contractSn = input('contractSn','','trim'); $programSn = input('programSn','','trim'); $title = input('title','','trim'); // $type = input('type/d',-1); $companyId = input('companyId/d',0); $map[] = ['renew','=',1]; $map[] = ['status','=',1]; // if($type >= 0){ // $map[] = ['type','=',$type]; // } if($companyId > 0){ $map[] = ['company_id','=',$companyId]; } if($companyId > 0){ $map[] = ['company_id','=',$companyId]; } $programId = input('programId/d',0); if($programId > 0){ $map[] = ['program_id','=',$programId]; } if($contractSn){ $map[] = ['contract_sn','like','%'.$contractSn.'%']; } if($programSn){ $map[] = ['program_sn','like','%'.$programSn.'%']; } if($title){ $map[] = ['title','like','%'.$title.'%']; } $startTime = input('startTime','','trim'); if($startTime){ $map[] = ['handle_date','>=',$startTime]; } $endTime = input('endTime','','trim'); if($endTime){ $map[] = ['handle_date','<=',$endTime]; } $renew = input('renew/d',-1); if($renew >= 0){ $map[] = ['renew','=',$renew]; } $lists = $this ->where($map) ->page($page,$size) ->order('id desc') ->select(); $lists = $lists?$lists->toArray():[]; foreach ($lists as $k=>$v){ $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title'); $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title'); // $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title'); // $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name'); $applyuser = Db::name('apply') ->alias('a') ->join('user_info u','u.user_id = a.user_id') ->where('a.id',$v['apply_id']) ->value('u.name'); $lists[$k]['apply_user'] = $applyuser?$applyuser:''; $lists[$k]['renew_text'] = $v['renew'] == 1?'是':'否'; } $columns = [ ["title" => "项目编号","key" => "programSn"], ["title" => "合同发起人","key" => "applyUser"], ["title" => "合同名称","key" => "title"], ["title" => "单位","key" => "company"], ["title" => "对方单位","key" => "company2"], ["title" => "项目名称","key" => "program"], ["title" => "合同金额","key" => "money"], ["title" => "办理日期","key" => "handleDate"], ["title" => "合同到期日期","key" => "endDate"], ["title" => "是否为连续签订合同","key" => "renewText"], ]; $data = [ 'columns' => $columns, 'list' => $lists ]; return $data; } }