1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Exception;
- use think\helper\Time;
- use think\Model;
- class Contract extends Model
- {
- public function advancedStartContract($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' => 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;
- }
- }
|