123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace app\common\model;
- use think\Db;
- use think\Exception;
- class Owner extends Base
- {
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- public $table = 'owner';
- protected $validateName = 'Owner';
- public function updates(){
- $data = request()->post();
- $data['org_id'] =cur_org_id();
- $result = validate($this->validateName)->check($data,[],'');
- if(true !== $result){
- $this->error = validate($this->validateName)->getError();
- return false;
- }
- $id = $data['id'];
- unset($data['id']);
- $this->startTrans();
- if($id > 0){
- $data['update_time'] = date('Y-m-d H:i:s');
- $old = $this->where('id',$id)->find()->toArray();
- $res =$this->addOwnerLog($data,$old,$id);
- if(!$res){
- $this->rollback();
- return false;
- }
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- $this->rollback();
- $this->error = '操作失败';
- return false;
- }
- $this->commit();
- return true;
- }
- public function getList(){
- $list =$this
- ->where('org_id',cur_org_id())
- ->where('del',0)
- ->where('enable',1)
- ->select()
- ->toArray();
- foreach ($list as $k=>$v){
- $list[$k]['title'] = $v['name'];
- }
- return $list;
- }
- //增加业主变更信息
- public function addOwnerLog($data,$olddata,$id){
- $this->startTrans();
- $tp = [
- 'name'=>"姓名",
- 'phone'=>"联系电话",
- 'card'=>"身份证",
- 'remark'=>"备注",
- 'money'=>"预存款",
- 'enable'=>"装态",
- 'type'=>"类型",
- ];
- try{
- unset($olddata['id']
- ,$olddata['del']
- ,$olddata['update_time']
- ,$olddata['create_time']
- ,$olddata['import_log_id']
- );
- unset($data['id']
- ,$data['update_time']
- );
- $msg = [];
- foreach ($data as $k=>$v){
- if($v!=$olddata[$k]){
- if($k=='enable'){
- if($v==1){
- $msg[]='状态由禁用更改为启用';
- }else{
- $msg[]='状态由启用更改为禁用';
- }
- }elseif ($k=='type'){
- if($v==1){
- $msg[]='状态由住户更改为住户';
- }else{
- $msg[]='状态由住户更改为租户';
- }
- }else{
- $oo = empty($olddata[$k])?'空':$olddata[$k];
- $msg[]=$tp[$k].'由'.$oo.'更改为'.$v;
- }
- }
- }
- if(empty($msg)){
- $this->commit();
- return true;
- }
- $s = [
- 'org_id'=>$data['org_id'],
- 'house_id'=>0,
- 'owner_id'=>$id,
- 'content'=>implode(',',$msg),
- 'create_time'=>date('y-m-d h:i:s'),
- ];
- $rs = Db::name('house_owner_log')
- ->insert($s);
- if(!$rs) exception('增加变更信息失败2');
- $this->commit();
- return true;
- }catch (Exception $e){
- $this->rollback();
- $this->error = $e->getmessage();
- return false;
- }
- }
- }
|