0
0

Owner.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use think\Exception;
  5. class Owner extends Base
  6. {
  7. protected $createTime = 'create_time';
  8. protected $updateTime = 'update_time';
  9. public $table = 'owner';
  10. protected $validateName = 'Owner';
  11. public function updates(){
  12. $data = request()->post();
  13. $data['org_id'] =cur_org_id();
  14. $result = validate($this->validateName)->check($data,[],'');
  15. if(true !== $result){
  16. $this->error = validate($this->validateName)->getError();
  17. return false;
  18. }
  19. $id = $data['id'];
  20. unset($data['id']);
  21. $this->startTrans();
  22. if($id > 0){
  23. $data['update_time'] = date('Y-m-d H:i:s');
  24. $old = $this->where('id',$id)->find()->toArray();
  25. $res =$this->addOwnerLog($data,$old,$id);
  26. if(!$res){
  27. $this->rollback();
  28. return false;
  29. }
  30. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  31. }else{
  32. $data['create_time'] = date('Y-m-d H:i:s');
  33. $ret = $this->allowField(true)->save($data);
  34. }
  35. if(!$ret){
  36. $this->rollback();
  37. $this->error = '操作失败';
  38. return false;
  39. }
  40. $this->commit();
  41. return true;
  42. }
  43. public function getList(){
  44. $list =$this
  45. ->where('org_id',cur_org_id())
  46. ->where('del',0)
  47. ->where('enable',1)
  48. ->select()
  49. ->toArray();
  50. foreach ($list as $k=>$v){
  51. $list[$k]['title'] = $v['name'];
  52. }
  53. return $list;
  54. }
  55. //增加业主变更信息
  56. public function addOwnerLog($data,$olddata,$id){
  57. $this->startTrans();
  58. $tp = [
  59. 'name'=>"姓名",
  60. 'phone'=>"联系电话",
  61. 'card'=>"身份证",
  62. 'remark'=>"备注",
  63. 'money'=>"预存款",
  64. 'enable'=>"装态",
  65. 'type'=>"类型",
  66. ];
  67. try{
  68. unset($olddata['id']
  69. ,$olddata['del']
  70. ,$olddata['update_time']
  71. ,$olddata['create_time']
  72. ,$olddata['import_log_id']
  73. );
  74. unset($data['id']
  75. ,$data['update_time']
  76. );
  77. $msg = [];
  78. foreach ($data as $k=>$v){
  79. if($v!=$olddata[$k]){
  80. if($k=='enable'){
  81. if($v==1){
  82. $msg[]='状态由禁用更改为启用';
  83. }else{
  84. $msg[]='状态由启用更改为禁用';
  85. }
  86. }elseif ($k=='type'){
  87. if($v==1){
  88. $msg[]='状态由住户更改为住户';
  89. }else{
  90. $msg[]='状态由住户更改为租户';
  91. }
  92. }else{
  93. $oo = empty($olddata[$k])?'空':$olddata[$k];
  94. $msg[]=$tp[$k].'由'.$oo.'更改为'.$v;
  95. }
  96. }
  97. }
  98. if(empty($msg)){
  99. $this->commit();
  100. return true;
  101. }
  102. $s = [
  103. 'org_id'=>$data['org_id'],
  104. 'house_id'=>0,
  105. 'owner_id'=>$id,
  106. 'content'=>implode(',',$msg),
  107. 'create_time'=>date('y-m-d h:i:s'),
  108. ];
  109. $rs = Db::name('house_owner_log')
  110. ->insert($s);
  111. if(!$rs) exception('增加变更信息失败2');
  112. $this->commit();
  113. return true;
  114. }catch (Exception $e){
  115. $this->rollback();
  116. $this->error = $e->getmessage();
  117. return false;
  118. }
  119. }
  120. }