wugg há 2 anos atrás
pai
commit
6d3c77c389
1 ficheiros alterados com 23 adições e 6 exclusões
  1. 23 6
      app/controller/UserInfo.php

+ 23 - 6
app/controller/UserInfo.php

@@ -171,16 +171,20 @@ class UserInfo extends BaseController
     		'companyCode|公司编号' => 'require',
             ]);
     	 if($validate->check($post)==false) return json_show(1004,$validate->getError());
+    	 $account = Db::name("account")->where(["id"=>$post['account_id'],"is_del"=>0])->findOrEmpty();
+    	 if(empty($account))return json_show(1004,"未找账户到数据");
     	 $acc = new AccountCompany();
     	 $info= $acc->where(["account_id"=>$post['account_id'],"companyCode"=>$post['companyCode'],"is_del"=>0])
 			     ->findOrEmpty();
     	 if($info->isEmpty()){
     	 	return json_show(1004,"未找账户到数据");
     	 }
-    	 if($info['is_main']==1) return json_show(1004,"默认企业不可禁用");
     	 $upda=["status"=>$post['status'],"updatetime"=>date("Y-m-d H:i:s")];
     	 $inser=$acc->update($upda,["account_id"=>$post['account_id'],"companyCode"=>$post['companyCode'],"is_del"=>0]);
-    	 return $inser?json_show(0,"关联企业状态设置成功"):json_show(1005,"关联企业状态设置失败");
+    	 if($inser==false) return json_show(1005,"关联企业状态设置失败");
+    	 $count = $acc->where([["account_id","=",$post['account_id']],["status","<>",$post['status']],["is_del","=",0]])->count();
+    	 if($count==0 && $account['status']!=$post['status'])Db::name("account")->where(["id"=>$post['account_id'],"is_del"=>0])->select($upda);
+    	 return json_show(0,"关联企业状态设置成功");
     }
 		/**
         * @param int $id
@@ -271,16 +275,29 @@ class UserInfo extends BaseController
             ]);
     	 if($validate->check($post)==false) return json_show(1004,$validate->getError());
        $account=Account::where("id",$post['id'])->findOrEmpty();
-        if(empty($account)){
+        if($account->isEmpty()){
             return json_show(1003,"账户不存在");
         }
         if($account['status']==$post['status']){
         	return json_show(1004,"数据已更新");
         }
         $message = $post['status']==1?"启用":"禁用";
-       $result= Db::name("account")->where("id","=",$post['id'])->save(['status'=>$post['status'],"updatetime"=>date("Y-m-d 
-       H:i:s")]);
-        return $result?json_show(0,"账户{$message}成功") : json_show(1005,"账户{$message}失败");
+        Db::startTrans();
+        try {
+        $result= Db::name("account")->where("id","=",$post['id'])->save(['status'=>$post['status'],"updatetime"=>date("Y-m-d H:i:s")]);
+       if($result){
+            $ip=  AccountCompany::update(['status'=>$post['status'],"updatetime"=>date("Y-m-d H:i:s")], ["account_id"=>$post['id'],"is_del"=>0]);
+            if($ip){
+            	Db::commit();
+            	return json_show(0,"账户{$message}成功");
+            }
+       }
+		Db::rollback();
+        return json_show(1005,"账户{$message}失败");
+        }catch (\Exception $e){
+			Db::rollback();
+			return  json_show(1004,$e->getMessage());
+        }
     }
 	//根据业务公司获取用户数据
     public function UserListByCompany()