House.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\HousePay;
  4. use think\App;
  5. use think\Db;
  6. use think\Exception;
  7. class House extends Auth
  8. {
  9. public function __construct(App $app = null) {
  10. parent::__construct($app);
  11. $this->model= new \app\common\model\House();
  12. $this->table= 'house_view';
  13. }
  14. public function index($import_id=0){
  15. if(request()->isAjax()){
  16. //分页参数
  17. $length = input('rows',10,'intval'); //每页条数
  18. $page = input('page',1,'intval'); //第几页
  19. $start = ($page - 1) * $length; //分页开始位置
  20. //排序
  21. $sortRow = input('sidx','id','trim'); //排序列
  22. $sort = input('sord','desc','trim'); //排序方式
  23. $order = $sortRow.' '.$sort;
  24. $title = input('title','','trim');
  25. if($title){
  26. $map[] = ['title','like','%'.$title.'%'];
  27. }
  28. $name = input('name','','trim');
  29. if($name){
  30. $map[] = ['name','like','%'.$name.'%'];
  31. }
  32. $xq_title = input('xq_title','','trim');
  33. if($xq_title){
  34. $map[] = ['xq_title','like','%'.$xq_title.'%'];
  35. }
  36. $card = input('card','','trim');
  37. if($card){
  38. $map[] = ['card','like','%'.$card.'%'];
  39. }
  40. $enable = input('enable','','trim');
  41. if($enable != ''){
  42. $map[] = ['enable','=',$enable];
  43. }
  44. $cate = input('cate','','trim');
  45. if($cate != ''){
  46. $map[] = ['cate','=',$cate];
  47. }
  48. $c_type = input('c_type','','trim');
  49. if($c_type != ''){
  50. $map[] = ['c_type','=',$c_type];
  51. }
  52. if($import_id >0){
  53. $map[] = ['import_log_id','=',$import_id];
  54. }else{
  55. $map[] = ['del','=',0];
  56. }
  57. $map[] = ['org_id','=',$this->orgId];
  58. $map= empty($map) ? true: $map;
  59. //数据查询
  60. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  61. foreach ($lists as $k=>$v){
  62. $lists[$k]['cate_name'] =$this->model->cate[$v['cate']];
  63. $lists[$k]['is_show_option'] =$import_id>0?false:true;
  64. }
  65. //数据返回
  66. $totalCount = db($this->table)->where($map)->count();
  67. $totalPage = ceil($totalCount/$length);
  68. $result['page'] = $page;
  69. $result['total'] = $totalPage;
  70. $result['records'] = $totalCount;
  71. $result['rows'] = $lists;
  72. return json($result);
  73. }else{
  74. $cType = Db::name('house_c_type')
  75. ->where('del',0)
  76. ->where('enable',1)
  77. ->select();
  78. $this->assign('m_name','资源');
  79. $this->assign('cType',$cType);
  80. $logInfo = [];
  81. if($import_id>0){
  82. $logInfo = Db::name('import_log')
  83. ->where('id',$import_id)
  84. ->find();
  85. }
  86. $this->assign('import_id',$import_id);
  87. $this->assign('importInfo',$logInfo);
  88. return $this->fetch();
  89. }
  90. }
  91. public function showfee(){
  92. if(request()->isAjax()){
  93. //分页参数
  94. $length = input('rows',10,'intval'); //每页条数
  95. $page = input('page',1,'intval'); //第几页
  96. $start = ($page - 1) * $length; //分页开始位置
  97. //排序
  98. $sortRow = input('sidx','id','trim'); //排序列
  99. $sort = input('sord','desc','trim'); //排序方式
  100. $order = $sortRow.' '.$sort;
  101. $title = input('title','','trim');
  102. if($title){
  103. $map[] = ['title','like','%'.$title.'%'];
  104. }
  105. $name = input('name','','trim');
  106. if($name){
  107. $map[] = ['name','like','%'.$name.'%'];
  108. }
  109. $xq_title = input('xq_title','','trim');
  110. if($xq_title){
  111. $map[] = ['xq_title','like','%'.$xq_title.'%'];
  112. }
  113. $card = input('card','','trim');
  114. if($card){
  115. $map[] = ['card','like','%'.$card.'%'];
  116. }
  117. $enable = input('enable','','trim');
  118. if($enable != ''){
  119. $map[] = ['enable','=',$enable];
  120. }
  121. $cate = input('cate','','trim');
  122. if($cate != ''){
  123. $map[] = ['cate','=',$cate];
  124. }
  125. $c_type = input('c_type','','trim');
  126. if($c_type != ''){
  127. $map[] = ['c_type','=',$c_type];
  128. }
  129. $map[] = ['del','=',0];
  130. $map[] = ['org_id','=',$this->orgId];
  131. $map= empty($map) ? true: $map;
  132. //数据查询
  133. $lists = db($this->table)->where($map)->limit($start,$length)->order($order)->select();
  134. foreach ($lists as $k=>$v){
  135. $lists[$k]['cate_name'] =$this->model->cate[$v['cate']];
  136. $start =Db::name('house_pay_log')
  137. ->alias('hpl')
  138. ->join('house_pay hp','hp.id = hpl.pay_id')
  139. ->where('hpl.bus_id',$v['id'])
  140. ->where('hp.status',1)
  141. ->where('hp.del',0)
  142. ->field('hpl.start')
  143. ->order('hpl.start','asc')
  144. ->find();
  145. $start = $start?$start['start']:'';
  146. $end = Db::name('house_pay_log')
  147. ->alias('hpl')
  148. ->join('house_pay hp','hp.id = hpl.pay_id')
  149. ->where('hpl.bus_id',$v['id'])
  150. ->where('hp.status',1)
  151. ->where('hp.del',0)
  152. ->field('hpl.end')
  153. ->order('hpl.end','asc')
  154. ->find();
  155. $end = $end?$end['end']:'';
  156. $money = Db::name('house_pay_log')
  157. ->alias('hpl')
  158. ->join('house_pay hp','hp.id = hpl.pay_id')
  159. ->where('hpl.bus_id',$v['id'])
  160. ->where('hp.status',1)
  161. ->where('hp.del',0)
  162. ->sum('hpl.money');
  163. $lists[$k]['startend'] = '';
  164. if($start && $end){
  165. $lists[$k]['startend'] = $start.' ~ '.$end;
  166. }
  167. $lists[$k]['money'] = 0;
  168. if($money){
  169. $lists[$k]['money'] = $money;
  170. }
  171. }
  172. //数据返回
  173. $totalCount = db($this->table)->where($map)->count();
  174. $totalPage = ceil($totalCount/$length);
  175. $result['page'] = $page;
  176. $result['total'] = $totalPage;
  177. $result['records'] = $totalCount;
  178. $result['rows'] = $lists;
  179. return json($result);
  180. }else{
  181. $cType = Db::name('house_c_type')
  182. ->where('del',0)
  183. ->where('enable',1)
  184. ->select();
  185. $this->assign('m_name','综合收费');
  186. $this->assign('cType',$cType);
  187. return $this->fetch();
  188. }
  189. }
  190. public function fee($id){
  191. $refer = isset($_SERVER['http_referer'])?$_SERVER['http_referer']:'';
  192. $lists = [];
  193. // 获取房产及房产下的储藏室和停车位
  194. $house = Db::name('house')->where(['id'=>$id,'enable'=>1,'del'=>0])->find();
  195. if(!$house){
  196. $this->error('资源不存在',$refer);
  197. }
  198. if($house['owner_id'] <= 0){
  199. $this->error('资源未绑定业主',$refer);
  200. }
  201. $fees = (new \app\common\model\HouseFee())->getTree(cur_org_id());;
  202. $fees = $fees?json_decode(json_encode($fees),true):[];
  203. $lists = $this->model->getlistbyowner($house['owner_id'],$house['area_id']);
  204. foreach ($lists as $k=>$v){
  205. $arrs = [];
  206. foreach ($fees as $kk=>$vv){
  207. if($vv['type'] == $v['type']){
  208. $children = $vv['child']?$vv['child']:[];
  209. foreach ($children as $kkk=>$vvv){
  210. $vvv['parent_title'] = $vv['title'];
  211. $vvv['end'] = $vvv['start'] = '';
  212. $info = Db::name('house_pay_log')
  213. ->alias('pl')
  214. ->join('house_pay p','p.id = pl.pay_id')
  215. ->where('pl.bus_id',$v['id'])
  216. ->where('pl.fee_id',$vvv['id'])
  217. ->order('pl.end','desc')
  218. ->field('pl.*')
  219. ->find();
  220. if($info){
  221. $vvv['end'] = $info['end'];
  222. $vvv['start'] = $info['start'];
  223. }
  224. $minfo =Db::name('house_pay_log')
  225. ->alias('pl')
  226. ->join('house_pay p','p.id = pl.pay_id')
  227. ->where('pl.bus_id',$v['id'])
  228. ->where('pl.fee_id',$vvv['id'])
  229. ->sum('pl.money');
  230. $vvv['tmoney'] = 0;
  231. if($minfo){
  232. $vvv['tmoney'] = $minfo;
  233. }
  234. $arrs[] = $vvv;
  235. }
  236. }
  237. }
  238. $lists[$k]['fee'] = $arrs;
  239. }
  240. $owner =Db::name('owner')
  241. ->where('id',$house['owner_id'])
  242. ->find();
  243. $this->assign('lists',$lists);
  244. $this->assign('houseId',$id);
  245. $this->assign('owner',$owner);
  246. return $this->fetch();
  247. }
  248. //保存收费记录
  249. public function feeSave(){
  250. $houseId = input('houseId');
  251. $lastDate = input('lastDate');
  252. $order = input('order');
  253. if(!$houseId){
  254. $this->error('参数错误');
  255. }
  256. if(!$lastDate){
  257. $this->error('请选择最晚缴费日期');
  258. }
  259. if(!$order){
  260. $this->error('请选择收费科目');
  261. }
  262. $order = json_decode($order,true);
  263. if(empty($order)){
  264. $this->error('请选择收费科目');
  265. }
  266. foreach ($order as $k=>$v){
  267. if($v['total_price'] <= 0){
  268. $this->error('收费金额必须大于0');
  269. }
  270. $fee = Db::name('house_fee')->where('id',$v['fee_id'])->find();
  271. if(!$fee||$fee['del']==1||$fee['enable'] == 0){
  272. $this->error('收费科目不存在');
  273. }
  274. if($fee['cycle'] == 1){ // 按周期
  275. if(!$v['start']||!$v['end']){
  276. $this->error('未选择收费周期');
  277. }
  278. $ret = Db::name('house_pay_log')
  279. ->alias('hpl')
  280. ->join('house_pay hp','hp.id = hpl.pay_id')
  281. ->where('hp.del',0)
  282. ->where('hp.status','<>',3)
  283. ->where('hpl.bus_id',$v['id'])
  284. ->where('hpl.fee_id',$v['fee_id'])
  285. ->where('hpl.start','<=',$v['end'])
  286. ->where('hpl.end','>=',$v['start'])
  287. ->field('hpl.*')
  288. ->find();
  289. if($ret){
  290. $this->error('请勿重复收费');
  291. }
  292. }
  293. }
  294. $ret = (new HousePay())->createOrder($houseId,$lastDate,$order,$this->userId,cur_org_id());
  295. if(!$ret){
  296. $this->error((new HousePay())->getError());
  297. }else{
  298. $data['info'] = '操作成功';
  299. $data['status'] = 1;
  300. $data['id'] = $ret;
  301. $this->success('','',$data);
  302. }
  303. }
  304. /**
  305. * 新增/编辑
  306. */
  307. public function add($id=0){
  308. if(request()->isPost()){
  309. $res = $this->model->updates();
  310. if($res){
  311. $this->success('操作成功',url('index'));
  312. }else{
  313. $this->error($this->model->getError());
  314. }
  315. }else{
  316. if($id){
  317. $info =db($this->table)->where('id',$id)->find();
  318. $info['c_type_list'] = $this->model->getCType($info['c_type']);
  319. $this->assign('info',$info);
  320. }
  321. $area = (new \app\common\model\HouseAreas())->getList();
  322. $owner = (new \app\common\model\Owner())->getList();
  323. $cate = $this->model->getCate();
  324. $this->assign('area',$area);
  325. $this->assign('owner',$owner);
  326. $this->assign('cate',$cate);
  327. return $this->fetch();
  328. }
  329. }
  330. /**
  331. * 删除记录
  332. * @param int $id
  333. */
  334. public function del($id=0){
  335. if(!$id){
  336. $this->error('参数错误');
  337. }
  338. $res = db('house')->where('id',$id)->setField('del',1);
  339. if($res){
  340. $this->success('删除成功');
  341. }else{
  342. $this->error('删除失败');
  343. }
  344. }
  345. /**
  346. * 改变字段值
  347. * @param int $fv
  348. * @param string $fn
  349. * @param int $fv
  350. */
  351. public function changeField($id=0,$fn='',$fv=0){
  352. if(!$fn||!$id){
  353. $this->error('参数错误');
  354. }
  355. $res = db('house')->where('id',$id)->setField($fn,$fv);
  356. if($res){
  357. $this->success('操作成功');
  358. }else{
  359. $this->error('操作失败');
  360. }
  361. }
  362. public function getType(){
  363. $catId = input('id');
  364. $list = Db::name('house_c_type')
  365. ->where('cate',$catId)
  366. ->where('del',0)
  367. ->where('enable',1)
  368. ->select();
  369. $this->success('','',$list);
  370. }
  371. // excel
  372. public function import(){
  373. return $this->fetch();
  374. }
  375. /**
  376. * 下载报修地点模板
  377. */
  378. public function downloadtem(){
  379. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  380. set_time_limit(0);
  381. ini_set("memory_limit","512M");
  382. $fileName = '资源模板.xlsx';
  383. $excel = new \PHPExcel();
  384. $sheet = $excel->setActiveSheetIndex(0);
  385. $arr = array('A','B','C','D','E','F','G','H','I','J');
  386. foreach($arr as $k=>$v){
  387. $excel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(true);//换行
  388. $excel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
  389. $excel->getActiveSheet()->getColumnDimension($v)->setWidth(18);
  390. }
  391. $sheet->setCellValueByColumnAndRow(0,1,'小区名称');
  392. $sheet->setCellValueByColumnAndRow(1,1,'名称');
  393. $sheet->setCellValueByColumnAndRow(2,1,'面积');
  394. $sheet->setCellValueByColumnAndRow(3,1,'资源属性(住房/商铺/营业房/储藏室/停车位)');
  395. $sheet->setCellValueByColumnAndRow(4,1,'类型');
  396. $sheet->setCellValueByColumnAndRow(5,1,'业主姓名');
  397. $sheet->setCellValueByColumnAndRow(6,1,'业主电话');
  398. $sheet->setCellValueByColumnAndRow(7,1,'业主身份证');
  399. $sheet->setCellValueByColumnAndRow(8,1,'业主预存款');
  400. $sheet->setCellValueByColumnAndRow(9,1,'业主类型(住户/租户)');
  401. ob_end_clean();//清除缓冲区,避免乱码
  402. header('Content-Type: application/vnd.ms-excel');
  403. header('Content-Disposition: attachment;filename="'.$fileName.'"');
  404. header('Cache-Control: max-age=0');
  405. $objWriter = \PHPExcel_IOFactory::createWriter($excel, 'Excel2007');
  406. $objWriter->save('php://output'); //文件通过浏览器下载
  407. }
  408. /**
  409. * 导入
  410. */
  411. public function importexcel(){
  412. include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
  413. $userId = $this->userId;
  414. $orgId = cur_org_id();
  415. set_time_limit(0);
  416. ini_set("memory_limit", -1);
  417. ob_flush();//清空缓存
  418. flush();//刷新缓存
  419. $file = request()->file('file');
  420. if(!$file){
  421. exit('请上传文件');
  422. }
  423. // 移动到框架应用根目录/uploads/ 目录下
  424. $info = $file->validate([ 'size'=>config('app.max_upload_file_size') ])
  425. ->move(env('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads'. DIRECTORY_SEPARATOR . 'files');
  426. if(!$info){
  427. exit('上传文件失败');
  428. }
  429. $img = env('root_path').'/public/uploads/files/' . $info->getSaveName();
  430. $finfo = $info->getInfo();
  431. $fileExt = explode('.',$finfo['name']);
  432. $finfo['file_name'] = $finfo['name'];
  433. $filepath = str_replace('\\', '/', $img);
  434. $file_type = $fileExt[count($fileExt)-1];
  435. if($file_type == 'xls'){
  436. $objReader = \PHPExcel_IOFactory::createReader('Excel5');
  437. }else{
  438. $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
  439. }
  440. $imData = [
  441. 'org_id'=>$orgId,
  442. 'title'=>$finfo['file_name'],
  443. 'type'=>1,
  444. 'create_time'=>getTime(),
  445. ];
  446. $importId =Db::name('import_log')->insertGetId($imData);
  447. $objPHPExcel = $objReader->load($filepath,$encode='utf-8');
  448. $table = array(0,1,2,3,4,5,6,7,8,9);
  449. $allobjWorksheets = $objPHPExcel->getAllSheets();
  450. try{
  451. @unlink($filepath);
  452. foreach($allobjWorksheets as $key=>$objWorksheet){
  453. $highestRow = $objWorksheet->getHighestRow();
  454. $success = 0;
  455. $error = 0;
  456. $errorMsg = [];
  457. for ($row = 2; $row <= $highestRow; ++$row) {
  458. $oneData = array();
  459. for ($col = 0; $col < count($table); ++$col) {
  460. $cell = $objWorksheet->getCellByColumnAndRow($col, $row);
  461. $value = (string)$cell->getValue();
  462. $oneData[$table[$col]]= $value;
  463. }
  464. if(!$oneData[0]||!$oneData[1]||!$oneData[3]){
  465. $msg = "第".$row."行,数据存在空值,未导入";
  466. echo "<font color=\"red\">".$msg."</font><br />";
  467. $error++;
  468. $errorMsg[] = $msg;
  469. continue;
  470. }
  471. if(!in_array($oneData[3],$this->model->cate)){
  472. $msg = "第".$row."行,资源属性错误,未导入";
  473. echo "<font color=\"red\">".$msg."</font><br />";
  474. $error++;
  475. $errorMsg[] = $msg;
  476. continue;
  477. }
  478. $c = array_reverse($this->model->cate1);
  479. if(in_array($c[$oneData[3]],[1,2,3,4])){
  480. if(!is_numeric($oneData[2]) || !$oneData[2]){
  481. $msg = "第".$row."行,面积字段数据格式错误(只能为纯数字),未导入";
  482. echo "<font color=\"red\">".$msg."</font><br />";
  483. $error++;
  484. $errorMsg[] = $msg;
  485. continue;
  486. }
  487. }else{
  488. $oneData[2] = '0.00';
  489. }
  490. if(in_array($c[$oneData[3]],[1,2,3])){
  491. $type = 1;
  492. }elseif ($c[$oneData[3]]==4){
  493. $type = 2;
  494. }elseif ($c[$oneData[3]]==5){
  495. $type = 3;
  496. }
  497. $pid = $this->getPH($oneData[0]);
  498. $ret = Db::name('house')
  499. ->where('org_id',$orgId)
  500. ->where('title',$oneData[1])
  501. ->where('area_id',$pid)
  502. ->where('del',0)
  503. ->find();
  504. if($ret){
  505. $msg = "第".$row."行,数据已存在,未导入";
  506. echo "<font color=\"red\">".$msg."</font><br />";
  507. $error++;
  508. $errorMsg[] = $msg;
  509. continue;
  510. }
  511. if(!$oneData[5] || !$oneData[6] ||!$oneData[7]){
  512. $owId = 0;
  513. }else{
  514. $oType = 1;
  515. if($oneData[9]){
  516. if(in_array($oneData[9],['住户','租户'])){
  517. $oType = $oneData[9]=='住户'?1:2;
  518. }
  519. }
  520. $oMoney = '0.00';
  521. if($oneData[8]){
  522. if(is_numeric($oneData[8])){
  523. $oMoney = $oneData[8];
  524. }
  525. }
  526. $owner = Db::name('owner')
  527. ->where('card',$oneData[7])
  528. ->where('del',0)
  529. ->where('org_id',$orgId)
  530. ->find();
  531. if ($owner){
  532. $owId = $owner['id'];
  533. }else{
  534. $oData = [
  535. 'org_id'=>$orgId,
  536. 'name'=>$oneData[5],
  537. 'phone'=>$oneData[6],
  538. 'card'=>$oneData[7],
  539. 'money'=>$oMoney,
  540. 'type'=>$oType,
  541. 'import_log_id'=>$importId,
  542. 'create_time'=>getTime(),
  543. ];
  544. $owId = Db::name('owner')->insertGetId($oData);
  545. if(!$owId){
  546. $msg = "第".$row."行,导入业主失败";
  547. echo "<font color=\"red\">".$msg."</font><br />";
  548. $error++;
  549. $errorMsg[] = $msg;
  550. continue;
  551. }
  552. }
  553. }
  554. $iii = 0;
  555. if($oneData[4]){
  556. $tId = Db::name('house_c_type')
  557. ->where('name',$oneData[4])
  558. ->where('org_id',$orgId)
  559. ->where('cate',$c[$oneData[3]])
  560. ->find();
  561. if($tId){
  562. $iii = $tId['id'];
  563. }
  564. }
  565. $data = [
  566. 'org_id'=>$orgId,
  567. 'area_id'=>$pid,
  568. 'owner_id'=>$owId,
  569. 'type'=>$type,
  570. 'cate'=>$c[$oneData[3]],
  571. 'title'=>$oneData[1],
  572. 'area'=>$oneData[2],
  573. 'c_type'=>$iii,
  574. 'create_time'=>getTime(),
  575. 'enable'=>1,
  576. 'import_log_id'=>$importId,
  577. ];
  578. $Id = Db::name('house')->insertGetId($data);
  579. if($owId>0){
  580. $this->model->addLog($Id);
  581. }
  582. if(!$Id){
  583. $msg = "第".$row."行,导入失败";
  584. echo "<font color=\"red\">".$msg."</font><br />";
  585. $error++;
  586. $errorMsg[] = $msg;
  587. continue;
  588. }
  589. $success++;
  590. }
  591. Db::name('import_log')->where('id',$importId)
  592. ->update(
  593. [
  594. 'success'=>$success,
  595. 'error'=>$error,
  596. 'error_msg'=>json_encode($errorMsg),
  597. ]
  598. );
  599. }
  600. echo "<font color=\"green\">导入完成</font><br />";
  601. }catch (Exception $e){
  602. echo $e->getMessage();
  603. echo "<font color=\"red\">数据异常,已停止导入</font><br />";
  604. }
  605. }
  606. public function getPH($name){
  607. $orgId = cur_org_id();
  608. $res = Db::name('house_areas')
  609. ->where('org_id',$orgId)
  610. ->where('title',$name)
  611. ->where('pid',0)
  612. ->where('type',1)
  613. ->find();
  614. if(empty($res)){
  615. $data = [
  616. 'org_id'=>$orgId,
  617. 'title'=>$name,
  618. 'type'=>1,
  619. ];
  620. $id = Db::name('house_areas')->insertGetId($data);
  621. }else{
  622. $id = $res['id'];
  623. }
  624. return $id;
  625. }
  626. }