扎金花算法

it2023-06-09  71

看牌(state = 1) 或 弃牌(state = 2)详细请看附件     public function controlCard(){          if(Request::instance()->isPost()){             $gid     =  input('gid');             $uid     =  input('uid');              $state   =  input('state');             $data    = input();                     if(!$uid || !$state || !$gid){                       $arr = [                      'state'     => 0,                     'message'   => "请求参数错误!"                  ];                 return json($arr);             }             $gameinfo = Db::name('PokerGameInfo')->where(['uid'=>$uid,'gid'=>$gid])->find();              if ($gameinfo && $gameinfo['handcard']) {                   $card = json_decode($gameinfo['handcard'],true);                              if ($state == 1) {                     // 看牌                     $data_game = [                         'id'            => $gameinfo['id'],                         'card_state'    => $state,                          'update_time'   => time()                      ];                 }else{                       // 弃牌                     $data_game = [                         'id'            => $gameinfo['id'],                         'card_state'    => $state,                          'win_lose'      => 2,                          'win_gold'      => $gameinfo['gold'],                          'update_time'   => time()                     ];                                           }                     $res = Db::name('PokerGameInfo')->update($data_game);                    if ($res) {                     $count = Db::name('PokerGameInfo')->where(['gid'=>$gid,'win_lose'=>['neq',2],'card_state'=>['neq',2]])->count();                       // return json($count);                              if ($count == 1 && $state == 2 ) {                                             $win = Db::name('PokerGameInfo')->where(['gid'=>$gid,'win_lose'=>['neq',2],'card_state'=>['neq',2]])->find();                         $result = self::Settlement($gid,$win['uid']);                                         if ($result) {                                  $arr = [                                 'state'     => 2,                                      'card'      => $card,                                     'message'   => "成功!"                             ];                                   }else{                             $arr = [                                 'state'     => 0,                                 'message'   => "结算失败!"                             ];                           }                       }else{                            $arr = [                             'state'     => 1,                             'card'      => $card,                              'message'   => "成功"                         ];                      }                    }else{                     $arr = [                         'state'     => 0,                         'message'   => "失败"                      ];                 }             }else{                 $arr = [                     'state'     => 0,                     'message'   => "非法请求!"                  ];             }          }else{              $arr = [                 'state'     => 0,                 'message'   => "非法请求!"             ];         }          return json($arr);     }
最新回复(0)