$params['name'] ]; $gameIds = [$params['id']]; if (isset($params['relation_game_id']) && $params['relation_game_id']) { $gameIds[] = $params['relation_game_id']; } $conditions['_logic'] = 'or'; $conditions['android_game_id'] = ['in', $gameIds]; $conditions['ios_game_id'] = ['in', $gameIds]; if ($params['sdk_version'] == 1) { $data['android_game_id'] = $params['id']; } elseif ($params['sdk_version'] == 2) { $data['ios_game_id'] = $params['id']; } $baseGame = M('base_game', 'tab_')->where($conditions)->find(); if (!$baseGame) { return M('base_game', 'tab_')->add($data); } else { return M('base_game', 'tab_')->where(['id' => $baseGame['id']])->save($data); } } public function isUniqueCodeExists($uniqueCode, $exceptId = 0, $exceptType = 'id') { $map = ['unique_code' => $uniqueCode]; if ($exceptId > 0) { $map[$exceptType] = ['neq', $exceptId]; } $count = M('game', 'tab_')->where($map)->count(); if ($count > 0) { return true; } return false; } }