Contract.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Exception;
  6. use think\helper\Time;
  7. use think\Model;
  8. class Contract extends Model
  9. {
  10. public function advancedStartContract($id,$orgId,$userId,$formJson){
  11. $formJson = json_decode($formJson,true);
  12. $data = [
  13. 'org_id' => $orgId,
  14. 'user_id' => $userId,
  15. 'apply_id' => $id,
  16. 'create_time' => date('Y-m-d H:i:s'),
  17. 'status' => 0,
  18. 'type' => 0
  19. ];
  20. foreach ($formJson as $k=>$v){
  21. if($v['componentName'] == 'ddjjcontractfield'){
  22. foreach ($v['components'] as $key=>$val){
  23. switch ($val['idx']){
  24. case '0':
  25. $company = json_decode($val['values'],true);
  26. $data['company_id'] = $company['id'];
  27. break;
  28. case '1':
  29. $program = json_decode($val['values'],true);
  30. $data['program_id'] = $program['id'];
  31. break;
  32. case '2':
  33. $data['handle_date'] = $val['values'];
  34. break;
  35. case '3':
  36. $data['title'] = $val['values'];
  37. break;
  38. case '4':
  39. $data['money'] = $val['values'];
  40. break;
  41. case '5':
  42. $data['company2'] = $val['values'];
  43. break;
  44. case '6':
  45. $data['company3'] = $val['values'];
  46. break;
  47. // case '7': // 经办人
  48. // $data['agent'] = $val['values'];
  49. // break;
  50. case '8':
  51. $data['company3_leader'] = $val['values'];
  52. break;
  53. case '9':
  54. $stamp = json_decode($val['values'],true);
  55. $data['sdid'] = $stamp['id'];
  56. break;
  57. case '10':
  58. $data['ispay'] = $val['values'] == '付款'?1:2;
  59. break;
  60. case '11': // 合同到期日期
  61. $data['end_date'] = $val['values'];
  62. break;
  63. case '12': // 采购方式
  64. $data['buy_type'] = $val['values'];
  65. break;
  66. case '13': // 采购方式
  67. $data['tax_sn'] = $val['values'];
  68. break;
  69. case '14': // 是否为连续签订合同
  70. $data['renew'] = $val['values']&&$val['values'] == '是'?1:0;
  71. break;
  72. }
  73. }
  74. break;
  75. }
  76. }
  77. $data['completion'] = $data['total_money'] = $data['money'];
  78. $pre = Db::name('company')->where('id',$data['company_id'])->value('sn');
  79. $programSn = Db::name('program')->where('id',$data['program_id'])->value('sn');
  80. $data['contract_sn'] = get_contact_sn($pre).$programSn;
  81. $sdinfo = Db::name('stamp_duty')->where('id',$data['sdid'])->find();
  82. // $sd_money = round($data['money'] * $sdinfo['bl'] / 1000,1); // 以前精确到角
  83. $sd_money = round($data['money'] * $sdinfo['bl'] / 1000,2); // 20220907 修改精确到分
  84. if($sd_money < 1 && $sdinfo['type'] == 1){
  85. $sd_money = 1;
  86. }
  87. if($sd_money < 1 && $sdinfo['type'] == 2){
  88. $sd_money = 0;
  89. }
  90. $data['sd_money'] = $sd_money;
  91. $ret = Db::name('contract')->insert($data);
  92. return $ret?true:false;
  93. }
  94. public function advancedEndContract($id,$orgId,$userId,$formJson){
  95. $data = [
  96. 'update_time' => date('Y-m-d H:i:s'),
  97. 'status' => 1
  98. ];
  99. $info = Db::name('contract')->where('apply_id',$id)->find();
  100. $program = Db::name('program')->where('id',$info['program_id'])->find();
  101. // 先获取最大项目编号
  102. $program_sn = Db::name('contract')
  103. ->alias('c')
  104. ->join('apply a','a.id = c.apply_id')
  105. ->where('c.status',1)
  106. ->where('c.program_id',$info['program_id'])
  107. ->where('a.del',0)
  108. ->where('c.type',0)
  109. ->order('a.finish_time desc')
  110. ->value('program_sn');
  111. if($program_sn){
  112. $sn = intval(substr($program_sn,-4)) + 1;
  113. $nsn = $program['sn'].str_pad($sn,4,'0',STR_PAD_LEFT);
  114. }else{
  115. $nsn = $program['sn'].'0001';
  116. }
  117. $data['program_sn'] = $nsn;
  118. $ret2 = $this->createHouseContract($info);
  119. if(!$ret2){
  120. return false;
  121. }
  122. $ret = Db::name('contract')->where('apply_id',$id)->update($data);
  123. return $ret?true:false;
  124. }
  125. public function advancedDisagreeContract($id){
  126. $data = [
  127. 'update_time' => date('Y-m-d H:i:s'),
  128. 'status' => 2
  129. ];
  130. $ret = Db::name('contract')->where('apply_id',$id)->update($data);
  131. return $ret?true:false;
  132. }
  133. public function advancedDelContract($id){
  134. $info = Db::name('contract')->where('apply_id',$id)->find();
  135. $data = [
  136. 'update_time' => date('Y-m-d H:i:s'),
  137. 'status' => 2
  138. ];
  139. // 检查合同是否又追加合同以及是否付/收过款,这种情况不允许删除
  140. if($info['status'] == 1){
  141. if($info['type'] == 0){ // 合同,检查是否有追加合同
  142. $res = Db::name('contract')->where('type',1)->where('parent_apply_id',$id)->where('status','in',[0,1])->find();
  143. if($res){
  144. $this->error = '已存在追加合同,不能删除';
  145. return false;
  146. }
  147. }
  148. // 检查是否否付/收过款
  149. $res = Db::name('contract_pay')->where('pay_apply_id',$id)->where('status','in',[0,1])->find();
  150. if($res){
  151. if($info['ispay'] == 1){
  152. $this->error = '已存付款记录,不能删除';
  153. return false;
  154. }else{
  155. $this->error = '已存收款记录,不能删除';
  156. return false;
  157. }
  158. }
  159. }
  160. $ret = Db::name('contract')->where('apply_id',$id)->update($data);
  161. if($ret){
  162. // 有房产合同的删除房产合同
  163. Db::name('house_contract')->where('contract_id',$info['id'])->setField('del',1);
  164. }else{
  165. $this->error = '操作失败';
  166. }
  167. return $ret?true:false;
  168. }
  169. public function advancedStartAddContract($id,$orgId,$userId,$formJson){
  170. $formJson = json_decode($formJson,true);
  171. $data = [
  172. 'org_id' => $orgId,
  173. 'user_id' => $userId,
  174. 'apply_id' => $id,
  175. 'create_time' => date('Y-m-d H:i:s'),
  176. 'status' => 0,
  177. 'type' => 1
  178. ];
  179. foreach ($formJson as $k=>$v){
  180. if($v['componentName'] == 'ddaddcontractfield'){
  181. foreach ($v['components'] as $key=>$val){
  182. switch ($val['idx']){
  183. // case '0':
  184. // $company = json_decode($val['values'],true);
  185. // $data['company_id'] = $company['id'];
  186. // break;
  187. // case '1':
  188. // $program = json_decode($val['values'],true);
  189. // $data['program_id'] = $program['id'];
  190. // break;
  191. case '2':
  192. $data['handle_date'] = $val['values'];
  193. break;
  194. case '3':
  195. $data['title'] = $val['values'];
  196. break;
  197. case '4':
  198. $data['money'] = $val['values'];
  199. break;
  200. // case '5':
  201. // $data['company2'] = $val['values'];
  202. // break;
  203. // case '6':
  204. // $data['company3'] = $val['values'];
  205. // break;
  206. // case '7':
  207. // $data['agent'] = $val['values'];
  208. // break;
  209. case '8':
  210. $data['company3_leader'] = $val['values'];
  211. break;
  212. case '9':
  213. $stamp = json_decode($val['values'],true);
  214. $data['sdid'] = $stamp['id'];
  215. break;
  216. case '10':
  217. $data['parent_apply_id'] = $val['values2'][0]['id'];
  218. break;
  219. case '11': // 合同到期日期
  220. $data['end_date'] = $val['values'];
  221. case '14': // 是否为连续签订合同
  222. $data['renew'] = $val['values']&&$val['values'] == '是'?1:0;
  223. break;
  224. }
  225. }
  226. break;
  227. }
  228. }
  229. $pinfo = Db::name('contract')
  230. ->where('apply_id',$data['parent_apply_id'])
  231. ->where('status',1)
  232. ->find();
  233. if(!$pinfo){
  234. return false;
  235. }
  236. $data['company_id'] = $pinfo['company_id'];
  237. $data['program_id'] = $pinfo['program_id'];
  238. $data['company2'] = $pinfo['company2'];
  239. $data['company3'] = $pinfo['company3'];
  240. $data['tax_sn'] = $pinfo['tax_sn'];
  241. $data['ispay'] = $pinfo['ispay'];
  242. $data['buy_type'] = $pinfo['buy_type'];
  243. $pre = Db::name('company')->where('id',$data['company_id'])->value('sn');
  244. // $data['contract_sn'] = get_contact_sn($pre);
  245. $sdinfo = Db::name('stamp_duty')->where('id',$data['sdid'])->find();
  246. $sd_money = round($data['money'] * $sdinfo['bl'] / 1000,1);
  247. if($sd_money < 1 && $sdinfo['type'] == 1){
  248. $sd_money = 1;
  249. }
  250. if($sd_money < 1 && $sdinfo['type'] == 2){
  251. $sd_money = 0;
  252. }
  253. $data['sd_money'] = $sd_money;
  254. $ret = Db::name('contract')->insert($data);
  255. return $ret?true:false;
  256. }
  257. public function advancedEndAddContract($id,$orgId,$userId,$formJson){
  258. $data = [
  259. 'update_time' => date('Y-m-d H:i:s'),
  260. 'status' => 1
  261. ];
  262. $info = Db::name('contract')->where('apply_id',$id)->find();
  263. $pinfo = Db::name('contract')
  264. ->where('apply_id',$info['parent_apply_id'])
  265. ->where('status',1)
  266. ->find();
  267. $contract_sn = $pinfo['contract_sn'];
  268. $count = Db::name('contract')
  269. ->where('type',1)
  270. ->where('parent_apply_id',$info['parent_apply_id'])
  271. ->where('status',1)
  272. ->count();
  273. $xh = $count == 0?1:($count+1);
  274. $contract_sn = $contract_sn.sprintf('%03s', $xh);
  275. $data['contract_sn'] = $contract_sn;
  276. $info['contract_sn'] = $contract_sn;
  277. // 项目编号
  278. $data['program_sn'] = $pinfo['program_sn'].'补'.str_pad($xh,2,'0',STR_PAD_LEFT);
  279. if($info['money'] > 0){
  280. $res = Db::name('contract')->where('id',$pinfo['id'])->update([
  281. 'completion' => round($pinfo['completion'] + $info['money'],2),
  282. 'total_money' => round($pinfo['total_money'] + $info['money'],2)
  283. ]);
  284. if(!$res){
  285. return false;
  286. }
  287. }
  288. $ret2 = $this->createHouseContract($info);
  289. if(!$ret2){
  290. return false;
  291. }
  292. $ret = Db::name('contract')->where('apply_id',$id)->update($data);
  293. return $ret?true:false;
  294. }
  295. public function advancedDisagreeAddContract($id){
  296. $data = [
  297. 'update_time' => date('Y-m-d H:i:s'),
  298. 'status' => 2
  299. ];
  300. $ret = Db::name('contract')->where('apply_id',$id)->update($data);
  301. return $ret?true:false;
  302. }
  303. public function advancedDelAddContract($id){
  304. $info = Db::name('contract')->where('apply_id',$id)->find();
  305. $data = [
  306. 'update_time' => date('Y-m-d H:i:s'),
  307. 'status' => 2
  308. ];
  309. // 检查合同是否又追加合同以及是否付/收过款,这种情况不允许删除
  310. if($info['status'] == 1){
  311. if($info['type'] == 0){ // 合同,检查是否有追加合同
  312. $res = Db::name('contract')->where('type',1)->where('parent_apply_id',$id)->where('status','in',[0,1])->find();
  313. if($res){
  314. $this->error = '已存在追加合同,不能删除';
  315. return false;
  316. }
  317. }
  318. // 检查是否否付/收过款
  319. $res = Db::name('contract_pay')->where('pay_apply_id',$id)->where('status','in',[0,1])->find();
  320. if($res){
  321. if($info['ispay'] == 1){
  322. $this->error = '已存付款记录,不能删除';
  323. return false;
  324. }else{
  325. $this->error = '已存收款记录,不能删除';
  326. return false;
  327. }
  328. }
  329. }
  330. $ret = Db::name('contract')->where('apply_id',$id)->update($data);
  331. if($ret && $info['status'] == 1){
  332. // 有房产合同的删除房产合同
  333. Db::name('house_contract')->where('contract_id',$info['id'])->setField('del',1);
  334. $pinfo = Db::name('contract')->where('apply_id',$info['parent_apply_id'])->where('status',1)->find();
  335. $d = [
  336. 'completion' => round($pinfo['completion'] - $info['total_money'],2),
  337. 'total_money' => round($pinfo['total_money'] - $info['total_money'],2)
  338. ];
  339. Db::name('contract')->where('id',$pinfo['id'])->update($d);
  340. }
  341. if(!$ret){
  342. $this->error = '操作失败';
  343. }
  344. return $ret?true:false;
  345. }
  346. private function createHouseContract($info){
  347. // return true; // 暂时隐藏
  348. $depid = Db::name('apply')->where('id',$info['apply_id'])->value('dep_id');
  349. if($depid == 210){ // 投资管理处提交的普通合同,生成租房合同
  350. $hdata = [
  351. 'contract_id' => $info['id'],
  352. 'sn' => $info['contract_sn'],
  353. 'org_id' => $info['org_id'],
  354. 'intro' => $info['title'],
  355. 'create_time' => date('Y-m-d H:i:s'),
  356. 'amount' => $info['money'],
  357. 'sign_date' => $info['handle_date'],
  358. 'user_id' => $info['user_id'],
  359. ];
  360. $ret2 = Db::name('house_contract')->insert($hdata);
  361. if(!$ret2){
  362. return false;
  363. }
  364. }
  365. return true;
  366. }
  367. public function info($applyId){
  368. $info = Db::name('contract')->where('apply_id',$applyId)->find();
  369. if($info){
  370. $info['company'] = Db::name('company')->where('id',$info['company_id'])->value('title');
  371. $stamp = Db::name('stamp_duty')->where('id',$info['sdid'])->field('id,title,bl,type')->find();
  372. $info['stamp'] = $stamp;
  373. $info['agent'] = Db::name('user_info')->where('user_id',$info['user_id'])->value('name');
  374. $info['fh_user_name'] = '';
  375. if($info['fh_user_id'] > 0){
  376. $info['fh_user_name'] = Db::name('user_info')->where('user_id',$info['fh_user_id'])->value('name');
  377. }
  378. }
  379. return $info;
  380. }
  381. public function lists($page,$size,$userId,$contractSn,$programSn,$title,$ispay,$programId,$companyId,$startTime,$endTime,$company2){
  382. // 获取用户权限
  383. $applyids1 = Db::name('apply_record')
  384. ->alias('ar')
  385. ->join('apply a','a.id = ar.apply_id')
  386. ->where('ar.user_id',$userId)
  387. ->where('a.status',2)
  388. ->where('a.del',0)
  389. ->where('a.advanced',3)
  390. ->where('ar.del',0)
  391. ->column('ar.apply_id');
  392. $applyids2 = Db::name('apply')
  393. ->where('status',2)
  394. ->where('advanced',3)
  395. ->where('del',0)
  396. ->where('user_id',$userId)
  397. ->column('id');
  398. $applyids1 = $applyids1?array_unique($applyids1):[];
  399. $applyids2 = $applyids2?array_unique($applyids2):[];
  400. $applyids = array_unique(array_merge($applyids1,$applyids2));
  401. if(empty($applyids)){
  402. return [
  403. 'total' => 0,
  404. 'list' => []
  405. ];
  406. }
  407. $map[] = ['apply_id','in',$applyids];
  408. $map[] = ['status','=',1];
  409. $map[] = ['type','=',0];
  410. if($contractSn){
  411. $map[] = ['contract_sn','like','%'.$contractSn.'%'];
  412. }
  413. if($programSn){
  414. $map[] = ['program_sn','like','%'.$programSn.'%'];
  415. }
  416. if($title){
  417. $map[] = ['title','like','%'.$title.'%'];
  418. }
  419. if($company2){
  420. $map[] = ['company2','like','%'.$company2.'%'];
  421. }
  422. if($ispay > 0){
  423. $map[] = ['ispay','=',$ispay];
  424. }
  425. if($programId > 0){
  426. $map[] = ['program_id','=',$programId];
  427. }
  428. if($companyId > 0){
  429. $map[] = ['company_id','=',$companyId];
  430. }
  431. if($startTime){
  432. $map[] = ['handle_date','>=',$startTime];
  433. }
  434. if($endTime){
  435. $map[] = ['handle_date','<=',$endTime];
  436. }
  437. $lists = $this
  438. ->where($map)
  439. ->page($page,$size)
  440. ->order('id desc')
  441. ->select();
  442. $lists = $lists?$lists->toArray():[];
  443. foreach ($lists as $k=>$v){
  444. $zjmoney = Db::name('contract')
  445. ->where('status',1)
  446. ->where('type',1)
  447. ->where('parent_apply_id',$v['apply_id'])
  448. ->sum('money');
  449. // $lists[$k]['totalMoney'] = $v['money'] + $zjmoney;
  450. $lists[$k]['zjMoney'] = $zjmoney;
  451. $zjpaymoney = Db::name('contract')
  452. ->where('status',1)
  453. ->where('type',1)
  454. ->where('parent_apply_id',$v['apply_id'])
  455. ->sum('pay_money');
  456. $lists[$k]['totalPayMoney'] = $v['pay_money'] + $zjpaymoney;
  457. $lists[$k]['paybl'] = 0;
  458. if($lists[$k]['total_money'] > 0){
  459. $lists[$k]['paybl'] = round($lists[$k]['totalPayMoney'] / $lists[$k]['total_money'],2)*100 . '%';
  460. }
  461. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  462. $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title');
  463. $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title');
  464. $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  465. $lists[$k]['children'] = $this->appendLists($v['apply_id']);
  466. }
  467. $total = $this->where($map)->count();
  468. $data = [
  469. 'total' => $total,
  470. 'list' => $lists
  471. ];
  472. return $data;
  473. }
  474. // 导出列表
  475. public function exportLists($userId,$contractSn,$programSn,$title,$ispay,$programId,$companyId,$startTime,$endTime,$company2){
  476. // 获取用户权限
  477. $applyids1 = Db::name('apply_record')
  478. ->alias('ar')
  479. ->join('apply a','a.id = ar.apply_id')
  480. ->where('ar.user_id',$userId)
  481. ->where('a.status',2)
  482. ->where('a.del',0)
  483. ->where('a.advanced',3)
  484. ->where('ar.del',0)
  485. ->column('ar.apply_id');
  486. $applyids2 = Db::name('apply')
  487. ->where('status',2)
  488. ->where('advanced',3)
  489. ->where('del',0)
  490. ->where('user_id',$userId)
  491. ->column('id');
  492. $applyids1 = $applyids1?array_unique($applyids1):[];
  493. $applyids2 = $applyids2?array_unique($applyids2):[];
  494. $applyids = array_unique(array_merge($applyids1,$applyids2));
  495. if(empty($applyids)){
  496. $map[] = ['apply_id','=',-1];
  497. }else{
  498. $map[] = ['apply_id','in',$applyids];
  499. }
  500. $map[] = ['status','=',1];
  501. $map[] = ['type','=',0];
  502. if($contractSn){
  503. $map[] = ['contract_sn','like','%'.$contractSn.'%'];
  504. }
  505. if($programSn){
  506. $map[] = ['program_sn','like','%'.$programSn.'%'];
  507. }
  508. if($title){
  509. $map[] = ['title','like','%'.$title.'%'];
  510. }
  511. if($company2){
  512. $map[] = ['company2','like','%'.$company2.'%'];
  513. }
  514. if($ispay > 0){
  515. $map[] = ['ispay','=',$ispay];
  516. }
  517. if($programId > 0){
  518. $map[] = ['program_id','=',$programId];
  519. }
  520. if($companyId > 0){
  521. $map[] = ['company_id','=',$companyId];
  522. }
  523. if($startTime){
  524. $map[] = ['handle_date','>=',$startTime];
  525. }
  526. if($endTime){
  527. $map[] = ['handle_date','<=',$endTime];
  528. }
  529. $lists = $this
  530. ->where($map)
  531. ->order('id desc')
  532. ->select();
  533. $lists = $lists?$lists->toArray():[];
  534. foreach ($lists as $k=>$v){
  535. $zjmoney = Db::name('contract')
  536. ->where('status',1)
  537. ->where('type',1)
  538. ->where('parent_apply_id',$v['apply_id'])
  539. ->sum('money');
  540. // $lists[$k]['totalMoney'] = $v['money'] + $zjmoney;
  541. $lists[$k]['zjMoney'] = $zjmoney;
  542. $zjpaymoney = Db::name('contract')
  543. ->where('status',1)
  544. ->where('type',1)
  545. ->where('parent_apply_id',$v['apply_id'])
  546. ->sum('pay_money');
  547. $lists[$k]['totalPayMoney'] = $v['pay_money'] + $zjpaymoney;
  548. $lists[$k]['paybl'] = 0;
  549. if($lists[$k]['total_money'] > 0){
  550. $lists[$k]['paybl'] = round($lists[$k]['totalPayMoney'] / $lists[$k]['total_money'],2)*100 . '%';
  551. }
  552. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  553. $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title');
  554. $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title');
  555. $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  556. if($v['sd_status'] == 0){
  557. $lists[$k]['sdStatusText'] = '未上传';
  558. }else{
  559. $lists[$k]['sdStatusText'] = '已上传';
  560. }
  561. if($v['ispay'] == 1){
  562. $lists[$k]['ispayText'] = '付款';
  563. }else{
  564. $lists[$k]['ispayText'] = '收款';
  565. }
  566. if($v['transferred'] == 0){
  567. $lists[$k]['transferredText'] = '未办结';
  568. }else{
  569. $lists[$k]['transferredText'] = '已办结';
  570. }
  571. }
  572. $columns = [
  573. ["title" => "合同编号","key" => "contractSn"],
  574. ["title" => "项目编号","key" => "programSn"],
  575. ["title" => "合同名称","key" => "title"],
  576. ["title" => "单位","key" => "company"],
  577. ["title" => "项目名称","key" => "program"],
  578. ["title" => "对方单位","key" => "company2"],
  579. ["title" => "经办单位","key" => "company3"],
  580. ["title" => "经办单位负责人","key" => "company3Leader"],
  581. ["title" => "经办人","key" => "agent"],
  582. ["title" => "印花税目","key" => "sdname"],
  583. ["title" => "印花税","key" => "sdMoney"],
  584. ["title" => "印花税上税凭证","key" => "sdStatusText"],
  585. ["title" => "类型","key" => "ispayText"],
  586. ["title" => "合同金额","key" => "money"],
  587. ["title" => "合同追加金额","key" => "zjMoney"],
  588. ["title" => "总金额","key" => "totalMoney"],
  589. ["title" => "已支付/收取款项","key" => "totalPayMoney"],
  590. ["title" => "办理日期","key" => "handleDate"],
  591. ["title" => "支付比例","key" => "paybl"],
  592. ["title" => "办结状态","key" => "transferredText"],
  593. ["title" => "合同到期日期","key" => "endDate"],
  594. ];
  595. $data = [
  596. 'columns' => $columns,
  597. 'list' => $lists
  598. ];
  599. return $data;
  600. }
  601. public function applists($page,$size,$userId){
  602. $map[] = ['status','=',1];
  603. $map[] = ['type','=',0];
  604. $lists = $this
  605. ->where($map)
  606. ->page($page,$size)
  607. ->order('id desc')
  608. ->select();
  609. $lists = $lists?$lists->toArray():[];
  610. foreach ($lists as $k=>$v){
  611. $zjpaymoney = Db::name('contract')
  612. ->where('status',1)
  613. ->where('type',1)
  614. ->where('parent_apply_id',$v['apply_id'])
  615. ->sum('pay_money');
  616. $lists[$k]['totalPayMoney'] = $v['pay_money'] + $zjpaymoney;
  617. if($lists[$k]['total_money'] > 0){
  618. $lists[$k]['paybl'] = round($lists[$k]['totalPayMoney'] / $lists[$k]['total_money'],2)*100 . '%';
  619. }else{
  620. $lists[$k]['paybl'] = '0%';
  621. }
  622. $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  623. }
  624. $total = $this->where($map)->count();
  625. $data = [
  626. 'total' => $total,
  627. 'list' => $lists
  628. ];
  629. return $data;
  630. }
  631. public function appendLists($applyId){
  632. $map[] = ['status','=',1];
  633. $map[] = ['parent_apply_id','=',$applyId];
  634. $lists = $this
  635. ->where($map)
  636. ->order('id asc')
  637. ->select();
  638. $lists = $lists?$lists->toArray():[];
  639. foreach ($lists as $k=>$v){
  640. $lists[$k]['paybl'] = '0%';
  641. if($v['money'] > 0){
  642. $lists[$k]['paybl'] = round($v['pay_money'] / $v['money'],2)*100 . '%';
  643. }
  644. $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title');
  645. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  646. $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title');
  647. $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  648. $lists[$k]['zjMoney'] = '';
  649. $lists[$k]['totalPayMoney'] = '';
  650. }
  651. return $lists;
  652. }
  653. // 印花税凭证
  654. public function stamplists($page,$size,$contractSn,$programSn,$title,$status,$startTime,$endTime,$type=0,$companyId,$sbStatus,$print){
  655. if($status >= 0){
  656. $map[] = ['sd_status','=',$status];
  657. }
  658. $map[] = ['status','=',1];
  659. // $map[] = ['type','=',0];
  660. if($type == 0){ // 财务
  661. $map[] = ['sd_money','>',0];
  662. }
  663. if($companyId > 0){
  664. $map[] = ['company_id','=',$companyId];
  665. }
  666. if($startTime){
  667. $map[] = ['handle_date','>=',$startTime];
  668. }
  669. if($endTime){
  670. $map[] = ['handle_date','<=',$endTime];
  671. }
  672. if($contractSn){
  673. $map[] = ['contract_sn','like','%'.$contractSn.'%'];
  674. }
  675. if($programSn){
  676. $map[] = ['program_sn','like','%'.$programSn.'%'];
  677. }
  678. if($title){
  679. $map[] = ['title','like','%'.$title.'%'];
  680. }
  681. if($sbStatus != ''){
  682. $map[] = ['sb_status','=',$sbStatus];
  683. }
  684. if($print != ''){
  685. $map[] = ['print','=',$print];
  686. }
  687. $programId = input('programId/d',0);
  688. if($programId > 0){
  689. $map[] = ['program_id','=',$programId];
  690. }
  691. $lists = $this
  692. ->where($map)
  693. ->page($page,$size)
  694. ->order('sd_status asc,id desc')
  695. ->select();
  696. $lists = $lists?$lists->toArray():[];
  697. foreach ($lists as $k=>$v){
  698. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  699. $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title');
  700. $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title');
  701. $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  702. $applyuser = Db::name('apply')
  703. ->alias('a')
  704. ->join('user_info u','u.user_id = a.user_id')
  705. ->where('a.id',$v['apply_id'])
  706. ->value('u.name');
  707. $lists[$k]['apply_user'] = $applyuser?$applyuser:'';
  708. }
  709. $total = $this->where($map)->count();
  710. $data = [
  711. 'total' => $total,
  712. 'list' => $lists
  713. ];
  714. return $data;
  715. }
  716. // 导出印花税凭证
  717. public function stampListsExport($contractSn,$programSn,$title,$status,$startTime,$endTime,$type=0,$companyId,$sbStatus,$print){
  718. if($status >= 0){
  719. $map[] = ['sd_status','=',$status];
  720. }
  721. $map[] = ['status','=',1];
  722. // $map[] = ['type','=',0];
  723. if($type == 0){ // 财务
  724. $map[] = ['sd_money','>',0];
  725. }
  726. if($companyId > 0){
  727. $map[] = ['company_id','=',$companyId];
  728. }
  729. if($startTime){
  730. $map[] = ['handle_date','>=',$startTime];
  731. }
  732. if($endTime){
  733. $map[] = ['handle_date','<=',$endTime];
  734. }
  735. if($contractSn){
  736. $map[] = ['contract_sn','like','%'.$contractSn.'%'];
  737. }
  738. if($programSn){
  739. $map[] = ['program_sn','like','%'.$programSn.'%'];
  740. }
  741. if($title){
  742. $map[] = ['title','like','%'.$title.'%'];
  743. }
  744. if($sbStatus != ''){
  745. $map[] = ['sb_status','=',$sbStatus];
  746. }
  747. if($print != ''){
  748. $map[] = ['print','=',$print];
  749. }
  750. $programId = input('programId/d',0);
  751. if($programId > 0){
  752. $map[] = ['program_id','=',$programId];
  753. }
  754. $lists = $this
  755. ->where($map)
  756. ->order('sd_status asc,id desc')
  757. ->select();
  758. $lists = $lists?$lists->toArray():[];
  759. foreach ($lists as $k=>$v){
  760. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  761. $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title');
  762. $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title');
  763. $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  764. $lists[$k]['type_text'] = $v['type'] == 1?"追加合同":"普通合同";
  765. $lists[$k]['sd_status_text'] = "未上传完税证明";
  766. if($v['sd_status'] == 1){
  767. $lists[$k]['sd_status_text'] = "已上传完税证明";
  768. }else if($v['sd_status'] == 2){
  769. $lists[$k]['sd_status_text'] = "已打回";
  770. }
  771. $lists[$k]['sb_status_text'] = $v['sb_status'] == 1?"已申报":"未申报";
  772. $lists[$k]['print_text'] = $v['print'] == 1?"已打印":"未打印";
  773. $applyuser = Db::name('apply')
  774. ->alias('a')
  775. ->join('user_info u','u.user_id = a.user_id')
  776. ->where('a.id',$v['apply_id'])
  777. ->value('u.name');
  778. $lists[$k]['apply_user'] = $applyuser?$applyuser:'';
  779. }
  780. $columns[] = ["title" => "项目编号","key" => "programSn"];
  781. $columns[] = ["title" => "合同发起人","key" => "applyUser"];
  782. $columns[] = ["title" => "合同名称","key" => "title"];
  783. $columns[] = ["title" => "单位","key" => "company"];
  784. $columns[] = ["title" => "项目名称","key" => "program"];
  785. $columns[] = ["title" => "对方单位","key" => "company2"];
  786. $columns[] = ["title" => "类型","key" => "typeText"];
  787. $columns[] = ["title" => "合同金额","key" => "money"];
  788. $columns[] = ["title" => "办理日期","key" => "handleDate"];
  789. $columns[] = ["title" => "报税状态","key" => "sdStatusText"];
  790. $columns[] = ["title" => "打回原因","key" => "sdReason"];
  791. $columns[] = ["title" => "申报状态","key" => "sbStatusText"];
  792. $columns[] = ["title" => "打印状态","key" => "printText"];
  793. $columns[] = ["title" => "合同到期日期","key" => "endDate"];
  794. $data = [
  795. 'columns' => $columns,
  796. 'list' => $lists
  797. ];
  798. return $data;
  799. }
  800. // 上传印花税凭证
  801. public function stampupdates($id,$sdFile){
  802. $data = [
  803. 'sd_file' => $sdFile,
  804. 'sd_time' => date('Y-m-d H:i:s'),
  805. 'sd_status' => 1
  806. ];
  807. if($id <= 0){
  808. HelpHander::error('参数错误');
  809. }
  810. if(!$data['sd_file']){
  811. HelpHander::error('未上传印花税上税凭证');
  812. }
  813. $info = Db::name('contract')->where('id',$id)->find();
  814. if(!$info || $info['status'] != 1){
  815. HelpHander::error('合同不存在');
  816. }
  817. if($info['transferred'] == 1){
  818. HelpHander::error('合同已办结');
  819. }
  820. $ret = Db::name('contract')->where('id',$id)->update($data);
  821. if(!$ret){
  822. HelpHander::error('操作失败');
  823. }
  824. return true;
  825. }
  826. // 确认印花税
  827. public function stampConfirm($id,$userId){
  828. if($id <= 0){
  829. HelpHander::error('参数错误');
  830. }
  831. $info = Db::name('contract')->where('id',$id)->find();
  832. if(!$info || $info['status'] != 1){
  833. HelpHander::error('合同不存在');
  834. }
  835. if($info['fh_user_id'] > 0){
  836. HelpHander::error('已确认,无需重复操作');
  837. }
  838. $data = [
  839. 'fh_user_id' => $userId,
  840. 'fh_time' => date('Y-m-d H:i:s')
  841. ];
  842. $ret = Db::name('contract')->where('id',$id)->update($data);
  843. if(!$ret){
  844. HelpHander::error('操作失败');
  845. }
  846. return true;
  847. }
  848. // 确认收到合同
  849. public function confirm($id){
  850. if($id <= 0){
  851. HelpHander::error('参数错误');
  852. }
  853. $info = Db::name('contract')->where('id',$id)->find();
  854. if(!$info || $info['status'] != 1){
  855. HelpHander::error('合同不存在');
  856. }
  857. if($info['transferred'] == 1){
  858. HelpHander::error('合同已办结');
  859. }
  860. $ret = Db::name('contract')->where('id',$id)->update([
  861. 'delivery_status' => 1,
  862. 'update_time' => date('Y-m-d H:i:s')
  863. ]);
  864. if(!$ret){
  865. HelpHander::error('操作失败');
  866. }
  867. return true;
  868. }
  869. // 已办结
  870. public function transferred($id){
  871. if($id <= 0){
  872. HelpHander::error('参数错误');
  873. }
  874. $info = Db::name('contract')->where('id',$id)->find();
  875. if(!$info || $info['status'] != 1){
  876. HelpHander::error('合同不存在');
  877. }
  878. if($info['delivery_status'] == 0){
  879. HelpHander::error('还未收到合同');
  880. }
  881. // if($info['sd_money'] > 0 && $info['sd_status'] == 0){
  882. // HelpHander::error('未上传印花税上税凭证');
  883. // }
  884. $ret = Db::name('contract')->where('id',$id)->update([
  885. 'transferred' => 1,
  886. 'transferred_date' => date('Y-m-d')
  887. ]);
  888. if(!$ret){
  889. HelpHander::error('操作失败');
  890. }
  891. return true;
  892. }
  893. // 修改印花税
  894. public function modifyStamp($contractId,$sdid,$money,$userId){
  895. $info = Db::name('contract')
  896. ->where('id',$contractId)
  897. ->where('status',1)
  898. ->find();
  899. if(!$info){
  900. HelpHander::error('合同不存在');
  901. }
  902. if($info['sdid'] == $sdid && $info['sd_money'] == $money){
  903. HelpHander::error('数据未做任何修改');
  904. }
  905. Db::startTrans();
  906. try{
  907. $ret = Db::name('contract')->where('id',$contractId)->update(['sdid' => $sdid,'sd_money'=>$money]);
  908. if(!$ret){
  909. \exception('修改失败');
  910. }
  911. // 添加修改记录
  912. $data = [
  913. 'contract_id' => $contractId,
  914. 'user_id' => $userId,
  915. 'sdid' => $sdid,
  916. 'sd_money' => $money,
  917. 'old_sdid' => $info['sdid'],
  918. 'old_sd_money' => $info['sd_money'],
  919. 'create_time' => date('Y-m-d H:i:s')
  920. ];
  921. $res = Db::name('contract_stamp_log')->insert($data);
  922. if(!$res){
  923. \exception('修改失败');
  924. }
  925. Db::commit();
  926. }catch (Exception $e){
  927. Db::rollback();
  928. HelpHander::error($e->getMessage());
  929. }
  930. return true;
  931. }
  932. public function modifyStampOld($contractId,$sdid,$money,$userId){
  933. $info = Db::name('contract')
  934. ->where('id',$contractId)
  935. ->where('status',1)
  936. ->find();
  937. if(!$info || $info['sd_status'] == 1){
  938. HelpHander::error('已上传印花税凭证,不能修改');
  939. }
  940. if($info['sdid'] == $sdid && $info['sd_money'] == $money){
  941. HelpHander::error('数据未做任何修改');
  942. }
  943. Db::startTrans();
  944. try{
  945. $ret = Db::name('contract')->where('id',$contractId)->update(['sd_status' => 0,'sdid' => $sdid,'sd_money'=>$money]);
  946. if(!$ret){
  947. \exception('修改失败');
  948. }
  949. // 添加修改记录
  950. $data = [
  951. 'contract_id' => $contractId,
  952. 'user_id' => $userId,
  953. 'sdid' => $sdid,
  954. 'sd_money' => $money,
  955. 'old_sdid' => $info['sdid'],
  956. 'old_sd_money' => $info['sd_money'],
  957. 'create_time' => date('Y-m-d H:i:s')
  958. ];
  959. $res = Db::name('contract_stamp_log')->insert($data);
  960. if(!$res){
  961. \exception('修改失败');
  962. }
  963. Db::commit();
  964. }catch (Exception $e){
  965. Db::rollback();
  966. HelpHander::error($e->getMessage());
  967. }
  968. return true;
  969. }
  970. // 印花税修改记录
  971. public function stampLogList($page,$size,$contractId){
  972. $map[] = ['contract_id','=',$contractId];
  973. $lists = Db::name('contract_stamp_log')
  974. ->where($map)
  975. ->page($page,$size)
  976. ->order('id desc')
  977. ->select();
  978. $lists = $lists?$lists:[];
  979. foreach ($lists as $k=>$v){
  980. $lists[$k]['user_name'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  981. $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title');
  982. $lists[$k]['old_sdname'] = Db::name('stamp_duty')->where('id',$v['old_sdid'])->value('title');
  983. }
  984. $total = Db::name('contract_stamp_log')->where($map)->count();
  985. $data = [
  986. 'total' => $total,
  987. 'list' => $lists
  988. ];
  989. return $data;
  990. }
  991. // 打回
  992. public function backStamp($contractId,$sdReason){
  993. $info = Db::name('contract')
  994. ->where('id',$contractId)
  995. ->where('status',1)
  996. ->find();
  997. if(!$info || $info['sd_status'] != 0){
  998. HelpHander::error('无权限打回');
  999. }
  1000. $ret = Db::name('contract')->where('id',$contractId)->update(['sd_status'=>2,'sd_reason'=>$sdReason]);
  1001. if(!$ret){
  1002. HelpHander::error('修改失败');
  1003. }
  1004. return true;
  1005. }
  1006. /**
  1007. * 获取数量
  1008. * @param $transId
  1009. * @return float|string
  1010. */
  1011. public function getCountByTransferred($transId){
  1012. $map[] = ['status','=',1];
  1013. $map[] = ['transferred','=',$transId];
  1014. $count = Db::name('contract')
  1015. ->where($map)
  1016. ->count();
  1017. return $count;
  1018. }
  1019. /**
  1020. * 根据月份获取合同金额
  1021. * @param $month
  1022. * @return mixed
  1023. */
  1024. public function getContractMoneyByMonth($month){
  1025. $map[] = ['status','=',1];
  1026. $nextmonth = date('Y-m',strtotime(" +1 month",strtotime($month.'-01'))).'-01';
  1027. $map[] = ['handle_date','>=',$month.'-01'];
  1028. $map[] = ['handle_date','<',$nextmonth];
  1029. $money = Db::name('contract')
  1030. ->where($map)
  1031. ->sum('money');
  1032. return $money;
  1033. }
  1034. public function appstatis(){
  1035. list($start, $end) = Time::month();
  1036. $start = date('Y-m-d',$start);
  1037. $end = date('Y-m-d',$end);
  1038. $map[] = ['status','=',1];
  1039. $map[] = ['handle_date','>=',$start];
  1040. $map[] = ['handle_date','<=',$end];
  1041. $count1 = Db::name('contract')
  1042. ->where($map)
  1043. ->where('type',0)
  1044. ->count();
  1045. $money1 = Db::name('contract')
  1046. ->where($map)
  1047. ->where('type',0)
  1048. ->sum('total_money');
  1049. $map2[] = ['status','=',1];
  1050. $map2[] = ['transferred','=',1];
  1051. $map2[] = ['transferred_date','>=',$start.' 00:00:00'];
  1052. $map2[] = ['transferred_date','<=',$end.' 23:59:59'];
  1053. $count2 = Db::name('contract')
  1054. ->where($map2)
  1055. ->where('type',0)
  1056. ->count();
  1057. $money2 = Db::name('contract')
  1058. ->where($map)
  1059. ->where('type',0)
  1060. ->sum('total_money');
  1061. return [
  1062. 'count1' => $count1,
  1063. 'count2' => $count2,
  1064. 'money1' => $money1,
  1065. 'money2' => $money2,
  1066. 'url' => "https://oa.dr-ipmc.org.cn/mobile/statistics/contractpay"
  1067. ];
  1068. }
  1069. public function renew(){
  1070. $page = input('page/d',1);
  1071. $size = input('size/d',10);
  1072. $contractSn = input('contractSn','','trim');
  1073. $programSn = input('programSn','','trim');
  1074. $title = input('title','','trim');
  1075. // $type = input('type/d',-1);
  1076. $companyId = input('companyId/d',0);
  1077. $map[] = ['renew','=',1];
  1078. $map[] = ['status','=',1];
  1079. // if($type >= 0){
  1080. // $map[] = ['type','=',$type];
  1081. // }
  1082. if($companyId > 0){
  1083. $map[] = ['company_id','=',$companyId];
  1084. }
  1085. $programId = input('programId/d',0);
  1086. if($programId > 0){
  1087. $map[] = ['program_id','=',$programId];
  1088. }
  1089. if($contractSn){
  1090. $map[] = ['contract_sn','like','%'.$contractSn.'%'];
  1091. }
  1092. if($programSn){
  1093. $map[] = ['program_sn','like','%'.$programSn.'%'];
  1094. }
  1095. if($title){
  1096. $map[] = ['title','like','%'.$title.'%'];
  1097. }
  1098. $startTime = input('startTime','','trim');
  1099. if($startTime){
  1100. $map[] = ['handle_date','>=',$startTime];
  1101. }
  1102. $endTime = input('endTime','','trim');
  1103. if($endTime){
  1104. $map[] = ['handle_date','<=',$endTime];
  1105. }
  1106. $renew = input('renew/d',-1);
  1107. if($renew >= 0){
  1108. $map[] = ['renew','=',$renew];
  1109. }
  1110. $lists = $this
  1111. ->where($map)
  1112. ->page($page,$size)
  1113. ->order('id desc')
  1114. ->select();
  1115. $lists = $lists?$lists->toArray():[];
  1116. foreach ($lists as $k=>$v){
  1117. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  1118. $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title');
  1119. $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title');
  1120. $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  1121. $applyuser = Db::name('apply')
  1122. ->alias('a')
  1123. ->join('user_info u','u.user_id = a.user_id')
  1124. ->where('a.id',$v['apply_id'])
  1125. ->value('u.name');
  1126. $lists[$k]['apply_user'] = $applyuser?$applyuser:'';
  1127. }
  1128. $total = $this->where($map)->count();
  1129. $data = [
  1130. 'total' => $total,
  1131. 'list' => $lists
  1132. ];
  1133. return $data;
  1134. }
  1135. public function renewConfirm($id,$renew,$userId){
  1136. $info = Db::name('contract')->where('id',$id)->where('status',1)->find();
  1137. if(!$info){
  1138. HelpHander::error('合同不存在');
  1139. }
  1140. if($info['renew_confirm'] != 0){
  1141. HelpHander::error('该合同已确认');
  1142. }
  1143. $ret = Db::name('contract')->where('id',$id)->update([
  1144. 'renew' => $renew,
  1145. 'renew_confirm' => 1,
  1146. 'renew_user' => $userId,
  1147. 'renew_time' => date('Y-m-d H:i:s')
  1148. ]);
  1149. if(!$ret){
  1150. HelpHander::error('操作失败');
  1151. }
  1152. return true;
  1153. }
  1154. public function renewExport(){
  1155. $page = input('page/d',1);
  1156. $size = input('size/d',10);
  1157. $contractSn = input('contractSn','','trim');
  1158. $programSn = input('programSn','','trim');
  1159. $title = input('title','','trim');
  1160. // $type = input('type/d',-1);
  1161. $companyId = input('companyId/d',0);
  1162. $map[] = ['renew','=',1];
  1163. $map[] = ['status','=',1];
  1164. // if($type >= 0){
  1165. // $map[] = ['type','=',$type];
  1166. // }
  1167. if($companyId > 0){
  1168. $map[] = ['company_id','=',$companyId];
  1169. }
  1170. if($companyId > 0){
  1171. $map[] = ['company_id','=',$companyId];
  1172. }
  1173. $programId = input('programId/d',0);
  1174. if($programId > 0){
  1175. $map[] = ['program_id','=',$programId];
  1176. }
  1177. if($contractSn){
  1178. $map[] = ['contract_sn','like','%'.$contractSn.'%'];
  1179. }
  1180. if($programSn){
  1181. $map[] = ['program_sn','like','%'.$programSn.'%'];
  1182. }
  1183. if($title){
  1184. $map[] = ['title','like','%'.$title.'%'];
  1185. }
  1186. $startTime = input('startTime','','trim');
  1187. if($startTime){
  1188. $map[] = ['handle_date','>=',$startTime];
  1189. }
  1190. $endTime = input('endTime','','trim');
  1191. if($endTime){
  1192. $map[] = ['handle_date','<=',$endTime];
  1193. }
  1194. $renew = input('renew/d',-1);
  1195. if($renew >= 0){
  1196. $map[] = ['renew','=',$renew];
  1197. }
  1198. $lists = $this
  1199. ->where($map)
  1200. ->page($page,$size)
  1201. ->order('id desc')
  1202. ->select();
  1203. $lists = $lists?$lists->toArray():[];
  1204. foreach ($lists as $k=>$v){
  1205. $lists[$k]['company'] = Db::name('company')->where('id',$v['company_id'])->value('title');
  1206. $lists[$k]['program'] = Db::name('program')->where('id',$v['program_id'])->value('title');
  1207. // $lists[$k]['sdname'] = Db::name('stamp_duty')->where('id',$v['sdid'])->value('title');
  1208. // $lists[$k]['agent'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  1209. $applyuser = Db::name('apply')
  1210. ->alias('a')
  1211. ->join('user_info u','u.user_id = a.user_id')
  1212. ->where('a.id',$v['apply_id'])
  1213. ->value('u.name');
  1214. $lists[$k]['apply_user'] = $applyuser?$applyuser:'';
  1215. $lists[$k]['renew_text'] = $v['renew'] == 1?'是':'否';
  1216. }
  1217. $columns = [
  1218. ["title" => "项目编号","key" => "programSn"],
  1219. ["title" => "合同发起人","key" => "applyUser"],
  1220. ["title" => "合同名称","key" => "title"],
  1221. ["title" => "单位","key" => "company"],
  1222. ["title" => "对方单位","key" => "company2"],
  1223. ["title" => "项目名称","key" => "program"],
  1224. ["title" => "合同金额","key" => "money"],
  1225. ["title" => "办理日期","key" => "handleDate"],
  1226. ["title" => "合同到期日期","key" => "endDate"],
  1227. ["title" => "是否为连续签订合同","key" => "renewText"],
  1228. ];
  1229. $data = [
  1230. 'columns' => $columns,
  1231. 'list' => $lists
  1232. ];
  1233. return $data;
  1234. }
  1235. }